Example #1
0
        override public void OnInspectorGUI()
        {
            base.OnInspectorGUI();
            EditorGUILayout.BeginVertical();

            EditorGUILayout.LabelField("Waypoints");

            bool dorepaint = false;


            if (waypoints != null)
            {
                int delIndex = -1;
                for (int cnt = 0; cnt < waypoints.Count; cnt++)
                {
                    Color guiColor = GUI.color;

                    Waypoint cwp = waypoints[cnt];

                    if (cwp == selectedWaypoint)
                    {
                        GUI.color = Color.green;
                    }

                    EditorGUILayout.BeginHorizontal();
                    if (GUILayout.Button("S", GUILayout.Width(20)))
                    {
                        if (selectedWaypoint == cwp)
                        {
                            selectedWaypoint = null;
                        }
                        else
                        {
                            selectedWaypoint = cwp;
                        }

                        dorepaint = true;
                    }

                    EditorGUI.BeginChangeCheck();
                    Vector3 oldV = cwp.GetPosition(waypointsGroup.XYZConstraint);
                    Vector3 newV = EditorGUILayout.Vector3Field("", oldV);
                    if (EditorGUI.EndChangeCheck())
                    {
                        Undo.RecordObject(waypointsGroup, "Waypoint Moved");
                        cwp.UpdatePosition(newV - oldV, waypointsGroup.XYZConstraint);
                    }



                    if (GUILayout.Button("D", GUILayout.Width(25)))
                    {
                        delIndex  = cnt;
                        dorepaint = true;
                    }
                    GUI.color = guiColor;
                    EditorGUILayout.EndHorizontal();
                }

                if (delIndex > -1)
                {
                    if (waypoints[delIndex] == selectedWaypoint)
                    {
                        selectedWaypoint = null;
                    }
                    waypoints.RemoveAt(delIndex);
                }
            }


            if (GUILayout.Button("Add"))
            {
                Undo.RecordObject(waypointsGroup, "Waypoint Added");
                int ndx = -1;
                if (selectedWaypoint != null)
                {
                    ndx = waypoints.IndexOf(selectedWaypoint);
                    if (ndx == -1)
                    {
                        selectedWaypoint = null;
                    }
                    else
                    {
                        ndx += 1;
                    }
                }


                Waypoint wp = new Waypoint();
                wp.CopyOther(selectedWaypoint);
                waypointsGroup.AddWaypoint(wp, ndx);
                selectedWaypoint = wp;
                dorepaint        = true;
            }

            EditorGUILayout.EndVertical();
            if (dorepaint)
            {
                SceneView.RepaintAll();
            }
        }