示例#1
0
        /// <summary>
        /// Updates the scene editor
        /// </summary>
        public static void OnSceneUpdate(SceneView view)
        {
            Handles.color = Color.blue;

            for (int i = 0; i < _currentPath.pathData.Length; i++)
            {
                DrawPoint(i, view);
            }

            //Reset selection if press escape
            if (Event.current.keyCode == KeyCode.Escape && Event.current.type == EventType.KeyDown)
            {
                _selectedId      = -1;
                _selectedTangent = (PathTangentType)(-1);
                DeselectPoint();
                Event.current.Use();
            }

            _currentPath.UpdatePath();
        }
示例#2
0
        public override void OnInspectorGUI()
        {
            GUILayout.Space(5.0f);

            EditorGUILayout.BeginHorizontal();
            ShapeAsset shapeAsset = (ShapeAsset)EditorGUILayout.ObjectField(
                "Shape", _currentPath.shapeAsset, typeof(ShapeAsset), false);

            _currentPath.shapeAsset = shapeAsset;

            if (shapeAsset != null)
            {
                if (GUILayout.Button("Edit", GUILayout.Width(60)))
                {
                    ShapeEditorWindow.Edit(shapeAsset);
                }
            }
            else
            {
                if (GUILayout.Button("Create", GUILayout.Width(60)))
                {
                    ShapeAsset newShapeAsset = CreateShapeAsset();
                    if (newShapeAsset != null)
                    {
                        _currentPath.shapeAsset = newShapeAsset;
                    }
                }
            }

            EditorGUILayout.EndHorizontal();

            GUILayout.Space(15);

            EditorGUI.BeginChangeCheck();

            Vector2 scale        = EditorGUILayout.Vector2Field("Scale", _currentPath.scale);
            int     subdivisions = EditorGUILayout.IntField("Subdivisions", Mathf.Clamp(_currentPath.subdivisions, 1, 100));
            float   uvResolution = EditorGUILayout.Slider("Uv resolution", _currentPath.uvResolution, 0.2f, 10.0f);
            bool    loopCurve    = EditorGUILayout.Toggle("Loop curve", _currentPath.loopCurve);

            if (EditorGUI.EndChangeCheck())
            {
                Undo.RecordObject(_currentPath, "Modify Path Settings");
                EditorUtility.SetDirty(_currentPath);
                _currentPath.scale        = scale;
                _currentPath.subdivisions = subdivisions;
                _currentPath.uvResolution = uvResolution;
                _currentPath.loopCurve    = loopCurve;
            }

            GUILayout.Space(20);

            for (int i = 0; i < _currentPath.pathData.Length; i++)
            {
                if (PathPointEditor.selectedId == i)
                {
                    PathPointEditor.EditPointGUI(i);
                }
            }

            if (GUILayout.Button("Add Point"))
            {
                Undo.RecordObject(_currentPath, "Add point");
                EditorUtility.SetDirty(_currentPath);
                _currentPath.pathData.AddPoint(_currentPath.transform.position);
                SceneView.RepaintAll();
            }

            if (GUILayout.Button("Remove Point") && _currentPath.pathData.Length > 1)
            {
                Undo.RecordObject(_currentPath, "Remove point");
                EditorUtility.SetDirty(_currentPath);
                _currentPath.pathData.RemovePoint(PathPointEditor.selectedId);
                SceneView.RepaintAll();
            }

            GUILayout.Space(20);

            _autoGenerateRoad = EditorGUILayout.Toggle("Auto Generate", _autoGenerateRoad);

            if (!_autoGenerateRoad && GUILayout.Button("Generate Road"))
            {
                _currentPath.UpdatePath();
                SceneView.RepaintAll();
            }
        }