Exemplo n.º 1
0
        /// <summary>
        /// プロジェクトで共有できるように、アセットファイルとしてGUIDを保存
        /// </summary>
        public static void Save(string guidAssetPath, Object asset)
        {
            string assetPath = AssetDatabase.GetAssetPath(asset);
            string guid      = AssetDatabase.AssetPathToGUID(assetPath);

            GuidAsset guidAsset = AssetDatabase.LoadAssetAtPath(guidAssetPath, typeof(GuidAsset)) as GuidAsset;

            if (guidAsset == null)
            {
                guidAsset = ScriptableObject.CreateInstance <GuidAsset>() as GuidAsset;
                AssetDatabase.CreateAsset(guidAsset, guidAssetPath);
            }
            guidAsset.hideFlags = HideFlags.NotEditable;

            if (guidAsset.guid == guid)
            {
                //変更がないならなにもしない
                return;
            }
            else
            {
                guidAsset.guid = guid;
                EditorUtility.SetDirty(guidAsset);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// アセットファイルとして保存してあるGUIDをロード
        /// </summary>
        public static Object Load(string guidAssetPath)
        {
            GuidAsset guidAsset = AssetDatabase.LoadAssetAtPath(guidAssetPath, typeof(GuidAsset)) as GuidAsset;

            if (guidAsset != null)
            {
                string assetPath = AssetDatabase.GUIDToAssetPath(guidAsset.guid);
                return(AssetDatabase.LoadAssetAtPath(assetPath, typeof(UnityEngine.Object)) as UnityEngine.Object);
            }
            else
            {
                return(null);
            }
        }