Пример #1
0
    public static void AddSchemas(AddressableAssetGroup group)
    {
        for (int i = 0; i < group.Schemas.Count; i++)
        {
            var sc = group.Schemas[i];
            group.RemoveSchema(sc.GetType());
        }

        group.AddSchema <ContentUpdateGroupSchema>();
        group.AddSchema <BundledAssetGroupSchema>();
    }
Пример #2
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();
        }
Пример #3
0
        public override void OnInspectorGUI()
        {
            try
            {
                serializedObject.Update();
                using (new EditorGUI.DisabledScope(true))
                {
                    EditorGUILayout.ObjectField("Addressable Asset Settings", m_GroupTarget.Settings, typeof(AddressableAssetSettings), false);
                    var prof = m_GroupTarget.Settings.profileSettings.GetProfile(m_GroupTarget.Settings.activeProfileId);
                    EditorGUILayout.TextField("Current Profile", prof.profileName);
                }

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

                for (int i = 0; i < m_GroupTarget.Schemas.Count; i++)
                {
                    var schema = m_GroupTarget.Schemas[i];
                    EditorGUILayout.BeginHorizontal();
                    m_FoldoutState[i] = EditorGUILayout.Foldout(m_FoldoutState[i], schema.GetType().Name);
                    if (!m_GroupTarget.ReadOnly)
                    {
                        if (GUILayout.Button("X", GUILayout.Width(40)))
                        {
                            if (EditorUtility.DisplayDialog("Delete selected schema?", "Are you sure you want to delete the selected 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[i];
                                    }
                                    else
                                    {
                                        newFoldoutstate[j] = m_FoldoutState[i + 1];
                                    }
                                }

                                m_FoldoutState = newFoldoutstate;
                                EditorGUILayout.EndHorizontal();
                                break;
                            }
                        }
                    }

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



                EditorGUILayout.LabelField("", UnityEngine.GUI.skin.horizontalSlider);
                EditorGUILayout.BeginHorizontal();
                GUILayout.FlexibleSpace();
                if (!m_GroupTarget.ReadOnly)
                {
                    if (EditorGUILayout.DropdownButton(new GUIContent("Add Schema", "Add new schema to this group."), FocusType.Keyboard))
                    {
                        var menu = new GenericMenu();
                        for (int i = 0; i < m_SchemaTypes.Count; i++)
                        {
                            var type = m_SchemaTypes[i];
                            menu.AddItem(new GUIContent(type.Name, ""), false, OnAddSchema, type);
                        }

                        menu.ShowAsContext();
                    }
                }

                EditorGUILayout.EndHorizontal();

                serializedObject.ApplyModifiedProperties();
            }
            catch (UnityEngine.ExitGUIException)
            {
                throw;
            }
            catch (Exception e)
            {
                Debug.LogException(e);
            }
        }