Пример #1
0
        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);
        }
Пример #2
0
        public static AssetCacheData LoadAssetAtGUIDAndLocalID(string guid, long localID)
        {
            if (guid == null)
            {
                // null‚ÍEmpty‚ÅŠÛ‚ß‚é
                guid = string.Empty;
            }
            var cache = GetCache(guid, localID);

            if (cache != null)
            {
                return(cache);
            }

            cache = new AssetCacheData();
            if (guid.IsEmpty())
            {
            }
            else
            {
                var result = localID == 0 ? guid.LoadAsset() : AssetDatabaseUtils.LoadAssetAtGUIDAndLocalID(guid, localID);
                cache.unityObject = result;
                if (result == null)
                {
                    cache.missing = true;
                }
            }
            SetCache(guid, localID, cache);
            return(cache);
        }