Playmaker Forum
PlayMaker News => General Discussion => Topic started by: zeeawk on September 27, 2017, 10:12:25 AM
-
I need to update the Collider Mask of the Platform 2D. I need to remove one of the layers and then re-add it. Any thoughts of how to do this?
-
HI,
Can you give some more information i am not sure what you mean?
You need to change this on an action or on a component?
-
https://docs.unity3d.com/Manual/class-PlatformEffector2D.html
I have this component on a platform object.
I want to dynamically alter the Collider mask, removing certain layers from it then adding them back
-
I went ahead and solved this myself.
https://gist.github.com/willt/80389584e207398f1209d9fcb699ef8f
https://gist.github.com/willt/c9f2c2326e64c45895b357e2a6ce46b9
Not sure I followed the right naming conventions but I could clean up and if I could add it to the eco system that would be cool.
-
Hi,
You beat me to it :P
Nice actions!
But OnUpdate is usually used if there is an 'every frame' option
Try looking to other actions how they are setup :)
I checked them out and i have rebuild it into a single action, if you like it i can add it to the ecosystem.
// (c) Copyright HutongGames, LLC 2010-2017. All rights reserved.
/*--- __ECO__ __PLAYMAKER__ __ACTION__ ---*/
//author : zeeawk
using UnityEngine;
namespace HutongGames.PlayMaker.Actions
{
[ActionCategory(ActionCategory.Physics2D)]
[Tooltip("Adds a collider mask to a Platform Effector 2D")]
public class SetPlatformEffector2DColliderMask : FsmStateAction
{
public enum Operation
{
Enable,
Disable
}
[RequiredField]
[CheckForComponent(typeof(PlatformEffector2D))]
[Tooltip("The GameObject with the PlatformEffector2D attached")]
public FsmOwnerDefault gameObject;
[UIHint(UIHint.Layer)]
[Tooltip("The collision layer to add or remove")]
public int collisionLayer;
[Tooltip("Add or Remove the collision layer")]
public Operation operation = Operation.Enable;
[Tooltip("Reset when exiting this state.")]
public FsmBool resetOnExit;
PlatformEffector2D pe;
public override void Reset()
{
gameObject = null;
collisionLayer = 0;
operation = Operation.Enable;
resetOnExit = false;
}
public override void OnEnter()
{
GameObject go = Fsm.GetOwnerDefaultTarget(gameObject);
if (go == null) return;
pe = go.GetComponent<PlatformEffector2D>();
if (pe != null)
{
switch (operation)
{
case Operation.Enable:
Enable();
break;
case Operation.Disable:
Disable();
break;
}
Finish();
}
}
public override void OnExit()
{
if (pe != null)
{
switch (operation)
{
case Operation.Enable:
pe.colliderMask ^= (1 << collisionLayer);
break;
case Operation.Disable:
Enable();
break;
}
}
}
void Enable()
{
pe.colliderMask |= (1 << collisionLayer);
}
void Disable()
{
pe.colliderMask ^= (1 << collisionLayer);
}
}
}
Instead of the Enum i could use an fsmbool (Named 'Enable') but i think this look better :)
If your are planning to make more actions and want to submit to the Ecosytem, let me know so i can contact Jean to give you access or you can contact jean (http://hutonggames.com/playmakerforum/index.php?action=profile;u=33) directly.
-
Very cool. I didn't even think about combining them.
Yes please add to the ecosystem. I'm definitely going to be making more actions. Being able to add to the ecosystem would be great.
-
Hi,
Added to the Ecosystem.
-
Thanks! I submitted a pull request to fix a bug.
Also I think its in the wrong category.
-
Hi,
Oops, i dropped it in the wrong folder indeed.
i have accepted the changes and moved it to its proper folder.
Thx
-
Hi,
thanks guys, appreciate the contribution!
Bye,
Jean