/*private GenericMenu MethodMenu(EasyTween.EasyTweenObject tweenObject)
         * {
         *  GenericMenu thisMenu = new GenericMenu();
         *  string[] componentStrings = FindComponentStrings(tweenObject.callbackGameObject);
         *
         *  for (int i = 0; i < componentStrings.Length; i++)
         *  {
         *      string[] methodStrings = FindMethodStrings(tweenObject.callbackGameObject, componentStrings[i]);
         *
         *      for (int j = 0; j < methodStrings.Length; j++)
         *      {
         *          thisMenu.AddItem(new GUIContent(componentStrings[i] + "/" + methodStrings[j]), false, MethodMenuCallback, (object)componentStrings[i] + "/" + methodStrings[j]);
         *      }
         *  }
         *
         *  return thisMenu;
         * }*/

        public override void OnInspectorGUI()
        {
            EnforceListLengths();

            for (int i = 0; i < m_ScriptTarget.tweens.Count; i++)
            {
                EasyTween.EasyTweenObject tweenObject = m_ScriptTarget.tweens[i];
                ConfigureTweenObject(ref tweenObject, i);
            }
        }
        public void MethodMenuCallback(object item)
        {
            string theString = (string)item;

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

            EasyTween.EasyTweenObject tweenObject = m_ScriptTarget.tweens[m_TempTweenIndex];

            tweenObject.callbackComponent     = tweenObject.callbackGameObject.GetComponent(stringArray[0]);
            tweenObject.callbackComponentName = tweenObject.callbackComponent.GetType().Name;

            tweenObject.callbackMethodInfo = tweenObject.callbackComponent.GetType().GetMethod(stringArray[1]);
            tweenObject.callbackName       = tweenObject.callbackMethodInfo.Name;

            m_ScriptTarget.tweens[m_TempTweenIndex] = tweenObject;
        }
        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;
        }
        private GenericMenu MethodMenu(EasyTween.EasyTweenObject tweenObject)
        {
            GenericMenu thisMenu = new GenericMenu();

            string[] componentStrings = FindComponentStrings(tweenObject.callbackGameObject);

            for (int i = 0; i < componentStrings.Length; i++)
            {
                string[] methodStrings = FindMethodStrings(tweenObject.callbackGameObject, componentStrings[i]);

                for (int j = 0; j < methodStrings.Length; j++)
                {
                    thisMenu.AddItem(new GUIContent(componentStrings[i] + "/" + methodStrings[j]), false, MethodMenuCallback, (object)componentStrings[i] + "/" + methodStrings[j]);
                }
            }

            return(thisMenu);
        }
        private GenericMenu VariableMenu(GameObject targetGameObject, EasyTween.EasyTweenObject tweenObject)
        {
            GenericMenu thisMenu = new GenericMenu();

            string[] componentStrings = FindComponentStrings(targetGameObject);

            for (int i = 0; i < componentStrings.Length; i++)
            {
                string[] variableStrings = FindVariableStrings(targetGameObject, componentStrings[i]);

                for (int j = 0; j < variableStrings.Length; j++)
                {
                    thisMenu.AddItem(new GUIContent(componentStrings[i] + "/" + variableStrings[j]), false, VariableMenuCallback, (object)componentStrings[i] + "/" + variableStrings[j]);
                }
            }

            return(thisMenu);
        }
 private void AddSubTweener(EasyTween.EasyTweenObject tweenObject)
 {
     tweenObject.subTweens.Add(new EasyTween.EasyTweenSubObject());
 }
        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();
            }
        }
        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);

                    var tweenObjectProperty = m_Tweens.GetArrayElementAtIndex(tweenIndex);
                    var onStart             = tweenObjectProperty != null?tweenObjectProperty.FindPropertyRelative("onStart") : null;

                    var onFinish = tweenObjectProperty != null?tweenObjectProperty.FindPropertyRelative("onFinish") : null;

                    if (onFinish != null || onStart != null)
                    {
                        EditorGUILayout.Space();
                        serializedObject.Update();
                        if (onStart != null)
                        {
                            EditorGUILayout.PropertyField(onStart);
                        }
                        if (onFinish != null)
                        {
                            EditorGUILayout.PropertyField(onFinish);
                        }
                        serializedObject.ApplyModifiedProperties();
                    }
                    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();
            }
        }