static void CreateBGMGroupFromCLips() { List <string> resourcePaths = new List <string>(); foreach (var clip in Selection.objects.OfType <AudioClip>()) { if (!clip) { continue; } string assetPath = AssetDatabase.GetAssetPath(clip); if (!assetPath.Contains("Resources/")) { continue; } string resourcePath = Regex.Replace(assetPath, ".*/Resources/(.*)", "$1"); if (!string.IsNullOrEmpty(resourcePath)) { resourcePaths.Add(resourcePath); } } var group = ScriptableObject.CreateInstance <BGMGroup>(); group.SetBGMClips(resourcePaths); AssetUtil.CreateAssetInProjectWindow(group); }
public static UnityObject CreatePrefab(string folderPath, GameObject obj = null, ReplacePrefabOptions options = ReplacePrefabOptions.ConnectToPrefab) { //Create Folder if it doesn't already exist AssetUtil.CreateFolder(folderPath); folderPath = "Assets/" + folderPath; if (obj == null) { return(PrefabUtility.CreateEmptyPrefab(folderPath + "New Prefab.prefab")); } return(PrefabUtility.CreatePrefab(folderPath + "/" + obj.name + ".prefab", obj, options)); }
static void CreateSoundEffect() { var tempGO = new GameObject("Temp", typeof(SoundEffect)); var audioSource = tempGO.GetComponent <AudioSource>(); var prefabs = new List <Object>(); foreach (var clip in Selection.objects.OfType <AudioClip>()) { if (!clip) { continue; } audioSource.clip = clip; tempGO.name = "sfx_" + clip.name; string folder = AssetUtil.GetAssetFolderPath(clip); Object prefab = PrefabUtil.CreatePrefab(folder, tempGO); prefabs.Add(prefab); } Selection.objects = prefabs.ToArray(); Object.DestroyImmediate(tempGO); }
void Update(Object obj) { _object = obj; _path = AssetUtil.GetResourcePath(_object); }