Ejemplo n.º 1
0
        public static void Show(SerializedProperty list)
        {
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.PropertyField(list, GUIContent.none, false, GUILayout.Width(30));
            Rect rect = EditorGUILayout.GetControlRect();

            rect.position -= Vector2.right * 30;
            rect.size      = new Vector2(30, 16);
            EditorGUI.PrefixLabel(rect, GUIUtility.GetControlID(FocusType.Passive), new GUIContent("Tweens : Size"));
            bool addTweenToArray = GUILayout.Button(new GUIContent("+", "add tween"));

            if (addTweenToArray)
            {
                list.arraySize += 1;
            }
            if (GUILayout.Button(new GUIContent("-", "remove tween")))
            {
                if (list.arraySize > 1)
                {
                    list.arraySize -= 1;
                }
            }
            EditorGUILayout.PropertyField(list.FindPropertyRelative("Array.size"), GUIContent.none);             //Use "Array.size" so that it's editable.
            EditorGUILayout.EndHorizontal();
            EditorGUI.indentLevel += 1;
            if (list.isExpanded)
            {
                for (int i = 0; i < list.arraySize; i++)
                {
                    var element = list.GetArrayElementAtIndex(i);                     //this is the tween reference
                    //element.name = "data" // element.displayName == "Element#"
                    //element.type == "PPtr<$TweenBase>"
                    //element.propertyType == "ObjectReference"

                    string    tweenName = element.displayName;
                    TweenBase tween     = null;
                    if (element.objectReferenceValue != null)
                    {
                        tween = (TweenBase)element.objectReferenceValue;
                        string nameVal = tween.name;
                        if (string.IsNullOrEmpty(nameVal) == false)
                        {
                            tweenName = nameVal;
                        }
                        else
                        {
                            int thisIndex = Array.IndexOf(tween.GetComponents <TweenBase>(), tween) + 1;
                            tweenName = "Tween-" + thisIndex + " : " + tween.GetType().Name.Replace("Tween", "");
                        }
                    }

                    EditorGUILayout.BeginHorizontal();
                    EditorGUILayout.PropertyField(element, new GUIContent(tweenName), true);                     //GUIContent.none,true);//
                    bool next     = GUILayout.Button(new GUIContent("*\u25bc", "select Next tween on target"), EditorStyles.miniButton, GUILayout.Width(30));
                    bool previous = GUILayout.Button(new GUIContent("*\u25b2", "select Previous tween on target"), EditorStyles.miniButton, GUILayout.Width(30));
                    if (tween != null)
                    {
                        if (next)
                        {
                            element.objectReferenceValue = IncrementTarget(tween, false);
                        }

                        if (previous)
                        {
                            element.objectReferenceValue = IncrementTarget(tween, true);
                        }
                    }

                    EditorGUILayout.EndHorizontal();
                }
            }

            EditorGUI.indentLevel -= 1;
        }