private static void _ExecAnimEvent(CutsceneController cc, string name) { Transform tr = _GetEventTrByName(cc, name); CC_EvtActions[] actions = tr.GetComponents <CC_EvtActions>(); Dbg.Assert(actions != null && actions.Length > 0, "CutsceneController._ExecAnimEvent: failed to get CC_EvtActions: {0}", name); for (int idx = 0; idx < actions.Length; ++idx) { CC_EvtActions action = actions[idx]; if (action.enabled) { action.OnAnimEvent(); } } }
/// <summary> /// make the AnimEvent and EventGO to be matched /// maybe not one-one match, multiple animEvent could match same EventGO /// </summary> private void _MatchEventGOAndAnimEvent() { ////////////////////////////////////////////////// // 1. for each AnimEvent, if there is not a corresponding eventGO, create it; // 2. for each eventGO, if there is not a corresponding AnimEvent, the delete the eventGO ////////////////////////////////////////////////// //if( _IsAnimEventPopupOpen() ) //{ // return; //don't execute matching if the AnimEventPopup is open //} // create a Dictionary for eventGO for (int idx = 0; idx < m_evtGoRoot.childCount; ++idx) { Transform ctr = m_evtGoRoot.GetChild(idx); m_evtGORefDict[ctr] = false; } // get the AnimEvent list AnimationEvent[] events = AnimationUtility.GetAnimationEvents(m_CurClip); // step 1 for (int idx = 0; idx < events.Length; ++idx) { AnimationEvent evt = events[idx]; string goName = evt.stringParameter; string funcName = evt.functionName; if (goName == null) { Dbg.LogWarn("CCEditor._MatchEventGOAndAnimEvent: found an event not specifying the GOName, at time: {0}", evt.time); ArrayUtility.RemoveAt(ref events, idx); --idx; } Transform oneTr = m_evtGoRoot.Find(goName); if (null == oneTr) { //create the go GameObject newEvtGO = new GameObject(goName); Misc.AddChild(m_evtGoRoot, newEvtGO); Dbg.Log("Sync AnimEvent with EventGO: create EventGO for: {0}", goName); //add component according to the funcName, the init-work should be executed by the MB's awake() or start() //CC_EvtActions newAct = newEvtGO.AddComponent("CC_" + funcName) as CC_EvtActions; //Dbg.Assert(m_CC != null, "CCEditor._MatchEventGOAndAnimEvent: failed to get CutsceneController"); //newAct.CC = m_CC; string tpName = "MH.CC_" + funcName; Type tp = RCall.GetTypeFromString(tpName); Dbg.Assert(tp != null, "CCEditor._MatchEventGOAndAnimEvent: failed to get type from string: {0}", tpName); CC_EvtActions newAct = newEvtGO.AddComponent(tp) as CC_EvtActions; Dbg.Assert(m_CC != null, "CCEditor._MatchEventGOAndAnimEvent: failed to get CutsceneController"); newAct.CC = m_CC; } else { m_evtGORefDict[oneTr] = true; //this event go is ref-ed, don't delete it } } // step 2 for (var ie = m_evtGORefDict.GetEnumerator(); ie.MoveNext();) { var pr = ie.Current; bool inUse = pr.Value; if (!inUse) { Transform tr = pr.Key; Dbg.Log("Sync AnimEvent with EventGO: delete EventGO: {0}", tr.name); GameObject.DestroyImmediate(tr.gameObject); } } m_evtGORefDict.Clear(); //clear the tmp data }