private GetMiniThumbnail ( Object obj ) : |
||
obj | Object | |
Résultat |
internal virtual void OnHeaderIconGUI(Rect iconRect) { if (Editor.s_Styles == null) { Editor.s_Styles = new Editor.Styles(); } Texture2D texture2D = null; if (!this.HasPreviewGUI()) { bool flag = AssetPreview.IsLoadingAssetPreview(this.target.GetInstanceID()); texture2D = AssetPreview.GetAssetPreview(this.target); if (!texture2D) { if (flag) { this.Repaint(); } texture2D = AssetPreview.GetMiniThumbnail(this.target); } } if (this.HasPreviewGUI()) { this.OnPreviewGUI(iconRect, Editor.s_Styles.inspectorBigInner); } else if (texture2D) { GUI.Label(iconRect, texture2D, Editor.s_Styles.centerStyle); } }
internal virtual void OnHeaderIconGUI(Rect iconRect) { if (s_Styles == null) { s_Styles = new Styles(); } Texture2D image = null; if (!this.HasPreviewGUI()) { bool flag = AssetPreview.IsLoadingAssetPreview(this.target.GetInstanceID()); image = AssetPreview.GetAssetPreview(this.target); if (image == null) { if (flag) { this.Repaint(); } image = AssetPreview.GetMiniThumbnail(this.target); } } if (this.HasPreviewGUI()) { this.OnPreviewGUI(iconRect, s_Styles.inspectorBigInner); } else if (image != null) { GUI.Label(iconRect, image, s_Styles.centerStyle); } }
internal virtual void OnHeaderIconGUI(Rect iconRect) { Texture2D icon = null; if (!HasPreviewGUI()) { // Fetch isLoadingAssetPreview to ensure that there is no situation where a preview needs a repaint because it hasn't finished loading yet. bool isLoadingAssetPreview = AssetPreview.IsLoadingAssetPreview(target.GetInstanceID()); icon = AssetPreview.GetAssetPreview(target); if (!icon) { // We have a static preview it just hasn't been loaded yet. Repaint until we have it loaded. if (isLoadingAssetPreview) { Repaint(); } icon = AssetPreview.GetMiniThumbnail(target); } } if (HasPreviewGUI()) { // OnPreviewGUI must have all events; not just Repaint, or else the control IDs will mis-match. OnPreviewGUI(iconRect, Styles.inspectorBigInner); } else if (icon) { GUI.Label(iconRect, icon, Styles.centerStyle); } }
void DoObjectLabel(Rect rect, Object entry, GUIStyle style) { GUI.Label(rect, AssetPreview.GetMiniThumbnail(entry)); if (Event.current.type == EventType.MouseDown && Event.current.button == 0 && rect.Contains(Event.current.mousePosition)) { // One click shows where the referenced object is if (Event.current.clickCount == 1) { GUIUtility.keyboardControl = GUIUtility.GetControlID(FocusType.Keyboard); EditorGUIUtility.PingObject(entry); Event.current.Use(); } // Double click changes selection to referenced object else if (Event.current.clickCount == 2) { if (entry) { Selection.SetActiveObjectWithContext(entry, null); Event.current.Use(); editorWindow.Close(); GUIUtility.ExitGUI(); } } } rect.x += rect.height; rect.width -= rect.height; GUI.Label(rect, EditorGUIUtility.TempContent(entry.name, entry.name), style); }
private void Refresh(int instanceID, Rect rect) { if (!display) { return; } if (items.ContainsKey(instanceID) && items[instanceID].go != null) { RefreshActive(items[instanceID], rect); RefreshIcon(items[instanceID], rect); } else { GameObject target = EditorUtility.InstanceIDToObject(instanceID) as GameObject; if (target == null) { return; } items.Add(instanceID, new Information() { go = target, components = new List <Texture2D>(), }); Component[] components = items[instanceID].go.GetComponents <Component>(); int count = components.Length; for (int i = 0; i < count; i++) { if (components[i] == null) { continue; } else if (ignore.Exists(x => x.Equals(components[i].GetType()) || x.IsSubclassOf(components[i].GetType()))) { continue; } else { if (AssetPreview.GetMiniThumbnail(components[i]) is Texture2D texture) { items[instanceID].components.Add(texture); } } } } }
private Texture GetAssetPreviewTexture() { bool flag = AssetPreview.IsLoadingAssetPreview(base.target.GetInstanceID()); Texture texture = AssetPreview.GetAssetPreview(base.target); if (!texture) { if (flag) { GUIView.current.Repaint(); } texture = AssetPreview.GetMiniThumbnail(base.target); } return(texture); }
public ComponentElement(int level, string name, string menuPath, string commandString) { this.level = level; this.typeName = name.Replace(" ", string.Empty); this.menuPath = menuPath; if (commandString.StartsWith("SCRIPT")) { Texture miniThumbnail = (Texture)AssetPreview.GetMiniThumbnail(EditorUtility.InstanceIDToObject(int.Parse(commandString.Substring(6)))); this.content = new GUIContent(name, miniThumbnail); } else { int classID = int.Parse(commandString); this.content = new GUIContent(name, (Texture)AssetPreview.GetMiniTypeThumbnailFromClassID(classID)); } }
Texture GetAssetPreviewTexture() { Texture tex = null; bool isLoadingAssetPreview = AssetPreview.IsLoadingAssetPreview(target.GetInstanceID()); tex = AssetPreview.GetAssetPreview(target); if (!tex) { // We have a static preview it just hasn't been loaded yet. Repaint until we have it loaded. if (isLoadingAssetPreview) { GUIView.current.Repaint(); } tex = AssetPreview.GetMiniThumbnail(target); } return(tex); }
internal virtual void OnHeaderIconGUI(Rect iconRect) { Texture2D icon = null; // Fetch isLoadingAssetPreview to ensure that there is no situation where a preview needs a repaint because it hasn't finished loading yet. bool isLoadingAssetPreview = AssetPreview.IsLoadingAssetPreview(target.GetInstanceID()); icon = AssetPreview.GetAssetPreview(target); if (!icon) { // We have a static preview it just hasn't been loaded yet. Repaint until we have it loaded. if (isLoadingAssetPreview) Repaint(); icon = AssetPreview.GetMiniThumbnail(target); } GUI.Label(iconRect, icon, BaseStyles.centerStyle); }
public ComponentElement(int level, string name, string menuPath, string commandString) { this.level = level; this.menuPath = menuPath; this.isLegacy = menuPath.Contains("Legacy"); if (commandString.StartsWith("SCRIPT")) { int instanceID = int.Parse(commandString.Substring(6)); UnityEngine.Object obj = EditorUtility.InstanceIDToObject(instanceID); Texture miniThumbnail = AssetPreview.GetMiniThumbnail(obj); this.content = new GUIContent(name, miniThumbnail); } else { int classID = int.Parse(commandString); this.content = new GUIContent(name, AssetPreview.GetMiniTypeThumbnailFromClassID(classID)); } }
public static GUIContent ObjectContent(UnityEngine.Object obj, Type type) { if (obj) { if (obj is AudioMixerGroup) { EditorGUIUtility.s_ObjectContent.text = obj.name + " (" + ((AudioMixerGroup)obj).audioMixer.name + ")"; } else { if (obj is AudioMixerSnapshot) { EditorGUIUtility.s_ObjectContent.text = obj.name + " (" + ((AudioMixerSnapshot)obj).audioMixer.name + ")"; } else { EditorGUIUtility.s_ObjectContent.text = obj.name; } } EditorGUIUtility.s_ObjectContent.image = AssetPreview.GetMiniThumbnail(obj); } else { string arg; if (type == null) { arg = "<no type>"; } else { if (type.Namespace != null) { arg = type.ToString().Substring(type.Namespace.ToString().Length + 1); } else { arg = type.ToString(); } } EditorGUIUtility.s_ObjectContent.text = string.Format("None ({0})", arg); EditorGUIUtility.s_ObjectContent.image = AssetPreview.GetMiniTypeThumbnail(type); } return(EditorGUIUtility.s_ObjectContent); }
public static GUIContent ObjectContent(UnityEngine.Object obj, Type type) { if (obj) { EditorGUIUtility.s_ObjectContent.text = EditorGUIUtility.GetObjectNameWithInfo(obj); EditorGUIUtility.s_ObjectContent.image = AssetPreview.GetMiniThumbnail(obj); } else if (type != null) { EditorGUIUtility.s_ObjectContent.text = EditorGUIUtility.GetTypeNameWithInfo(type.Name); EditorGUIUtility.s_ObjectContent.image = AssetPreview.GetMiniTypeThumbnail(type); } else { EditorGUIUtility.s_ObjectContent.text = "<no type>"; EditorGUIUtility.s_ObjectContent.image = null; } return(EditorGUIUtility.s_ObjectContent); }
public static GUIContent ObjectContent(Object obj, Type type) { if (obj != null) { if (obj is AudioMixerGroup) { s_ObjectContent.text = obj.name + " (" + ((AudioMixerGroup)obj).audioMixer.name + ")"; } else if (obj is AudioMixerSnapshot) { s_ObjectContent.text = obj.name + " (" + ((AudioMixerSnapshot)obj).audioMixer.name + ")"; } else { s_ObjectContent.text = obj.name; } s_ObjectContent.image = AssetPreview.GetMiniThumbnail(obj); } else { string str; if (type == null) { str = "<no type>"; } else if (type.Namespace != null) { str = type.ToString().Substring(type.Namespace.ToString().Length + 1); } else { str = type.ToString(); } s_ObjectContent.text = string.Format("None ({0})", str); s_ObjectContent.image = AssetPreview.GetMiniTypeThumbnail(type); } return(s_ObjectContent); }
public ComponentDropdownItem(string name, string menuPath, string command) : base(name, -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(name, AssetPreview.GetMiniTypeThumbnailFromClassID(classId)); } m_ContentWhenSearching = new GUIContent(m_Content); if (m_IsLegacy) { m_ContentWhenSearching.text += " (Legacy)"; } }
public ComponentDropdownElement(string name, string menuPath, string command) : base(name) { this.m_MenuPath = menuPath; this.m_Command = command; this.m_IsLegacy = menuPath.Contains("Legacy"); if (command.StartsWith("SCRIPT")) { int instanceID = int.Parse(command.Substring(6)); UnityEngine.Object obj = EditorUtility.InstanceIDToObject(instanceID); Texture2D miniThumbnail = AssetPreview.GetMiniThumbnail(obj); this.m_Content = new GUIContent(name, miniThumbnail); } else { int classID = int.Parse(command); this.m_Content = new GUIContent(name, AssetPreview.GetMiniTypeThumbnailFromClassID(classID)); } this.m_ContentWhenSearching = new GUIContent(this.m_Content); if (this.m_IsLegacy) { GUIContent expr_A4 = this.m_ContentWhenSearching; expr_A4.text += " (Legacy)"; } }
private void OnGUIShaderPropTexture(Rect nameRect, Rect flagsRect, Rect valueRect, ShaderTextureInfo t) { GUI.Label(nameRect, t.name, EditorStyles.miniLabel); this.DrawShaderPropertyFlags(flagsRect, t.flags); Event current = Event.current; Rect position = valueRect; position.width = position.height; if (t.value != null && position.Contains(current.mousePosition)) { GUI.Label(position, GUIContent.Temp(string.Empty, "Ctrl + Click to show preview")); } if (current.type == EventType.Repaint) { Rect position2 = valueRect; position2.xMin += position.width; if (t.value != null) { Texture texture = t.value; if (texture.dimension != TextureDimension.Tex2D) { texture = AssetPreview.GetMiniThumbnail(texture); } EditorGUI.DrawPreviewTexture(position, texture); } GUI.Label(position2, (!(t.value != null)) ? t.textureName : t.value.name); } else if (current.type == EventType.MouseDown) { if (valueRect.Contains(current.mousePosition)) { EditorGUI.PingObjectOrShowPreviewOnClick(t.value, valueRect); current.Use(); } } }
public static void CreateAsset(UnityEngine.Object asset, string pathName) { ProjectWindowUtil.StartNameEditingIfProjectWindowExists(asset.GetInstanceID(), ScriptableObject.CreateInstance <DoCreateNewAsset>(), pathName, AssetPreview.GetMiniThumbnail(asset), null); }
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); }
// This method takes either object reference directly, or via SerializedObject. // Since it's not easy to know which parameters are mutually exclusively used, this method is // private and internal/public methods instead EITHER take SerializedObject OR direct reference. static Object DoObjectField(Rect position, Rect dropRect, int id, Object obj, Object objBeingEdited, System.Type objType, SerializedProperty property, ObjectFieldValidator validator, bool allowSceneObjects, GUIStyle style) { if (validator == null) { validator = ValidateObjectFieldAssignment; } if (property != null) { obj = property.objectReferenceValue; } Event evt = Event.current; EventType eventType = evt.type; // special case test, so we continue to ping/select objects with the object field disabled if (!GUI.enabled && GUIClip.enabled && (Event.current.rawType == EventType.MouseDown)) { eventType = Event.current.rawType; } bool hasThumbnail = EditorGUIUtility.HasObjectThumbnail(objType); // Determine visual type ObjectFieldVisualType visualType = ObjectFieldVisualType.IconAndText; if (hasThumbnail && position.height <= kObjectFieldMiniThumbnailHeight && position.width <= kObjectFieldMiniThumbnailWidth) { visualType = ObjectFieldVisualType.MiniPreview; } else if (hasThumbnail && position.height > kSingleLineHeight) { visualType = ObjectFieldVisualType.LargePreview; } Vector2 oldIconSize = EditorGUIUtility.GetIconSize(); if (visualType == ObjectFieldVisualType.IconAndText) { EditorGUIUtility.SetIconSize(new Vector2(12, 12)); // Have to be this small to fit inside a single line height ObjectField } else if (visualType == ObjectFieldVisualType.LargePreview) { EditorGUIUtility.SetIconSize(new Vector2(64, 64)); } switch (eventType) { case EventType.DragExited: if (GUI.enabled) { HandleUtility.Repaint(); } break; case EventType.DragUpdated: case EventType.DragPerform: if (eventType == EventType.DragPerform) { string errorString; if (!ValidDroppedObject(DragAndDrop.objectReferences, objType, out errorString)) { Object reference = DragAndDrop.objectReferences[0]; EditorUtility.DisplayDialog("Can't assign script", errorString, "OK"); break; } } if (dropRect.Contains(Event.current.mousePosition) && GUI.enabled) { Object[] references = DragAndDrop.objectReferences; Object validatedObject = validator(references, objType, property, ObjectFieldValidatorOptions.None); if (validatedObject != null) { // If scene objects are not allowed and object is a scene object then clear if (!allowSceneObjects && !EditorUtility.IsPersistent(validatedObject)) { validatedObject = null; } } if (validatedObject != null) { DragAndDrop.visualMode = DragAndDropVisualMode.Generic; if (eventType == EventType.DragPerform) { if (property != null) { property.objectReferenceValue = validatedObject; } else { obj = validatedObject; } GUI.changed = true; DragAndDrop.AcceptDrag(); DragAndDrop.activeControlID = 0; } else { DragAndDrop.activeControlID = id; } Event.current.Use(); } } break; case EventType.MouseDown: // Ignore right clicks if (Event.current.button != 0) { break; } if (position.Contains(Event.current.mousePosition)) { // Get button rect for Object Selector Rect buttonRect = GetButtonRect(visualType, position); EditorGUIUtility.editingTextField = false; if (buttonRect.Contains(Event.current.mousePosition)) { if (GUI.enabled) { GUIUtility.keyboardControl = id; if (property != null) { ObjectSelector.get.Show(objType, property, allowSceneObjects); } else { ObjectSelector.get.Show(obj, objType, objBeingEdited, allowSceneObjects); } ObjectSelector.get.objectSelectorID = id; evt.Use(); GUIUtility.ExitGUI(); } } else { Object actualTargetObject = property != null ? property.objectReferenceValue : obj; Component com = actualTargetObject as Component; if (com) { actualTargetObject = com.gameObject; } if (showMixedValue) { actualTargetObject = null; } // One click shows where the referenced object is, or pops up a preview if (Event.current.clickCount == 1) { GUIUtility.keyboardControl = id; PingObjectOrShowPreviewOnClick(actualTargetObject, position); evt.Use(); } // Double click opens the asset in external app or changes selection to referenced object else if (Event.current.clickCount == 2) { if (actualTargetObject) { AssetDatabase.OpenAsset(actualTargetObject); GUIUtility.ExitGUI(); } evt.Use(); } } } break; case EventType.ExecuteCommand: string commandName = evt.commandName; if (commandName == ObjectSelector.ObjectSelectorUpdatedCommand && ObjectSelector.get.objectSelectorID == id && GUIUtility.keyboardControl == id && (property == null || !property.isScript)) { return(AssignSelectedObject(property, validator, objType, evt)); } else if (commandName == ObjectSelector.ObjectSelectorClosedCommand && ObjectSelector.get.objectSelectorID == id && GUIUtility.keyboardControl == id && property != null && property.isScript) { if (ObjectSelector.get.GetInstanceID() == 0) { // User canceled object selection; don't apply evt.Use(); break; } return(AssignSelectedObject(property, validator, objType, evt)); } break; case EventType.KeyDown: if (GUIUtility.keyboardControl == id) { if (evt.keyCode == KeyCode.Backspace || (evt.keyCode == KeyCode.Delete && (evt.modifiers & EventModifiers.Shift) == 0)) { if (property != null) { property.objectReferenceValue = null; } else { obj = null; } GUI.changed = true; evt.Use(); } // Apparently we have to check for the character being space instead of the keyCode, // otherwise the Inspector will maximize upon pressing space. if (evt.MainActionKeyForControl(id)) { if (property != null) { ObjectSelector.get.Show(objType, property, allowSceneObjects); } else { ObjectSelector.get.Show(obj, objType, objBeingEdited, allowSceneObjects); } ObjectSelector.get.objectSelectorID = id; evt.Use(); GUIUtility.ExitGUI(); } } break; case EventType.Repaint: GUIContent temp; if (showMixedValue) { temp = s_MixedValueContent; } else if (property != null) { temp = EditorGUIUtility.TempContent(property.objectReferenceStringValue, AssetPreview.GetMiniThumbnail(property.objectReferenceValue)); obj = property.objectReferenceValue; if (obj != null) { Object[] references = { obj }; if (EditorSceneManager.preventCrossSceneReferences && CheckForCrossSceneReferencing(obj, property.serializedObject.targetObject)) { if (!EditorApplication.isPlaying) { temp = s_SceneMismatch; } else { temp.text = temp.text + string.Format(" ({0})", GetGameObjectFromObject(obj).scene.name); } } else if (validator(references, objType, property, ObjectFieldValidatorOptions.ExactObjectTypeValidation) == null) { temp = s_TypeMismatch; } } } else { temp = EditorGUIUtility.ObjectContent(obj, objType); } switch (visualType) { case ObjectFieldVisualType.IconAndText: BeginHandleMixedValueContentColor(); style.Draw(position, temp, id, DragAndDrop.activeControlID == id, position.Contains(Event.current.mousePosition)); Rect buttonRect = EditorStyles.objectFieldButton.margin.Remove(GetButtonRect(visualType, position)); EditorStyles.objectFieldButton.Draw(buttonRect, GUIContent.none, id, DragAndDrop.activeControlID == id, buttonRect.Contains(Event.current.mousePosition)); EndHandleMixedValueContentColor(); break; case ObjectFieldVisualType.LargePreview: DrawObjectFieldLargeThumb(position, id, obj, temp); break; case ObjectFieldVisualType.MiniPreview: DrawObjectFieldMiniThumb(position, id, obj, temp); break; default: throw new ArgumentOutOfRangeException(); } break; } EditorGUIUtility.SetIconSize(oldIconSize); return(obj); }
internal override void OnHeaderIconGUI(Rect iconRect) { // Even though we have a Preview panel, we don't want to reuse it for the header icon, because it looks very odd when // you start scrubbing through different slices etc. Just render the default icon for Texture2DArray objects. GUI.Label(iconRect, AssetPreview.GetMiniThumbnail(target)); }
private static void CreateDefaultAsset(Object asset, string pathName) { StartNameEditingIfProjectWindowExists(asset.GetInstanceID(), ScriptableObject.CreateInstance <DoCreateNewDefaultAsset>(), pathName, AssetPreview.GetMiniThumbnail(asset), null); }