コード例 #1
0
ファイル: HOTweenEditorGUI.cs プロジェクト: yinlei/iss
    static void DrawTargetSelectionMode()
    {
        if (Selection.transforms.Length == 0 || Selection.transforms[0].gameObject != selection)
        {
            if (Event.current.type == EventType.Repaint)
            {
                panelMode = HOTweenPanelMode.Default;
            }
        }
        if (GUILayout.Button("Cancel", GUILayout.Height(24)))
        {
            panelMode = HOTweenPanelMode.Default;
        }
        GUILayout.Space(HOTweenEditorGUI.ControlsVPadding);
        List <ObjectData> objDatas = objDatasCollection[objDatasCollection.Count - 1];
        ObjectData        o;

        for (int i = 0; i < objDatas.Count; ++i)
        {
            o = objDatas[i];
            if (i == 0)
            {
                HOGUILayout.Vertical(GUI.skin.box, () => {
                    GUILayout.Label("Select tween target...", HOGUIStyle.centeredLabel);
                    HOGUILayout.Horizontal(GUI.skin.box, () => {
                        GUILayout.Label(GetSelectionTargetPath(), HOGUIStyle.centeredLabelBold);
                    });
                    HOGUILayout.Horizontal(() => {
                        if (objDatasCollection.Count > 1)
                        {
                            if (GUILayout.Button("<- Back", HOGUIStyle.button, GUILayout.Width(60), GUILayout.Height(24)))
                            {
                                objDatasCollection.RemoveAt(objDatasCollection.Count - 1);
                            }
                        }
                        if (HOGUILayout.ColoredButton("Tween this!", HOGUIStyle.button, HOTweenEditorVars.strongButtonBgColor, HOTweenEditorVars.strongButtonFontColor, GUILayout.Height(24)))
                        {
                            undoManager.ForceDirty();
                            SelectTweenTarget(o);
                        }
                    });
                });
                GUILayout.Space(HOTweenEditorGUI.ControlsVPadding);
                GUILayout.BeginVertical();
                GUILayout.Label("...or search inner elements", HOGUIStyle.centeredLabel);
            }
            else
            {
                if (GUILayout.Button(o.name + "\n(" + o.type + ")", HOGUIStyle.menubarButton, GUILayout.Height(30)))
                {
                    objDatasCollection.Add(GetTargetAndSubTargets(o.obj, o.name));
                }
            }
        }
        GUILayout.EndVertical();
    }
コード例 #2
0
ファイル: HOTweenEditorGUI.cs プロジェクト: yinlei/iss
    static void DrawTweens()
    {
        src.tweenDatas.Sort(SortTweenDatas);
        int tweensCount = src.tweenDatas.Count;

        for (int i = 0; i < tweensCount; ++i)
        {
            EditorGUIUtility.LookLikeControls(81);
            HOTweenManager.HOTweenData twData = src.tweenDatas[i];
            HOTweenManager.HOPropData  propData;
            PluginData plugData      = null;
            bool       invalidTarget = twData.targetRoot == null;
            bool       emptyTween    = twData.propDatas == null || twData.propDatas.Count == 0;

            // Group everything to allow drag
            HOGUILayout.Vertical(() => {
                Color toolbarColor = invalidTarget ? HOTweenEditorVars.errorBgColor : emptyTween ? HOTweenEditorVars.warningBgColor : HOTweenEditorVars.tweenToolbarColor;
                HOGUILayout.Toolbar(toolbarColor, () => {
                    twData.isActive = HOGUILayout.ToolbarToggle(twData.isActive);
                    twData.foldout  = HOGUILayout.MiniFoldout(twData.foldout, (twData.id == "" ? "" : "[" + twData.id + "] ") + (isManagerGUI ? twData.targetPath : twData.partialTargetPath), true);
                    if (HOGUILayout.ColoredButton(new GUIContent("+", "Add a property to tween"), HOGUIStyle.toolbarButton, HOTweenEditorVars.strongButtonBgColor, HOTweenEditorVars.strongButtonFontColor, GUILayout.Width(HOGUIStyle.IconButtonWidth * 2)))
                    {
                        currentTwData      = twData;
                        objDatasCollection = new List <List <ObjectData> >();
                        objDatasCollection.Add(GetProperties(twData.target));
                        panelMode = HOTweenPanelMode.PropertySelection;
                    }
                    if (GUILayout.Button(new GUIContent("╣", "Duplicate this tween"), HOGUIStyle.toolbarIconButton))
                    {
                        undoManager.ForceDirty();
                        HOTweenManager.HOTweenData twDataClone = twData.Clone(++src.creationTime);
                        foreach (HOTweenManager.HOPropData pd in twDataClone.propDatas)
                        {
                            StoreValidPluginsFor(twDataClone.targetType, pd);
                        }
                        src.tweenDatas.Add(twDataClone);
                        ++tweensCount;
                    }
                    if (isManagerGUI)
                    {
                        if (GUILayout.Button(new GUIContent("□", "Select GameObject"), HOGUIStyle.toolbarIconButton))
                        {
                            Selection.activeGameObject = twData.targetRoot;
                            EditorWindow h             = GetHierarchyPanel();
                            if (h != null)
                            {
                                h.Focus();            // Focus Hierarchy panel.
                            }
                        }
                    }
                    if (HOGUILayout.ColoredButton(new GUIContent("x", "Delete this tween"), HOGUIStyle.toolbarIconButton, Color.red, Color.white))
                    {
                        undoManager.ForceDirty();
                        src.tweenDatas.RemoveAt(i);
                        --tweensCount;
                    }
                });
                if (twData.foldout)
                {
                    if (invalidTarget)
                    {
                        GUILayout.Label("This tween's target doesn't exist anymore", HOGUIStyle.wordWrapLabelBold);
                        GUILayout.Space(4);
                    }
                    else
                    {
                        HOGUILayout.DisabledGroup(!twData.isActive, () => {
                            // General options toolbar
                            HOGUILayout.Toolbar(() => {
                                GUILayout.Label("Id", HOGUIStyle.miniLabel);
                                twData.id        = EditorGUILayout.TextField("", twData.id, HOGUIStyle.toolbarTextField, GUILayout.ExpandWidth(true));
                                twData.tweenFrom = HOGUILayout.ToggleButton(twData.tweenFrom, new GUIContent("From", "If selected the tween will animate FROM instead than TO the given value"), HOGUIStyle.toolbarButton, HOTweenEditorVars.toggleBgColor, HOTweenEditorVars.toggleFontColor, GUILayout.Width(40));
                                twData.paused    = !HOGUILayout.ToggleButton(!twData.paused, new GUIContent("Autoplay"), HOGUIStyle.toolbarButton, HOTweenEditorVars.toggleBgColor, HOTweenEditorVars.toggleFontColor, GUILayout.Width(60));
                                twData.autoKill  = HOGUILayout.ToggleButton(twData.autoKill, new GUIContent("Autokill", "If selected, destroys the tween after it reaches completion"), HOGUIStyle.toolbarButton, HOTweenEditorVars.toggleBgColor, HOTweenEditorVars.toggleFontColor, GUILayout.Width(60));
                            });
                            // Properties
                            int propDatasCount = twData.propDatas.Count;
                            for (int c = 0; c < propDatasCount; ++c)
                            {
                                HOGUILayout.Vertical(GUI.skin.box, () => {
                                    propData         = twData.propDatas[c];
                                    bool propDeleted = false;
                                    HOGUILayout.Horizontal(() => {
                                        propData.isActive = EditorGUILayout.Toggle(propData.isActive, GUILayout.Width(HOTweenEditorGUI.TinyToggleWidth));
                                        GUILayout.Label(propData.propName + " (" + propData.shortPropType + ")", HOGUIStyle.miniLabel);
                                        GUILayout.FlexibleSpace();
                                        if (GUILayout.Button(new GUIContent("╣", "Duplicate this property tween"), HOGUIStyle.iconButton))
                                        {
                                            undoManager.ForceDirty();
                                            HOTweenManager.HOPropData propDataClone = propData.Clone();
                                            StoreValidPluginsFor(twData.targetType, propDataClone);
                                            twData.propDatas.Add(propDataClone);
                                        }
                                        if (HOGUILayout.ColoredButton(new GUIContent("x", "Delete this property tween"), HOGUIStyle.iconButton, Color.white, Color.red))
                                        {
                                            undoManager.ForceDirty();
                                            dcPropDataToValidPluginDatas.Remove(propData);
                                            dcPropDataToValidPluginsEnum.Remove(propData);
                                            twData.propDatas.RemoveAt(c);
                                            --propDatasCount;
                                            propDeleted = true;
                                        }
                                    });
                                    if (!propDeleted)
                                    {
                                        HOGUILayout.DisabledGroup(!propData.isActive, () => {
                                            string[] propPluginsEnum = dcPropDataToValidPluginsEnum[propData];
                                            // Plugin type popup
                                            int ind = 0;
                                            // Get index of currently applied plugin.
                                            Type plugType = propData.pluginType;
                                            List <PluginData> propPlugins = dcPropDataToValidPluginDatas[propData];
                                            if (plugType != null)
                                            {
                                                for (int d = 0; d < propPlugins.Count; ++d)
                                                {
                                                    if (propPlugins[d].type == plugType)
                                                    {
                                                        ind = d;
                                                        break;
                                                    }
                                                }
                                            }
                                            else
                                            {
                                                propData.pluginType = propPlugins[0].type;
                                            }
                                            // Show popup
                                            HOGUILayout.DisabledGroup(propPluginsEnum.Length <= 1, () => {
                                                int newInd = EditorGUILayout.Popup("Plugin Type", ind, propPluginsEnum);
                                                if (newInd != ind)
                                                {
                                                    propData.pluginType = propPlugins[newInd].type;
                                                    propData.valueType  = null;
                                                }
                                            });
                                            // Property type popup.
                                            ind = 0;
                                            // Get reference to currently used plugin.
                                            foreach (PluginData pd in pluginDatas)
                                            {
                                                if (pd.type == propData.pluginType)
                                                {
                                                    plugData = pd;
                                                    break;
                                                }
                                            }
                                            if (plugData != null)
                                            {
                                                // Get index of currently used value type.
                                                Type valType = propData.valueType;
                                                if (valType != null)
                                                {
                                                    for (int d = 0; d < plugData.validValueTypes.Length; ++d)
                                                    {
                                                        if (plugData.validValueTypes[d] == valType)
                                                        {
                                                            ind = d;
                                                            break;
                                                        }
                                                    }
                                                }
                                                else
                                                {
                                                    propData.valueType = plugData.validValueTypes[0];
                                                }
                                                // Show popup
                                                HOGUILayout.DisabledGroup(plugData.validValueTypesEnum.Length <= 1, () => {
                                                    int newInd = EditorGUILayout.Popup("Value Type", ind, plugData.validValueTypesEnum);
                                                    if (newInd != ind)
                                                    {
                                                        propData.valueType = plugData.validValueTypes[newInd];
                                                    }
                                                });
                                            }
                                            // Value field.
                                            string twSuffix = "TO";
                                            if (twData.tweenFrom)
                                            {
                                                twSuffix = (propData.isRelative ? "BY FROM" : "FROM");
                                            }
                                            else
                                            {
                                                twSuffix = (propData.isRelative ? "BY" : "TO");
                                            }
                                            if (propData.valueType == typeof(Vector2))
                                            {
                                                propData.endVal = EditorGUILayout.Vector2Field("Tween " + twSuffix, (Vector2)propData.endVal);
                                            }
                                            else if (propData.valueType == typeof(Vector3))
                                            {
                                                propData.endVal = EditorGUILayout.Vector3Field("Tween " + twSuffix, (Vector3)propData.endVal);
                                            }
                                            else if (propData.valueType == typeof(Quaternion))
                                            {
                                                propData.endVal = EditorGUILayout.Vector4Field("Tween " + twSuffix, (Vector4)propData.endVal);
                                            }
                                            else if (propData.valueType == typeof(Color))
                                            {
                                                propData.endVal = EditorGUILayout.ColorField("Tween " + twSuffix, (Color)propData.endVal);
                                            }
                                            else if (propData.valueType == typeof(Int32))
                                            {
                                                propData.endVal = EditorGUILayout.IntField("Tween " + twSuffix, (int)propData.endVal);
                                            }
                                            else if (propData.valueType == typeof(String))
                                            {
                                                propData.endVal = EditorGUILayout.TextField("Tween " + twSuffix, (string)propData.endVal);
                                            }
                                            else if (propData.valueType == typeof(Single))
                                            {
                                                propData.endVal = EditorGUILayout.FloatField("Tween " + twSuffix, (float)propData.endVal);
                                            }
                                            else if (propData.valueType == typeof(Rect))
                                            {
                                                propData.endVal = EditorGUILayout.RectField("Tween " + twSuffix, (Rect)propData.endVal);
                                            }
                                            // Is relative.
                                            EditorGUIUtility.LookLikeControls(81);
                                            propData.isRelative = EditorGUILayout.Toggle("Relative", propData.isRelative);
                                        });
                                    }
                                });
                            }
                            // General tween parameters
                            // Other parameters.
                            HOGUILayout.Horizontal(() => {
                                EditorGUIUtility.LookLikeControls(86, 70);
                                twData.duration = EditorGUILayout.FloatField("Duration", twData.duration);
                                if (twData.duration < 0)
                                {
                                    twData.duration = 0;
                                }
                                GUILayout.Space(10);
                                EditorGUIUtility.LookLikeControls(50, 40);
                                twData.delay = EditorGUILayout.FloatField("Delay", twData.delay);
                                if (twData.delay < 0)
                                {
                                    twData.delay = 0;
                                }
                            });
                            HOGUILayout.Horizontal(() => {
                                EditorGUIUtility.LookLikeControls(86, 70);
                                twData.timeScale = EditorGUILayout.FloatField("TimeScale", twData.timeScale);
                                if (twData.timeScale < 0)
                                {
                                    twData.timeScale = 0;
                                }
                                GUILayout.Space(10);
                                EditorGUIUtility.LookLikeControls(50, 40);
                                twData.loops = EditorGUILayout.IntField("Loops", twData.loops);
                                if (twData.loops < -1)
                                {
                                    twData.loops = -1;
                                }
                            });
                            EditorGUIUtility.LookLikeControls(86, 100);
                            twData.updateType = (Holoville.HOTween.UpdateType)EditorGUILayout.EnumPopup("Update Type", twData.updateType);
                            HOGUILayout.DisabledGroup(twData.loops == 0 || twData.loops == 1, () => {
                                twData.loopType = (Holoville.HOTween.LoopType)EditorGUILayout.EnumPopup("Loop Type", twData.loopType);
                            });
                            twData.easeType = (Holoville.HOTween.EaseType)EditorGUILayout.EnumPopup("Ease Type", twData.easeType);
                            HOGUILayout.HorizontalDivider(2);
                            EditorGUIUtility.LookLikeControls(86, 100);
                            twData.onCompleteActionType = (HOTweenManager.HOTweenData.OnCompleteActionType)EditorGUILayout.EnumPopup("OnComplete", twData.onCompleteActionType);
                            if (twData.onCompleteActionType == HOTweenManager.HOTweenData.OnCompleteActionType.PlayTweensById)
                            {
                                twData.onCompletePlayId = EditorGUILayout.TextField("Id", twData.onCompletePlayId);
                            }
                            else if (twData.onCompleteActionType == HOTweenManager.HOTweenData.OnCompleteActionType.SendMessage)
                            {
                                HOGUILayout.ShadedGroup(twData.onCompleteTarget == null ? Color.red : GUI.backgroundColor, () => {
                                    twData.onCompleteTarget = EditorGUILayout.ObjectField("GameObject", twData.onCompleteTarget, typeof(GameObject), !EditorUtility.IsPersistent(src)) as GameObject;
                                });
                                HOGUILayout.ShadedGroup(twData.onCompleteMethodName == null || twData.onCompleteMethodName == "" ? Color.red : GUI.backgroundColor, () => {
                                    twData.onCompleteMethodName = EditorGUILayout.TextField("Method Name", twData.onCompleteMethodName);
                                });
                                twData.onCompleteParmType = (HOTweenManager.HOTweenData.ParameterType)EditorGUILayout.EnumPopup("Value type", twData.onCompleteParmType);
                                switch (twData.onCompleteParmType)
                                {
                                case HOTweenManager.HOTweenData.ParameterType.Color:
                                    twData.onCompleteParmColor = EditorGUILayout.ColorField("Value", twData.onCompleteParmColor);
                                    break;

                                case HOTweenManager.HOTweenData.ParameterType.Number:
                                    twData.onCompleteParmNumber = EditorGUILayout.FloatField("Value", twData.onCompleteParmNumber);
                                    break;

                                case HOTweenManager.HOTweenData.ParameterType.Object:
                                    twData.onCompleteParmObject = EditorGUILayout.ObjectField("Value", twData.onCompleteParmObject, typeof(UnityEngine.Object), !EditorUtility.IsPersistent(src));
                                    break;

                                case HOTweenManager.HOTweenData.ParameterType.Quaternion:
                                    twData.onCompleteParmQuaternion = (Quaternion.Euler(EditorGUILayout.Vector3Field("Value", twData.onCompleteParmQuaternion.eulerAngles)));
                                    break;

                                case HOTweenManager.HOTweenData.ParameterType.Rect:
                                    twData.onCompleteParmRect = EditorGUILayout.RectField("Value", twData.onCompleteParmRect);
                                    break;

                                case HOTweenManager.HOTweenData.ParameterType.String:
                                    twData.onCompleteParmString = EditorGUILayout.TextField("Value", twData.onCompleteParmString);
                                    break;

                                case HOTweenManager.HOTweenData.ParameterType.Vector2:
                                    twData.onCompleteParmVector2 = EditorGUILayout.Vector2Field("Value", twData.onCompleteParmVector2);
                                    break;

                                case HOTweenManager.HOTweenData.ParameterType.Vector3:
                                    twData.onCompleteParmVector3 = EditorGUILayout.Vector3Field("Value", twData.onCompleteParmVector3);
                                    break;

                                case HOTweenManager.HOTweenData.ParameterType.Vector4:
                                    twData.onCompleteParmVector4 = EditorGUILayout.Vector4Field("Value", twData.onCompleteParmVector4);
                                    break;
                                }
                            }
                            EditorGUIUtility.LookLikeControls(labelsWidth, fieldsWidth);
                            GUILayout.Space(HOTweenEditorGUI.ControlsVPadding);
                        });
                    }
                }
            });
        }
    }
コード例 #3
0
ファイル: HOTweenEditorGUI.cs プロジェクト: yinlei/iss
    static void DrawDefaultMode()
    {
        objDatasCollection = null;

        Transform[] selTrans = Selection.transforms;

        HOGUILayout.Menubar(22, HOTweenEditorVars.mainToolbarColor, () => {
            int twCount = src.tweenDatas.Count;
            GUILayout.Label(twCount + (twCount == 0 || twCount > 1 ? " Tweens" : " Tween"), HOGUIStyle.labelBold);
            if (src.TotEmptyTweens() > 0)
            {
                GUILayout.Label("(" + src.TotEmptyTweens() + " empty)", HOGUIStyle.miniLabel);
            }
            GUILayout.FlexibleSpace();
            GUIContent addLabel = isManagerGUI ? new GUIContent("+ Tween Selection", "Add a tween to the currently selected object") : new GUIContent("+ Add Tween", "Add a tween to this object or one of its Components");
            HOGUILayout.DisabledGroup(isManagerGUI && (selTrans.Length == 0 || selTrans.Length > 1), () => {
                if (HOGUILayout.ColoredButton(addLabel, HOGUIStyle.menubarButton, HOTweenEditorVars.strongButtonBgColor, HOTweenEditorVars.strongButtonFontColor))
                {
                    selection          = isManagerGUI ? selTrans[0].gameObject : src.gameObject;
                    currentTargetRoot  = selection;
                    objDatasCollection = new List <List <ObjectData> >();
                    objDatasCollection.Add(GetTargetAndSubTargets(selection, selection.name));
                    panelMode = HOTweenPanelMode.TargetSelection;
                }
            });
            if (isManagerGUI)
            {
                if (GUILayout.Button(new GUIContent("□", "Select all GameObjects that contain a tweened target"), HOGUIStyle.toolbarIconButton))
                {
                    List <GameObject> tRoots = new List <GameObject>();
                    foreach (HOTweenManager.HOTweenData td in src.tweenDatas)
                    {
                        if (td.targetRoot != null)
                        {
                            tRoots.Add(td.targetRoot);
                        }
                    }
                    Selection.objects = tRoots.ToArray();
                    EditorWindow h    = GetHierarchyPanel();
                    if (h != null)
                    {
                        h.Focus();            // Focus Hierarchy panel.
                    }
                }
            }
            else
            {
                componentSrc.destroyAfterSetup = HOGUILayout.ToggleButton(componentSrc.destroyAfterSetup, new GUIContent("AutoDestroy", "If selected, destroys this Component after the tween has been setup"), HOGUIStyle.toolbarButton, HOTweenEditorVars.toggleBgColor, HOTweenEditorVars.toggleFontColor);
            }
            if (HOGUILayout.ToolbarExpandButton("Expand all foldouts"))
            {
                bool expanded = false;
                foreach (HOTweenManager.HOTweenData td in src.tweenDatas)
                {
                    if (!td.foldout)
                    {
                        expanded = true;
                    }
                    td.foldout = true;
                }
                if (expanded)
                {
                    undoManager.ForceDirty();
                }
            }
            if (HOGUILayout.ToolbarCollapseButton("Collapse all foldouts"))
            {
                bool collapsed = false;
                foreach (HOTweenManager.HOTweenData td in src.tweenDatas)
                {
                    if (td.foldout)
                    {
                        collapsed = true;
                    }
                    td.foldout = false;
                }
                if (collapsed)
                {
                    undoManager.ForceDirty();
                }
            }
            GUILayout.Space(6);
        });
        HOGUILayout.Vertical(HOGUIStyle.blankBox, HOTweenEditorVars.globalsBgColor, () => {
            HOGUILayout.Horizontal(() => {
                EditorGUIUtility.LookLikeControls(80, 50);
                src.globalDelay = EditorGUILayout.FloatField("Global Delay", src.globalDelay);
                if (src.globalDelay < 0)
                {
                    src.globalDelay = 0;
                }
                EditorGUIUtility.LookLikeControls(104, 74);
                GUILayout.Space(10);
                src.globalTimeScale = EditorGUILayout.FloatField("GlobalTimeScale", src.globalTimeScale);
                if (src.globalTimeScale < 0)
                {
                    src.globalTimeScale = 0;
                }
            });
            GUILayout.Space(4);
        });

        DrawTweens();
    }