Exemple #1
0
        private void RefreshAddList()
        {
            this.m_AddedTypes.Clear();
            for (int i = 0; i < this.m_DefaultPresets.arraySize; i++)
            {
                this.m_AddedTypes.Add(this.target.GetPresetTypeNameAtIndex(i));
            }
            IEnumerable <Preset> enumerable = from a in AssetDatabase.FindAssets("t:Preset")
                                              select AssetDatabase.LoadAssetAtPath <Preset>(AssetDatabase.GUIDToAssetPath(a));

            this.m_DiscoveredPresets.Clear();
            foreach (Preset current in enumerable)
            {
                string targetFullTypeName = current.GetTargetFullTypeName();
                if (current.IsValid() && !Preset.IsPresetExcludedFromDefaultPresets(current))
                {
                    if (!this.m_DiscoveredPresets.ContainsKey(targetFullTypeName))
                    {
                        this.m_DiscoveredPresets.Add(targetFullTypeName, new List <Preset>());
                    }
                    this.m_DiscoveredPresets[targetFullTypeName].Add(current);
                }
            }
            this.m_AddingMenu = new GenericMenu();
            foreach (KeyValuePair <string, List <Preset> > current2 in this.m_DiscoveredPresets)
            {
                if (!this.m_AddedTypes.Contains(current2.Key))
                {
                    foreach (Preset current3 in current2.Value)
                    {
                        this.m_AddingMenu.AddItem(new GUIContent(current2.Key.Replace(".", "/") + "/" + current3.name), false, new GenericMenu.MenuFunction2(this.OnAddingPreset), current3);
                    }
                }
            }
        }
        void RefreshAddList()
        {
            m_AddedTypes.Clear();
            for (int i = 0; i < m_DefaultPresets.arraySize; i++)
            {
                m_AddedTypes.Add(target.GetPresetTypeNameAtIndex(i));
            }

            var assets = AssetDatabase.FindAssets("t:Preset")
                         .Select(a => AssetDatabase.LoadAssetAtPath <Preset>(AssetDatabase.GUIDToAssetPath(a)));

            m_DiscoveredPresets.Clear();
            foreach (var preset in assets)
            {
                string presetclass = preset.GetTargetFullTypeName();
                if (preset.IsValid() && !Preset.IsPresetExcludedFromDefaultPresets(preset))
                {
                    if (!m_DiscoveredPresets.ContainsKey(presetclass))
                    {
                        m_DiscoveredPresets.Add(presetclass, new List <Preset>());
                    }
                    m_DiscoveredPresets[presetclass].Add(preset);
                }
            }

            m_AddingMenu = new GenericMenu();
            foreach (var discoveredPreset in m_DiscoveredPresets)
            {
                if (!m_AddedTypes.Contains(discoveredPreset.Key))
                {
                    foreach (var preset in discoveredPreset.Value)
                    {
                        m_AddingMenu.AddItem(new GUIContent(discoveredPreset.Key.Replace(".", "/") + "/" + preset.name), false, OnAddingPreset, preset);
                    }
                }
            }

            if (m_AddingMenu.GetItemCount() == 0)
            {
                m_AddingMenu.AddDisabledItem(EditorGUIUtility.TrTextContent("No Preset to add"));
            }
        }
Exemple #3
0
 internal override void OnHeaderControlsGUI()
 {
     using (new EditorGUI.DisabledScope(targets.Length != 1 || Preset.IsPresetExcludedFromDefaultPresets(target as Preset)))
     {
         var preset = (Preset)target;
         if (Preset.GetDefaultForPreset(preset) == preset)
         {
             if (GUILayout.Button(string.Format("Remove from {0} Default", preset.GetTargetTypeName()), EditorStyles.miniButton, GUILayout.ExpandWidth(false)))
             {
                 Preset.RemoveFromDefault(preset);
             }
         }
         else
         {
             if (GUILayout.Button(string.Format("Set as {0} Default", preset.GetTargetTypeName()), EditorStyles.miniButton, GUILayout.ExpandWidth(false)))
             {
                 Preset.SetAsDefault(preset);
             }
         }
     }
 }