Exemplo n.º 1
0
        protected virtual void HeaderGUI()
        {
            SplineUser user = (SplineUser)target;

            Undo.RecordObject(user, "Inspector Change");
            SplineComputer lastSpline = (SplineComputer)spline.objectReferenceValue;

            EditorGUILayout.PropertyField(spline);
            SplineComputer newSpline = (SplineComputer)spline.objectReferenceValue;

            if (lastSpline != (SplineComputer)spline.objectReferenceValue)
            {
                for (int i = 0; i < users.Length; i++)
                {
                    if (lastSpline != null)
                    {
                        lastSpline.Unsubscribe(users[i]);
                    }
                    if (newSpline != null)
                    {
                        newSpline.Subscribe(users[i]);
                    }
                }
                user.Rebuild();
            }


            if (user.spline == null)
            {
                EditorGUILayout.HelpBox("No SplineComputer is referenced. Link a SplineComputer to make this SplineUser work.", MessageType.Error);
            }

            settingsFoldout = EditorGUILayout.Foldout(settingsFoldout, "User Configuration", foldoutHeaderStyle);
            if (settingsFoldout)
            {
                EditorGUI.indentLevel++;
                if (showClip)
                {
                    InspectorClipEdit();
                }
                if (showUpdateMethod)
                {
                    EditorGUILayout.PropertyField(updateMethodProperty);
                }
                EditorGUILayout.PropertyField(autoUpdateProperty, new GUIContent("Auto Rebuild"));
                if (showMultithreading)
                {
                    EditorGUILayout.PropertyField(multithreadedProperty);
                }
                EditorGUILayout.PropertyField(buildOnAwakeProperty);
                EditorGUILayout.PropertyField(buildOnEnableProperty);
                EditorGUI.indentLevel--;
            }
        }
        SplineComputer CreateNewSpline()
        {
            GameObject go = Object.Instantiate(spline.gameObject);

            Undo.RegisterCreatedObjectUndo(go, "New Spline");
            go.name = spline.name + "_split";
            SplineUser[]   users     = go.GetComponents <SplineUser>();
            SplineComputer newSpline = go.GetComponent <SplineComputer>();

            for (int i = 0; i < users.Length; i++)
            {
                spline.Unsubscribe(users[i]);
                users[i].spline = newSpline;
                newSpline.Subscribe(users[i]);
            }
            for (int i = go.transform.childCount - 1; i >= 0; i--)
            {
                Undo.DestroyObjectImmediate(go.transform.GetChild(i).gameObject);
            }
            return(newSpline);
        }
Exemplo n.º 3
0
        protected virtual void HeaderGUI()
        {
            SplineUser user = (SplineUser)target;

            bool isClosed    = true;
            bool loopSamples = true;

            for (int i = 0; i < users.Length; i++)
            {
                if (users[i].spline == null)
                {
                    isClosed = false;
                }
                else if (!users[i].spline.isClosed)
                {
                    isClosed = false;
                }
                else if (!users[i].loopSamples)
                {
                    loopSamples = false;
                }
            }

            Undo.RecordObject(user, "Inspector Change");
            SplineComputer lastSpline = (SplineComputer)spline.objectReferenceValue;

            EditorGUILayout.PropertyField(spline);
            SplineComputer newSpline = (SplineComputer)spline.objectReferenceValue;

            if (lastSpline != (SplineComputer)spline.objectReferenceValue)
            {
                for (int i = 0; i < users.Length; i++)
                {
                    if (lastSpline != null)
                    {
                        lastSpline.Unsubscribe(users[i]);
                    }
                    if (newSpline != null)
                    {
                        newSpline.Subscribe(users[i]);
                    }
                }
                user.Rebuild();
            }

            //if (GUI.changed) serializedObject.ApplyModifiedProperties();


            if (user.spline == null)
            {
                EditorGUILayout.HelpBox("No SplineComputer is referenced. Link a SplineComputer to make this SplineUser work.", MessageType.Error);
            }

            if (showClip)
            {
                float clipFrom = 0f, clipTo = 1f;
                clipFrom = this.clipFrom.floatValue;
                clipTo   = this.clipTo.floatValue;
                float lastFrom = clipFrom, lastTo = clipTo;
                EditorGUI.BeginChangeCheck();

                if (isClosed && loopSamples)
                {
                    EditorGUILayout.BeginHorizontal();
                    if (EditButton(_editIndex == 0))
                    {
                        if (_editIndex == 0)
                        {
                            _editIndex = -1;
                        }
                        else
                        {
                            _editIndex = 0;
                        }
                    }
                    EditorGUILayout.BeginVertical();
                    clipFrom = EditorGUILayout.Slider("Clip From", clipFrom, 0f, 1f);
                    clipTo   = EditorGUILayout.Slider("Clip To", clipTo, 0f, 1f);
                    EditorGUILayout.EndVertical();
                    EditorGUILayout.EndHorizontal();
                }
                else
                {
                    EditorGUILayout.BeginHorizontal();
                    EditorGUILayout.BeginHorizontal();
                    if (EditButton(_editIndex == 0))
                    {
                        if (_editIndex == 0)
                        {
                            _editIndex = -1;
                        }
                        else
                        {
                            _editIndex = 0;
                        }
                    }
                    EditorGUIUtility.labelWidth = 80f;
                    EditorGUILayout.MinMaxSlider(new GUIContent("Clip Range:"), ref clipFrom, ref clipTo, 0f, 1f);
                    EditorGUIUtility.labelWidth = 0f;
                    EditorGUILayout.EndHorizontal();
                    EditorGUILayout.BeginHorizontal(GUILayout.MaxWidth(30));
                    clipFrom = EditorGUILayout.FloatField(clipFrom);
                    clipTo   = EditorGUILayout.FloatField(clipTo);
                    EditorGUILayout.EndHorizontal();
                    EditorGUILayout.EndHorizontal();
                }
                if (EditorGUI.EndChangeCheck())
                {
                    this.clipFrom.floatValue = clipFrom;
                    this.clipTo.floatValue   = clipTo;
                }
                SplineComputerEditor.hold = _editIndex >= 0;

                if (isClosed)
                {
                    EditorGUILayout.PropertyField(this.loopSamples, new GUIContent("Loop Samples"));
                }
                if (!this.loopSamples.boolValue || !isClosed)
                {
                    if (this.clipFrom.floatValue > this.clipTo.floatValue)
                    {
                        float temp = this.clipTo.floatValue;
                        this.clipTo.floatValue   = this.clipFrom.floatValue;
                        this.clipFrom.floatValue = temp;
                    }
                }
            }

            settings = EditorGUILayout.Foldout(settings, "Settings");
            if (settings)
            {
                EditorGUI.indentLevel++;
                if (showUpdateMethod)
                {
                    EditorGUILayout.PropertyField(updateMethod);
                }
                EditorGUILayout.PropertyField(autoUpdate, new GUIContent("Auto Rebuild"));
                if (showMultithreading)
                {
                    EditorGUILayout.PropertyField(multithreaded);
                }
                EditorGUILayout.PropertyField(buildOnAwake);
                EditorGUILayout.PropertyField(buildOnEnable);
                EditorGUI.indentLevel--;
            }
        }