Ejemplo n.º 1
0
        public void Continue(Vector3 position)
        {
            Waypoint w = RoadUtility.CreateWayPoint(newRoad, position);

            lastWaypoint.ConnectTo(w);
            lastWaypoint = w;
        }
Ejemplo n.º 2
0
        public static void DoSceneGUI()
        {
            int      controlID = GUIUtility.GetControlID(FocusType.Passive);
            Event    e         = Event.current;
            RoadRoot root      = RoadUtility.GetRoadRoot();

            switch (root.selectedTool)
            {
            case RoadRoot.ToolType.Select:
                break;

            case RoadRoot.ToolType.Road:
                _EditRoad(root, e, controlID);
                break;

            case RoadRoot.ToolType.Decal:
                break;

            case RoadRoot.ToolType.SidePoints:
                break;

            case RoadRoot.ToolType.Wall:
                break;
            }
        }
Ejemplo n.º 3
0
        void OnGUI()
        {
            if (m_root == null)
            {
                m_root = RoadUtility.GetRoadRoot();
            }
            if (m_root != null)
            {
                EditorGUILayout.BeginVertical();

                GUILayout.Label("Tool:", EditorStyles.boldLabel);
                m_root.selectedTool = (RoadRoot.ToolType)GUILayout.SelectionGrid((int)m_root.selectedTool, toolLabel, 1);

                if (m_root.selectedTool == RoadRoot.ToolType.Road)
                {
                    Selection.activeGameObject = m_root.gameObject;
                }

                switch (m_root.selectedTool)
                {
                case RoadRoot.ToolType.Select:
                    break;

                case RoadRoot.ToolType.Road:
                    GUILayout.Label("Mode:", EditorStyles.boldLabel);
                    if (m_root.activeRoad == null)
                    {
                        m_root.selectedRoadToolMode = (RoadRoot.RoadToolType)GUILayout.SelectionGrid((int)m_root.selectedRoadToolMode, roadToolModeLabel_NoRoadSelected, 1);
                    }
                    else
                    {
                        m_root.selectedRoadToolMode = (RoadRoot.RoadToolType)GUILayout.SelectionGrid((int)m_root.selectedRoadToolMode, roadToolModeLabel_RoadSelected, 1);
                    }
                    break;

                case RoadRoot.ToolType.Decal:
                    break;

                case RoadRoot.ToolType.SidePoints:
                    break;

                case RoadRoot.ToolType.Wall:
                    break;
                }

                EditorGUILayout.EndVertical();
            }
            else
            {
                EditorGUILayout.HelpBox("RoadTool is not available during gameplay.", MessageType.Info);
            }
        }
Ejemplo n.º 4
0
        public static Road CreateRoad(Vector3 position)
        {
            GameObject obj = new GameObject();

            obj.name = "Road";
            obj.transform.position = position;
            Road r = obj.AddComponent <Road>();

            Waypoint w = RoadUtility.CreateWayPoint(r, position);

            r.SetRoot(w);

            return(r);
        }
Ejemplo n.º 5
0
        void OnEnable()
        {
            m_target = target as Path;

            RoadRoot rr = RoadUtility.GetRoadRoot();

            if (!serializedObject.isEditingMultipleObjects)
            {
                rr.SetActivePath(m_target);
            }
            else
            {
                rr.SetActivePath(null);
            }
        }
Ejemplo n.º 6
0
        public void ConnectTo(Waypoint next)
        {
            if (m_next)
            {
                DestroyImmediate(m_next.gameObject);
            }
            if (next != null)
            {
                if (next.m_last != null)
                {
                    DestroyImmediate(next.m_last.gameObject);
                }

                m_next      = RoadUtility.CreatePath(this, next);
                next.m_last = m_next;
            }

            UpdateWaypointDirection(true);
        }
Ejemplo n.º 7
0
        public void ConnectFrom(Waypoint last)
        {
            if (m_last)
            {
                DestroyImmediate(m_last.gameObject);
            }
            if (last != null)
            {
                if (last.m_next != null)
                {
                    DestroyImmediate(last.m_next.gameObject);
                }

                m_last      = RoadUtility.CreatePath(last, this);
                last.m_next = m_last;
            }

            UpdateWaypointDirection(true);
        }
Ejemplo n.º 8
0
        void OnEnable()
        {
            root            = serializedObject.FindProperty("m_root");
            roadMesh        = serializedObject.FindProperty("m_roadMesh");
            meshQuality     = serializedObject.FindProperty("m_meshQuality");
            roadWidth       = serializedObject.FindProperty("defaultWidth");
            defaultMaterial = serializedObject.FindProperty("m_defaultMaterial");
            m_target        = target as Road;

            RoadRoot rr = RoadUtility.GetRoadRoot();

            if (!serializedObject.isEditingMultipleObjects)
            {
                rr.SetActiveRoad(m_target);
            }
            else
            {
                rr.SetActiveRoad(null);
            }
        }
Ejemplo n.º 9
0
        public override void OnInspectorGUI()
        {
            //		// Update the serializedProperty - always do this in the beginning of OnInspectorGUI.
            serializedObject.Update();

            EditorGUILayout.Slider(centerRatio, 0.0f, 1.0f, new GUIContent("Center Ratio"));
            EditorGUILayout.Slider(width, 0.1f, 2.0f, new GUIContent("Road Width(%)"));

            if (GUILayout.Button(new GUIContent("Add Waypoint")))
            {
                Waypoint newWaypoint = RoadUtility.InsertWaypoint(m_target);
                Selection.activeGameObject = newWaypoint.gameObject;
            }

            serializedObject.ApplyModifiedProperties();

            if (GUILayout.Button(new GUIContent("Update Mesh")))
            {
                _UpdateMesh();
            }
        }
Ejemplo n.º 10
0
        void OnEnable()
        {
            centerRatio = serializedObject.FindProperty("centerRatio");
            angle       = serializedObject.FindProperty("angle");
            width       = serializedObject.FindProperty("m_width");

            last = serializedObject.FindProperty("m_last");
            next = serializedObject.FindProperty("m_next");

            m_target = serializedObject.targetObject as Waypoint;

            RoadRoot rr = RoadUtility.GetRoadRoot();

            if (!serializedObject.isEditingMultipleObjects)
            {
                rr.SetActiveWaypoint(m_target);
            }
            else
            {
                rr.SetActiveRoad(null);
            }
        }
Ejemplo n.º 11
0
        public static Waypoint InsertWaypoint(Waypoint w)
        {
            Vector3 newPos;

            if (w.next != null)
            {
                newPos = w.next.transform.position;
            }
            else
            {
                newPos = w.transform.TransformPoint(Vector3.forward);
            }

            Waypoint newWaypoint = RoadUtility.CreateWayPoint(w.parent, newPos);

            newWaypoint.ConnectTo(w.nextWaypoint);
            w.ConnectTo(newWaypoint);

//			EditorUtility.SetDirty(m_target.parent);

            return(w);
        }
Ejemplo n.º 12
0
        public static void BuildMeshForPath(Path p)
        {
            if (p == null)
            {
                return;
            }

            Mesh m = p.mesh;

            if (m == null)
            {
                m      = new Mesh();
                m.name = "Road Mesh";
                p.SetMesh(m);
            }

            if (p.hidden)
            {
                p.RemoveMesh();
                return;
            }

            p.UpdateRoadMaterial();

            int meshLengthValue  = p.parent.meshQuality;
            int meshDensityValue = meshLengthValue + 1;             // temp solution
            int vertLength       = (meshDensityValue + 1) * 3;

            Vector3[] vertices = new Vector3[vertLength];
            Vector2[] uv       = new Vector2[vertLength];
            int[]     indices  = new int[vertLength * 3 * 2];

            Debug.Log("Vertices size:" + vertices.Length);

            Waypoint wp0    = p.last;
            Waypoint wp1    = p.next;
            int      vcount = 0;

            for (int mi = 0; mi <= meshDensityValue; ++mi)
            {
                float lerpamount = ((float)mi) / ((float)meshDensityValue);                //TODO:

                Debug.Log("Building vert for|" + mi + ":" + vcount + " -> " + (vcount + 2) + " => " + lerpamount);

                Vector3 st = p.startTangent;
                Vector3 et = p.endTangent;

                Vector3 left   = RoadUtility.BezierLerp(wp0.left, wp1.left, st, st, lerpamount);
                Vector3 middle = Vector3.Lerp(wp0.transform.position, wp1.transform.position, lerpamount);
                Vector3 right  = RoadUtility.BezierLerp(wp0.right, wp1.right, et, et, lerpamount);
                vertices[vcount] = p.transform.InverseTransformPoint(left);
                uv[vcount]       = new Vector2(0.0f, lerpamount);           //TODO
                ++vcount;
                vertices[vcount] = p.transform.InverseTransformPoint(middle);
                float mid = Vector3.Distance(left, middle) / Vector3.Distance(left, right);
                uv[vcount] = new Vector2(mid, lerpamount);                 //TODO
                ++vcount;
                vertices[vcount] = p.transform.InverseTransformPoint(right);
                uv[vcount]       = new Vector2(1.0f, lerpamount);           //TODO
                ++vcount;

                if (vcount >= 6)
                {
                    int v = vcount - 6;
                    int c = (v) * 4;
                    Debug.Log("Building index for:" + v + " -> " + (v + 6) + " (" + c + " - " + (c + 11) + " )");

                    indices[c]     = (v + 0) % vertLength;
                    indices[c + 1] = (v + 4) % vertLength;
                    indices[c + 2] = (v + 1) % vertLength;

                    indices[c + 3] = (v + 0) % vertLength;
                    indices[c + 4] = (v + 3) % vertLength;
                    indices[c + 5] = (v + 4) % vertLength;

                    indices[c + 6] = (v + 1) % vertLength;
                    indices[c + 7] = (v + 4) % vertLength;
                    indices[c + 8] = (v + 5) % vertLength;

                    indices[c + 9]  = (v + 1) % vertLength;
                    indices[c + 10] = (v + 5) % vertLength;
                    indices[c + 11] = (v + 2) % vertLength;
                }
            }

            m.vertices  = vertices;
            m.triangles = indices;
            m.uv        = uv;
            m.RecalculateBounds();
            m.RecalculateNormals();
        }
Ejemplo n.º 13
0
 public void Begin(Vector3 position)
 {
     newRoad      = RoadUtility.CreateRoad(position);
     lastWaypoint = newRoad.root;
 }