Ejemplo n.º 1
0
        static public void Show(Rect buttonRect, string[] classNames, int initialSelectedInstanceID)
        {
            var menu = new GenericMenu();

            var objs = AssetDatabase.FindAllAssets(new SearchFilter()
            {
                classNames = classNames
            }).Select(property => property.pptrValue).ToList();

            if (objs.Any())
            {
                objs.Sort((result1, result2) => EditorUtility.NaturalCompare(result1.name, result2.name));
                foreach (var obj in objs)
                {
                    var  assetName = new GUIContent(obj.name);
                    bool selected  = obj.GetInstanceID() == initialSelectedInstanceID;
                    menu.AddItem(assetName, selected, SelectCallback, obj);
                }
            }
            else
            {
                menu.AddDisabledItem(EditorGUIUtility.TrTextContent("No Audio Mixers found in this project"));
            }
            menu.DropDown(buttonRect);
        }
Ejemplo n.º 2
0
        static List <AudioMixerController> FindAllAudioMixerControllers()
        {
            var result = new List <AudioMixerController>();

            foreach (var prop in AssetDatabase.FindAllAssets(new SearchFilter()
            {
                classNames = new[] { "AudioMixerController" }
            }))
            {
                var controller = prop.pptrValue as AudioMixerController;
                if (controller)
                {
                    result.Add(controller);
                }
            }
            return(result);
        }
Ejemplo n.º 3
0
            public override void FetchData()
            {
                int depth = -1;

                m_RootItem = new TreeViewItem(1010101010, depth, null, "InvisibleRoot");
                SetExpanded(m_RootItem.id, true);

                List <int> allowedInstanceIDs = ObjectSelector.get.allowedInstanceIDs;

                var controllers = new List <AudioMixerController>();

                foreach (var prop in AssetDatabase.FindAllAssets(new SearchFilter()
                {
                    classNames = new[] { "AudioMixerController" }
                }))
                {
                    var controller = prop.pptrValue as AudioMixerController;
                    if (ShouldShowController(controller, allowedInstanceIDs))
                    {
                        controllers.Add(controller);
                    }
                }

                var roots = new List <TreeViewItem>();

                // First add the 'None' item, then add all groups
                roots.Add(new TreeViewItem(kNoneItemID, 0, m_RootItem, s_NoneText));

                foreach (var controller in controllers)
                {
                    roots.Add(BuildSubTree(controller));
                }

                m_RootItem.children = roots;

                // If we only have one controller then just expand that entirely to the user doesnt have to. (If we have more than one root keep them collapsed and let the user expand)
                if (controllers.Count == 1)
                {
                    m_TreeView.data.SetExpandedWithChildren(m_RootItem, true);
                }

                m_NeedRefreshRows = true;
            }
Ejemplo n.º 4
0
        static void ShowAssetsPopupMenu <T>(Rect buttonRect, string typeName, SerializedProperty serializedProperty, string fileExtension, string defaultFieldName) where T : Object, new()
        {
            GenericMenu gm = new GenericMenu();

            int selectedInstanceID = serializedProperty.objectReferenceValue != null?serializedProperty.objectReferenceValue.GetInstanceID() : 0;


            bool foundDefaultAsset = false;
            var  type    = UnityEditor.UnityType.FindTypeByName(typeName);
            int  classID = type != null ? type.persistentTypeID : 0;

            BuiltinResource[] resourceList = null;

            // Check the assets for one that matches the default name.
            if (classID > 0)
            {
                resourceList = EditorGUIUtility.GetBuiltinResourceList(classID);
                foreach (var resource in resourceList)
                {
                    if (resource.m_Name == defaultFieldName)
                    {
                        gm.AddItem(new GUIContent(resource.m_Name), resource.m_InstanceID == selectedInstanceID, AssetPopupMenuCallback, new object[] { resource.m_InstanceID, serializedProperty });
                        resourceList      = resourceList.Where(x => x != resource).ToArray();
                        foundDefaultAsset = true;
                        break;
                    }
                }
            }

            // If no defalut asset was found, add defualt null value.
            if (!foundDefaultAsset)
            {
                gm.AddItem(new GUIContent(defaultFieldName), selectedInstanceID == 0, AssetPopupMenuCallback, new object[] { 0, serializedProperty });
            }

            // Add items from asset database
            foreach (var property in AssetDatabase.FindAllAssets(new SearchFilter()
            {
                classNames = new[] { typeName }
            }))
            {
                gm.AddItem(new GUIContent(property.name), property.instanceID == selectedInstanceID, AssetPopupMenuCallback, new object[] { property.instanceID, serializedProperty });
            }

            // Add builtin items, except for the already added default item.
            if (classID > 0 && resourceList != null)
            {
                foreach (var resource in resourceList)
                {
                    gm.AddItem(new GUIContent(resource.m_Name), resource.m_InstanceID == selectedInstanceID, AssetPopupMenuCallback, new object[] { resource.m_InstanceID, serializedProperty });
                }
            }

            var  target   = serializedProperty.serializedObject.targetObject;
            bool isPreset = target is Component ? ((int)(target as Component).gameObject.hideFlags == 93) : !AssetDatabase.Contains(target);

            // the preset object is destroyed with the inspector, and nothing new can be created that needs this link. Fix for case 1208437
            if (!isPreset)
            {
                // Create item
                gm.AddSeparator("");
                gm.AddItem(EditorGUIUtility.TrTextContent("Create New..."), false, delegate
                {
                    var newAsset = Activator.CreateInstance <T>();
                    var doCreate = ScriptableObject.CreateInstance <DoCreateNewAsset>();
                    doCreate.SetProperty(serializedProperty);
                    ProjectWindowUtil.StartNameEditingIfProjectWindowExists(newAsset.GetInstanceID(), doCreate, "New " + typeName + "." + fileExtension, AssetPreview.GetMiniThumbnail(newAsset), null);
                });
            }

            gm.DropDown(buttonRect);
        }
Ejemplo n.º 5
0
        // private

        static void ShowAssetsPopupMenu <T>(Rect buttonRect, string typeName, SerializedProperty serializedProperty, string fileExtension, string defaultFieldName) where T : Object, new()
        {
            GenericMenu gm = new GenericMenu();

            int selectedInstanceID = serializedProperty.objectReferenceValue != null?serializedProperty.objectReferenceValue.GetInstanceID() : 0;


            bool foundDefaultAsset = false;
            var  type    = UnityEditor.UnityType.FindTypeByName(typeName);
            int  classID = type != null ? type.persistentTypeID : 0;

            BuiltinResource[] resourceList = null;

            // Check the assets for one that matches the default name.
            if (classID > 0)
            {
                resourceList = EditorGUIUtility.GetBuiltinResourceList(classID);
                foreach (var resource in resourceList)
                {
                    if (resource.m_Name == defaultFieldName)
                    {
                        gm.AddItem(new GUIContent(resource.m_Name), resource.m_InstanceID == selectedInstanceID, AssetPopupMenuCallback, new object[] { resource.m_InstanceID, serializedProperty });
                        resourceList      = resourceList.Where(x => x != resource).ToArray();
                        foundDefaultAsset = true;
                        break;
                    }
                }
            }

            // If no defalut asset was found, add defualt null value.
            if (!foundDefaultAsset)
            {
                gm.AddItem(new GUIContent(defaultFieldName), selectedInstanceID == 0, AssetPopupMenuCallback, new object[] { 0, serializedProperty });
            }

            // Add items from asset database
            foreach (var property in AssetDatabase.FindAllAssets(new SearchFilter()
            {
                classNames = new[] { typeName }
            }))
            {
                gm.AddItem(new GUIContent(property.name), property.instanceID == selectedInstanceID, AssetPopupMenuCallback, new object[] { property.instanceID, serializedProperty });
            }

            // Add builtin items, except for the already added default item.
            if (classID > 0 && resourceList != null)
            {
                foreach (var resource in resourceList)
                {
                    gm.AddItem(new GUIContent(resource.m_Name), resource.m_InstanceID == selectedInstanceID, AssetPopupMenuCallback, new object[] { resource.m_InstanceID, serializedProperty });
                }
            }

            // Create item
            gm.AddSeparator("");
            gm.AddItem(EditorGUIUtility.TrTextContent("Create New..."), false, delegate
            {
                var newAsset = Activator.CreateInstance <T>();
                ProjectWindowUtil.CreateAsset(newAsset, "New " + typeName + "." + fileExtension);
                serializedProperty.objectReferenceValue = newAsset;
                serializedProperty.m_SerializedObject.ApplyModifiedProperties();
            });

            gm.DropDown(buttonRect);
        }