Search Unity

Handles not updating Custom Editor

Discussion in 'Editor & General Support' started by Adam2Marsh, Jun 21, 2015.

  1. Adam2Marsh

    Adam2Marsh

    Joined:
    Mar 2, 2014
    Posts:
    5
    Good Evening All,

    I'm having issues with a customer editor script I've written, the problem is when I move the handles I've drawn the editor isn't updated.

    Here's what it looks like - http://gfycat.com/PastelShoddyHummingbird

    Now here's my code:
    Code (CSharp):
    1.     public override void OnInspectorGUI ()
    2.     {
    3.         serializedObject.Update ();
    4.  
    5.         if (aniDetList.animationDetails.Count > 0) {
    6.             UpdateDropDown ();
    7.  
    8.             PopUpIndex = EditorGUILayout.Popup (PopUpIndex, aniDropDownList);
    9.  
    10.             aniDetList.animationDetails [PopUpIndex].animationName = EditorGUILayout.TextField ("Animaton Name: ", aniDetList.animationDetails [PopUpIndex].animationName);
    11.             waypointFold = EditorGUILayout.Foldout (waypointFold, "Waypoints");
    12.  
    13.             EditorGUILayout.BeginVertical ();
    14.             if (waypointFold) {
    15.  
    16.                 if (aniDetList.animationDetails [PopUpIndex].wayPoints.Count > 0) {
    17.                     for (int i = 0; i < (aniDetList.animationDetails[PopUpIndex].wayPoints.Count); i++) {
    18.                         aniDetList.animationDetails [PopUpIndex].wayPoints [i] = EditorGUILayout.Vector3Field ("Waypoint " + i, aniDetList.animationDetails [PopUpIndex].wayPoints [i]);
    19.                     }
    20.                 } else {
    21.                     EditorGUILayout.HelpBox ("No Waypoints for this animation, you need to create some", MessageType.Warning);
    22.                 }
    23.             }
    24.             EditorGUILayout.EndVertical ();
    25.             aniDetList.animationDetails [PopUpIndex].loopAnimation = EditorGUILayout.Toggle ("Loop Animaton: ", aniDetList.animationDetails [PopUpIndex].loopAnimation);
    26.  
    27.             if (GUILayout.Button ("Create new Waypoint")) {
    28.                 Debug.Log ("Created new Waypoint, Let's hope it shows!");
    29.                 CreateNewWaypoint ();
    30.             }
    31.            
    32.             if (GUILayout.Button ("Create new Animation")) {
    33.                 Debug.Log ("Created new Waypoint, Let's hope it shows!");
    34.                 CreateNewAnimation ();
    35.             }
    36.  
    37.             if (GUI.changed) {
    38.                 EditorUtility.SetDirty (aniDetList);
    39.             }
    40.  
    41.         } else {
    42.             EditorGUILayout.HelpBox ("No Animations, Please Create at least one", MessageType.Error);
    43.         }
    44.  
    45.         serializedObject.ApplyModifiedProperties ();
    46.     }
    47.  
    48.     void OnSceneGUI ()
    49.     {
    50.  
    51.         if (aniDetList.animationDetails.Count > 0) {
    52.             Handles.color = Color.yellow;
    53.             for (int i = 0; i <= (aniDetList.animationDetails[PopUpIndex].wayPoints.Count-1); i++) {
    54.                 aniDetList.animationDetails [PopUpIndex].wayPoints [i] = DrawHandle (i);
    55.                 if (GUI.changed) {
    56.                     EditorUtility.SetDirty (aniDetList);
    57.                 }
    58.                 if (i == 0) {
    59.                     Handles.DrawLine (me.gameObject.transform.position, aniDetList.animationDetails [PopUpIndex].wayPoints [i]);
    60.                 } else {
    61.                     Handles.DrawLine (aniDetList.animationDetails [PopUpIndex].wayPoints [i - 1], aniDetList.animationDetails [PopUpIndex].wayPoints [i]);
    62.                 }
    63.             }
    64.         }
    65.     }
    66.  
    67.     private Vector3 DrawHandle (int index)
    68.     {
    69.         Vector3 point = aniDetList.animationDetails [PopUpIndex].wayPoints [index];
    70.  
    71.         EditorGUI.BeginChangeCheck ();
    72.         point = Handles.FreeMoveHandle (point, Quaternion.identity, 0.3f, pointSnap, Handles.DotCap);
    73.         if (EditorGUI.EndChangeCheck ()) {
    74.             Undo.RecordObject (aniDetList, "Move point");
    75.             EditorUtility.SetDirty (aniDetList);
    76.             aniDetList.animationDetails [PopUpIndex].wayPoints [index] = point;
    77.         }
    78.         return point;
    79.     }
    If I edit the waypoints in the editor the Handles get updated straight away, but when I move the waypoints they don't get updated on the editor until I click on the inspector.

    Can anyone see where I've made the mistake? Thanks Everyone.