Пример #1
0
        public void OnGUIMultiple(Rect position, SerializedProperty property, GUIContent label, bool showMixed)
        {
            m_Property = property;
            if (m_SerializedFieldInfo == null)
            {
                m_SerializedFieldInfo = GetFieldInfo(property);
            }
            if (m_Types == null)
            {
                m_Types = GetTypes(m_SerializedFieldInfo);
            }

            List <GUIContent> typeContent = new List <GUIContent>();

            typeContent.Add(new GUIContent("<none>", "Clear the type."));
            foreach (var type in m_Types)
            {
                typeContent.Add(new GUIContent(AddressableAssetUtility.GetCachedTypeDisplayName(type), ""));
            }

            bool resetShowMixed = EditorGUI.showMixedValue;

            EditorGUI.BeginProperty(position, label, property);
            EditorGUI.showMixedValue = showMixed;

            var st = (SerializedType)m_SerializedFieldInfo.GetValue(property.serializedObject.targetObject);

            int index         = GetIndexForType(st.Value);
            int selectedValue = EditorGUI.Popup(position, label, index, typeContent.ToArray());

            if (selectedValue != index)
            {
                Undo.RecordObject(m_Property.serializedObject.targetObject, "Set Serialized Type");
                m_SerializedFieldInfo.SetValue(m_Property.serializedObject.targetObject,
                                               new SerializedType
                {
                    Value        = selectedValue == 0 ? null : m_Types[selectedValue - 1],
                    ValueChanged = true
                });
                EditorUtility.SetDirty(m_Property.serializedObject.targetObject);
                AddressableAssetUtility.OpenAssetIfUsingVCIntegration(m_Property.serializedObject.targetObject);
            }

            EditorGUI.EndProperty();
            EditorGUI.showMixedValue = resetShowMixed;
        }
Пример #2
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            m_Property = property;
            if (m_SerializedFieldInfo == null)
            {
                m_SerializedFieldInfo = GetFieldInfo(property);
            }
            if (m_Types == null)
            {
                m_Types = GetTypes(m_SerializedFieldInfo);
            }

            EditorGUI.BeginProperty(position, label, property);
            var smallPos = EditorGUI.PrefixLabel(position, label);
            var st       = (SerializedType)m_SerializedFieldInfo.GetValue(property.serializedObject.targetObject);

            string display = AddressableAssetUtility.GetCachedTypeDisplayName(st.Value);

//            if (st.ShowMixedValue)
//            {
//                display = "—";
//            }

            if (EditorGUI.DropdownButton(smallPos, new GUIContent(display), FocusType.Keyboard))
            {
                var menu = new GenericMenu();
                menu.AddItem(new GUIContent("<none>", "Clear the type."), false, OnSetType, null);
                for (int i = 0; i < m_Types.Count; i++)
                {
                    var type = m_Types[i];
                    menu.AddItem(new GUIContent(AddressableAssetUtility.GetCachedTypeDisplayName(type), ""), false, OnSetType, type);
                }
                menu.ShowAsContext();
            }

            EditorGUI.EndProperty();
        }
        public void GetCachedTypeDisplayName_WithAttribute_ReturnsAttributeValue()
        {
            var subName = AddressableAssetUtility.GetCachedTypeDisplayName(typeof(TestSubClass));

            Assert.AreEqual("TestSubClass_DisplayName", subName);
        }
        public void GetCachedTypeDisplayName_WithNoAttribute_ReturnsTypeName()
        {
            var name = AddressableAssetUtility.GetCachedTypeDisplayName(typeof(TestBaseClass));

            Assert.AreEqual(typeof(TestBaseClass).Name, name);
        }
        public void GetCachedTypeDisplayName_WithNullType_ReturnsNONE()
        {
            var subName = AddressableAssetUtility.GetCachedTypeDisplayName(null);

            Assert.AreEqual("<none>", subName);
        }
Пример #6
0
        void DrawSingleGroup()
        {
            GUILayout.Space(6);

            EditorGUILayout.BeginHorizontal();
            var activeProfileName = m_GroupTarget.Settings.profileSettings.GetProfileName(m_GroupTarget.Settings.activeProfileId);

            if (string.IsNullOrEmpty(activeProfileName))
            {
                m_GroupTarget.Settings.activeProfileId = null; //this will reset it to default.
                activeProfileName = m_GroupTarget.Settings.profileSettings.GetProfileName(m_GroupTarget.Settings.activeProfileId);
            }
            EditorGUILayout.PrefixLabel("Active Profile: " + activeProfileName);
            if (GUILayout.Button("Inspect Top Level Settings"))
            {
                EditorGUIUtility.PingObject(AddressableAssetSettingsDefaultObject.Settings);
                Selection.activeObject = AddressableAssetSettingsDefaultObject.Settings;
            }

            EditorGUILayout.EndHorizontal();
            GUILayout.Space(6);


            if (m_FoldoutState == null || m_FoldoutState.Length != m_GroupTarget.Schemas.Count)
            {
                m_FoldoutState = new bool[m_GroupTarget.Schemas.Count];
            }

            EditorGUILayout.BeginVertical();
            for (int i = 0; i < m_GroupTarget.Schemas.Count; i++)
            {
                var schema       = m_GroupTarget.Schemas[i];
                int currentIndex = i;

                DrawDivider();
                EditorGUILayout.BeginHorizontal();
                m_FoldoutState[i] = EditorGUILayout.Foldout(m_FoldoutState[i], AddressableAssetUtility.GetCachedTypeDisplayName(schema.GetType()));
                if (!m_GroupTarget.ReadOnly)
                {
                    GUILayout.FlexibleSpace();
                    GUIStyle gearIconStyle = UnityEngine.GUI.skin.FindStyle("IconButton") ?? EditorGUIUtility.GetBuiltinSkin(EditorSkin.Inspector).FindStyle("IconButton");

                    if (EditorGUILayout.DropdownButton(EditorGUIUtility.IconContent("_Popup"), FocusType.Keyboard, gearIconStyle))
                    {
                        var menu = new GenericMenu();
                        menu.AddItem(AddressableAssetGroup.RemoveSchemaContent, false, () =>
                        {
                            if (EditorUtility.DisplayDialog("Remove selected schema?", "Are you sure you want to remove " + AddressableAssetUtility.GetCachedTypeDisplayName(schema.GetType()) + " schema?\n\nYou cannot undo this action.", "Yes", "No"))
                            {
                                m_GroupTarget.RemoveSchema(schema.GetType());
                                var newFoldoutstate = new bool[m_GroupTarget.Schemas.Count];
                                for (int j = 0; j < newFoldoutstate.Length; j++)
                                {
                                    if (j < i)
                                    {
                                        newFoldoutstate[j] = m_FoldoutState[j];
                                    }
                                    else
                                    {
                                        newFoldoutstate[j] = m_FoldoutState[i + 1];
                                    }
                                }

                                m_FoldoutState = newFoldoutstate;
                            }
                        });
                        menu.AddItem(AddressableAssetGroup.MoveSchemaUpContent, false, () =>
                        {
                            if (currentIndex > 0)
                            {
                                m_GroupTarget.Schemas[currentIndex]     = m_GroupTarget.Schemas[currentIndex - 1];
                                m_GroupTarget.Schemas[currentIndex - 1] = schema;
                                return;
                            }
                        });
                        menu.AddItem(AddressableAssetGroup.MoveSchemaDownContent, false, () =>
                        {
                            if (currentIndex < m_GroupTarget.Schemas.Count - 1)
                            {
                                m_GroupTarget.Schemas[currentIndex]     = m_GroupTarget.Schemas[currentIndex + 1];
                                m_GroupTarget.Schemas[currentIndex + 1] = schema;
                                return;
                            }
                        });
                        menu.AddSeparator("");
                        menu.AddItem(AddressableAssetGroup.ExpandSchemaContent, false, () =>
                        {
                            m_FoldoutState[currentIndex] = true;
                            schema.ShowAllProperties();
                        });
                        menu.ShowAsContext();
                    }
                }

                EditorGUILayout.EndHorizontal();
                if (m_FoldoutState[i])
                {
                    try
                    {
                        EditorGUI.indentLevel++;
                        schema.OnGUI();
                        EditorGUI.indentLevel--;
                    }
                    catch (Exception se)
                    {
                        Debug.LogException(se);
                    }
                }
            }

            if (m_GroupTarget.Schemas.Count > 0)
            {
                DrawDivider();
            }
            GUILayout.Space(4);
            EditorGUILayout.BeginHorizontal();

            GUILayout.FlexibleSpace();
            GUIStyle addSchemaButton = new GUIStyle(UnityEngine.GUI.skin.button);

            addSchemaButton.fontSize    = 12;
            addSchemaButton.fixedWidth  = 225;
            addSchemaButton.fixedHeight = 22;

            if (!m_GroupTarget.ReadOnly)
            {
                if (EditorGUILayout.DropdownButton(new GUIContent("Add Schema", "Add new schema to this group."), FocusType.Keyboard, addSchemaButton))
                {
                    var menu = new GenericMenu();
                    for (int i = 0; i < m_SchemaTypes.Count; i++)
                    {
                        var type = m_SchemaTypes[i];

                        if (m_GroupTarget.GetSchema(type) == null)
                        {
                            menu.AddItem(new GUIContent(AddressableAssetUtility.GetCachedTypeDisplayName(type), ""), false, () => OnAddSchema(type));
                        }
                        else
                        {
                            menu.AddDisabledItem(new GUIContent(AddressableAssetUtility.GetCachedTypeDisplayName(type), ""), true);
                        }
                    }

                    menu.ShowAsContext();
                }
            }

            GUILayout.FlexibleSpace();

            EditorGUILayout.EndHorizontal();
            EditorGUILayout.EndVertical();
        }
        void DrawSingleGroup()
        {
            EditorGUILayout.LabelField("Group Template Description");
            m_AddressableAssetGroupTarget.Description = EditorGUILayout.TextArea(m_AddressableAssetGroupTarget.Description);

            int objectCount = m_AddressableAssetGroupTarget.SchemaObjects.Count;

            if (m_FoldoutState == null || m_FoldoutState.Length != objectCount)
            {
                m_FoldoutState = new bool[objectCount];
            }

            for (int i = 0; i < objectCount; i++)
            {
                var schema       = m_AddressableAssetGroupTarget.SchemaObjects[i];
                int currentIndex = i;

                DrawDivider();
                EditorGUILayout.BeginHorizontal();
                m_FoldoutState[i] = EditorGUILayout.Foldout(m_FoldoutState[i], AddressableAssetUtility.GetCachedTypeDisplayName(m_AddressableAssetGroupTarget.SchemaObjects[i].GetType()));

                GUILayout.FlexibleSpace();
                GUIStyle gearIconStyle = UnityEngine.GUI.skin.FindStyle("IconButton") ?? EditorGUIUtility.GetBuiltinSkin(EditorSkin.Inspector).FindStyle("IconButton");

                if (EditorGUILayout.DropdownButton(EditorGUIUtility.IconContent("_Popup"), FocusType.Keyboard, gearIconStyle))
                {
                    var menu = new GenericMenu();
                    menu.AddItem(AddressableAssetGroup.RemoveSchemaContent, false, () =>
                    {
                        var schemaName = AddressableAssetUtility.GetCachedTypeDisplayName(m_AddressableAssetGroupTarget.SchemaObjects[currentIndex].GetType());
                        if (EditorUtility.DisplayDialog("Remove selected schema?", "Are you sure you want to remove " + schemaName + " schema?\n\nYou cannot undo this action.", "Yes", "No"))
                        {
                            m_AddressableAssetGroupTarget.RemoveSchema(currentIndex);
                            var newFoldoutstate = new bool[objectCount - 1];
                            for (int j = 0; j < newFoldoutstate.Length; j++)
                            {
                                if (j < i)
                                {
                                    newFoldoutstate[j] = m_FoldoutState[j];
                                }
                                else
                                {
                                    newFoldoutstate[j] = m_FoldoutState[currentIndex + 1];
                                }
                            }

                            m_FoldoutState = newFoldoutstate;
                        }
                    });
                    menu.AddItem(AddressableAssetGroup.MoveSchemaUpContent, false, () =>
                    {
                        if (currentIndex > 0)
                        {
                            m_AddressableAssetGroupTarget.SchemaObjects[currentIndex]     = m_AddressableAssetGroupTarget.SchemaObjects[currentIndex - 1];
                            m_AddressableAssetGroupTarget.SchemaObjects[currentIndex - 1] = schema;
                            return;
                        }
                    });
                    menu.AddItem(AddressableAssetGroup.MoveSchemaDownContent, false, () =>
                    {
                        if (currentIndex < m_AddressableAssetGroupTarget.SchemaObjects.Count - 1)
                        {
                            m_AddressableAssetGroupTarget.SchemaObjects[currentIndex]     = m_AddressableAssetGroupTarget.SchemaObjects[currentIndex + 1];
                            m_AddressableAssetGroupTarget.SchemaObjects[currentIndex + 1] = schema;
                            return;
                        }
                    });
                    menu.AddSeparator("");
                    menu.AddItem(AddressableAssetGroup.ExpandSchemaContent, false, () =>
                    {
                        m_FoldoutState[currentIndex] = true;
                        m_AddressableAssetGroupTarget.SchemaObjects[currentIndex].ShowAllProperties();
                    });
                    menu.ShowAsContext();
                }

                EditorGUILayout.EndHorizontal();

                if (m_FoldoutState[i])
                {
                    try
                    {
                        EditorGUI.indentLevel++;
                        m_AddressableAssetGroupTarget.SchemaObjects[i].OnGUI();
                        EditorGUI.indentLevel--;
                    }
                    catch (Exception se)
                    {
                        Debug.LogException(se);
                    }
                }
            }

            DrawDivider();
            EditorGUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();
            GUIStyle addSchemaButton = new GUIStyle(UnityEngine.GUI.skin.button);

            addSchemaButton.fontSize    = 12;
            addSchemaButton.fixedWidth  = 225;
            addSchemaButton.fixedHeight = 22;

            if (EditorGUILayout.DropdownButton(new GUIContent("Add Schema", "Add new schema to this group."), FocusType.Keyboard, addSchemaButton))
            {
                var menu = new GenericMenu();
                for (int i = 0; i < m_SchemaTypes.Count; i++)
                {
                    var type = m_SchemaTypes[i];

                    if (Array.IndexOf(m_AddressableAssetGroupTarget.GetTypes(), type) == -1)
                    {
                        menu.AddItem(new GUIContent(AddressableAssetUtility.GetCachedTypeDisplayName(type), ""), false, () => OnAddSchema(type));
                    }
                    else
                    {
                        menu.AddDisabledItem(new GUIContent(AddressableAssetUtility.GetCachedTypeDisplayName(type), ""), true);
                    }
                }

                menu.ShowAsContext();
            }

            GUILayout.FlexibleSpace();
            EditorGUILayout.EndHorizontal();
        }