Last active
June 21, 2017 06:46
-
-
Save sehm/84c48eb97bf1178ca646 to your computer and use it in GitHub Desktop.
Unity Editor スクリプト:参照切れ(missing) を起こさない CreateAsset() AssetDatabase.CreateAsset() ですでにあるアセットを作成すると、管理IDが変わってしまうために参照切れが起こる
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using UnityEditor; | |
public class AssetDatabaseHelper | |
{ | |
// Editor スクリプト : 指定パスに指定アセットを書き込む. ない場合は新規作成. | |
// AssetDatabase.CreateAsset() ですでにあるアセットを作成すると、管理IDが変わってしまうために参照切れ(missing)が起こる。 | |
void CreateAsset(Object newAsset,string path,System.Type type) | |
{ | |
var asset = AssetDatabase.LoadAssetAtPath(path,type); | |
if( asset == null){ | |
AssetDatabase.CreateAsset(newAsset, path); | |
} else { | |
EditorUtility.CopySerialized(newAsset,asset); | |
AssetDatabase.SaveAssets(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment