|
Post by Ash Blue on Apr 27, 2017 5:38:30 GMT
For my game we've decided to use the room component and manually control transitions to new rooms via triggers (a lot of them overlap for us). I wrote a simple PlayMaker action that will allow you to easily swap out the current room manually. Hopefully this is useful for someone.
using Com.LuisPedroFonseca.ProCamera2D;
namespace HutongGames.PlayMaker.Actions.ProCamera2D { [ActionCategory(ActionCategory.Camera)] [Tooltip("Set Pro Camera 2D's current room")] public class EnterRoom : FsmStateAction { private ProCamera2DRooms _rooms;
[Tooltip("Set the current room by index"), RequiredField] public FsmInt roomIndex;
[Tooltip("Set the current room by ID. Note that using ID will override index")] public FsmString roomId;
public override void Reset () { roomIndex = 0; roomId = null; }
public override void OnEnter () { var cam = ProCamera2D.Instance; if (cam == null) { Finish(); return; }
_rooms = cam.GetComponent<ProCamera2DRooms>(); if (_rooms == null) { Finish(); return; }
SetRoom(); Finish(); }
void SetRoom () { if (!roomId.IsNone && !string.IsNullOrEmpty(roomId.Value)) { _rooms.EnterRoom(roomId.Value); } else { _rooms.EnterRoom(roomIndex.Value); } } } }
|
|
|
Post by Luís Pedro Fonseca on Apr 27, 2017 10:20:30 GMT
Thanks for sharing Ash! Would you mind if I included this on the package?
|
|
|
Post by Ash Blue on Apr 28, 2017 2:25:42 GMT
That would be awesome! Feel free to include it. Felt like a missing action for working with rooms.
PS A static action category with the string "Pro Camera 2D" would probably be a good idea (there are a lot of pre-bundled PlayMaker camera actions). An abstract base class for all "Pro Camera 2D" actions might be helpful too. Never know when you might need to hook all the actions for something as the library grows. Example "FsmStateActionProCamera2dBase." I've been base classing a lot of my action libraries in PlayMaker and it makes writing unit tests and upgrading functionality down the road super easy (who wants to maintain a giant mess of unconnected code type of a deal).
Also, on a side note about rooms. Would be nice if the rooms module allowed the `TransitionInstanlyOnStart` bool logic to be called publicly at any time. A method such as `SnapToRoom(room)` could be nice to prevent a transition or `EnterRoom(room, transition = true)` with a transition hook.
Snippet below of how I'm hijacking the camera currently to force set a target and room for various reasons. My character gets attached out of sync with the module setup. So I have to forcefully inject the position and room after scene load.
// Triggers after the room module has run its setup var startingRoom = rooms.ComputeCurrentRoom(StatsPlayer.current.transform.position); if (startingRoom != -1) { // Hack since the field we need is private SetPrivateField(rooms, "_currentRoomIndex", startingRoom);
var tempRoom = new Room(rooms.Rooms[startingRoom]); tempRoom.TransitionDuration = 0;
// Hack since the method we need is private var type = typeof(ProCamera2DRooms); var methodInfo = type.GetMethod("TransitionToRoom", BindingFlags.NonPublic | BindingFlags.Instance); if (methodInfo != null) { methodInfo.Invoke(rooms, new object[]{tempRoom}); } }
Might be a better way to accomplish this. But it felt like the methods I needed were hidden.
PS The rooms module is so freaking powerful. It solves a lot of modern platformer camera issues.
|
|
|
Post by Luís Pedro Fonseca on May 2, 2017 16:21:25 GMT
Hi Ash, just to let you know that these suggestions will be part of the next release. All playmaker actions now inherit from an abstract class. It's currently empty except for setting up the category, but it could be useful in the future. Also, the EnterRoom method now has an extra parameter (useTransition = true) which should give you the results you're looking for. Again, thank you so much for all the suggestions!
|
|