示例#1
0
 public static void DrawGenericProperty <T>(ref T propertyValue, string propertyName, Object recordingObject = null)
 {
     DrawGenericProperty(ref propertyValue, Color.white, new GUIContent(TSSText.GetHumanReadableString(propertyName)), recordingObject);
 }
示例#2
0
        public static void DrawItemProperty(TSSItem item, string propertyName, string displayPropertyName = null, GUILayoutOption displayPropertyOption = null, bool shortCheckBox = false, bool alternative = false)
        {
            GUI.color           = Color.white;
            GUI.backgroundColor = Color.white;

            if (!ItemPropertyIsValid(propertyName))
            {
                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.HelpBox(string.Format(invalidPropertyName.text, propertyName), MessageType.Warning);
                EditorGUILayout.EndHorizontal();
                return;
            }

            if (string.IsNullOrEmpty(displayPropertyName))
            {
                displayPropertyName = propertyName;
            }
            if (displayPropertyOption == null)
            {
                displayPropertyOption = TSSEditorUtils.max100pxWidth;
            }

            Type propertyType = GetItemPropertyType(propertyName);

            EditorGUI.BeginChangeCheck();
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField(TSSText.GetHumanReadableString(displayPropertyName), displayPropertyOption);

            if (propertyType == typeof(float))
            {
                float displayedValue      = GetItemValue <float>(item, propertyName);
                bool  itemValuesIdentical = ValuesIsIdentical(GetSelectedItemsValues <float>(propertyName));
                if (!itemValuesIdentical)
                {
                    EditorGUI.showMixedValue = true;
                }
                float enteredValue = Mathf.Clamp(EditorGUILayout.FloatField(displayedValue), 0, float.MaxValue);
                if (EditorGUI.EndChangeCheck())
                {
                    SelectedItemsSetValue(propertyName, enteredValue);
                }
            }
            else if (propertyType == typeof(bool))
            {
                bool displayedValue      = GetItemValue <bool>(item, propertyName);
                bool itemValuesIdentical = ValuesIsIdentical(GetSelectedItemsValues <bool>(propertyName));
                if (!itemValuesIdentical)
                {
                    EditorGUI.showMixedValue = true;
                }
                bool enteredValue = EditorGUILayout.Toggle(displayedValue, shortCheckBox ? TSSEditorUtils.max18pxWidth : TSSEditorUtils.max120pxWidth);
                if (EditorGUI.EndChangeCheck())
                {
                    SelectedItemsSetValue(propertyName, enteredValue);
                }
            }
            else if (propertyType == typeof(string))
            {
                string displayedValue      = GetItemValue <string>(item, propertyName);
                bool   itemValuesIdentical = ValuesIsIdentical(GetSelectedItemsValues <string>(propertyName));
                if (!itemValuesIdentical)
                {
                    EditorGUI.showMixedValue = true;
                }
                string enteredValue = EditorGUILayout.TextField(displayedValue);
                if (EditorGUI.EndChangeCheck())
                {
                    SelectedItemsSetValue(propertyName, enteredValue);
                }
            }
            else if (propertyType == typeof(int))
            {
                int  displayedValue      = GetItemValue <int>(item, propertyName);
                bool itemValuesIdentical = ValuesIsIdentical(GetSelectedItemsValues <int>(propertyName));
                if (!itemValuesIdentical)
                {
                    EditorGUI.showMixedValue = true;
                }
                int enteredValue = EditorGUILayout.IntField(displayedValue);
                if (EditorGUI.EndChangeCheck())
                {
                    SelectedItemsSetValue(propertyName, enteredValue);
                }
            }
            else if (propertyType == typeof(ChainDirection))
            {
                ChainDirection displayedValue      = GetItemValue <ChainDirection>(item, propertyName);
                bool           itemValuesIdentical = ValuesIsIdentical(GetSelectedItemsValues <ChainDirection>(propertyName));
                if (!itemValuesIdentical)
                {
                    EditorGUI.showMixedValue = true;
                }
                ChainDirection enteredValue = (ChainDirection)EditorGUILayout.EnumPopup(displayedValue);
                if (EditorGUI.EndChangeCheck())
                {
                    SelectedItemsSetValue(propertyName, enteredValue);
                }
            }
            else if (propertyType == typeof(RotationMode))
            {
                RotationMode displayedValue      = GetItemValue <RotationMode>(item, propertyName);
                bool         itemValuesIdentical = ValuesIsIdentical(GetSelectedItemsValues <RotationMode>(propertyName));
                if (!itemValuesIdentical)
                {
                    EditorGUI.showMixedValue = true;
                }
                RotationMode enteredValue = (RotationMode)EditorGUILayout.EnumPopup(displayedValue);
                if (EditorGUI.EndChangeCheck())
                {
                    SelectedItemsSetValue(propertyName, enteredValue);
                }
            }
            else if (propertyType == typeof(MaterialMode))
            {
                MaterialMode displayedValue      = GetItemValue <MaterialMode>(item, propertyName);
                bool         itemValuesIdentical = ValuesIsIdentical(GetSelectedItemsValues <MaterialMode>(propertyName));
                if (!itemValuesIdentical)
                {
                    EditorGUI.showMixedValue = true;
                }
                MaterialMode enteredValue = (MaterialMode)EditorGUILayout.EnumPopup(displayedValue);
                if (EditorGUI.EndChangeCheck())
                {
                    SelectedItemsSetValue(propertyName, enteredValue);
                }
            }
            else if (propertyType == typeof(AnimationCurve))
            {
                AnimationCurve displayedValue      = GetItemValue <AnimationCurve>(item, propertyName);
                bool           itemValuesIdentical = ValuesIsIdentical(GetSelectedItemsValues <AnimationCurve>(propertyName));
                if (!itemValuesIdentical)
                {
                    EditorGUI.showMixedValue = true;
                }
                AnimationCurve enteredValue = (AnimationCurve)EditorGUILayout.CurveField(displayedValue);
                if (EditorGUI.EndChangeCheck())
                {
                    SelectedItemsSetValue(propertyName, enteredValue);
                }
            }
            else if (propertyType == typeof(TSSProfile))
            {
                TSSProfile displayedValue      = GetItemValue <TSSProfile>(item, propertyName);
                bool       itemValuesIdentical = ValuesIsIdentical(GetSelectedItemsValues <TSSProfile>(propertyName));
                if (!itemValuesIdentical)
                {
                    EditorGUI.showMixedValue = true;
                }
                TSSProfile enteredValue = (TSSProfile)EditorGUILayout.ObjectField(displayedValue, typeof(TSSProfile), false);
                if (EditorGUI.EndChangeCheck())
                {
                    SelectedItemsSetValue(propertyName, enteredValue);
                    if (enteredValue != null && EditorUtility.DisplayDialog(confirmRevertTitle.text, string.Format(confirmRevertMessage.text, item.profile.name), "Yes", "No"))
                    {
                        TSSProfile.ProfileRevert(item, item.profile);
                    }
                }
            }
            else if (propertyType == typeof(ActivationMode))
            {
                if (alternative)
                {
                    ItemLoopModePattern displayedValue = ActivationModeToLoopPattern(GetItemValue <ActivationMode>(item, propertyName));
                    bool itemValuesIdentical           = ValuesIsIdentical(GetSelectedItemsValues <ActivationMode>(propertyName));
                    if (!itemValuesIdentical)
                    {
                        EditorGUI.showMixedValue = true;
                    }
                    ItemLoopModePattern enteredValue = (ItemLoopModePattern)EditorGUILayout.EnumPopup(displayedValue);
                    if (EditorGUI.EndChangeCheck())
                    {
                        SelectedItemsSetValue(propertyName, LoopPatternToActivationMode(enteredValue));
                    }
                }
                else
                {
                    ActivationMode displayedValue      = GetItemValue <ActivationMode>(item, propertyName);
                    bool           itemValuesIdentical = ValuesIsIdentical(GetSelectedItemsValues <ActivationMode>(propertyName));
                    if (!itemValuesIdentical)
                    {
                        EditorGUI.showMixedValue = true;
                    }
                    ActivationMode enteredValue = (ActivationMode)EditorGUILayout.EnumPopup(displayedValue);
                    if (EditorGUI.EndChangeCheck())
                    {
                        SelectedItemsSetValue(propertyName, enteredValue);
                    }
                }
            }
            else if (propertyType == typeof(ButtonDirection))
            {
                ButtonDirection displayedValue      = GetItemValue <ButtonDirection>(item, propertyName);
                bool            itemValuesIdentical = ValuesIsIdentical(GetSelectedItemsValues <ButtonDirection>(propertyName));
                if (!itemValuesIdentical)
                {
                    EditorGUI.showMixedValue = true;
                }
                ButtonDirection enteredValue = (ButtonDirection)EditorGUILayout.EnumPopup(displayedValue);
                if (EditorGUI.EndChangeCheck())
                {
                    SelectedItemsSetValue(propertyName, enteredValue);
                }
            }
            else if (propertyType == typeof(ItemUpdateType))
            {
                ItemUpdateType displayedValue      = GetItemValue <ItemUpdateType>(item, propertyName);
                bool           itemValuesIdentical = ValuesIsIdentical(GetSelectedItemsValues <ItemUpdateType>(propertyName));
                if (!itemValuesIdentical)
                {
                    EditorGUI.showMixedValue = true;
                }
                ItemUpdateType enteredValue = (ItemUpdateType)EditorGUILayout.EnumPopup(displayedValue);
                if (EditorGUI.EndChangeCheck())
                {
                    SelectedItemsSetValue(propertyName, enteredValue);
                }
            }
            else if (propertyType == typeof(PathNormal))
            {
                PathNormal displayedValue      = GetItemValue <PathNormal>(item, propertyName);
                bool       itemValuesIdentical = ValuesIsIdentical(GetSelectedItemsValues <PathNormal>(propertyName));
                if (!itemValuesIdentical)
                {
                    EditorGUI.showMixedValue = true;
                }
                PathNormal enteredValue = (PathNormal)EditorGUILayout.EnumPopup(displayedValue);
                if (EditorGUI.EndChangeCheck())
                {
                    SelectedItemsSetValue(propertyName, enteredValue);
                }
            }


            EditorGUILayout.EndHorizontal();

            EditorGUI.showMixedValue = false;
        }
示例#3
0
        private void DrawItemOnTimeLine(TSSItem item, Vector2 position)
        {
            position.y = controlLineHeight + itemCount * (itemHeight + itemLineSpacing);

            if (item.parent != null && ItemChildBefore(item.parent))
            {
                position.x -= (ItemDelay(item.parent) - ItemDelay(item)) / GetPeriod() * timeLineRect.width;
            }
            else
            {
                position.x += ItemDelay(item) / GetPeriod() * timeLineRect.width;
            }

            bool itemChained   = (item.parent != null && item.parent.childChainMode);
            Rect itemRect      = new Rect(position.x, position.y, timeLineRect.width * ItemDuration(item) / GetPeriod(), itemHeight);
            Rect itemTitleRect = new Rect(itemRect.x + (itemChained ? 24 : 12), itemRect.y + itemRect.height * 0.5f - 6, itemRect.width - 24, 24);


            if (selectedItem == item)
            {
                if (!itemChained)
                {
                    EditorGUIUtility.AddCursorRect(new Rect(itemRect.x - itemHandleSize, itemRect.y, itemHandleSize * 2, itemHeight), MouseCursor.ResizeHorizontal);
                }
                EditorGUIUtility.AddCursorRect(new Rect(itemRect.x + itemHandleSize, itemRect.y, itemRect.width - itemHandleSize * 2, itemHeight), MouseCursor.SlideArrow);

                EditorGUIUtility.AddCursorRect(new Rect(itemRect.x + itemRect.width - itemHandleSize, itemRect.y, itemHandleSize * 2, itemHeight), MouseCursor.ResizeHorizontal);
            }
            else
            {
                EditorGUIUtility.AddCursorRect(itemRect, MouseCursor.Link);
            }

            if (boolMousePressed && new Rect(itemRect.x - itemHandleSize, itemRect.y, itemRect.width + itemHandleSize * 2, itemRect.height).Contains(mousePosition))
            {
                selectedItem     = item;
                selectedItemRect = itemRect;
                boolMousePressed = false;

                controlLineSelectionPosition = itemRect.x;
                controlLineSelectionSize     = itemRect.width;

                Selection.SetActiveObjectWithContext(item.gameObject, item);
                Undo.RegisterCompleteObjectUndo(item, "[TSS TimeLine]");
            }

            lastBackColor = !lastBackColor;
            if (!lastBackColor)
            {
                EditorGUI.DrawRect(new Rect(timeLineRect.x, itemRect.y - itemLineSpacing, timeLineRect.width, itemHeight + itemLineSpacing), new Color(0, 0, 0, 0.125f));
            }

            float itemEffectsValue = 0;

            if (itemRect.x > controlLineHandlerPosition)
            {
                itemEffectsValue = 0;
            }
            else if (itemRect.x + itemRect.width < controlLineHandlerPosition)
            {
                itemEffectsValue = 1;
            }
            else
            {
                itemEffectsValue = (controlLineHandlerPosition - itemRect.x) / itemRect.width;
            }

            if (direction == ItemKey.closed)
            {
                itemEffectsValue = 1 - itemEffectsValue;
            }


            if ((controlLineHandlerSelected || timeLinePlaying) && item.tweens.Count > 0)
            {
                item.state = ItemState.slave;

                if (mode == Mode.openClode)
                {
                    if (direction == ItemKey.closed && controlLineHandlerPosition > timeLineRect.width)
                    {
                        TSSItemBase.Evaluate(item, Mathf.Clamp01(itemEffectsValue), ItemKey.closed);
                    }
                    if (direction == ItemKey.opened && controlLineHandlerPosition < timeLineRect.width)
                    {
                        TSSItemBase.Evaluate(item, Mathf.Clamp01(itemEffectsValue), ItemKey.opened);
                    }
                }
                else
                {
                    TSSItemBase.Evaluate(item, Mathf.Clamp01(itemEffectsValue), direction);
                }
            }


            GUI.Box(itemRect, string.Empty, item == selectedItem ? itemSelectedStyle : (itemChained ? itemChainStyle : itemStyle));
            GUI.Label(itemTitleRect, TSSText.GetHumanReadableString(item.name), itemTitleStyle);

            if (itemChained)
            {
                Rect chainIconRect = new Rect(itemRect.x + 7, itemRect.y + itemRect.height * 0.5f - 7, 14, 14);
                GUI.DrawTexture(chainIconRect, TSSEditorTextures.itemChainIcon, ScaleMode.StretchToFill);
            }

            if (item == selectedItem)
            {
                if (!itemChained)
                {
                    Handles.color = new Color(1, 1, 1, 0.5f);
                    Handles.color = Color.white;
                    Handles.DrawLine(new Vector2(itemRect.x, itemRect.y), new Vector2(itemRect.x, itemRect.y + itemRect.height));
                }

                Handles.color = Color.white;
                Handles.DrawLine(new Vector2(itemRect.x + itemRect.width, itemRect.y), new Vector2(itemRect.x + itemRect.width, itemRect.y + itemRect.height));
            }

            if (item.parent == selectedItem && selectedItem != null)
            {
                EditorGUI.DrawRect(itemRect, new Color(0.45f, 0.66f, 1f, 0.15f));
            }
            else if (selectedItem != null)
            {
                EditorGUI.DrawRect(itemRect, new Color(0, 0, 0, 0.15f));
            }

            itemCount++;

            for (int i = 0; i < item.childItems.Count; i++)
            {
                DrawItemOnTimeLine(item.childItems[i], position);
            }
        }