public static bool ObjectPickerField(SerializedProperty property, Action <UnityEngine.Object> itemSelectedCallback = null, string folderPath = "Assets") { if (GUILayout.Button("C", EditorStyles.miniButton, GUILayout.Width(24f))) { ObjectSelectorWindow.ShowObjectPicker(property, itemSelectedCallback, folderPath); } return(true); }
/// <summary> /// 显示资源选择窗口 /// </summary> /// <param name="otherWindow">选择了资源后需要刷新的界面</param> /// <param name="assetName">当前选择的资源名字</param> /// <param name="paths">选择当前文件夹下资源(包含子文件夹)</param> /// <param name="assetType">资源类型</param> /// <param name="selectFileCallBack">选择后的回调</param> public static void Show(EditorWindow otherWindow, string assetName, string[] paths, Type assetType, CallBack <string, UnityEngine.Object> selectFileCallBack) { if (win == null) { win = GetWindow <ObjectSelectorWindow>(); } win.titleContent = new GUIContent("Select " + assetType.Name); win.Init(otherWindow, assetName, paths, assetType, selectFileCallBack); }
private object DrawTextureGUI(string text, object value) { if (editTextureValue != null) { value = editTextureValue; editTextureValue = null; } GUILayout.BeginHorizontal(); value = EditorDrawGUIUtil.DrawBaseValue(text, value); if (GUILayout.Button("o", GUILayout.Width(20))) { ObjectSelectorWindow.Show(GeneralDataModificationWindow.GetInstance(), value.ToString(), new string[] { "Assets/Resources" }, typeof(GameObject), (assetName, obj) => { editTextureValue = assetName; } ); } GUILayout.EndHorizontal(); string content = value.ToString(); bool isHave = false; try { ResourcesConfigManager.Initialize(); if (ResourcesConfigManager.GetIsExitRes(content)) { Texture2D obj = ResourceManager.Load <Texture2D>(content); if (obj) { if (obj != previewTex) { previewEditor1 = Editor.CreateEditor(obj); previewTex = obj; } previewEditor1.OnPreviewGUI(GUILayoutUtility.GetRect(300, 300), EditorStyles.helpBox); isHave = true; } } } catch { } if (!isHave) { EditorGUILayout.HelpBox("没有图片 [" + value + "] !!", MessageType.Error); } return(value); }
private void OnDisable() { m_ItemSelectedCallback = null; m_CurrentBuiltinResources = null; m_ActiveBuiltinList = null; m_LastSelectedObject = null; m_LastSelectedObjectIcon = null; if (s_SharedObjectSelector == this) { s_SharedObjectSelector = null; } if (m_EditorCache != null) { m_EditorCache.Dispose(); } }
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { float w = position.width; position.width = w - 16; EditorGUI.PropertyField(position, property); position.x += position.width; position.width = 16; if (GUI.Button(position, "s", EditorStyles.miniButton)) { ObjectSelecterAttribute selecterAttribute = attribute as ObjectSelecterAttribute; //Type extention = selecterAttribute.type; ObjectSelectorWindow.ShowObjectPicker(selecterAttribute.type, property.objectReferenceValue, property, null, selecterAttribute.path); } }
public override void OnInspectorGUI() { targetObj.Update(); EditorGUILayout.BeginHorizontal(); EditorGUILayout.PropertyField(person); EditorGUIUtil.ObjectPickerField(person, null, "Assets/AC"); EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); EditorGUILayout.PropertyField(person2); if (GUILayout.Button("C", EditorStyles.miniButton, GUILayout.Width(24f))) { ObjectSelectorWindow.ShowObjectPicker <Sprite>(person.objectReferenceValue, OnObjectPicker, "Assets"); } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); EditorGUILayout.PropertyField(person3); if (GUILayout.Button("C", EditorStyles.miniButton, GUILayout.Width(24f))) { ObjectSelectorWindow.ShowObjectPicker <AudioClip>(person3.objectReferenceValue, OnObjectPicker3, "Assets/Sound"); } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); EditorGUILayout.PropertyField(person4); if (GUILayout.Button("C", EditorStyles.miniButton, GUILayout.Width(24f))) { GameObject go = AssetDatabase.LoadAssetAtPath <GameObject>( "Assets/Standard Assets/Characters/ThirdPersonCharacter/Prefabs/ThirdPersonController.prefab"); AnimationClip[] clips = AnimationUtility.GetAnimationClips(go); List <int> ids = new List <int>(); foreach (var clip in clips) { ids.Add(clip.GetInstanceID()); } ObjectSelectorWindow.ShowObjectPicker <AnimationClip>(person4.objectReferenceValue, OnObjectPicker4, "Assets/Standard Assets/Characters/ThirdPersonCharacter/Animation", ids); } EditorGUILayout.EndHorizontal(); targetObj.ApplyModifiedProperties(); }