コード例 #1
0
        static void DrawPresetField(Rect rect, SerializedProperty presetProperty, PresetType keyType, Preset presetObject)
        {
            // lets hack a bit the ObjectField because we want to open our own preset selector.
            var buttonRect = new Rect(rect.xMax - rect.height, rect.y, rect.height, rect.height);

            switch (Event.current.type)
            {
            case EventType.MouseDown:
                if (buttonRect.Contains(Event.current.mousePosition))
                {
                    var changed = ScriptableObject.CreateInstance <PresetChanged>();
                    changed.property  = presetProperty;
                    changed.undoGroup = Undo.GetCurrentGroup();
                    PresetSelector.ShowSelector(keyType, presetObject, false, changed);
                    Event.current.Use();
                }

                break;
            }

            var controlID = GUIUtility.GetControlID(GUIContent.Temp(presetProperty.displayName), FocusType.Passive);
            var dropRect  = rect;

            dropRect.xMax -= rect.height;
            EditorGUI.DoObjectField(rect, dropRect, controlID, typeof(Preset), presetProperty, (references, type, property, options) => PresetFieldDropValidator(references, keyType), false);
        }
コード例 #2
0
        internal static void CreateAndShow(UnityEngine.Object[] targets)
        {
            PresetContextMenu presetContextMenu = ScriptableObject.CreateInstance <PresetContextMenu>();

            if (targets[0] is AssetImporter)
            {
                presetContextMenu.m_ImporterEditors = (from e in Resources.FindObjectsOfTypeAll <AssetImporterEditor>()
                                                       where e.targets == targets
                                                       select e).ToArray <AssetImporterEditor>();
                presetContextMenu.m_Targets = new UnityEngine.Object[]
                {
                    UnityEngine.Object.Instantiate(targets[0])
                };
                presetContextMenu.m_ImporterSerialized = new SerializedObject(targets);
                SerializedProperty iterator = presetContextMenu.m_ImporterEditors[0].m_SerializedObject.GetIterator();
                while (iterator.Next(true))
                {
                    presetContextMenu.m_ImporterSerialized.CopyFromSerializedProperty(iterator);
                }
            }
            else
            {
                presetContextMenu.m_Targets = targets;
                presetContextMenu.m_Presets = (from t in targets
                                               select new Preset(t)).ToArray <Preset>();
            }
            PresetSelector.ShowSelector(targets[0], null, true, presetContextMenu);
        }
コード例 #3
0
        internal static void CreateAndShow(Object[] targets)
        {
            var instance = CreateInstance <PresetContextMenu>();

            if (targets[0] is AssetImporter)
            {
                // we need to keep our own instance of the selected importer in order to handle the Apply/Reset correctly
                instance.m_ImporterEditors = Resources
                                             .FindObjectsOfTypeAll <AssetImporterEditor>()
                                             .Where(e => e.targets == targets)
                                             .ToArray();
                instance.m_Targets            = new[] { Instantiate(targets[0]) };
                instance.m_ImporterSerialized = new SerializedObject(targets);
                var prop = instance.m_ImporterEditors[0].m_SerializedObject.GetIterator();
                while (prop.Next(true))
                {
                    instance.m_ImporterSerialized.CopyFromSerializedProperty(prop);
                }
            }
            else
            {
                instance.m_Targets = targets;
                instance.m_Presets = targets.Select(t => new Preset(t)).ToArray();
            }
            PresetSelector.ShowSelector(targets[0], null, true, instance);
        }
コード例 #4
0
        public static void ShowSelector(UnityEngine.Object[] targets, Preset currentSelection, bool createNewAllowed)
        {
            DefaultPresetSelectorReceiver defaultPresetSelectorReceiver = ScriptableObject.CreateInstance <DefaultPresetSelectorReceiver>();

            defaultPresetSelectorReceiver.Init(targets);
            PresetSelector.ShowSelector(targets[0], currentSelection, createNewAllowed, defaultPresetSelectorReceiver);
        }
コード例 #5
0
        internal static void CreateAndShow(Object[] targets)
        {
            var instance = CreateInstance <PresetContextMenu>();

            instance.m_Targets = targets;
            instance.m_Presets = targets.Select(t => new Preset(t)).ToArray();
            PresetSelector.ShowSelector(targets[0], null, true, instance);
        }
コード例 #6
0
 public PresetListArea(ObjectListAreaState state, PresetSelector owner)
     : base(state, owner, true)
 {
     if (noneItem != null)
     {
         noneItem.m_Icon = EditorGUIUtility.LoadIcon("Preset.Current");
     }
 }
コード例 #7
0
        internal static void CreateAndShow(Object[] targets)
        {
            var instance = CreateInstance <PresetContextMenu>();

            if (targets[0] is AssetImporter)
            {
                // AssetImporterEditor never applies the AssetImporter's SerializedObject because it uses it for the Apply/Revert mechanic.
                // This means we need to write/read the data directly from the SerializedObject instead of the AssetImporter itself
                // And thus, we can't use Presets directly.
                instance.m_ImporterEditors = Resources
                                             .FindObjectsOfTypeAll <AssetImporterEditor>()
                                             .Where(e => e.targets == targets)
                                             .ToArray();
                // m_Targets needs to keep a dummy version of each real target to avoid overriding the real importers.
                var dummyPresets = targets.Select(t => new Preset(t));
                instance.m_Targets            = dummyPresets.Select(p => p.GetReferenceObject()).ToArray();
                instance.m_ImporterSerialized = new SerializedObject(instance.m_Targets);
                // copy values from the first editor serializedObject, because user may have done changes we want to apply back when selecting none.
                var currentEditorValues = instance.m_ImporterEditors[0].m_SerializedObject;
                // Do only apply on the properties that are part of the Preset modifications list
                // That will particularly avoid the AudioImporter preview data that can be a 30k+ array we don't want.
                var    presetProperties = dummyPresets.First().PropertyModifications;
                string propertyPath     = "";
                foreach (var propertyModification in presetProperties)
                {
                    // We need to filter out .Array.* properties and use the parent one instead,
                    // because changing .Array.size from CopyFromSerializedProperty will corrupt the SerializedObject data.
                    if (!string.IsNullOrEmpty(propertyPath) && propertyModification.propertyPath.StartsWith(propertyPath + ".Array."))
                    {
                        continue;
                    }
                    if (propertyModification.propertyPath.Contains(".Array."))
                    {
                        propertyPath = propertyModification.propertyPath.Substring(0, propertyModification.propertyPath.IndexOf(".Array."));
                    }
                    else
                    {
                        propertyPath = propertyModification.propertyPath;
                    }
                    instance.m_ImporterSerialized.CopyFromSerializedProperty(currentEditorValues.FindProperty(propertyPath));
                }
                instance.m_ImporterSerialized.ApplyModifiedPropertiesWithoutUndo();
                // create a list of Presets that contains the current values of each object
                instance.m_Presets = instance.m_Targets.Select(t => new Preset(t)).ToArray();
            }
            else
            {
                instance.m_Targets = targets;
                instance.m_Presets = targets.Select(t => new Preset(t)).ToArray();
            }
            PresetSelector.ShowSelector(targets[0], null, true, instance);
        }
コード例 #8
0
        private static string CreatePresetDialog(ref Preset preset, UnityEngine.Object target)
        {
            string result;

            if (target is AssetImporter && PresetSelector.ApplyImportSettingsBeforeSavingPreset(ref preset, target))
            {
                result = null;
            }
            else
            {
                result = EditorUtility.SaveFilePanelInProject("New Preset", preset.GetTargetTypeName(), "preset", "", ProjectWindowUtil.GetActiveFolderPath());
            }
            return(result);
        }
コード例 #9
0
        private static void CreatePreset(UnityEngine.Object target)
        {
            Preset preset = new Preset(target);
            string text   = PresetSelector.CreatePresetDialog(ref preset, target);

            if (!string.IsNullOrEmpty(text))
            {
                Preset preset2 = AssetDatabase.LoadAssetAtPath <Preset>(text);
                if (preset2 != null)
                {
                    EditorUtility.CopySerialized(preset, preset2);
                    preset2.name = Path.GetFileNameWithoutExtension(text);
                }
                else
                {
                    AssetDatabase.CreateAsset(preset, text);
                }
            }
        }
コード例 #10
0
        private void OnGUI()
        {
            this.m_ListArea.HandleKeyboard(false);
            this.HandleKeyInput();
            EditorGUI.FocusTextInControl("ComponentSearch");
            this.DrawSearchField();
            Rect controlRect = EditorGUILayout.GetControlRect(true, new GUILayoutOption[]
            {
                GUILayout.ExpandHeight(true)
            });
            int controlID = GUIUtility.GetControlID(FocusType.Keyboard);

            this.m_ListArea.OnGUI(new Rect(0f, controlRect.y, base.position.width, controlRect.height), controlID);
            using (new EditorGUILayout.HorizontalScope(PresetSelector.Style.bottomBarBg, new GUILayoutOption[]
            {
                GUILayout.MinHeight(24f)
            }))
            {
                if (this.m_CanCreateNew)
                {
                    if (GUILayout.Button("Save current to...", new GUILayoutOption[0]))
                    {
                        PresetSelector.CreatePreset(this.m_MainTarget);
                    }
                }
                GUILayout.FlexibleSpace();
                if (this.m_ListArea.CanShowThumbnails())
                {
                    using (EditorGUI.ChangeCheckScope changeCheckScope = new EditorGUI.ChangeCheckScope())
                    {
                        int gridSize = (int)GUILayout.HorizontalSlider((float)this.m_ListArea.gridSize, (float)this.m_ListArea.minGridSize, (float)this.m_ListArea.maxGridSize, new GUILayoutOption[]
                        {
                            GUILayout.Width(55f)
                        });
                        if (changeCheckScope.changed)
                        {
                            this.m_ListArea.gridSize = gridSize;
                        }
                    }
                }
            }
        }
コード例 #11
0
        private void Init(UnityEngine.Object target, Preset currentSelection, bool createNewAllowed, PresetSelectorReceiver eventReceiver)
        {
            this.m_ModalUndoGroup = Undo.GetCurrentGroup();
            ContainerWindow.SetFreezeDisplay(true);
            this.m_SearchField = string.Empty;
            this.m_MainTarget  = target;
            this.InitListArea();
            this.m_Presets = PresetSelector.FindAllPresetsForObject(target);
            this.UpdateSearchResult((!(currentSelection != null)) ? 0 : currentSelection.GetInstanceID());
            this.m_EventObject  = eventReceiver;
            this.m_CanCreateNew = createNewAllowed;
            base.ShowWithMode(ShowMode.AuxWindow);
            base.titleContent = EditorGUIUtility.TrTextContent("Select Preset", null, null);
            Rect position = this.m_Parent.window.position;

            position.width  = EditorPrefs.GetFloat("PresetSelectorWidth", 200f);
            position.height = EditorPrefs.GetFloat("PresetSelectorHeight", 390f);
            base.position   = position;
            base.minSize    = new Vector2(200f, 335f);
            base.maxSize    = new Vector2(10000f, 10000f);
            base.Focus();
            ContainerWindow.SetFreezeDisplay(false);
            this.m_Parent.AddToAuxWindowList();
        }