예제 #1
0
        void CreateNode(vWaypointArea wayArea, Vector3 position)
        {
            var nodeObj = new GameObject("node");
            var node    = nodeObj.AddComponent <vWaypoint>();

            node.subPoints             = new List <vPoint>();
            nodeObj.transform.position = position;
            nodeObj.transform.parent   = wayArea.transform;
            wayArea.waypoints.Add(node);
            currentNode     = node;
            indexOfWaypoint = wayArea.waypoints.IndexOf(currentNode);
        }
예제 #2
0
        void OnEnable()
        {
            pathArea = (vWaypointArea)target;
            if (pathArea.waypoints == null)
            {
                pathArea.waypoints = new List <vWaypoint>();
            }
            if (pathArea.waypoints.Count > 0)
            {
                currentNode = pathArea.waypoints[0];
            }

            EditorApplication.playmodeStateChanged = HandleOnPlayModeChanged;
            SetVisiblePoints(false);
        }
예제 #3
0
 void CreatePatrolPoint(vWaypointArea wayArea, Vector3 position)
 {
     if (currentNode)
     {
         if (currentNode.subPoints == null)
         {
             currentNode.subPoints = new List <vPoint>();
         }
         var nodeObj = new GameObject("patrolPoint");
         var node    = nodeObj.AddComponent <vPoint>();
         nodeObj.transform.position = position;
         nodeObj.transform.parent   = currentNode.transform;
         currentNode.subPoints.Add(node);
         indexOfPatrolPoint = currentNode.subPoints.IndexOf(node);
     }
 }
예제 #4
0
        public override void OnInspectorGUI()
        {
            if (skin == null)
            {
                skin = Resources.Load("skin") as GUISkin;
            }
            GUI.skin = skin;
            //base.DrawDefaultInspector();
            _wayArea = new SerializedObject(target);
            var waypoints = _wayArea.FindProperty("waypoints");

            pathArea = (vWaypointArea)target;

            GUILayout.BeginVertical("Waypoint Area", "window", GUILayout.ExpandHeight(false), GUILayout.ExpandWidth(true));
            GUILayout.Space(40);
            if (GUILayout.Button(editMode ? "Exit Edit Mode" : "Enter Edit Mode", GUILayout.ExpandWidth(true)))
            {
                editMode = !editMode;
                if (!editMode)
                {
                    Selection.activeGameObject = pathArea.gameObject;
                }
                ActiveEditorTracker.sharedTracker.isLocked = editMode;
                SetVisiblePoints(editMode);
                Repaint();
            }
            GUI.color   = Color.white;
            GUI.enabled = editMode;
            EditorGUILayout.Space();

            if (editMode && pathArea.waypoints.Count == 0)
            {
                EditorGUILayout.HelpBox("Starting by holding Shift and Left Click on any surface with a collider.", MessageType.Info);
            }

            if (pathArea.waypoints != null && pathArea.waypoints.Count > 0)
            {
                for (int i = 0; i < waypoints.arraySize; i++)
                {
                    GUI.color = (i.Equals(indexOfWaypoint) ? Color.green : Color.white);
                    GUILayout.BeginHorizontal();
                    if (GUILayout.Button("Waypoint " + (i + 1).ToString("00"), "box", GUILayout.ExpandWidth(true)))
                    {
                        indexOfWaypoint            = i;
                        currentNode                = pathArea.waypoints[i];
                        Selection.activeGameObject = currentNode.gameObject;
                        SceneView.lastActiveSceneView.FrameSelected();
                    }
                    if (!PointIsInNavMesh(pathArea.waypoints[i].transform.position))
                    {
                        GUI.color = Color.white;
                        EditorGUILayout.HelpBox("Out of NavMesh", MessageType.Error);
                        Repaint();
                    }
                    EditorGUILayout.Space();

                    if (GUILayout.Button("x", GUILayout.MaxWidth(20)))
                    {
                        RemoveNode(ref waypoints, i);
                        GUILayout.EndVertical();
                        break;
                    }
                    GUILayout.EndHorizontal();
                    EditorGUILayout.Space();
                }
            }

            GUI.color = Color.white;
            if (indexOfWaypoint >= waypoints.arraySize)
            {
                indexOfWaypoint = waypoints.arraySize - 1;
            }
            try
            {
                if (waypoints != null && waypoints.arraySize > 0)
                {
                    var vPoint = new SerializedObject(waypoints.GetArrayElementAtIndex(indexOfWaypoint).objectReferenceValue as vWaypoint);
                    DrawWaypoint(vPoint, waypoints);
                }
            }
            catch { }
            GUILayout.EndVertical();
            GUI.enabled = true;
            GUILayout.BeginVertical("Hot Keys", "window");
            GUILayout.Space(40);
            hotKeys = GUILayout.Toggle(hotKeys, hotKeys ? "Hide Hot Keys" : "Show Hot Keys", "button", GUILayout.ExpandWidth(true));
            if (hotKeys)
            {
                GUILayout.BeginVertical("box");
                GUI.color = Color.green;
                GUILayout.Label("Shift + Left Mouse Click", "box");
                GUI.color = Color.white;
                GUILayout.Label("Create New Way Point");
                GUILayout.EndVertical();
                EditorGUILayout.Separator();

                GUILayout.BeginVertical("box");
                GUI.color = Color.green;
                GUILayout.Label("Ctrl + Left Mouse Click", "box");
                GUI.color = Color.white;
                GUILayout.Label("Create New Patrol Point to selected way point");
                GUILayout.EndVertical();
                EditorGUILayout.Separator();

                GUILayout.BeginVertical("box");
                GUI.color = Color.green;
                GUILayout.Label("Shift + Right Mouse Click", "box");
                GUI.color = Color.white;
                GUILayout.Label("Set click point position to way point selected");
                GUILayout.EndVertical();
                EditorGUILayout.Separator();

                GUILayout.BeginVertical("box");
                GUI.color = Color.green;
                GUILayout.Label("Ctrl + Right Mouse Click", "box");
                GUI.color = Color.white;
                GUILayout.Label("Set click point position to patrol point selected");
                GUILayout.EndVertical();
                EditorGUILayout.Separator();
            }
            EditorGUILayout.Separator();

            GUILayout.EndVertical();
            if (Event.current.commandName == "UndoRedoPerformed")
            {
                Repaint();
            }
            if (GUI.changed)
            {
                _wayArea.ApplyModifiedProperties();
                EditorUtility.SetDirty(pathArea);
            }
        }