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 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));
        }
Beispiel #3
0
        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));
        }
Beispiel #4
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 );
            }
        }
Beispiel #5
0
        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();
            }
        }
Beispiel #6
0
 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);
        }
Beispiel #8
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 (_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 );
            }
        }