PlayMaker Updates & Downloads > Share New Actions

Get Scale

(1/1)

MaDDoX:
Hey it looks as I'm the first ;) C'mon coders, stop saving up stuff for yourselves and share the goodies! This is a little request from another thread, a missing lil' action to get the scale of a given game object. It returns the "lossy scale" if you use world, read about it here: http://unity3d.com/support/documentation/ScriptReference/Transform-lossyScale.html

To add it, just copy and paste the code below into a new C# script (I generally do it straight inside the Unity editor for consistency sake), name it as "GetScale.cs", save and you're done. It'll show up in the Transform category inside the action browser. Enjoy:


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

using UnityEngine;

namespace HutongGames.PlayMaker.Actions
{
    [ActionCategory(ActionCategory.Transform)]
    [Tooltip("Gets the Scale of a Game Object and stores it in a Vector3 Variable or each Axis in a Float Variable")]
    public class GetScale : FsmStateAction
    {
        [RequiredField]
        public FsmOwnerDefault gameObject;
        [UIHint(UIHint.Variable)]
        public FsmVector3 vector;
        [UIHint(UIHint.Variable)]
        public FsmFloat xScale;
        [UIHint(UIHint.Variable)]
        public FsmFloat yScale;
        [UIHint(UIHint.Variable)]
        public FsmFloat zScale;
        public Space space;
        public bool everyFrame;

        public override void Reset()
        {
            gameObject = null;
            vector = null;
            xScale = null;
            yScale = null;
            zScale = null;
            space = Space.World;
            everyFrame = false;
        }

        public override void OnEnter()
        {
            DoGetScale();

            if (!everyFrame)
                Finish();
        }

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

        void DoGetScale()
        {
            GameObject go = Fsm.GetOwnerDefaultTarget(gameObject);
            if (go == null) return;

            Vector3 scale;

            if (space == Space.World)
            {
                scale = go.transform.lossyScale;
            }
            else
            {
                scale = go.transform.localScale;
            }

            vector.Value = scale;
            xScale.Value = scale.x;
            yScale.Value = scale.y;
            zScale.Value = scale.z;
        }


    }
}
--- End code ---

tobbeo:
Thank you!

Alex Chouls:
Thanks MaDDoX!!  ;D

flekoun:
Thanks a lot! Was looking for it!

Steamgauge:
Nice one MaDDoX! Thank you!

Navigation

[0] Message Index

Go to full version