playMaker

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - fimmfingur

Pages: [1]
1
Share New Actions / Re: 2d toolkit custom actions: Some minor changes.
« on: October 26, 2012, 03:23:18 AM »
Thank you for the positive feedback Jeanfabre.
The actions are now in separate threads :)

2
Share New Actions / 2D Toolkit Custom FlipX Action
« on: October 26, 2012, 03:18:12 AM »
Just made a new one. This is for the 2D ToolKit FlipX() function. I'm sure most of you already have a better solution, but I didn't find one on this forum so I just made my own.

I posted a picture about how to use it.

1) First I set a variable
2) I named mine Flip because that's the only function it will be used for.
3) I set the value of the int to 0. 0 being the "original" flip direction. on this animation, its left.
4) My states look like this.
5) My right states has these action.
6) First i selected the variable the action has to check
7) Here is a basic If statement and IF the flip variable is 0 (which is left for me) it does the .FlipX() to flip the animation.
8) If the character was flipped, the action sets the flip variable to 1 (1 being right for me)
9) Next is the left side
10) Flip variable is selected like before
11) and in this if the flip var is set to 1 the action will make the animation flip to the other side
12) And now if the animation was flipped the action will set the Flip var to 0 again.

This works like a charm for me. And hopefully someone else is looking for something like this :)

Code: [Select]
// (c) Copyright HutongGames, LLC 2010-2012. All rights reserved.

using UnityEngine;

namespace HutongGames.PlayMaker.Actions
{
    [ActionCategory("2D ToolKit/Sprite")]
    [Tooltip("Flips the sprite animation. \nNOTE: The Game Object must have a tk2dAnimatedSprite attached.")]
    public class Tk2dFlipX : FsmStateAction
    {
        [RequiredField]
        [Tooltip("The Game Object to work with. NOTE: The Game Object must have a tk2dAnimatedSprite component attached.")]
        [CheckForComponent(typeof(tk2dAnimatedSprite))]
        public FsmOwnerDefault gameObject;

        [RequiredField]
        [UIHint(UIHint.Variable)]
        public FsmInt intFlipVariable;
        public FsmInt ifFlipVarIs;
        public FsmInt setInt;

        tk2dAnimatedSprite anim;

        public override void Reset()
        {
            gameObject = null;
            intFlipVariable = null;
            ifFlipVarIs = null;
            setInt = null;
        }

        public override void OnEnter()
        {
            GameObject go = Fsm.GetOwnerDefaultTarget(gameObject);
            anim = go.GetComponent<tk2dAnimatedSprite>();
            FlipSprite();
        }

        void FlipSprite()
        {
            if (intFlipVariable.Value == ifFlipVarIs.Value)
            {
                anim.FlipX();
                intFlipVariable.Value = setInt.Value;
                return;
            }
            else
            {
                return;
            }
        }
    }

}

3
Share New Actions / 2D Toolkit Custom Play Animation Action
« on: October 26, 2012, 03:16:03 AM »
I made a small change to the Action that comes with the 2DTK download from here
https://hutonggames.fogbugz.com/default.asp?W717

All i did was change the PlayAnimation action so that I didn't to add a StopAnimation action before every play animation action.

Code: [Select]
// (c) Copyright HutongGames, LLC 2010-2012. All rights reserved.

using UnityEngine;

namespace HutongGames.PlayMaker.Actions
{
    [ActionCategory("2D ToolKit/Sprite")]
    [Tooltip("Plays a sprite animation. \nNOTE: The Game Object must have a tk2dAnimatedSprite attached.")]
    public class Tk2dPlayNewAnimation : FsmStateAction
    {
        [RequiredField]
        [Tooltip("The Game Object to work with. NOTE: The Game Object must have a tk2dAnimatedSprite component attached.")]
        [CheckForComponent(typeof(tk2dAnimatedSprite))]
        public FsmOwnerDefault gameObject;

        [RequiredField]
        [Tooltip("The clip name to play")]
        public FsmString clipName;


        private tk2dAnimatedSprite _sprite;

        private void _getSprite()
        {
            GameObject go = Fsm.GetOwnerDefaultTarget(gameObject);
            if (go == null)
            {
                return;
            }

            _sprite = go.GetComponent<tk2dAnimatedSprite>();
        }


        public override void Reset()
        {
            gameObject = null;
            clipName = null;
        }

        public override void OnEnter()
        {
            _getSprite();

            DoPlayAnimation();
        }

        void DoPlayAnimation()
        {
            if (_sprite == null)
            {
                LogWarning("Missing tk2dAnimatedSprite component");
                return;
            }

                _sprite.Play(clipName.Value);
           
        }
    }

}

4
Share New Actions / AxisRawEvent Action
« on: October 26, 2012, 03:09:39 AM »
I'm using the AxisRawEvent for my 2D Toolkit animations. With the AxisEvent my character kept playing the animation just a little longer than I wanted. The AxisRawEvent plays them perfectly.

Code: [Select]
// (c) Copyright HutongGames, LLC 2010-2011. All rights reserved.

using UnityEngine;

namespace HutongGames.PlayMaker.Actions
{
    [ActionCategory(ActionCategory.Input)]
    [Tooltip("Sends events based on the direction of Input Axis Raw (Left/Right/Up/Down...).")]
    public class AxisRawEvent : FsmStateAction
    {
        [Tooltip("Horizontal axis as defined in the Input Manager")]
        public FsmString horizontalAxis;

        [Tooltip("Vertical axis as defined in the Input Manager")]
        public FsmString verticalAxis;

        [Tooltip("Event to send if input is to the left.")]
        public FsmEvent leftEvent;

        [Tooltip("Event to send if input is to the right.")]
        public FsmEvent rightEvent;

        [Tooltip("Event to send if input is to the up.")]
        public FsmEvent upEvent;

        [Tooltip("Event to send if input is to the down.")]
        public FsmEvent downEvent;

        [Tooltip("Event to send if input is in any direction.")]
        public FsmEvent anyDirection;

        [Tooltip("Event to send if no axis input (centered).")]
        public FsmEvent noDirection;

        public override void Reset()
        {
            horizontalAxis = "Horizontal";
            verticalAxis = "Vertical";
            leftEvent = null;
            rightEvent = null;
            upEvent = null;
            downEvent = null;
            anyDirection = null;
            noDirection = null;
        }

        public override void OnUpdate()
        {
            // get axes offsets

            var x = horizontalAxis.Value != "" ? Input.GetAxisRaw(horizontalAxis.Value) : 0;
            var y = verticalAxis.Value != "" ? Input.GetAxisRaw(verticalAxis.Value) : 0;

            // get squared offset from center

            var offset = (x * x) + (y * y);

            // no offset?

            if (offset.Equals(0))
            {
                if (noDirection != null)
                {
                    Fsm.Event(noDirection);
                }
                return;
            }

            // get integer direction sector (4 directions)
            // TODO: 8 directions? or new action?

            var angle = (Mathf.Atan2(y, x) * Mathf.Rad2Deg) + 45f;
            if (angle < 0f)
            {
                angle += 360f;
            }

            var direction = (int)(angle / 90f);

            // send events bases on direction

            if (direction == 0 && rightEvent != null)
            {
                Fsm.Event(rightEvent);
                //Debug.Log("Right");
            }
            else if (direction == 1 && upEvent != null)
            {
                Fsm.Event(upEvent);
                //Debug.Log("Up");
            }
            else if (direction == 2 && leftEvent != null)
            {
                Fsm.Event(leftEvent);
                //Debug.Log("Left");
            }
            else if (direction == 3 && downEvent != null)
            {
                Fsm.Event(downEvent);
                //Debug.Log("Down");
            }
            else if (anyDirection != null)
            {
                // since we already no offset > 0

                Fsm.Event(anyDirection);
                //Debug.Log("AnyDirection");
            }
        }
    }
}


5
Share New Actions / GetAxisRaw Action
« on: October 26, 2012, 03:07:30 AM »
My character kept sliding a little when I used Get Axis and I wanted to use GetAxisRaw instead of GetKeyDown so that the user can use either the Arrow Keys or WASD. 

Code: [Select]
// (c) Copyright HutongGames, LLC 2010-2011. All rights reserved.

using UnityEngine;

namespace HutongGames.PlayMaker.Actions
{
    [ActionCategory(ActionCategory.Input)]
    [Tooltip("Gets the value of the specified Input AxisRaw and stores it in a Float Variable. See Unity Input Manager doc.")]
    public class GetAxisRaw : FsmStateAction
    {
        [RequiredField]
        public FsmString axisName;
        public FsmFloat multiplier;
        [RequiredField]
        [UIHint(UIHint.Variable)]
        public FsmFloat store;
        public bool everyFrame;

        public override void Reset()
        {
            axisName = "";
            multiplier = 1.0f;
            store = null;
            everyFrame = true;
        }

        public override void OnEnter()
        {
            DoGetAxis();

            if (!everyFrame)
            {
                Finish();
            }
        }

        public override void OnUpdate()
        {
            DoGetAxis();
        }

        void DoGetAxis()
        {
            var axisValue = Input.GetAxisRaw(axisName.Value);

            // if variable set to none, assume multiplier of 1
            if (!multiplier.IsNone)
            {
                axisValue *= multiplier.Value;
            }

            store.Value = axisValue;
        }
    }
}


6
Share New Actions / Re: Some minor changes.
« on: October 25, 2012, 04:19:37 AM »
Just made a new one. This is for the 2D ToolKit FlipX() function. I'm sure most of you already have a better solution, but I didn't find one on this forum so I just made my own.

I posted a picture about how to use it.

1) First I set a variable
2) I named mine Flip because that's the only function it will be used for.
3) I set the value of the int to 0. 0 being the "original" flip direction. on this animation, its left.
4) My states look like this.
5) My right states has these action.
6) First i selected the variable the action has to check
7) Here is a basic If statement and IF the flip variable is 0 (which is left for me) it does the .FlipX() to flip the animation.
8) If the character was flipped, the action sets the flip variable to 1 (1 being right for me)
9) Next is the left side
10) Flip variable is selected like before
11) and in this if the flip var is set to 1 the action will make the animation flip to the other side
12) And now if the animation was flipped the action will set the Flip var to 0 again.

This works like a charm for me. And hopefully someone else is looking for something like this :)

7
Share New Actions / 2d toolkit custom actions: Some minor changes.
« on: October 24, 2012, 06:09:53 PM »
Hi guys,
I just recently started using Unity and I just bought Playmaker. And I love it.

I have been playing around with Playmaker and 2D Toolkit to make just a small prototype game for fun (nothing interesting at all) and I found out that the actions I wanted were not included and I didn't find them by searching. So I made some new ones (Not really, I just made a few changes to some older scripts and gave them a new name(I don't take any credit for doing this))

I understand if some of you think it's silly off me to put this up here because the changes that I made to these already great actions are so minor that a lot of you have probably already done this. But I'm guessing there are some people that might be in need off this that don't have any understanding of code. For those, here you go.

The first Action is just a change to the Get Axis Action that comes with Playmaker. My character kept sliding a little when I used Get Axis and I wanted to use GetAxisRaw instead of GetKeyDown so that the user can use either the Arrow Keys or WASD.  

The second Action I made changes to was AxisEvent. Once Again I just did a minor change and added the RAW. I'm using the AxisRawEvent for my 2D Toolkit animations. With the AxisEvent my character kept playing the animation just a little longer than I wanted. The AxisRawEvent plays them perfectly.

That last one is for 2DToolkit and I got the original files from
https://hutonggames.fogbugz.com/default.asp?W717
All i did was change the PlayAnimation action so that I didn't to add a StopAnimation before every play animation.

I'm fairly new to these kind of things and any criticism is accepted.
 

Pages: [1]