예제 #1
0
    static void DrawPropertySelectionMode()
    {
        if (GUILayout.Button("Cancel", HOGUIStyle.button, GUILayout.Height(24)))
        {
            panelMode = HOTweenPanelMode.Default;
        }
        GUILayout.Space(HOTweenEditorGUI.ControlsVPadding);
        GUILayout.BeginVertical();
        GUILayout.Label("Select a property to tween:", HOGUIStyle.centeredLabel);

        List <ObjectData> objDatas = objDatasCollection[0];
        ObjectData        o;

        HOTweenManager.HOPropData propData;
        for (int i = 0; i < objDatas.Count; ++i)
        {
            o = objDatas[i];
            if (GUILayout.Button(o.name + "\n(" + o.type + ")", HOGUIStyle.menubarButton, GUILayout.Height(30)))
            {
                undoManager.ForceDirty();
                propData = new HOTweenManager.HOPropData(o.name, o.type);
                currentTwData.propDatas.Add(propData);
                StoreValidPluginsFor(currentTwData.targetType, propData);
                currentTwData.propDatas.Sort(SortPropDatas);
                panelMode = HOTweenPanelMode.Default;
            }
        }

        GUILayout.EndVertical();
    }
예제 #2
0
    /// <summary>
    /// Stores in dictionaries the valid plugins and plugins enums for the given target and property.
    /// </summary>
    static void StoreValidPluginsFor(Type p_targetType, HOTweenManager.HOPropData p_propData)
    {
        List <PluginData> li = new List <PluginData>();

        foreach (PluginData plugData in pluginDatas)
        {
            if ((plugData.validTargetTypes == null || Array.IndexOf(plugData.validTargetTypes, p_targetType) != -1) &&
                (plugData.validPropTypes == null || Array.IndexOf(plugData.validPropTypes, p_propData.propType) != -1)
                )
            {
                li.Add(plugData);
            }
        }
        li.Sort(SortPluginDatas);
        dcPropDataToValidPluginDatas[p_propData] = li;
        string[] plugNames = new string[li.Count];
        for (int i = 0; i < plugNames.Length; ++i)
        {
            plugNames[i] = li[i].name;
        }
        dcPropDataToValidPluginsEnum[p_propData] = plugNames;
    }
예제 #3
0
    static void DrawPropertySelectionMode()
    {
        if (GUILayout.Button("Cancel", HOGUIStyle.button, GUILayout.Height(24))) panelMode = HOTweenPanelMode.Default;
        GUILayout.Space(HOTweenEditorGUI.ControlsVPadding);
        GUILayout.BeginVertical();
        GUILayout.Label("Select a property to tween:", HOGUIStyle.centeredLabel);

        List<ObjectData> objDatas = objDatasCollection[0];
        ObjectData o;
        HOTweenManager.HOPropData propData;
        for (int i = 0; i < objDatas.Count; ++i) {
            o = objDatas[i];
            if (GUILayout.Button(o.name + "\n(" + o.type + ")", HOGUIStyle.menubarButton, GUILayout.Height(30))) {
                undoManager.ForceDirty();
                propData = new HOTweenManager.HOPropData(o.name, o.type);
                currentTwData.propDatas.Add(propData);
                StoreValidPluginsFor(currentTwData.targetType, propData);
                currentTwData.propDatas.Sort(SortPropDatas);
                panelMode = HOTweenPanelMode.Default;
            }
        }

        GUILayout.EndVertical();
    }
예제 #4
0
    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);
                        });
                    }
                }
            });
        }
    }
예제 #5
0
 static int SortPropDatas(HOTweenManager.HOPropData p1, HOTweenManager.HOPropData p2)
 {
     return(String.Compare(p1.propName, p2.propName));
 }