iTweenPath Editor, Can I move the entire path?

I only seem to be able to move one node at a time. Is there a way to move all the nodes at once?

I hacked iTweenPath to place all nodes in local space of a parent object. This way you can simply move the parent path object to move all the nodes in the scene. Code available if anyone wants to see it.

i wouldn’t mind seeing that!

Both of these files are a part of the iTweenEditor package that is freely available with source. So I don’t think it’s a problem for me to repro the whole thing here.

I actually told a small fib, I do the transformation manually in

void OnDrawGizmosSelected()

in iTweenPath.cs. Check that function for more details.

Also I don’t pretend this is the most efficient way of doing this and I am not responsible for your project/life/etc if you use it. :wink:

Code for iTweenPathEditor.cs:

//by Bob Berkebile : Pixelplacement : http://www.pixelplacement.com

using UnityEngine;
using UnityEditor;
using System.Collections;

[CustomEditor(typeof(iTweenPath))]
public class iTweenPathEditor : Editor
{
iTweenPath _target;
GUIStyle style = new GUIStyle();
public static int count = 0;
Vector3 newNodeOffset = new Vector3(5, 5, 5);

void OnEnable()
{
    //i like bold handle labels since I'm getting old:
    style.fontStyle = FontStyle.Bold;
    style.normal.textColor = Color.white;
    _target = (iTweenPath)target;        

    //lock in a default path name:
    if (!_target.initialized)
    {
        _target.initialized = true;
        _target.pathName = "New Path " + ++count;
        _target.initialName = _target.pathName;            
    }
}

public override void OnInspectorGUI()
{        
    //path name:
    EditorGUILayout.BeginHorizontal();
    EditorGUILayout.PrefixLabel("Path Name");
    _target.pathName = EditorGUILayout.TextField(_target.pathName);
    EditorGUILayout.EndHorizontal();

    if (_target.pathName == "")
    {
        _target.pathName = _target.initialName;
    }

    //path color:
    EditorGUILayout.BeginHorizontal();
    EditorGUILayout.PrefixLabel("Path Color");
    _target.pathColor = EditorGUILayout.ColorField(_target.pathColor);
    EditorGUILayout.EndHorizontal();             

    //exploration segment count control:
    EditorGUILayout.BeginHorizontal();
    EditorGUILayout.PrefixLabel("Node Count");
    _target.nodeCount = Mathf.Clamp(EditorGUILayout.IntSlider(_target.nodeCount, 0, 20), 2, 100);
    EditorGUILayout.EndHorizontal();

    //add node?
    if (_target.nodeCount > _target.nodes.Count)
    {
        for (int i = 0; i < _target.nodeCount - _target.nodes.Count; i++)
        {                
            var pos = _target.nodes[_target.nodes.Count - 1];
            pos += newNodeOffset;                
            _target.nodes.Add(pos);
        }
    }

    //remove node?
    if (_target.nodeCount < _target.nodes.Count)
    {
        if (EditorUtility.DisplayDialog("Remove path node?", "Shortening the node list will permantently destory parts of your path. This operation cannot be undone.", "OK", "Cancel"))
        {
            int removeCount = _target.nodes.Count - _target.nodeCount;
            _target.nodes.RemoveRange(_target.nodes.Count - removeCount, removeCount);
        }
        else
        {
            _target.nodeCount = _target.nodes.Count;
        }
    }

    //node display:
    EditorGUI.indentLevel = 4;
    for (int i = 0; i < _target.nodes.Count; i++)
    {
        _target.nodes <em>= EditorGUILayout.Vector3Field("Node " + (i + 1), _target.nodes*);*</em>

}
//update and redraw:
if (GUI.changed)
{
EditorUtility.SetDirty(_target);
}
}
void OnSceneGUI()
{
if (_target.enabled)
{ // dkoontz
if (_target.nodes.Count > 0)
{
//allow path adjustment undo:
Undo.SetSnapshotTarget(_target, “Adjust iTween Path”);
//path begin and end labels:
Handles.Label(_target.transform.TransformPoint(_target.nodes[0]), “'” + _target.pathName + “’ Begin”, style);
Handles.Label(_target.transform.TransformPoint(_target.nodes[_target.nodes.Count - 1]), “'” + _target.pathName + “’ End”, style);
//node handle display:
for (int i = 0; i < _target.nodes.Count; i++)
{
target.nodes = _target.transform.InverseTransformPoint(
Handles.PositionHandle(target.transform.TransformPoint(target.nodes*), Quaternion.identity));*
}

}
} // dkoontz
}
}
Code for iTweenPath.cs
//by Bob Berkebile : Pixelplacement : http://www.pixelplacement.com
using UnityEngine;
using System.Collections.Generic;
public class iTweenPath : MonoBehaviour
{
public string pathName = “”;
public Color pathColor = Color.cyan;
public List nodes = new List() { Vector3.zero, Vector3.zero };
public List localNodes = new List() { Vector3.zero, Vector3.zero };
public int nodeCount;
public static Dictionary<string, iTweenPath> paths = new Dictionary<string, iTweenPath>();
public bool initialized = false;
public string initialName = “”;
public bool sealedPath = false;
void OnEnable()
{
paths.Add(pathName.ToLower(), this);
}
void OnDrawGizmosSelected()
{
if (enabled)
{ // dkoontz
if (nodes.Count > 0)
{
Vector3[] globalPoints = new Vector3[nodes.Count];
for (int i = 0; i < nodes.Count; i++)
{
globalPoints = gameObject.transform.TransformPoint(nodes*);*
}
iTween.DrawPath(globalPoints, pathColor);
}
} // dkoontz
}
public static Vector3[] GetPath(string requestedName)
{
requestedName = requestedName.ToLower();
if (paths.ContainsKey(requestedName))
{
iTweenPath path = paths[requestedName];
Vector3[] globalPoints = new Vector3[path.nodes.Count];
for (int i = 0; i < path.nodes.Count; i++)
{
globalPoints = path.gameObject.transform.TransformPoint(path.nodes*);*
}
return globalPoints;
}
else
{
Debug.Log(“No path with that name exists! Are you sure you wrote it correctly?”);
return null;
}
}
}_