Beispiel #1
0
 static Object PresetFieldDropValidator(Object[] references, PresetType presetType)
 {
     if (references.Length == 1)
     {
         var preset = references[0] as Preset;
         if (preset != null && presetType == preset.GetPresetType())
         {
             return(references[0]);
         }
     }
     return(null);
 }
Beispiel #2
0
        static IEnumerable <Preset> FindAllPresetsOfType(PresetType presetType)
        {
            // If a preset is currently inspected, it doesn't make sense for it to be applied on itself so we filter it from the list.
            Preset inspectedPreset = null;

            if (InspectedObjects != null && InspectedObjects.Length == 1 && InspectedObjects[0] is Preset preset)
            {
                inspectedPreset = preset;
            }

            return(AssetDatabase.FindAssets("t:Preset")
                   .Select(a => AssetDatabase.LoadAssetAtPath <Preset>(AssetDatabase.GUIDToAssetPath(a)))
                   .Where(preset => preset.GetPresetType() == presetType && preset != inspectedPreset));
        }
        void SetupDefaultList()
        {
            m_DefaultPresets = serializedObject.FindProperty("m_DefaultPresets");
            m_Defaults       = new List <DefaultPresetReorderableList>(m_DefaultPresets.arraySize);
            for (int i = 0; i < m_DefaultPresets.arraySize; ++i)
            {
                SerializedProperty defaultPreset = m_DefaultPresets.GetArrayElementAtIndex(i);
                var presetType = new PresetType(defaultPreset.FindPropertyRelative("first"));
                var list       = new DefaultPresetReorderableList(serializedObject, defaultPreset.FindPropertyRelative("second"), presetType);
                m_Defaults.Add(list);
            }

            m_Defaults.Sort((a, b) => a.className.CompareTo(b.className));
        }
 public PresetTypeDropdownItem(string name, string command) : base(name)
 {
     //Re-used method from ComponentDropdownItem
     if (command.StartsWith("SCRIPT"))
     {
         var scriptId = int.Parse(command.Substring(6));
         var obj      = EditorUtility.InstanceIDToObject(scriptId) as MonoScript;
         presetType = new PresetType(obj.GetClass());
     }
     else
     {
         var classId = int.Parse(command);
         presetType = new PresetType(classId);
     }
     icon             = presetType.GetIcon();
     m_SearchableName = name;
 }
Beispiel #5
0
        void Init(PresetType presetType, Preset currentSelection, bool createNewAllowed, PresetSelectorReceiver eventReceiver)
        {
            AssemblyReloadEvents.beforeAssemblyReload -= OnBeforeAssemblyReload;
            AssemblyReloadEvents.beforeAssemblyReload += OnBeforeAssemblyReload;
            m_ModalUndoGroup = Undo.GetCurrentGroup();

            // Freeze to prevent flicker on OSX.
            // Screen will be updated again when calling
            // SetFreezeDisplay(false) further down.
            ContainerWindow.SetFreezeDisplay(true);

            // Set member variables
            m_SearchField  = string.Empty;
            m_CanCreateNew = createNewAllowed;
            InitListArea();
            m_Presets = FindAllPresetsOfType(presetType);
            UpdateSearchResult(currentSelection != null ? currentSelection.GetInstanceID() : 0);

            m_EventObject = eventReceiver;

            ShowWithMode(ShowMode.AuxWindow);
            titleContent = EditorGUIUtility.TrTextContent("Select Preset");

            // Deal with window size
            Rect rect = m_Parent.window.position;

            rect.width  = EditorPrefs.GetFloat(k_PresetSelectorWidthEditorPref, 200);
            rect.height = EditorPrefs.GetFloat(k_PresetSelectorHeightEditorPref, 200);
            position    = rect;
            minSize     = new Vector2(kMinWidth, kMinTopSize + kPreviewExpandedAreaHeight + 2 * kPreviewMargin);
            maxSize     = new Vector2(500, 600);

            // Focus
            Focus();
            ContainerWindow.SetFreezeDisplay(false);

            // Add after unfreezing display because AuxWindowManager.cpp assumes that aux windows are added after we get 'got/lost'- focus calls.
            m_Parent.AddToAuxWindowList();


            SetSelectedPath(GetCurrentSelection());
        }
 public PresetTypeDropdownItem(string name, PresetType type) : base(name)
 {
     presetType       = type;
     icon             = type.GetIcon();
     m_SearchableName = name;
 }
Beispiel #7
0
        public DefaultPresetReorderableList(SerializedObject serializedObject, SerializedProperty propertyArray, PresetType type)
            : base(serializedObject, propertyArray)
        {
            draggable     = true;
            headerHeight *= 2f;
            fullClassName = type.GetManagedTypeName();
            className     = ClassName(type.GetManagedTypeName());
            var content         = new GUIContent(className, type.GetIcon());
            var fullNameContent = new GUIContent($"({fullClassName})");

            drawHeaderCallback            = rect => DrawHeaderCallback(rect, content, fullNameContent);
            drawElementCallback           = (rect, index, active, focused) => DrawElementCallback(rect, index, active, focused, type, serializedProperty);
            drawElementBackgroundCallback = DrawElementBackgroundCallback;
        }
Beispiel #8
0
        static void DrawElementCallback(Rect rect, int index, bool isActive, bool isFocused, PresetType keyType, SerializedProperty listProperty)
        {
            rect.yMin += 2f;
            rect.yMax  = rect.yMin + EditorGUIUtility.singleLineHeight;
            var defaultProperty  = listProperty.GetArrayElementAtIndex(index);
            var presetProperty   = defaultProperty.FindPropertyRelative("m_Preset");
            var disabledProperty = defaultProperty.FindPropertyRelative("m_Disabled");
            var presetObject     = (Preset)presetProperty.objectReferenceValue;

            var enableRect = rect;

            enableRect.y   -= 1f;
            enableRect.xMax = enableRect.xMin + enableRect.height;
            using (new EditorGUI.PropertyScope(enableRect, GUIContent.none, disabledProperty))
            {
                var toggleValue = EditorGUI.Toggle(enableRect, GUIContent.none, !disabledProperty.boolValue);
                if (toggleValue == disabledProperty.boolValue)
                {
                    disabledProperty.boolValue = !disabledProperty.boolValue;
                }
            }
            rect.xMin += enableRect.width + 2f;
            using (new EditorGUI.DisabledScope(disabledProperty.boolValue))
            {
                var filterRect = rect;
                filterRect.xMax = filterRect.xMin + rect.width / 2f;
                DrawFilterField(filterRect, defaultProperty.FindPropertyRelative("m_Filter"));

                var presetFieldRect = rect;
                presetFieldRect.xMin = presetFieldRect.xMax - rect.width / 2f;
                DrawPresetField(presetFieldRect, presetProperty, keyType, presetObject);
            }
        }
Beispiel #9
0
 public static void ShowSelector(PresetType presetType, Preset currentSelection, bool createNewAllowed, PresetSelectorReceiver eventReceiver)
 {
     get.Init(presetType, currentSelection, createNewAllowed, eventReceiver);
 }
Beispiel #10
0
 public static extern bool SetDefaultPresetsForType(PresetType type, DefaultPreset[] presets);
Beispiel #11
0
 public static extern DefaultPreset[] GetDefaultPresetsForType(PresetType type);
 static IEnumerable <Preset> FindAllPresetsOfType(PresetType presetType)
 {
     return(AssetDatabase.FindAssets("t:Preset")
            .Select(a => AssetDatabase.LoadAssetAtPath <Preset>(AssetDatabase.GUIDToAssetPath(a)))
            .Where(preset => preset.GetPresetType() == presetType));
 }
Beispiel #13
0
        protected AdvancedDropdownItem RebuildTree()
        {
            m_SearchableElements = new List <AdvancedDropdownItem>();
            AdvancedDropdownItem root = new PresetTypeDropdownItem(L10n.Tr("Add Default Type"));

            var type        = UnityType.FindTypeByName("AssetImporter");
            var presetTypes = UnityType.GetTypes()
                              .Where(t => t.IsDerivedFrom(type) && !t.isAbstract)
                              .Select(t => new PresetType(t.persistentTypeID))
                              .Union(
                TypeCache.GetTypesDerivedFrom <ScriptedImporter>()
                .Where(t => !t.IsAbstract)
                .Select(t => new PresetType(t))
                )
                              .Distinct()
                              .Where(pt => pt.IsValidDefault());

            // Add Importers
            var importersRoot = new PresetTypeDropdownItem(L10n.Tr("Importer"));

            root.AddChild(importersRoot);
            foreach (var presetType in presetTypes)
            {
                var menuPath = presetType.GetManagedTypeName();
                var paths    = menuPath.Split('.').Last();
                var element  = new PresetTypeDropdownItem(paths, presetType);
                importersRoot.AddChild(element);
                m_SearchableElements.Add(element);
            }

            // Add Components
            var menuDictionary = GetMenuDictionary();

            menuDictionary.Sort(CompareItems);
            for (var i = 0; i < menuDictionary.Count; i++)
            {
                var menu = menuDictionary[i];
                if (menu.Value == "ADD")
                {
                    continue;
                }

                var menuPath = menu.Key;
                var paths    = menuPath.Split('/');

                var parent = root;
                for (var j = 0; j < paths.Length; j++)
                {
                    var path = paths[j];
                    if (j == paths.Length - 1)
                    {
                        var element = new PresetTypeDropdownItem(path, menu.Value);
                        parent.AddChild(element);
                        m_SearchableElements.Add(element);
                        continue;
                    }
                    var group = (PresetTypeDropdownItem)parent.children.SingleOrDefault(c => c.name == path);
                    if (group == null)
                    {
                        group = new PresetTypeDropdownItem(path);
                        parent.AddChild(group);
                    }
                    parent = group;
                }
            }

            // Add ScriptableObjects
            var scriptableObjectRoot = new PresetTypeDropdownItem(L10n.Tr("ScriptableObject"));

            root.AddChild(scriptableObjectRoot);
            foreach (var entry in GetScriptableObjectMenuItem())
            {
                var menuPath = entry.Item2;
                var paths    = menuPath.Split('/');

                AdvancedDropdownItem parent = scriptableObjectRoot;
                for (var j = 0; j < paths.Length; j++)
                {
                    var path = paths[j];
                    if (j == paths.Length - 1)
                    {
                        var presetType = new PresetType(entry.Item1);
                        var element    = new PresetTypeDropdownItem(path, presetType);
                        parent.AddChild(element);
                        m_SearchableElements.Add(element);
                        continue;
                    }
                    var group = parent.children.SingleOrDefault(c => c.name == path);
                    if (group == null)
                    {
                        group = new PresetTypeDropdownItem(path);
                        parent.AddChild(group);
                    }
                    parent = group;
                }
            }

            return(root);
        }
 internal extern void AddPresetType(PresetType presetType);
Beispiel #15
0
        static void DrawElementCallback(Rect rect, int index, bool isActive, bool isFocused, PresetType keyType, SerializedProperty listProperty)
        {
            rect.yMin += 2f;
            rect.yMax  = rect.yMin + EditorGUIUtility.singleLineHeight;
            var defaultProperty = listProperty.GetArrayElementAtIndex(index);
            var presetProperty  = defaultProperty.FindPropertyRelative("m_Preset");
            var presetObject    = (Preset)presetProperty.objectReferenceValue;

            var filterRect = rect;

            filterRect.xMax = filterRect.xMin + rect.width / 2f;
            DrawFilterField(filterRect, defaultProperty.FindPropertyRelative("m_Filter"));

            var presetFieldRect = rect;

            presetFieldRect.xMin = presetFieldRect.xMax - rect.width / 2f;
            DrawPresetField(presetFieldRect, presetProperty, keyType, presetObject);
        }