예제 #1
0
        public void Setter(string n, object o)
        {
            switch (n.ToLower())
            {
            case "isplaying":
                if ((bool)o && !unitySource.isPlaying)
                {
                    unitySource.Play();
                }
                else if (!(bool)o && unitySource.isPlaying)
                {
                    unitySource.Stop();
                }
                break;

            case "clip":
                currentClip      = (AudioClipAsset)o;
                unitySource.clip = currentClip.GetClip();
                break;

            case "volume":
                unitySource.volume = (float)o;
                break;

            default:
                throw new Exception();
            }
        }
예제 #2
0
        public static void CreateAudioClipAsset()
        {
            var    selection = Selection.objects;
            string path      = string.Empty;

            StringBuilder sb = new StringBuilder();

            foreach (Object s in selection)
            {
                if (s is DefaultAsset && (path = AssetDatabase.GetAssetPath(s)) != null && Directory.Exists(path))
                {
                    var ragName = s.name.ToLower() + "_audio.asset";
                    var tagName = s.name.ToLower() + "_atlas";

                    string res_path = Path.Combine(path, ragName);

                    sb.Append("Crate audioclip asset :");
                    sb.Append(ragName);
                    sb.Append("\r\n");

                    var              allchildren = EditorUtils.getAllChildFiles(path, @"\.meta$|\.manifest$|\.DS_Store$|\.u$", null, false);
                    List <int>       names       = new List <int>();
                    List <AudioClip> audioClips  = new List <AudioClip>();

                    for (int i = 0; i < allchildren.Count; i++)
                    {
                        var itemPath = allchildren[i];
                        var ti       = AssetImporter.GetAtPath(itemPath);
                        var aclip    = AssetDatabase.LoadAssetAtPath <AudioClip>(itemPath);
                        if (aclip)
                        {
                            audioClips.Add(aclip);
                            names.Add(LuaHelper.StringToHash(aclip.name));
                            if (ti != null)
                            {
                                ti.assetBundleName = tagName + Common.CHECK_ASSETBUNDLE_SUFFIX;
                            }
                        }

                        EditorUtility.DisplayProgressBar("Processing...", "生成中... (" + (i + 1) + " / " + allchildren.Count + ")", (i + 1) / allchildren.Count);
                    }

                    EditorUtility.ClearProgressBar();

                    //生成或者替换资源
                    var audioAsset = AssetDatabase.LoadAssetAtPath <AudioClipAsset>(res_path);
                    if (audioAsset == null)
                    {
                        audioAsset = AudioClipAsset.CreateInstance <AudioClipAsset>();
                        AssetDatabase.CreateAsset(audioAsset, res_path);
                    }

                    audioAsset.audioClips = audioClips.ToArray();
                    audioAsset.audioNames = names.ToArray();
                    EditorUtility.SetDirty(audioAsset);
                    var import = AssetImporter.GetAtPath(res_path);
                    import.assetBundleName = Path.GetFileNameWithoutExtension(ragName) + Common.CHECK_ASSETBUNDLE_SUFFIX;
                    sb.AppendFormat("build {0} success  count = {1} ", ragName, audioClips.Count);
                    AssetDatabase.SaveAssets();
                }
            }

            sb.AppendLine("\r\nall completed");
            Debug.Log(sb.ToString());
        }