예제 #1
0
        protected override void BodyGUI()
        {
            EditorGUILayout.Space();
            EditorGUILayout.LabelField("Positioning", EditorStyles.boldLabel);

            serializedObject.Update();
            SerializedProperty mode = serializedObject.FindProperty("_mode");

            EditorGUI.BeginChangeCheck();
            SplinePositioner positioner = (SplinePositioner)target;

            EditorGUILayout.PropertyField(mode, new GUIContent("Mode"));
            if (positioner.mode == SplinePositioner.Mode.Distance)
            {
                positioner.position = EditorGUILayout.FloatField("Distance", (float)positioner.position);
            }
            else
            {
                SerializedProperty percent = serializedObject.FindProperty("_result").FindPropertyRelative("percent");

                EditorGUILayout.BeginHorizontal();
                SerializedProperty position = serializedObject.FindProperty("_position");
                double             pos      = positioner.ClipPercent(percent.floatValue);
                EditorGUI.BeginChangeCheck();
                pos = EditorGUILayout.Slider("Percent", (float)pos, 0f, 1f);
                if (EditorGUI.EndChangeCheck())
                {
                    position.floatValue = (float)pos;
                }
                if (GUILayout.Button("Set Distance", GUILayout.Width(85)))
                {
                    DistanceWindow w = EditorWindow.GetWindow <DistanceWindow>(true);
                    w.Init(OnSetDistance, positioner.CalculateLength());
                }
                EditorGUILayout.EndHorizontal();
            }
            SerializedProperty targetObject = serializedObject.FindProperty("_targetObject");

            EditorGUILayout.PropertyField(targetObject, new GUIContent("Target Object"));
            if (EditorGUI.EndChangeCheck())
            {
                serializedObject.ApplyModifiedProperties();
            }
            base.BodyGUI();
        }
        protected override void BodyGUI()
        {
            EditorGUILayout.Space();
            EditorGUILayout.LabelField("Following", EditorStyles.boldLabel);
            SplineFollower follower = (SplineFollower)target;

            serializedObject.Update();
            SerializedProperty followMode        = serializedObject.FindProperty("followMode");
            SerializedProperty wrapMode          = serializedObject.FindProperty("wrapMode");
            SerializedProperty startPosition     = serializedObject.FindProperty("_startPosition");
            SerializedProperty autoStartPosition = serializedObject.FindProperty("autoStartPosition");
            SerializedProperty follow            = serializedObject.FindProperty("follow");


            EditorGUI.BeginChangeCheck();

            EditorGUILayout.PropertyField(follow);
            EditorGUILayout.PropertyField(followMode);
            if (followMode.intValue == (int)SplineFollower.FollowMode.Uniform)
            {
                SerializedProperty followSpeed = serializedObject.FindProperty("_followSpeed");
                EditorGUILayout.PropertyField(followSpeed, new GUIContent("Follow Speed"));
                if (followSpeed.floatValue < 0f)
                {
                    followSpeed.floatValue = 0f;
                }
            }
            else
            {
                follower.followDuration = EditorGUILayout.FloatField("Follow duration", follower.followDuration);
            }

            EditorGUILayout.PropertyField(wrapMode);


            if (follower.motion.applyRotation)
            {
                follower.applyDirectionRotation = EditorGUILayout.Toggle("Face Direction", follower.applyDirectionRotation);
            }


            EditorGUILayout.Space();
            EditorGUILayout.LabelField("Start Position", EditorStyles.boldLabel);
            EditorGUILayout.PropertyField(autoStartPosition, new GUIContent("Project"));
            EditorGUILayout.BeginHorizontal();
            EditorGUIUtility.labelWidth = 100f;
            if (!follower.autoStartPosition && !Application.isPlaying)
            {
                EditorGUILayout.PropertyField(startPosition, new GUIContent("Start Position"));
                if (GUILayout.Button("Set Distance", GUILayout.Width(85)))
                {
                    DistanceWindow w = EditorWindow.GetWindow <DistanceWindow>(true);
                    w.Init(OnSetDistance, follower.CalculateLength());
                }
            }
            else
            {
                EditorGUILayout.LabelField("Start position", GUILayout.Width(EditorGUIUtility.labelWidth));
            }
            EditorGUILayout.EndHorizontal();

            if (EditorGUI.EndChangeCheck())
            {
                serializedObject.ApplyModifiedProperties();
                if (!Application.isPlaying && follower.spline.sampleCount > 0)
                {
                    if (!follower.autoStartPosition)
                    {
                        follower.SetPercent(startPosition.floatValue);
                        if (!follower.follow)
                        {
                            SceneView.RepaintAll();
                        }
                    }
                }
            }
            base.BodyGUI();
        }
        void DrawTriggerGUI(int index, int groupIndex, SerializedProperty groupProperty)
        {
            bool               isSelected       = selected == index && selectedGroup == groupIndex;
            TriggerGroup       group            = spline.triggerGroups[groupIndex];
            SplineTrigger      trigger          = group.triggers[index];
            SerializedProperty triggersProperty = groupProperty.FindPropertyRelative("triggers");
            SerializedProperty triggerProperty  = triggersProperty.GetArrayElementAtIndex(index);
            SerializedProperty eventProperty    = triggerProperty.FindPropertyRelative("onCross");
            SerializedProperty positionProperty = triggerProperty.FindPropertyRelative("position");
            SerializedProperty colorProperty    = triggerProperty.FindPropertyRelative("color");
            SerializedProperty nameProperty     = triggerProperty.FindPropertyRelative("name");
            SerializedProperty enabledProperty  = triggerProperty.FindPropertyRelative("enabled");
            SerializedProperty workOnceProperty = triggerProperty.FindPropertyRelative("workOnce");
            SerializedProperty typeProperty     = triggerProperty.FindPropertyRelative("type");

            Color col = colorProperty.colorValue;

            if (isSelected)
            {
                col.a = 1f;
            }
            else
            {
                col.a = 0.6f;
            }
            GUI.backgroundColor = col;

            EditorGUILayout.BeginVertical(GUI.skin.box);
            GUI.backgroundColor = Color.white;
            if (trigger == null)
            {
                EditorGUILayout.BeginHorizontal();
                GUILayout.Label("NULL");
                if (GUILayout.Button("x"))
                {
                    ArrayUtility.RemoveAt(ref group.triggers, index);
                }
                EditorGUILayout.EndHorizontal();
                EditorGUILayout.EndVertical();
                return;
            }


            if (isSelected && renameTrigger)
            {
                if (Event.current.type == EventType.KeyDown && (Event.current.keyCode == KeyCode.Return || Event.current.keyCode == KeyCode.KeypadEnter))
                {
                    renameTrigger = false;
                    Repaint();
                }
                nameProperty.stringValue = EditorGUILayout.TextField(nameProperty.stringValue);
            }
            else
            {
                EditorGUILayout.LabelField(nameProperty.stringValue);
            }

            if (isSelected)
            {
                EditorGUILayout.Space();
                EditorGUILayout.PropertyField(enabledProperty);
                EditorGUILayout.PropertyField(colorProperty);

                EditorGUILayout.BeginHorizontal();
                positionProperty.floatValue = EditorGUILayout.Slider("Position", positionProperty.floatValue, 0f, 1f);
                if (GUILayout.Button("Set Distance", GUILayout.Width(85)))
                {
                    DistanceWindow w = EditorWindow.GetWindow <DistanceWindow>(true);
                    w.Init(OnSetDistance, spline.CalculateLength());
                    setDistanceGroup   = groupIndex;
                    setDistanceTrigger = index;
                }
                EditorGUILayout.EndHorizontal();
                EditorGUILayout.PropertyField(typeProperty);
                EditorGUILayout.PropertyField(workOnceProperty);

                EditorGUILayout.PropertyField(eventProperty);
            }
            EditorGUILayout.EndVertical();

            Rect lastRect = GUILayoutUtility.GetLastRect();

            if (lastRect.Contains(Event.current.mousePosition) && Event.current.type == EventType.MouseDown)
            {
                if (Event.current.button == 0)
                {
                    Select(groupIndex, index);
                }
                else if (Event.current.button == 1)
                {
                    GenericMenu menu = new GenericMenu();
                    menu.AddItem(new GUIContent("Deselect"), false, delegate { Select(-1, -1); });
                    menu.AddItem(new GUIContent("Rename"), false, delegate { Select(groupIndex, index); renameTrigger = true; renameGroup = false; });
                    if (index > 0)
                    {
                        menu.AddItem(new GUIContent("Move Up"), false, delegate {
                            RecordUndo("Move Trigger Up");
                            SplineTrigger temp        = group.triggers[index - 1];
                            group.triggers[index - 1] = trigger;
                            group.triggers[index]     = temp;
                            selected--;
                            renameTrigger = false;
                        });
                    }
                    else
                    {
                        menu.AddDisabledItem(new GUIContent("Move Up"));
                    }
                    if (index < group.triggers.Length - 1)
                    {
                        menu.AddItem(new GUIContent("Move Down"), false, delegate {
                            RecordUndo("Move Trigger Down");
                            SplineTrigger temp        = group.triggers[index + 1];
                            group.triggers[index + 1] = trigger;
                            group.triggers[index]     = temp;
                            selected--;
                            renameTrigger = false;
                        });
                    }
                    else
                    {
                        menu.AddDisabledItem(new GUIContent("Move Down"));
                    }

                    menu.AddItem(new GUIContent("Duplicate"), false, delegate {
                        RecordUndo("Duplicate Trigger");
                        SplineTrigger newTrigger = new SplineTrigger(SplineTrigger.Type.Double);
                        newTrigger.color         = colorProperty.colorValue;
                        newTrigger.enabled       = enabledProperty.boolValue;
                        newTrigger.position      = positionProperty.floatValue;
                        newTrigger.type          = (SplineTrigger.Type)typeProperty.intValue;
                        newTrigger.name          = "Trigger " + (group.triggers.Length + 1);
                        ArrayUtility.Add(ref group.triggers, newTrigger);
                        Select(groupIndex, group.triggers.Length - 1);
                    });
                    menu.AddItem(new GUIContent("Delete"), false, delegate {
                        RecordUndo("Delete Trigger");
                        ArrayUtility.RemoveAt(ref group.triggers, index);
                        Select(-1, -1);
                    });
                    menu.ShowAsContext();
                }
            }
        }