public static T CreateAsset(string _assetPath) { string[] _pathComponents = _assetPath.Split('/'); string _parentFolderPath = _pathComponents[0]; int _pIter = 0; while (++_pIter < (_pathComponents.Length - 1)) { string _currentFolderPath = _parentFolderPath + "/" + _pathComponents[_pIter]; if (!AssetsUtility.FolderExists(_currentFolderPath)) { AssetDatabase.CreateFolder(_parentFolderPath, _pathComponents[_pIter]); } // Update parent folder reference _parentFolderPath = _currentFolderPath; } // Ask Unity to import changes AssetDatabase.Refresh(); // Create the asset T _newAsset = ScriptableObject.CreateInstance <T>(); AssetDatabase.CreateAsset(_newAsset, AssetDatabase.GenerateUniqueAssetPath(_assetPath)); // Save the changes (_newAsset as AdvancedScriptableObject <T>).Save(); return(_newAsset); }
public static T GetAsset(string _assetName) { #if !UNITY_EDITOR if (assetGroupFolderName == null) { return(Resources.Load <T>(_assetName)); } else { return(Resources.Load <T>(string.Format("{0}/{1}", assetGroupFolderName, _assetName))); } #else string _assetSavedAtPath = string.Format("{0}/{1}.asset", kRelativePathToAssetsGroup, _assetName); T _scriptableObject = AssetDatabase.LoadAssetAtPath(_assetSavedAtPath, typeof(T)) as T; if (_scriptableObject == null) { // Need to create folder "Assets/Resources", if it doesnt exist if (!AssetsUtility.FolderExists(kRelativePathToResources)) { AssetDatabase.CreateFolder(kAssetsFolderName, kResourcesFolderName); } // Need to create folder "Assets/Resources/Group", if it doesnt exist if (!AssetsUtility.FolderExists(kRelativePathToAssetsGroup)) { AssetDatabase.CreateFolder(kRelativePathToResources, assetGroupFolderName); } // Refresh AssetDatabase.Refresh(); // Create asset T _newAsset = ScriptableObject.CreateInstance <T>(); AssetDatabase.CreateAsset(_newAsset, AssetDatabase.GenerateUniqueAssetPath(_assetSavedAtPath)); // Save (_newAsset as AdvancedScriptableObject <T>).Save(); // Assign reference of newly created asset _scriptableObject = _newAsset; } return(_scriptableObject); #endif }