public ComponentDropdownItem(string name, string localized, string menuPath, string command, bool isLegacy) : base(name)
        {
            m_LocalizedName = localized;
            m_MenuPath      = menuPath;
            m_IsLegacy      = isLegacy;

            if (command.StartsWith("SCRIPT"))
            {
                var scriptId = int.Parse(command.Substring(6));
                var obj      = EditorUtility.InstanceIDToObject(scriptId);
                var icon     = AssetPreview.GetMiniThumbnail(obj);
                base.name = name;
                base.icon = icon;
            }
            else
            {
                var classId = int.Parse(command);
                base.name = name;
                base.icon = AssetPreview.GetMiniTypeThumbnailFromClassID(classId);
            }
            m_SearchableName          = name;
            m_SearchableNameLocalized = localized;
            if (m_IsLegacy)
            {
                m_SearchableName += " (Legacy)";
            }
        }
Beispiel #2
0
        internal Texture2D GetIcon()
        {
            Texture2D icon = null;

            if (m_ManagedTypePPtr != null)
            {
                icon = AssetPreview.GetMiniThumbnail(m_ManagedTypePPtr);
            }
            if (icon == null)
            {
                icon = AssetPreview.GetMiniTypeThumbnailFromClassID(m_NativeTypeID);
            }

            return(icon);
        }
Beispiel #3
0
        public ComponentDropdownItem(string name, string localizedName, string menuPath, string command) : base(name, localizedName, menuPath, -1)
        {
            m_MenuPath = menuPath;
            m_IsLegacy = menuPath.Contains("Legacy");

            if (command.StartsWith("SCRIPT"))
            {
                var scriptId = int.Parse(command.Substring(6));
                var obj      = EditorUtility.InstanceIDToObject(scriptId);
                var icon     = AssetPreview.GetMiniThumbnail(obj);
                m_Content = new GUIContent(name, icon);
            }
            else
            {
                var classId = int.Parse(command);
                m_Content = new GUIContent(localizedName, AssetPreview.GetMiniTypeThumbnailFromClassID(classId));
            }
            m_ContentWhenSearching = new GUIContent(m_Content);
            if (m_IsLegacy)
            {
                m_ContentWhenSearching.text += " (Legacy)";
            }
        }
Beispiel #4
0
        void GenerateInternalEditor()
        {
            if (m_InternalEditor == null)
            {
                Object[] objs = new Object[targets.Length];
                for (var index = 0; index < targets.Length; index++)
                {
                    var            p         = (Preset)targets[index];
                    ReferenceCount reference = null;
                    if (!s_References.TryGetValue(p.GetInstanceID(), out reference))
                    {
                        reference = new ReferenceCount()
                        {
                            count     = 0,
                            reference = p.GetReferenceObject()
                        };
                        if (reference.reference == null)
                        {
                            // fast exit on NULL targets as we do not support their inspector in Preset.
                            m_NotSupportedEditorName = p.GetTargetTypeName();
                            m_UnsupportedIcon        = EditorGUIUtility.LoadIcon(m_NotSupportedEditorName.Replace('.', '/') + " Icon");
                            if (m_UnsupportedIcon == null)
                            {
                                m_UnsupportedIcon = AssetPreview.GetMiniTypeThumbnailFromType((serializedObject.FindProperty("m_TargetType.m_ManagedTypePPtr").objectReferenceValue as MonoScript)?.GetClass());
                                if (m_UnsupportedIcon == null)
                                {
                                    m_UnsupportedIcon = AssetPreview.GetMiniTypeThumbnailFromClassID(serializedObject.FindProperty("m_TargetType.m_NativeTypeID").intValue);
                                    if (m_UnsupportedIcon == null)
                                    {
                                        m_UnsupportedIcon = AssetPreview.GetMiniTypeThumbnail(typeof(Object));
                                    }
                                }
                            }
                            return;
                        }

                        reference.reference.name = p.name;
                        s_References.Add(p.GetInstanceID(), reference);
                        m_PresetsInstanceIds.Add(p.GetInstanceID());
                    }
                    reference.count++;
                    objs[index] = reference.reference;
                }
                m_InternalEditor = CreateEditor(objs);
            }
            else
            {
                //Coming back from an assembly reload... our references are probably broken and we need to fix them.
                for (var index = 0; index < targets.Length; index++)
                {
                    var            instanceID = targets[index].GetInstanceID();
                    ReferenceCount reference  = null;
                    if (!s_References.TryGetValue(instanceID, out reference))
                    {
                        reference = new ReferenceCount()
                        {
                            count     = 0,
                            reference = m_InternalEditor.targets[index]
                        };
                        s_References.Add(instanceID, reference);
                    }
                    reference.count++;
                }
            }

            m_InternalEditor.firstInspectedEditor = true;
        }