public override void OnInspectorGUI()
        {
            DrawDocumentationIcon();

            serializedObject.Update();

            Timekeeper timekeeper = (Timekeeper)serializedObject.targetObject;

            EditorGUILayout.PropertyField(debug, new GUIContent("Debug Mode"));

            EditorGUILayout.HelpBox("Add global clocks to this object to configure each clock individually.", MessageType.Info);

            string[] duplicates = timekeeper.GetComponents <GlobalClock>()
                                  .Select(gc => gc.key)
                                  .Where(k => !string.IsNullOrEmpty(k))
                                  .GroupBy(k => k)
                                  .Where(g => g.Count() > 1)
                                  .Select(y => y.Key)
                                  .ToArray();

            if (duplicates.Length > 0)
            {
                EditorGUILayout.HelpBox("The following global clocks have identical keys:\n" + string.Join("\n", duplicates.Select(d => "    - " + d).ToArray()), MessageType.Error);
            }

            serializedObject.ApplyModifiedProperties();
        }
示例#2
0
        public override void OnInspectorGUI()
        {
            DrawDocumentationIcon();

            serializedObject.Update();

            if (!serializedObject.isEditingMultipleObjects)
            {
                Timekeeper timekeeper = ((Clock)serializedObject.targetObject).GetComponent <Timekeeper>();

                if (timekeeper == null || !timekeeper.enabled)
                {
                    EditorGUILayout.HelpBox("Global clocks only function when attached to the timekeeper.", MessageType.Error);
                }
            }

            EditorGUILayout.PropertyField(key, new GUIContent("Key"));

            base.OnInspectorGUI();

            if (!key.hasMultipleDifferentValues &&
                string.IsNullOrEmpty(key.stringValue))
            {
                EditorGUILayout.HelpBox("The key cannot be empty.", MessageType.Error);
            }

            serializedObject.ApplyModifiedProperties();
        }
        public override void OnInspectorGUI()
        {
            serializedObject.Update();

            if (!serializedObject.isEditingMultipleObjects)
            {
                TAreaClock clock = (TAreaClock)serializedObject.targetObject;

                Timekeeper timekeeper = clock.GetComponent <Timekeeper>();

                if (timekeeper != null)
                {
                    EditorGUILayout.HelpBox("Only global clocks should be attached to the timekeeper.", MessageType.Error);
                }

                CheckForCollider();
            }

            base.OnInspectorGUI();

            EditorGUILayout.PropertyField(mode, new GUIContent("Mode"));

            if (!mode.hasMultipleDifferentValues &&
                mode.enumValueIndex != (int)AreaClockMode.Instant)
            {
                if (!serializedObject.isEditingMultipleObjects)                 // TODO: Multiple object editing
                {
                    // Bug: Doesn't work in Unity 2017.2.
                    // https://issuetracker.unity3d.com/issues/editorguilayout-dot-curvefield-does-not-return-edited-curve-when-dynamically-creating-curve
                    // https://issuetracker.unity3d.com/issues/animationcurve-value-cannot-be-changed-in-custom-inspector-when-it-is-accessed-as-serialized-propertys-animationcurvevalue
                    // curve.animationCurveValue = EditorGUILayout.CurveField(new GUIContent("Curve"),
                    //                                                     curve.animationCurveValue,
                    //                                                     Color.magenta,
                    //                                                     new Rect(0, -1, 1, 2),
                    //                                                     GUILayout.Height(30));
                    // Moreover, CurveField doesn't seemt trigger GUI.changed, so we can't rely on that for optimization

                    // Fallback to fix the bug:
                    Undo.RecordObject(serializedObject.targetObject, "Modify Area Clock Curve");
                    TAreaClock clock = (TAreaClock)serializedObject.targetObject;
                    clock.curve = EditorGUILayout.CurveField(new GUIContent("Curve"),
                                                             clock.curve,
                                                             Color.magenta,
                                                             new Rect(0, -1, 1, 2),
                                                             GUILayout.Height(30));
                }

                if (mode.enumValueIndex == (int)AreaClockMode.PointToEdge)
                {
                    EditorGUILayout.PropertyField(center, new GUIContent("Center"));
                }
                else if (mode.enumValueIndex == (int)AreaClockMode.DistanceFromEntry)
                {
                    EditorGUILayout.PropertyField(padding, new GUIContent("Padding"));
                }
            }

            serializedObject.ApplyModifiedProperties();
        }
示例#4
0
        public override void OnInspectorGUI()
        {
            DrawDocumentationIcon();

            serializedObject.Update();

            if (!serializedObject.isEditingMultipleObjects)
            {
                TAreaClock clock = (TAreaClock)serializedObject.targetObject;

                Timekeeper timekeeper = clock.GetComponent <Timekeeper>();

                if (timekeeper != null)
                {
                    EditorGUILayout.HelpBox("Only global clocks should be attached to the timekeeper.", MessageType.Error);
                }

                CheckForCollider();
            }

            base.OnInspectorGUI();

            EditorGUILayout.PropertyField(mode, new GUIContent("Mode"));

            if (!mode.hasMultipleDifferentValues &&
                mode.enumValueIndex != (int)AreaClockMode.Instant)
            {
                if (!curve.hasMultipleDifferentValues)                 // TODO: Multiple different values editing
                {
                    Undo.RecordObjects(serializedObject.targetObjects, "_curve");
                    curve.animationCurveValue = EditorGUILayout.CurveField(new GUIContent("Curve"),
                                                                           curve.animationCurveValue,
                                                                           Color.magenta,
                                                                           new Rect(0, -1, 1, 2),
                                                                           GUILayout.Height(30));
                }

                if (mode.enumValueIndex == (int)AreaClockMode.PointToEdge)
                {
                    EditorGUILayout.PropertyField(center, new GUIContent("Center"));
                }
                else if (mode.enumValueIndex == (int)AreaClockMode.DistanceFromEntry)
                {
                    EditorGUILayout.PropertyField(padding, new GUIContent("Padding"));
                }
            }

            serializedObject.ApplyModifiedProperties();
        }
        private static void MenuCommand(MenuCommand menuCommand)
        {
            if (GameObject.FindObjectOfType <Timekeeper>() != null)
            {
                EditorUtility.DisplayDialog("Chronos", "The scene already contains a timekeeper.", "OK");
                return;
            }

            GameObject go = new GameObject("Timekeeper");

            GameObjectUtility.SetParentAndAlign(go, menuCommand.context as GameObject);
            Timekeeper timekeeper = go.AddComponent <Timekeeper>();

            timekeeper.AddClock("Root");
            Undo.RegisterCreatedObjectUndo(go, "Create " + go.name);
            Selection.activeObject = go;
        }
示例#6
0
        public override void OnInspectorGUI()
        {
            serializedObject.Update();

            if (!serializedObject.isEditingMultipleObjects)
            {
                LocalClock clock      = (LocalClock)serializedObject.targetObject;
                Timekeeper timekeeper = clock.GetComponent <Timekeeper>();

                if (timekeeper != null)
                {
                    EditorGUILayout.HelpBox("Only global clocks should be attached to the timekeeper.", MessageType.Error);
                }
            }

            base.OnInspectorGUI();

            serializedObject.ApplyModifiedProperties();
        }