Пример #1
0
        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)));
        }
Пример #2
0
        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());
        }