Esempio n. 1
0
        private void ConfgureSubObject(ref EasyTween.EasyTweenSubObject subObject, int tweenIndex, int subIndex)
        {
            using (new GUILayout.HorizontalScope())
            {
                GUILayout.Label("Variable");

                if (GUILayout.Button(subObject.targetComponentName + "/" + subObject.targetVariableName, GUI.skin.GetStyle("Popup")))
                {
                    m_TempTweenIndex    = tweenIndex;
                    m_TempSubTweenIndex = subIndex;
                    VariableMenu(m_ScriptTarget.tweens[m_TempTweenIndex].targetGameObject, m_ScriptTarget.tweens[m_TempTweenIndex]).ShowAsContext();
                    return;
                }

                if (m_ScriptTarget.tweens[tweenIndex].subTweens.Count > 1)
                {
                    if (GUILayout.Button("-", GUILayout.Width(CalcWidth("-") + 8f), GUILayout.Height(18f)))
                    {
                        RemoveSubTweener(tweenIndex, subIndex);
                    }
                }
            }

            if (subObject.targetComponent != null)
            {
                ConfigureTargetValue(ref subObject, tweenIndex, subIndex);
            }

            EditorGUILayout.Space();
            EditorGUILayout.Space();
        }
Esempio n. 2
0
        public void VariableMenuCallback(object item)
        {
            string theString = (string)item;

            string[] stringArray = theString.Split('/');

            EasyTween.EasyTweenObject    tweenObject = m_ScriptTarget.tweens[m_TempTweenIndex];
            EasyTween.EasyTweenSubObject subObject   = m_ScriptTarget.tweens[m_TempTweenIndex].subTweens[m_TempSubTweenIndex];

            subObject.targetComponent     = tweenObject.targetGameObject.GetComponent(stringArray[0]);
            subObject.targetComponentName = subObject.targetComponent.GetType().Name;

            subObject.targetFieldInfo    = subObject.targetComponent.GetType().GetField(stringArray[1]);
            subObject.targetPropertyInfo = subObject.targetComponent.GetType().GetProperty(stringArray[1]);

            if (subObject.targetFieldInfo != null)
            {
                subObject.isProperty         = false;
                subObject.variableType       = subObject.targetFieldInfo.GetValue(subObject.targetComponent).GetType().Name;
                subObject.targetVariableName = subObject.targetFieldInfo.Name;
            }
            if (subObject.targetPropertyInfo != null)
            {
                subObject.isProperty         = true;
                subObject.variableType       = subObject.targetPropertyInfo.GetValue(subObject.targetComponent, null).GetType().Name;
                subObject.targetVariableName = subObject.targetPropertyInfo.Name;
            }

            if (subObject.variableType == "Int32" || subObject.variableType == "Single")
            {
                subObject.targetValueLength = 1;
            }
            if (subObject.variableType == "Vector2")
            {
                subObject.targetValueLength = 2;
            }
            if (subObject.variableType == "Vector3")
            {
                subObject.targetValueLength = 3;
            }
            if (subObject.variableType == "Vector4" || subObject.variableType == "Rect" || subObject.variableType == "Color")
            {
                subObject.targetValueLength = 4;
            }

            m_ScriptTarget.tweens[m_TempTweenIndex].subTweens[m_TempSubTweenIndex] = subObject;
        }
Esempio n. 3
0
        private void ConfigureTargetValue(ref EasyTween.EasyTweenSubObject subObject, int tweenIndex, int subIndex)
        {
            string[] subStrings = { "" };

            if (subObject.variableType == "Int32" || subObject.variableType == "Single")
            {
                subStrings = new[] { "value" };
            }
            if (subObject.variableType == "Vector2")
            {
                subStrings = new[] { "X", "Y" };
            }
            if (subObject.variableType == "Vector3")
            {
                subStrings = new[] { "X", "Y", "Z" };
            }
            if (subObject.variableType == "Vector4")
            {
                subStrings = new[] { "X", "Y", "Z", "W" };
            }
            if (subObject.variableType == "Rect")
            {
                subStrings = new[] { "X", "Y", "Width", "Height" };
            }
            if (subObject.variableType == "Color")
            {
                subStrings = new[] { "R", "G", "B", "A" };
            }

            EditorGUILayout.Space();

            using (new GUILayout.HorizontalScope())
            {
                EditorGUILayout.LabelField("Target values", GUILayout.Width(CalcWidth("TargetValues") + 8f));
            }
            GUILayout.FlexibleSpace();
            if (GUILayout.Button("Copy from gameObject", GUILayout.Width(CalcWidth("Copy from gameObject") + 8f)))
            {
                object theValue;

                if (subObject.isProperty)
                {
                    Component component = m_ScriptTarget.GetComponent <EasyTween>().tweens[tweenIndex].targetGameObject.GetComponent(
                        m_ScriptTarget.GetComponent <EasyTween>().tweens[tweenIndex].subTweens[subIndex].targetComponentName);

                    string variableName =
                        m_ScriptTarget.GetComponent <EasyTween>().tweens[tweenIndex].subTweens[subIndex].targetVariableName;

                    theValue = component.GetType().GetProperty(variableName).GetValue(component, null);
                }
                else
                {
                    Component component = m_ScriptTarget.GetComponent <EasyTween>().tweens[tweenIndex].targetGameObject.GetComponent(
                        m_ScriptTarget.GetComponent <EasyTween>().tweens[tweenIndex].subTweens[subIndex].targetComponentName);

                    string variableName =
                        m_ScriptTarget.GetComponent <EasyTween>().tweens[tweenIndex].subTweens[subIndex].targetVariableName;

                    theValue = component.GetType().GetField(variableName).GetValue(component);
                }

                subObject.targetValue = ObjectToVector4(subObject.variableType, theValue);
            }

            if (GUILayout.Button("Apply to gameObject", GUILayout.Width(CalcWidth("Apply to gameObject") + 8f)))
            {
                if (subObject.isProperty)
                {
                    Component component = m_ScriptTarget.GetComponent <EasyTween>().tweens[tweenIndex].targetGameObject.GetComponent(
                        m_ScriptTarget.GetComponent <EasyTween>().tweens[tweenIndex].subTweens[subIndex].targetComponentName);

                    string variableName =
                        m_ScriptTarget.GetComponent <EasyTween>().tweens[tweenIndex].subTweens[subIndex].targetVariableName;

                    component.GetType().GetProperty(variableName).SetValue(component, Vector4ToObject(subObject.variableType, subObject.targetValue), null);
                }
                else
                {
                    Component component = m_ScriptTarget.GetComponent <EasyTween>().tweens[tweenIndex].targetGameObject.GetComponent(
                        m_ScriptTarget.GetComponent <EasyTween>().tweens[tweenIndex].subTweens[subIndex].targetComponentName);

                    string variableName =
                        m_ScriptTarget.GetComponent <EasyTween>().tweens[tweenIndex].subTweens[subIndex].targetVariableName;

                    component.GetType().GetField(variableName).SetValue(component, Vector4ToObject(subObject.variableType, subObject.targetValue));
                }
            }

            for (int i = 0; i < subObject.targetValueLength; i++)
            {
                using (new GUILayout.HorizontalScope())
                {
                    subObject.modifyParameters[i] = GUILayout.Toggle(subObject.modifyParameters[i], "Tween " + subStrings[i]);

                    if (subObject.modifyParameters[i])
                    {
                        subObject.targetValue[i] = EditorGUILayout.FloatField(subObject.targetValue[i]);
                    }
                }
            }
        }
Esempio n. 4
0
        private void ConfigureTweenObject(ref EasyTween.EasyTweenObject tweenObject, int tweenIndex)
        {
            using (new GUILayout.HorizontalScope())
            {
                tweenObject.optionsVisible = EditorGUILayout.Foldout(tweenObject.optionsVisible, tweenObject.tag);
                if (tweenIndex == 0)
                {
                    if (GUILayout.Button("+", GUILayout.Width(CalcWidth("+") + 8f)))
                    {
                        AddTweener();
                    }
                }
                if (m_ScriptTarget.tweens.Count > 1)
                {
                    if (GUILayout.Button("-", GUILayout.Width(CalcWidth("-") + 8f)))
                    {
                        RemoveTweener(tweenIndex);
                    }
                }
            }

            if (tweenObject.optionsVisible)
            {
                using (new GUILayout.VerticalScope("Box"))
                {
                    tweenObject.tag = EditorGUILayout.TextField("Tag", tweenObject.tag);

                    using (new GUILayout.HorizontalScope())
                    {
                        tweenObject.targetGameObject = (GameObject)EditorGUILayout.ObjectField("Target GameObject", tweenObject.targetGameObject, typeof(GameObject), true);

                        m_TempString = "This";
                        if (GUILayout.Button(m_TempString, GUILayout.Width(CalcWidth(m_TempString) + 8f)))
                        {
                            tweenObject.targetGameObject = m_ScriptTarget.gameObject;
                        }
                    }

                    tweenObject.tweenType = (Tween.TweenType)EditorGUILayout.EnumPopup("Tween type", tweenObject.tweenType);

                    if (tweenObject.tweenType == Tween.TweenType.Custom)
                    {
                        tweenObject.customCurve = EditorGUILayout.CurveField(tweenObject.customCurve);

                        if (tweenObject.customCurve.keys[0].time != 0f || tweenObject.customCurve.keys[tweenObject.customCurve.keys.Length - 1].time != 1f)
                        {
                            tweenObject.customCurve = new AnimationCurve(new[] { new Keyframe(0f, 0f), new Keyframe(1f, 1f) });
                        }
                    }

                    tweenObject.duration = EditorGUILayout.FloatField("Duration", tweenObject.duration);

                    tweenObject.delay = EditorGUILayout.FloatField("Delay", tweenObject.delay);

                    tweenObject.tweenOnStart = EditorGUILayout.Toggle("Tween on Start", tweenObject.tweenOnStart);

                    tweenObject.hasCallback = EditorGUILayout.Toggle("Call method when done", tweenObject.hasCallback);

                    using (new GUILayout.HorizontalScope())
                    {
                        if (tweenObject.hasCallback)
                        {
                            tweenObject.callbackGameObject =
                                (GameObject)EditorGUILayout.ObjectField("GameObject", tweenObject.callbackGameObject, typeof(GameObject), true);
                        }
                    }

                    if (tweenObject.hasCallback && tweenObject.callbackGameObject != null)
                    {
                        using (new GUILayout.HorizontalScope())
                        {
                            if (tweenObject.hasCallback)
                            {
                                GUILayout.Label("Method");
                                if (GUILayout.Button(tweenObject.callbackComponentName + "/" + tweenObject.callbackName, GUI.skin.GetStyle("Popup")))
                                {
                                    m_TempTweenIndex = tweenIndex;
                                    MethodMenu(tweenObject).ShowAsContext();
                                    return;
                                }
                            }
                        }
                    }

                    EditorGUILayout.Space();

                    if (tweenObject.targetGameObject)
                    {
                        using (new GUILayout.HorizontalScope())
                        {
                            tweenObject.subOptionsVisible = EditorGUILayout.Foldout(tweenObject.subOptionsVisible,
                                                                                    tweenObject.tag + " Subtweens");

                            if (tweenObject.subOptionsVisible)
                            {
                                if (GUILayout.Button("+", GUILayout.Width(CalcWidth("+") + 8f)))
                                {
                                    AddSubTweener(tweenObject);
                                }
                            }
                        }

                        if (tweenObject.subOptionsVisible)
                        {
                            for (int i = 0; i < tweenObject.subTweens.Count; i++)
                            {
                                EasyTween.EasyTweenSubObject subObject = tweenObject.subTweens[i];

                                using (new GUILayout.VerticalScope("Box"))
                                {
                                    ConfgureSubObject(ref subObject, tweenIndex, i);
                                }
                            }
                        }
                    }
                }
                EditorGUILayout.Space();
                EditorGUILayout.Space();
            }
        }