Пример #1
0
        public override void DrawInspector()
        {
            base.DrawInspector();
            if (spline == null)
            {
                return;
            }
            SplineEditorGUI.SetHighlightColors(SplinePrefs.highlightColor, SplinePrefs.highlightContentColor);
            EditorGUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();
            EditorGUI.BeginChangeCheck();
            operationsToolbar.SetContent(0, new GUIContent(spline.isClosed ? "Break" : "Close"));
            operationsToolbar.SetContent(1, new GUIContent("Reverse"));
            operationsToolbar.SetContent(2, new GUIContent(spline.is2D ? "3D Mode" : "2D Mode"));
            operationsToolbar.Draw(ref operation);
            //operation = GUILayout.Toolbar(operation, new string[] { , "Reverse", text2D }, GUILayout.Width(220f));
            if (EditorGUI.EndChangeCheck())
            {
                PerformOperation();
            }
            EditorGUI.BeginChangeCheck();
            if (splines.Length == 1)
            {
                int mod = module;
                utilityToolbar.Draw(ref mod);
                if (EditorGUI.EndChangeCheck())
                {
                    ToggleModule(mod);
                }
            }
            GUILayout.FlexibleSpace();
            EditorGUILayout.EndHorizontal();
            if (module >= 0 && module < modules.Length)
            {
                modules[module].DrawInspector();
            }
            EditorGUILayout.Space();
            DreamteckEditorGUI.DrawSeparator();

            EditorGUILayout.Space();

            serializedObject.Update();
            SerializedProperty splineProperty            = serializedObject.FindProperty("spline");
            SerializedProperty sampleRate                = serializedObject.FindProperty("spline").FindPropertyRelative("sampleRate");
            SerializedProperty type                      = serializedObject.FindProperty("spline").FindPropertyRelative("type");
            SerializedProperty linearAverageDirection    = splineProperty.FindPropertyRelative("linearAverageDirection");
            SerializedProperty space                     = serializedObject.FindProperty("_space");
            SerializedProperty sampleMode                = serializedObject.FindProperty("_sampleMode");
            SerializedProperty optimizeAngleThreshold    = serializedObject.FindProperty("_optimizeAngleThreshold");
            SerializedProperty updateMode                = serializedObject.FindProperty("updateMode");
            SerializedProperty rebuildOnAwake            = serializedObject.FindProperty("rebuildOnAwake");
            SerializedProperty multithreaded             = serializedObject.FindProperty("multithreaded");
            SerializedProperty customNormalInterpolation = splineProperty.FindPropertyRelative("customNormalInterpolation");
            SerializedProperty customValueInterpolation  = splineProperty.FindPropertyRelative("customValueInterpolation");

            EditorGUI.BeginChangeCheck();
            Spline.Type lastType = (Spline.Type)type.intValue;
            EditorGUILayout.PropertyField(type);
            if (lastType == Spline.Type.CatmullRom && type.intValue == (int)Spline.Type.Bezier)
            {
                if (EditorUtility.DisplayDialog("Hermite to Bezier", "Would you like to retain the Catmull Rom shape in Bezier mode?", "Yes", "No"))
                {
                    for (int i = 0; i < splines.Length; i++)
                    {
                        splines[i].CatToBezierTangents();
                    }

                    serializedObject.Update();
                    pathEditor.Refresh();
                }
            }
            if (spline.type == Spline.Type.Linear)
            {
                EditorGUILayout.PropertyField(linearAverageDirection);
            }
            int lastSpace = space.intValue;

            EditorGUILayout.PropertyField(space, new GUIContent("Space"));
            EditorGUILayout.PropertyField(sampleMode, new GUIContent("Sample Mode"));
            if (sampleMode.intValue == (int)SplineComputer.SampleMode.Optimized)
            {
                EditorGUILayout.PropertyField(optimizeAngleThreshold);
            }
            EditorGUILayout.PropertyField(updateMode);
            if (updateMode.intValue == (int)SplineComputer.UpdateMode.None && Application.isPlaying)
            {
                if (GUILayout.Button("Rebuild"))
                {
                    for (int i = 0; i < splines.Length; i++)
                    {
                        splines[i].RebuildImmediate(true, true);
                    }
                }
            }
            if (spline.type != Spline.Type.Linear)
            {
                EditorGUILayout.PropertyField(sampleRate, new GUIContent("Sample Rate"));
            }
            EditorGUILayout.PropertyField(rebuildOnAwake);
            EditorGUILayout.PropertyField(multithreaded);

            EditorGUI.indentLevel++;
            bool curveUpdate = false;

            interpolationFoldout = EditorGUILayout.Foldout(interpolationFoldout, "Point Value Interpolation");
            if (interpolationFoldout)
            {
                if (customValueInterpolation.animationCurveValue == null || customValueInterpolation.animationCurveValue.keys.Length == 0)
                {
                    if (GUILayout.Button("Size & Color Interpolation"))
                    {
                        AnimationCurve curve = new AnimationCurve();
                        curve.AddKey(new Keyframe(0, 0, 0, 0));
                        curve.AddKey(new Keyframe(1, 1, 0, 0));
                        for (int i = 0; i < splines.Length; i++)
                        {
                            splines[i].customValueInterpolation = curve;
                        }
                        serializedObject.Update();
                        curveUpdate = true;
                    }
                }
                else
                {
                    EditorGUILayout.BeginHorizontal();
                    EditorGUILayout.PropertyField(customValueInterpolation, new GUIContent("Size & Color Interpolation"));
                    if (GUILayout.Button("x", GUILayout.MaxWidth(25)))
                    {
                        customValueInterpolation.animationCurveValue = null;
                        for (int i = 0; i < splines.Length; i++)
                        {
                            splines[i].customValueInterpolation = null;
                        }
                        serializedObject.Update();
                        curveUpdate = true;
                    }
                    EditorGUILayout.EndHorizontal();
                }
                if (customNormalInterpolation.animationCurveValue == null || customNormalInterpolation.animationCurveValue.keys.Length == 0)
                {
                    if (GUILayout.Button("Normal Interpolation"))
                    {
                        AnimationCurve curve = new AnimationCurve();
                        curve.AddKey(new Keyframe(0, 0));
                        curve.AddKey(new Keyframe(1, 1));
                        for (int i = 0; i < splines.Length; i++)
                        {
                            splines[i].customNormalInterpolation = curve;
                        }
                        serializedObject.Update();
                        curveUpdate = true;
                    }
                }
                else
                {
                    EditorGUILayout.BeginHorizontal();
                    EditorGUILayout.PropertyField(customNormalInterpolation, new GUIContent("Normal Interpolation"));
                    if (GUILayout.Button("x", GUILayout.MaxWidth(25)))
                    {
                        customNormalInterpolation.animationCurveValue = null;
                        for (int i = 0; i < splines.Length; i++)
                        {
                            splines[i].customNormalInterpolation = null;
                        }
                        serializedObject.Update();
                        curveUpdate = true;
                    }
                    EditorGUILayout.EndHorizontal();
                }
            }

            EditorGUI.indentLevel--;

            if (EditorGUI.EndChangeCheck() || curveUpdate)
            {
                if (sampleRate.intValue < 2)
                {
                    sampleRate.intValue = 2;
                }
                if (lastSpace != space.intValue)
                {
                    for (int i = 0; i < splines.Length; i++)
                    {
                        splines[i].space = (SplineComputer.Space)space.intValue;
                    }
                    serializedObject.Update();
                    if (splines.Length == 1)
                    {
                        pathEditor.Refresh();
                    }
                }
                serializedObject.ApplyModifiedProperties();
                for (int i = 0; i < splines.Length; i++)
                {
                    splines[i].Rebuild(true);
                }
            }


            if (pathEditor.currentModule != null)
            {
                transformTool = 0;
            }
            EditorGUILayout.BeginHorizontal();
            GUILayout.Label("Edit Transform");
            GUILayout.FlexibleSpace();
            int lastTool = transformTool;

            transformToolbar.Draw(ref transformTool);
            if (lastTool != transformTool && transformTool > 0)
            {
                pathEditor.UntoggleCurrentModule();
            }
            EditorGUILayout.EndHorizontal();
        }