public static string GUIDObjectField <T>(Rect position, string guid, bool safeCheck = true) where T : UnityObject { T value = null; var path = AssetDatabase.GUIDToAssetPath(guid); if (!path.IsEmpty()) { value = AssetDatabase.LoadAssetAtPath <T>(path); } using (new GUIBackgroundColorScope()) { if (safeCheck && value == null) { GUI.backgroundColor = HEditorStyles.fieldInvalidColor; } if (value == null && !guid.IsEmpty()) { var sz = guid.CalcSize(EditorStyles.miniLabel); EditorGUI.DrawRect(position.W(sz.x).AlignCenterH(sz.y), HEditorStyles.fieldInvalidColor); HEditorGUI.MiniLabel(position, guid); //HEditorGUI.MiniLabelR( position, guid ); value = ObjectField <T>(position.AlignR(32), value); } else { value = ObjectField <T>(position, value); } if (value == null) { return(guid); } } return(AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(value))); }
public static string FolderFiled(Rect position, GUIContent content, string path) { var name = path.IsEmpty() ? "None (Folder)" : path; var rcL = position; rcL.width -= 18; var icon = EditorIcon.folder; if (content == null) { EditorGUI.LabelField(rcL, GUIContent.none, EditorHelper.TempContent(name, icon), HEditorStyles.folderField); } else { rcL = EditorGUI.PrefixLabel(rcL, GUIUtility.GetControlID(FocusType.Passive), content); EditorGUI.LabelField(rcL, EditorHelper.TempContent(name, icon), HEditorStyles.folderField); } if (IconButton(position.AlignR(16), EditorIcon.folder, 1)) { var path2 = EditorUtility.OpenFolderPanel("Select Folder", "", ""); if (!path2.IsEmpty() && path != path2) { path = path2; GUI.changed = true; } } HEditorGUI.lastRect = rcL; return(path); }
public bool UIDraw(Rect rect, P.Params currentParams) { ScopeChange.Begin(); currentParams.WebGL_threadsSupport = EditorGUI.Toggle(rect.W(16), currentParams.WebGL_threadsSupport); if (HEditorGUI.IconButton(rect.AlignR(16).AddX(-4), EditorIcon._help)) { EditorUtility.DisplayDialog(SS._Info, infoText, SS._OK); } if (ScopeChange.End()) { P.Save(); return(true); } return(false); }
public bool UIDraw(Rect rect, P.Params currentParams) { ScopeChange.Begin(); currentParams.WebGL_exceptionSupport = (WebGLExceptionSupport)EditorGUI.EnumPopup(rect.TrimR(20), currentParams.WebGL_exceptionSupport); if (HEditorGUI.IconButton(rect.AlignR(16).AddX(-4), EditorIcon._help)) { EditorUtility.DisplayDialog(SS._Info, infoText, SS._OK); } if (ScopeChange.End()) { P.Save(); return(true); } return(false); }
public static T ObjectFieldAndAction <T>(Rect position, string label, SerializedProperty obj, Action <SerializedProperty> addButton = null, bool allowSceneObjects = false) where T : UnityObject { try { if (label.IsEmpty()) { var r = position; if (addButton != null) { r.width -= 16; var rr = position.AlignR(16); if (HEditorGUI.IconButton(rr, EditorIcon.plus)) { addButton.Invoke(obj); } } return((T)EditorGUI.ObjectField(r, obj.objectReferenceValue, typeof(T), allowSceneObjects)); } return((T)EditorGUI.ObjectField(position, EditorHelper.TempContent(label), obj.objectReferenceValue, typeof(T), allowSceneObjects)); } catch (ExitGUIException) { } return((T)obj.objectReferenceValue); }
// フォームのファイル拡張子 { "Image files", "png,jpg,jpeg", "All files", "*" }。 public static string FileFiled(Rect position, GUIContent content, string path, string[] filters) { var name = path.IsEmpty() ? "None (File)" : path; var rcL = position; rcL.width -= 18; //if( !path.IsEmpty() && !path.IsExistsFile() ) { // HEditorGUI.DrawDebugRect( position ); //} var icon = EditorIcon.icons_processed_unityeditor_defaultasset_icon_asset; if (content == null) { EditorGUI.LabelField(rcL, GUIContent.none, EditorHelper.TempContent(name, icon), HEditorStyles.folderField); } else { rcL = EditorGUI.PrefixLabel(rcL, GUIUtility.GetControlID(FocusType.Passive), content); EditorGUI.LabelField(rcL, EditorHelper.TempContent(name, icon), HEditorStyles.folderField); } if (IconButton(position.AlignR(16), EditorIcon.folder, 1)) { // new string[] { "Image files", "png,jpg,jpeg", "All files", "*" } var path2 = EditorUtility.OpenFilePanelWithFilters("Select File", "", filters); if (!path2.IsEmpty() && path != path2) { path = path2; GUI.changed = true; } //throw new ExitGUIException(); } HEditorGUI.lastRect = rcL; return(path); }