playMaker

Author Topic: Platform Effector 2D [SOLVED]  (Read 5131 times)

zeeawk

  • Playmaker Newbie
  • *
  • Posts: 12
Platform Effector 2D [SOLVED]
« 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?
« Last Edit: September 28, 2017, 04:01:03 AM by djaydino »

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7614
    • jinxtergames
Re: Platform Effector 2D
« Reply #1 on: September 27, 2017, 12:56:32 PM »
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?

zeeawk

  • Playmaker Newbie
  • *
  • Posts: 12
Re: Platform Effector 2D
« Reply #2 on: September 27, 2017, 08:44:47 PM »
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

zeeawk

  • Playmaker Newbie
  • *
  • Posts: 12
Re: Platform Effector 2D
« Reply #3 on: September 27, 2017, 11:01:58 PM »
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.

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7614
    • jinxtergames
Re: Platform Effector 2D
« Reply #4 on: September 28, 2017, 01:16:18 AM »
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.

Code: [Select]
// (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 directly.


zeeawk

  • Playmaker Newbie
  • *
  • Posts: 12
Re: Platform Effector 2D
« Reply #5 on: September 28, 2017, 01:40:39 AM »
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.

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7614
    • jinxtergames
Re: Platform Effector 2D [SOLVED]
« Reply #6 on: September 28, 2017, 04:34:24 AM »
Hi,
Added to the Ecosystem.

zeeawk

  • Playmaker Newbie
  • *
  • Posts: 12
Re: Platform Effector 2D [SOLVED]
« Reply #7 on: September 28, 2017, 11:56:18 AM »
Thanks! I submitted a pull request to fix a bug.
Also I think its in the wrong category.

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7614
    • jinxtergames
Re: Platform Effector 2D [SOLVED]
« Reply #8 on: September 29, 2017, 02:36:40 AM »
Hi,
Oops, i dropped it in the wrong folder indeed.
i have accepted the changes and moved it to its proper folder.
Thx


jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Platform Effector 2D [SOLVED]
« Reply #9 on: September 29, 2017, 02:51:28 AM »
Hi,

 thanks guys, appreciate the contribution!

 Bye,

 Jean