Created
February 2, 2013 13:47
-
-
Save anchan828/4697447 to your computer and use it in GitHub Desktop.
.assetファイル作成/保存ときのコード
This file contains 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
public class Asset | |
{ | |
public static void Save <T> (T asset) where T : ScriptableObject | |
{ | |
Directory.CreateDirectory (DeployGateUtility.settingsFolderPath); | |
string assetPath = DeployGateUtility.settingsFolderPath + typeof(T).Name + ".asset"; | |
T _asset = (T)AssetDatabase.LoadAssetAtPath (assetPath, typeof(T)); | |
if (_asset == null) | |
AssetDatabase.CreateAsset (asset, assetPath); | |
AssetDatabase.SaveAssets (); | |
AssetDatabase.Refresh (); | |
} | |
public static T Load<T> () where T : ScriptableObject | |
{ | |
string assetPath = DeployGateUtility.settingsFolderPath + typeof(T).Name + ".asset"; | |
T asset = (T)AssetDatabase.LoadAssetAtPath (assetPath, typeof(T)); | |
if (asset == null) { | |
asset = ScriptableObject.CreateInstance<T> (); | |
Save<T> (asset); | |
} | |
return asset; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment