//TODO: This should go to State Player class public static void BuildMap(List<TRAnimationClip> clips, Animation animation, Parser.Tr2Level leveldata) { for(int clipid = 0; clipid < clips.Count; clipid++) { //collect statechange info into TRAnimStateChange class int offsetstatechange = (int) leveldata.Animations[clipid].StateChangeOffset; int nstatechange = leveldata.Animations[clipid].NumStateChanges; for(int statechangeid = 0; statechangeid < nstatechange; statechangeid++) { //read statechange info from global Parser.Tr2StateChange leveldata.StateChanges Parser.Tr2StateChange statechange = leveldata.StateChanges[offsetstatechange + statechangeid]; int ndispatch = statechange.NumAnimDispatches; int offsetdispatch = statechange.AnimDispatch; //create wrapper statechange object TRAnimStateChange unitystatechange = new TRAnimStateChange(); unitystatechange.stateid = (int)statechange.StateID; for(int dispatchid = 0; dispatchid < ndispatch; dispatchid++) { Parser.Tr2AnimDispatch animdispatch = leveldata.AnimDispatches[offsetdispatch + dispatchid]; TRAnimDispatcher unityanimdispacher = new TRAnimDispatcher(); unityanimdispacher.NextAnimation = animdispatch.NextAnimation; unitystatechange.dispatchers.Add(unityanimdispacher); } clips[clipid].statechanges.Add(unitystatechange); } clips[clipid].state = animation[""+ clipid]; } }
void StateCrossFade(State from, State to) { if(from!=null && from.StateID !=-1 && to!=null && to.StateID!= -1) { //Debug.Log("Cross fade"); //Debug.Log("Cross fade from: " + from.name + " to:" + to.name ); int nstatechange = tranimations[from.AnimationID].statechanges.Count; for(int statechangeid = 0; statechangeid < nstatechange; statechangeid++) { TRAnimStateChange unitystatechange = tranimations[from.AnimationID].statechanges[statechangeid]; if(unitystatechange.stateid == to.StateID) { gunitystatechange = unitystatechange; animdispatchcount = 0; crossfading = true; rootanim.Stop(); current_state = to; if(from == statemap[KeyMapper.Idle]) Debug.Log("Cross fade from: " + from.AnimationID + " to:" + unitystatechange.stateid + " nstatechange: "+ nstatechange ); CrossFadeHandler(); return; } } //if(from == statemap[Jump]) //Debug.Log("Failed to Cross fade from: " + from.name + " to:" + to.name); rootanim.Stop(); current_state = to; PlayCurrentState(to); } }