playMaker

Author Topic: need help add gizmo script into action  (Read 1272 times)

Maart

  • Junior Playmaker
  • **
  • Posts: 92
need help add gizmo script into action
« on: February 04, 2022, 08:06:50 AM »
Hi I got this script to add a gizmo that I want to make into a playmaker action
I want to add a gameobject variable to add the gizmo to.
Is there anyone who could please help me out?

Code: [Select]
using UnityEngine;
using System.Collections.Generic;

namespace RTG


{
   

public class Demo : MonoBehaviour
    {
        private void Start()
        {

            var moveTargetNames = new string[] { "Blue Cube", "Sphere" };
            foreach (var targetName in moveTargetNames)
            {
                var transformGizmo = RTGizmosEngine.Get.CreateObjectMoveGizmo();

                GameObject targetObject = GameObject.Find(targetName);
                transformGizmo.SetTargetObject(targetObject);
                transformGizmo.Gizmo.MoveGizmo.SetVertexSnapTargetObjects(new List<GameObject> { targetObject });
                transformGizmo.SetTransformSpace(GizmoSpace.Local);
            }
        }
    }
}
« Last Edit: February 04, 2022, 10:45:39 AM by djaydino »

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7618
    • jinxtergames
Re: need help add gizmo script into action
« Reply #1 on: February 04, 2022, 10:57:14 AM »
Hi.
Something like this might work, but i can't test as i do not have this RTG asset

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

using UnityEngine;
using RTG

namespace HutongGames.PlayMaker.Actions
{
[ActionCategory("RTG")]
[Tooltip("Adds a value to a Float Variable.")]
public class SetGizmos : FsmStateAction
{
        [UIHint(UIHint.Variable)]
        [ArrayEditor(VariableType.String)]
        public FsmArray moveTargetNames;

        public override void Reset()
        {

            moveTargetNames = new FsmArray { UseVariable = true };

        }

        public override void OnEnter()
{

            foreach (var targetName in moveTargetNames)
            {
                var transformGizmo = RTGizmosEngine.Get.CreateObjectMoveGizmo();

                GameObject targetObject = GameObject.Find(targetName);
                transformGizmo.SetTargetObject(targetObject);
                transformGizmo.Gizmo.MoveGizmo.SetVertexSnapTargetObjects(new List<GameObject> { targetObject });
                transformGizmo.SetTransformSpace(GizmoSpace.Local);
            }
            Finish();
}
}
}

but GameObject.Findis 'cpu heavy' so its best only to use at the start of a scene especially if you have a lot of objects in the scene

Maart

  • Junior Playmaker
  • **
  • Posts: 92
Re: need help add gizmo script into action
« Reply #2 on: February 04, 2022, 08:51:16 PM »
sadly I get "error CS1579: foreach statement cannot operate on variables of type 'FsmArray' because 'FsmArray' does not contain a public instance definition for 'GetEnumerator'"