Exemplo n.º 1
0
        public static void DrawTransitionPreset(SerializedProperty property, UITransition transition)
        {
            var spPreset = property.FindPropertyRelative("m_Preset");

            using (new EditorGUILayout.HorizontalScope())
            {
                var oldPreset = spPreset.objectReferenceValue as UITransitionPreset;
                DrawAssetField <UITransitionPreset>(EditorGUILayout.GetControlRect(), null, spPreset, (asset, created) =>
                {
                    if (created)
                    {
                        var so = new SerializedObject(asset);
                        so.CopyFromSerializedProperty(property);
                        property.FindPropertyRelative("m_Preset").objectReferenceValue = null;
                        so.ApplyModifiedProperties();
                    }
                    else if (oldPreset && !asset)
                    {
                        var so = new SerializedObject(oldPreset);
                        property.serializedObject.CopyFromSerializedProperty(so.FindProperty("m_TransitionData"));
                        property.serializedObject.ApplyModifiedProperties();
                    }
                    else if (asset)
                    {
                        property.FindPropertyRelative("m_AnimationDatas").ClearArray();
                        property.serializedObject.ApplyModifiedProperties();
                    }
                    spPreset.objectReferenceValue = asset;
                    spPreset.serializedObject.ApplyModifiedProperties();
                });
            }
        }
Exemplo n.º 2
0
        public static void DrawTransitionData(SerializedProperty property, UITransition transition)
        {
            var spPreset = property.FindPropertyRelative("m_Preset");

//			EditorGUI.BeginDisabledGroup(spPreset.objectReferenceValue && !enableEdit);
            var spAnimationDatas = spPreset.objectReferenceValue
                                ? new SerializedObject(spPreset.objectReferenceValue).FindProperty("m_TransitionData").FindPropertyRelative("m_AnimationDatas")
                                : property.FindPropertyRelative("m_AnimationDatas");

            // Animation datas.
            for (int i = 0; i < spAnimationDatas.arraySize; i++)
            {
                var   spAnimationData = spAnimationDatas.GetArrayElementAtIndex(i);
                State tag             = (State)spAnimationData.FindPropertyRelative("m_State").intValue;

                bool isCurrent = transition.state == tag && Application.isPlaying;
                using (new EditorGUILayout.VerticalScope(isCurrent ? "TL SelectionButton PreDropGlow" : EditorStyles.label))
                {
                    // Header
                    var backgroundColor = GUI.backgroundColor;
                    GUI.backgroundColor = s_BgColor[(int)tag];
                    var rHeader = GUILayoutUtility.GetRect(18, 18);
                    GUI.Label(rHeader, GUIContent.none, styleHeader);


                    Rect rToggle  = new Rect(rHeader.x + 5, rHeader.y, 80, rHeader.height);
                    bool expanded = 0 != (s_ExpandedTags & tag);

                    bool enabled = GUI.enabled;
                    GUI.enabled = true;
                    if (GUI.Toggle(rToggle, expanded, tag.ToString(), EditorStyles.foldout) != expanded)
                    {
                        expanded       = !expanded;
                        s_ExpandedTags = expanded
                                                        ? s_ExpandedTags | tag
                                                        : s_ExpandedTags & ~tag;

                        EditorPrefs.SetInt("UITransition_ExpandedTags", (int)s_ExpandedTags);
                    }
                    GUI.enabled = enabled;


                    // Preset
                    var   spAnimationPreset = spAnimationData.FindPropertyRelative("m_Preset");
                    Rect  rPreset           = new Rect(rHeader.x + 85, rHeader.y + 1, rHeader.width - 85, 16);
                    float labelWidth        = EditorGUIUtility.labelWidth;
                    EditorGUIUtility.labelWidth = 40;

//					DrawAnimationPresetField(rPreset, null, spAnimationPreset, spAnimationData);


                    int index     = i;
                    var oldPreset = spAnimationPreset.objectReferenceValue as UIAnimationPreset;
                    DrawAssetField <UIAnimationPreset>(rPreset, null, spAnimationPreset, (asset, created) =>
                    {
                        if (created)
                        {
                            asset.m_AnimationData          = JsonUtility.FromJson <UIAnimationData>(JsonUtility.ToJson(transition.m_TransitionData.animationDatas[index]));
                            asset.m_AnimationData.m_Preset = null;
                            EditorUtility.SetDirty(asset);
                        }
                        else if (oldPreset && !asset)
                        {
                            if (transition.m_TransitionData.m_Preset)
                            {
                                var datas             = transition.m_TransitionData.m_Preset.m_TransitionData.m_AnimationDatas;
                                datas[index]          = JsonUtility.FromJson <UIAnimationData>(JsonUtility.ToJson(oldPreset.m_AnimationData));
                                datas[index].m_Preset = null;
                                datas[index].m_State  = tag;
                                EditorUtility.SetDirty(transition.m_TransitionData.m_Preset);
                            }
                            else
                            {
                                var datas             = transition.m_TransitionData.m_AnimationDatas;
                                datas[index]          = JsonUtility.FromJson <UIAnimationData>(JsonUtility.ToJson(oldPreset.m_AnimationData));
                                datas[index].m_Preset = null;
                                EditorUtility.SetDirty(transition);
                            }
                            EditorUtility.SetDirty(transition);
                        }
                        else if (asset)
                        {
                            spAnimationData.FindPropertyRelative("m_TweenDatas").ClearArray();
                            spAnimationData.serializedObject.ApplyModifiedProperties();
                        }
                    });


                    EditorGUIUtility.labelWidth = labelWidth;

                    // Inner
                    if (expanded)
                    {
                        using (new EditorGUILayout.VerticalScope(styleInner))
                        {
                            GUI.backgroundColor = backgroundColor;

                            using (new EditorGUI.DisabledGroupScope(spAnimationData.FindPropertyRelative("m_Preset").objectReferenceValue&& !enableEdit))
                            {
                                DrawAnimationData(spAnimationData, transition.helper, isCurrent);
                            }
                        }
                    }
                    GUI.backgroundColor = backgroundColor;
                }
            }
//			EditorGUI.EndDisabledGroup();

            spAnimationDatas.serializedObject.ApplyModifiedProperties();
        }
Exemplo n.º 3
0
        /// <summary>
        /// Transitionタグの描画
        /// </summary>
        public static void DrawTransitionTag(SerializedProperty property, UITransition transition)
        {
            var spPreset         = property.FindPropertyRelative("m_Preset");
            var spAnimationDatas = spPreset.objectReferenceValue
                                ? new SerializedObject(spPreset.objectReferenceValue).FindProperty("m_TransitionData").FindPropertyRelative("m_AnimationDatas")
                                : property.FindPropertyRelative("m_AnimationDatas");

            // Collect valid Tags.
            State availableStates = 0;

            for (int i = 0; i < spAnimationDatas.arraySize; i++)
            {
                availableStates += spAnimationDatas.GetArrayElementAtIndex(i).FindPropertyRelative("m_State").intValue;
            }

            for (int i = 0; i < spAnimationDatas.arraySize; i++)
            {
                if (spAnimationDatas.GetArrayElementAtIndex(i).FindPropertyRelative("m_State").intValue <= 0)
                {
                    spAnimationDatas.DeleteArrayElementAtIndex(i);
                }
            }

            EditorGUI.BeginChangeCheck();
            State selectedTag = (State)EditorGUILayout.EnumMaskField("Available States", availableStates);

            if (!EditorGUI.EndChangeCheck())
            {
                return;
            }

            foreach (State t in Enum.GetValues(typeof(State)))
            {
                //カテゴリ追加
                if (0 == (availableStates & t) && 0 != (selectedTag & t))
                {
                    int index = spAnimationDatas.arraySize;
                    for (int i = 0; i < spAnimationDatas.arraySize; i++)
                    {
                        if ((int)t < spAnimationDatas.GetArrayElementAtIndex(i).FindPropertyRelative("m_State").intValue)
                        {
                            index = i;
                            break;
                        }
                    }

                    spAnimationDatas.InsertArrayElementAtIndex(index);
                    var newData = spAnimationDatas.GetArrayElementAtIndex(index);
                    newData.FindPropertyRelative("m_State").intValue = (int)t;
                }
                //カテゴリ削除
                else if (0 != (availableStates & t) && 0 == (selectedTag & t))
                {
                    for (int i = 0; i < spAnimationDatas.arraySize; i++)
                    {
                        if (spAnimationDatas.GetArrayElementAtIndex(i).FindPropertyRelative("m_State").intValue == (int)t)
                        {
                            spAnimationDatas.DeleteArrayElementAtIndex(i);
                        }
                    }
                }
            }
            spAnimationDatas.serializedObject.ApplyModifiedProperties();
        }