public static T ObjectField <T>(GUIContent content, UnityObject obj, bool allowSceneObjects = false, bool safeCheck = true, params GUILayoutOption[] options) where T : UnityObject { var rc = GUILayoutUtility.GetRect(content, EditorStyles.objectField, options); if (content != GUIContent.none) { rc = EditorGUI.PrefixLabel(rc, GUIUtility.GetControlID(FocusType.Passive), content); } T _obj; using (new GUIBackgroundColorScope()) { if (safeCheck && obj == null) { GUI.backgroundColor = HEditorStyles.fieldInvalidColor; rc.width -= 16; } _obj = (T)EditorGUI.ObjectField(rc, obj, typeof(T), allowSceneObjects); } if (_obj == null) { rc.x = rc.xMax; rc.width = 16; if (HEditorGUI.IconButton(rc, EditorIcon.plus)) { var path = $"{ProjectBrowserUtils.activeFolderPath}/New {typeof( T ).Name}.asset".GenerateUniqueAssetPath(); _obj = (T)AssetDatabaseUtils.CreateScriptableObject(typeof(T), path); } } return(_obj); }
public static Vector3 Vector3Field(string label, Vector3 value, params GUILayoutOption[] options) { var cont = EditorHelper.TempContent(label); var rect = GUILayoutUtility.GetRect(cont, EditorStyles.numberField); return(HEditorGUI.Vector3Field(rect, cont, value)); }
///////////////////////////////////////// protected override void OnRowGUI(Item item, RowGUIArgs args) { if (item.missingなasmdefを検知) { EditorGUI.DrawRect(args.rowRect, ColorUtils.RGBA(Color.red, 0.2f)); } DefaultRowGUI(args); var rc2 = args.rowRect.W(16); rc2.x += (16 * (item.depth + 1)); rc2 = rc2.AlignCenter(14, 14); if (EditorHelper.HasMouseClick(rc2)) { EditorApplication.delayCall += () => { EditorHelper.PingAndSelectObject(item.target); }; } if (item.isDIRTY) { GUI.DrawTexture(args.rowRect.W(16), EditorIcon.warning); } if (item.isGUID) { HEditorGUI.MiniLabelR(args.rowRect, "GUID"); } }
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 void HeaderTitle(string title, float space = 4) { var labelCont = EditorHelper.TempContent(title); var rc = GUILayoutUtility.GetRect(labelCont, EditorStyles.label); HEditorGUI.HeaderTitle(rc, title); GUILayout.Space(space); }
public static bool FlatButton(GUIContent content, bool expand = false) { var style = new GUIStyle(HEditorStyles.flatButton); var size = content.text.CalcSizeFromLabel(); var rect = expand ? GUILayoutUtility.GetRect(content, style, GUILayout.Width(size.x + 16 + 8)) : GUILayoutUtility.GetRect(content, style); return(HEditorGUI.FlatButton(rect, content, style)); }
public static bool ImageButton(Texture2D tex, params GUILayoutOption[] option) { var style = new GUIStyle(HEditorStyles.imageButton); //style.margin = new RectOffset( 0, 0, 0, 0 ); var r = EditorHelper.GetLayout(tex, style, option); return(HEditorGUI.ImageButton(r, EditorHelper.TempContent(tex), style)); }
public static bool IconButton(Texture2D image, string tooltip, int marginHeighOffset = 0, bool mouseUp = false) { var style = new GUIStyle(HEditorStyles.iconButton); style.margin = new RectOffset(0, 0, marginHeighOffset, 0); var r = EditorHelper.GetLayout(image, style); return(HEditorGUI.IconButton(r, EditorHelper.TempContent(image, tooltip), style, 0, mouseUp)); }
public static bool IconButton(Texture2D tex, int marginHeighOffset = 0) { var style = new GUIStyle(HEditorStyles.iconButton); style.margin = new RectOffset(0, 0, marginHeighOffset, 0); var r = EditorHelper.GetLayout(tex, style); return(HEditorGUI.IconButton(r, tex, style, 0)); }
protected virtual void ShowButton(Rect r) { var rb = r; rb.x += (17 * 3); //HEditorGUI.DrawDebugRect( rb ); if (EditorHelper.HasMouseClick(rb)) { OnClose(); } if (!E.i.m_windowShade) { return; } if (m_disableShadeMode) { return; } var a = (Texture2D)EditorIcon.icons_processed_unityengine_ui_aspectratiofitter_icon_asset; if (showMode == 4) { return; } //} if (HEditorGUI.IconButton(r, a)) { //var dockArea = _editorWindow.dockArea; if (position.height < 25) { var rr = position; rr.height = m_height + 21; m_self.containerWindow.SetProperty <Rect>("position", rr); } else { minSize = new Vector2(minSize.x, -10); var rr = position; m_height = rr.height; rr.height = 21; m_self.containerWindow.SetProperty <Rect>("position", rr); } m_shade = !m_shade; //Debug.Log( m_shade ); } }
protected void _AlphaSlider(ref Rect rect, UnityObject obj, float alpha, Action <float> changed) { rect.width = 40; ScopeChange.Begin(); var _a = HEditorGUI.Slider(rect, alpha, 0, 1); if (ScopeChange.End()) { EditorHelper.Dirty(obj, () => { changed(_a); }); } rect.x += rect.width + 4; }
public static void PropertyField(SerializedProperty prop, string displayName, Texture2D icon, Action action) { var cont = EditorHelper.TempContent(displayName); var rect = GUILayoutUtility.GetRect(cont, EditorStyles.objectField); var lsss = EditorGUI.PrefixLabel(rect, cont); EditorGUI.PropertyField(lsss, prop, GUIContent.none); lsss.x -= 16; lsss.width = 16; lastRect = lsss; if (HEditorGUI.IconButton(lsss, icon, 1)) { action?.Invoke(); } }
protected void _AlphaSlider(ref Rect rect, UnityObject obj, Color color, Action <Color> changed) { rect.width = 40; ScopeChange.Begin(); var _a = HEditorGUI.Slider(rect, color.a, 0, 1); if (ScopeChange.End()) { EditorHelper.Dirty(obj, () => { changed(ColorUtils.RGBA(color, _a)); }); } rect.x += rect.width + 4; }
public static string FolderObjectField(Rect position, string guid, bool safeCheck = true) { UnityObject value = null; var path = guid.ToAssetPath(); if (!path.IsEmpty()) { value = path.LoadAsset <UnityObject>(); } 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 ); EditorGUI.LabelField(position, value.name); } else { value = EditorGUI.ObjectField(position, value, typeof(DefaultAsset), false); if (!UnitySymbol.UNITY_2019_3_OR_NEWER) { EditorGUI.DrawRect(position.TrimR(18), HEditorStyles.backGroundColor); } EditorGUI.LabelField(position.TrimR(18), EditorHelper.TempContent(value.ToAssetPath(), EditorIcon.folder), EditorStyles.textField); } if (value == null) { return(guid); } } return(value.ToGUID()); }
public static string FileFiled(string label, string file, string[] filters, params GUILayoutOption[] options) { if (!label.IsEmpty()) { EditorGUILayout.LabelField(label /*, EditorStyles.boldLabel*/); } var backgroundColor = GUI.backgroundColor; if (!file.IsEmpty() && !file.IsExistsFile()) { GUI.backgroundColor = HEditorStyles.helpBoxInvalidColor; } ScopeHorizontal.Begin(EditorStyles.helpBox); var rect = GUILayoutUtility.GetRect(GUIContent.none, HEditorStyles.folderField, options); var newfile = HEditorGUI.FileFiled(rect, GUIContent.none, file, filters); ScopeHorizontal.End(); GUI.backgroundColor = backgroundColor; return(newfile); }
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); }
public static string TextFieldAndAction(string label, string text, Action buttonAction, bool safeCheck = true, params GUILayoutOption[] options) { var labelCont = EditorHelper.TempContent(label); var rc = GUILayoutUtility.GetRect(labelCont, EditorStyles.textField, options); rc = EditorGUI.PrefixLabel(rc, GUIUtility.GetControlID(FocusType.Passive), new GUIContent(label)); using (new GUIBackgroundColorScope()) { if (label.IsEmpty()) { GUI.backgroundColor = HEditorStyles.fieldInvalidColor; } var fieldRect = rc; fieldRect.width -= 18; label = EditorGUI.TextField(fieldRect, text); if (HEditorGUI.IconButton(rc.AlignR(16), EditorIcon.settings, 1)) { buttonAction?.Invoke(); } } return(label); }
public static string FolderFiled(string path, params GUILayoutOption[] options) { var rect = GUILayoutUtility.GetRect(GUIContent.none, HEditorStyles.folderField, options); return(HEditorGUI.FolderFiled(rect, path)); }
void _Draw(SerializedProperty it, ref bool fold) { Type type = null; var field = ScriptAttributeUtility.GetFieldInfoFromProperty(it, ref type); var attrs = ScriptAttributeUtility.GetFieldAttributes(field); //Debug.Log(it.displayName); if (GetHas(attrs, typeof(GroupAttribute))) { if (!_foldLists.ContainsKey(it.displayName)) { _foldLists.Add(it.displayName, true); } var atb = Get <GroupAttribute>(attrs); var rect = GUILayoutUtility.GetRect(EditorHelper.TempContent(it.displayName), EditorStyles.helpBox); if (Event.current.type == EventType.Repaint) { var rect2 = rect; rect2.x -= 16; rect2.width += 16; EditorStyles.helpBox.Draw(rect2, false, false, false, false); } var sss = ""; if (atb.prefix) { sss = "Group - "; } sss += atb.name; _foldLists[it.displayName] = EditorGUI.Foldout(rect, _foldLists[it.displayName], sss, true); fold = _foldLists[it.displayName]; //EditorGUILayout.LabelField( it.displayName ); //if( _foldLists[ it.displayName ] ) { // EditorGUILayout.PropertyField( it, true ); //} //if( fold ) { // EditorGUI.indentLevel++; //} //else { // EditorGUI.indentLevel--; //} } if (fold == false) { return; } #if false if (it.isArray && type != typeof(string)) { HReorderableList lst = null; _reorderableLists.TryGetValue(it.displayName, out lst); if (lst == null) { lst = HReorderableList.CreateInstance(serializedObject, it.name); _reorderableLists.Add(it.displayName, lst); } //EditorGUILayout.LabelField( it.displayName ); lst.DoLayoutList(); } //else if( it.propertyType == SerializedPropertyType.Vector3 ) { //} else #endif //if( GetHas( attrs, typeof( PropertyAttribute ) ) { // var hander = UnityScriptAttributeUtility.GetHandler( it ); // hander.MethodInvoke<bool>( "OnGUI", new object[] { } ); //} //OnGUI( Rect position, SerializedProperty property, GUIContent label, bool includeChildren ) #if UNITY_2019_3_OR_NEWER if (it.propertyType == SerializedPropertyType.ManagedReference) { DrawSerializeReference(it); } else #endif if (it.propertyType == SerializedPropertyType.ObjectReference && !GetHas(attrs, typeof(PropertyAttribute))) { if (it.objectReferenceValue == null) { //EditorGUILayout.PropertyField( it, true ); //Debug.Log( it.GetTypeReflection().Name ); //if( it.GetTypeReflection() == typeof( Sprite ) ) { // it.objectReferenceValue = EditorGUILayout.ObjectField( it.displayName, it.objectReferenceValue,typeof( Sprite), false ); //} //else { // EditorGUILayout.PropertyField( it, true ); //} ScopeHorizontal.Begin(); it.objectReferenceValue = EditorGUILayout.ObjectField(it.displayName, it.objectReferenceValue, type, true); if (HEditorGUILayout.IconButton(EditorIcon.plus, 3)) { var so = CreateInstance(type); var path = $"Assets/New {type.Name}.asset".GenerateUniqueAssetPath(); AssetDatabase.CreateAsset(so, path); AssetDatabase.Refresh(); it.objectReferenceValue = so; } ScopeHorizontal.End(); //it.objectReferenceValue = EditorGUILayout.ObjectField( it.displayName, it.objectReferenceValue, it.GetTypeReflection(), true ); //it.objectReferenceValue=EditorGUILayout.ObjectField( it.displayName, it.objectReferenceValue, it.GetTypeReflection(), true, GUILayout.Height() ); } else if (it.objectReferenceValue.GetType() == typeof(Animator)) { HEditorGUI.PropertyField(it, EditorIcon.unityeditor_animationwindow, () => { EditorWindowUtils.Find(UnityTypes.UnityEditor_AnimationWindow); }, EditorIcon.unityeditor_graphs_animatorcontrollertool, () => { EditorWindowUtils.Find(UnityTypes.UnityEditor_Graphs_AnimatorControllerTool); }); } else if (it.objectReferenceValue.GetType().IsSubclassOf(typeof(ScriptableObject))) { Editor ed = null; if (_editorLists == null) { return; } _editorLists.TryGetValue(it.displayName, out ed); if (ed == null) { ed = Editor.CreateEditor(it.objectReferenceValue); _editorLists.Add(it.displayName, ed); } var h = EditorStyles.objectField.CalcHeight(GUIContent.none, 10); EditorGUILayout.PropertyField(it, EditorHelper.TempContent(" "), true); var r = GUILayoutUtility.GetLastRect(); r.y = r.yMax - h; r.height = h; it.isExpanded = EditorGUI.Foldout(r, it.isExpanded, EditorHelper.TempContent(it.displayName), true); if (it.isExpanded) { try { EditorGUI.indentLevel++; EditorGUIUtility.hierarchyMode = false; ScopeVertical.Begin(/*EditorStyles.helpBox*/); ed.OnInspectorGUI(); //GUILayout.FlexibleSpace(); ScopeVertical.End(); EditorGUIUtility.hierarchyMode = true; EditorGUI.indentLevel--; } catch (Exception e) { Debug.LogException(e); } } } else { //HGUIScope.Horizontal(_); //void _() { //it.objectReferenceValue = EditorGUILayout.ObjectField( it.displayName, it.objectReferenceValue, type, true ); EditorGUILayout.PropertyField(it, EditorHelper.TempContent(L10n.Tr(it.displayName)), true); // GUILayout.Button("aaaa"); //} } } else { //Debug.Log( type .Name); EditorGUILayout.PropertyField(it, EditorHelper.TempContent(L10n.Tr(it.displayName)), true); } }
protected virtual void ShowButton(Rect r) { var rb = r; rb.x += (17 * 3); //HEditorGUI.DrawDebugRect(rb); if (EditorHelper.HasMouseClick(rb)) { OnClose(); } if (!E.i.m_windowShade) { return; } if (m_disableShadeMode) { return; } var a = (Texture2D)EditorIcon.icons_processed_unityengine_ui_aspectratiofitter_icon_asset; if (_editorWindow == null) { return; } //if( _editorWindow.dockArea != null ) { if (_editorWindow.showMode == 4) { return; } //} if (HEditorGUI.IconButton(r, a)) { //Debug.Log( $"{position}" ); var dockArea = _editorWindow.dockArea; //if( dockArea != null ) { // var wnd = dockArea.GetProperty<object>( "window" ); // var inaa = wnd.GetField<int>( "m_ShowMode" ); // Debug.Log( inaa ); //} if (position.height < 25) { var rr = position; rr.height = m_height; //if( dockArea == null ) Debug.Log( "dockArea null" ); if (dockArea != null) { var wnd = dockArea.GetProperty <object>("window"); var rrc = wnd.GetProperty <Rect>("position"); //Debug.Log( rrc ); wnd.SetProperty <Rect>("position", rr); } //position = rr; } else { minSize = new Vector2(minSize.x, -10); var rr = position; m_height = rr.height; rr.height = 21; //var dockArea = _editorWindow.dockArea; //if( dockArea == null ) Debug.Log( "dockArea null" ); if (dockArea != null) { var wnd = dockArea.GetProperty <object>("window"); wnd.SetProperty <Rect>("position", rr); } //position = rr; } m_shade = !m_shade; //Debug.Log( m_shade ); } }