コード例 #1
0
        public static AssetReference ToAssetReference(this Object obj)
        {
            var reference = new AssetReference();

            if (!obj || null == obj)
            {
                return(reference);
            }

#if UNITY_EDITOR
            var json = UnityEditor.EditorJsonUtility.ToJson(new Container {
                o = obj
            });
            if (string.IsNullOrEmpty(json) || json == s_EmptyJsonObject)
            {
                return(reference);
            }
            json = json.Substring(5, json.Length - 6);
            object handleObject = new UnityObjectHandle();
            UnityEditor.EditorJsonUtility.FromJsonOverwrite(json, handleObject);
            var handle = (UnityObjectHandle)handleObject;
            reference.Guid   = new Guid(handle.guid);
            reference.FileId = handle.fileID;
            reference.Type   = handle.type;
#endif
            return(reference);
        }
コード例 #2
0
        public static Object ToUnityObject(this AssetReference assetReference)
        {
#if UNITY_EDITOR
            var handle = new UnityObjectHandle
            {
                fileID = assetReference.FileId,
                guid   = assetReference.Guid.ToString("N"),
                type   = assetReference.Type
            };
            var json = "{\"o\":" + UnityEditor.EditorJsonUtility.ToJson(handle) + "}";

            Container.Instance.o = null;
            UnityEditor.EditorJsonUtility.FromJsonOverwrite(json, Container.Instance);
            return(Container.Instance.o);
#else
            return(null);
#endif
        }