/// <summary> /// Acr task remove /// </summary> /// <param name="node"></param> public void Remove(ListenerNode node) { // 空实例不添加 if (node != null) { _dashCount++; _deletes.Add(node); } }
/// <summary> /// Action indexer /// </summary> /// <param name="id"></param> /// <returns></returns> public ListenerNode this[int id] { get { ListenerNode node = default; if (!(bool)_nodes?.TryGetValue(id, out node)) { Debug.Log($"listener nodes no exist this instance id = {id}."); } return(node); } }
/// <summary> /// Act task add. /// </summary> /// <param name="id"></param> /// <param name="action"></param> public void Add(ListenerNode node) { if (node != null && !_nodes.ContainsKey(node.Id)) { _nodes?.Add(node.Id, node); node.Start(this); } else { Debug.Log("node id repeat, can't manage it by this way."); } }
/// <summary> /// Auto play clips by list. /// </summary> /// <param name="audio">player</param> /// <param name="clips">clips</param> /// <param name="repeat">repeat mode</param> public void PlayList(AudioSource audio, ClipListMgr clipLstMgr, bool repeat = false) { // pass null instance if (audio == null) { Debug.Log("Refuse null instace or create AudioSource by 'new'."); return; } // test way will be change in the feature. if (_node != null) { Debug.Log("Now support one handler act only. in progress has been canceled."); Administrators.Instance.Mgr <Listeners>().Remove(_node); return; } bool trail = false; _node = new ListenerNode((int)InternalEvents.Listener_Players_AudioPlayer_PlayList, new Action( () => { if (clipLstMgr != null && clipLstMgr.Clips.Count > 0) { if (!audio.isPlaying) { if (trail) { _node.Shut(); Debug.Log(string.Format("Remove listener task:{0}", _node)); return; } Play(audio, clipLstMgr.Current); trail = clipLstMgr.Next(); // repeat task from first to end. if (trail && repeat) { trail = false; } } } else { _node.Shut(); Debug.Log(string.Format("Remove listener task:{0}", _node)); } } )); Administrators.Instance.Mgr <Listeners>().Add(_node); }