Beispiel #1
0
    void OnSceneGUI()
    {
        WaypointNetwork network = (WaypointNetwork)target;

        for (int i = 0; i < network.Waypoints.Count; i++)
        {
            if (network.Waypoints[i] != null)
            {
                Handles.Label(network.Waypoints[i].position, "Waypoint " + i.ToString());
            }
        }

        if (network.DisplayMode == PathDisplayMode.Connections)
        {
            //this stores Waypoints position
            Vector3[] linePoints = new Vector3[network.Waypoints.Count + 1];

            for (int i = 0; i <= network.Waypoints.Count; i++)
            {
                int index = i != network.Waypoints.Count ? i : 0;

                //if (i != network.Waypoints.Count)
                //{
                //    i = 0;
                //}

                if (network.Waypoints[index] != null)
                {
                    linePoints[i] = network.Waypoints[index].position;
                }
                else
                {
                    linePoints[i] = new Vector3(Mathf.Infinity, Mathf.Infinity, Mathf.Infinity);
                }
            }

            Handles.color = Color.cyan;
            Handles.DrawPolyLine(linePoints);
        }

        else
        if (network.DisplayMode == PathDisplayMode.Paths)
        {
            NavMeshPath path = new NavMeshPath();

            if (network.Waypoints[network.UIStart] != null && network.Waypoints[network.UIEnd] != null)
            {
                Vector3 from = network.Waypoints[network.UIStart].position;
                Vector3 to   = network.Waypoints[network.UIEnd].position;

                //calculates all path from one node to the other
                NavMesh.CalculatePath(from, to, NavMesh.AllAreas, path);

                Handles.color = Color.red;
                Handles.DrawPolyLine(path.corners);
            }
        }
    }
Beispiel #2
0
    public override void OnInspectorGUI()
    {
        WaypointNetwork network = (WaypointNetwork)target;

        network.DisplayMode = (PathDisplayMode)EditorGUILayout.EnumPopup("Display Mode", network.DisplayMode);

        if (network.DisplayMode == PathDisplayMode.Paths)
        {
            network.UIStart = EditorGUILayout.IntSlider("Waypoint Start", network.UIStart, 0, network.Waypoints.Count - 1);
            network.UIEnd   = EditorGUILayout.IntSlider("Waypoint End", network.UIEnd, 0, network.Waypoints.Count - 1);
        }

        DrawDefaultInspector();
    }
Beispiel #3
0
    public void OnSceneGUI()
    {
        WaypointNetwork network = (WaypointNetwork)target;

        for (int i = 0; i < network.Waypoints.Count; i++)
        {
            Debug.Log("in here");

            if (network.Waypoints[i] != null)
            {
                Handles.Label(network.Waypoints[i].position, "Waypoint " + i.ToString());
            }
        }
        Vector3[] linePoints = new Vector3[network.Waypoints.Count + 1];

        for (int i = 0; i <= network.Waypoints.Count; i++)
        {
            int index = i != network.Waypoints.Count ? i : 0;

            if (network.Waypoints[index] != null)
            {
                linePoints[i] = network.Waypoints[index].position;
            }
            else
            {
                linePoints[i] = new Vector3(Mathf.Infinity, Mathf.Infinity, Mathf.Infinity);
            }
        }

        Handles.color = Color.white;
        Handles.DrawPolyLine(linePoints);



        Debug.Log("in here2");

        /*
         *          var t = (target as LookAtPoint);
         *
         *      EditorGUI.BeginChangeCheck();
         *      Vector3 pos = Handles.PositionHandle(t.lookAtPoint, Quaternion.identity);
         *      if (EditorGUI.EndChangeCheck())
         *      {
         *          Undo.RecordObject(target, "Move point");
         *          t.lookAtPoint = pos;
         *          t.Update();
         *      }*/
    }
Beispiel #4
0
    // Draw somethings on Scene
    // Just like transform component does draws the movement lines
    void OnSceneGUI()
    {
        WaypointNetwork waypointNetwork = (WaypointNetwork)target;
        List <Waypoint> waypoints       = waypointNetwork.waypoints;

        LabelPoints(waypoints);

        if (waypointNetwork.mode == PathMode.Connecions)
        {
            DrawConnections(waypoints);
        }
        else if (waypointNetwork.mode == PathMode.Paths)
        {
            DrawPaths(waypointNetwork);
        }
    }
Beispiel #5
0
    // We override the default behaviour , Custom Inspector
    public override void OnInspectorGUI()
    {
        WaypointNetwork waypointNetwork = (WaypointNetwork)target;

        waypointNetwork.mode = (PathMode)EditorGUILayout.EnumPopup("Display Mode: ", waypointNetwork.mode);

        if (waypointNetwork.mode == PathMode.Paths)
        {
            waypointNetwork.startWaypointIndex = EditorGUILayout.IntSlider("Start Point", waypointNetwork.startWaypointIndex, 0, waypointNetwork.waypoints.Count - 1);
            waypointNetwork.endWaypointIndex   = EditorGUILayout.IntSlider("Start Point", waypointNetwork.endWaypointIndex, 0, waypointNetwork.waypoints.Count - 1);
        }

        // Last but not least, we just want to draw the default inspector
        // why?
        // Because we didn't want to customize everything but the things we want
        DrawDefaultInspector();
    }
Beispiel #6
0
    // Draw the actual path that will be taken by an agent if we were to go from start to end
    private void DrawPaths(WaypointNetwork waypointNetwork)
    {
        NavMeshPath navMeshPath = new NavMeshPath();

        if (waypointNetwork == null || waypointNetwork.waypoints == null)
        {
            return;
        }

        Waypoint start = waypointNetwork.waypoints[waypointNetwork.startWaypointIndex];
        Waypoint end   = waypointNetwork.waypoints[waypointNetwork.endWaypointIndex];

        if (start == null || end == null)
        {
            return;
        }

        NavMesh.CalculatePath(start.transform.position, end.transform.position, NavMesh.AllAreas, navMeshPath);
        Handles.color = Color.yellow;
        Handles.DrawPolyLine(navMeshPath.corners);
    }