- Home /
Using PositionHandle to set a a directional vector, using TransformDirection causing editor freakouts. Help!
using UnityEditor;
using UnityEngine;
[CustomEditor(typeof(AutoMove))]
public class PositionHandleEditor : Editor
{
AutoMove obj;
private void OnEnable()
{
obj = (AutoMove) target;
}
public override void OnInspectorGUI()
{
DrawDefaultInspector();
}
private void OnSceneGUI()
{
int i = obj.steps.Length -1;
while (i >= 0) {
obj.steps [i].pos = Handles.PositionHandle(obj.steps[i].pos + obj.transform.position, Quaternion.identity) - obj.transform.position;
i--;
}
}
}
"Automove" is simply a script where the variable "step.pos" is simple a vector, which during runtime, a gameobject under "automove" will have its local position set as this "step vector.
Currently the script does create a handle for each step! The handle moves and returns a position which does "seem" local to the target object, but only by way of its being offset by the position of the object. It isn't taking into account the objects rotation (because this vector will later be a local position, so it definitely should take into account the rotation)
So! If I have a vector, a simple one, let's say Vector3.forward. I want this handle to be at "0,0,1" as if it were a local position under the gameobject, which moves with the gameobject.
I have tried different variations of breaking down the vector calculations and trying "TransformDirection" all over the place, but the handles would either lock up / not move, or start spinning and freaking out.
It doesn't seem like it should be this hard! But I admit this is the first time i have tried editor scripting.