// Use this for initialization void Start() { //Animation state codes are coupled with keycodes. Initialised Keymapper first. KeyMapper.InitKeyCode(); animevent = new AnimationEvent(); //tranimations = movableobj.AnimClips; /* * Showing how I looked up animation clip to its engine state ID. * For example Idle animation is mapped to state id 2. Actually engine uses Idle animation * via its state id 2. This mapping is realized throgh tranimations list. I had to * go through error and trial process to realize this map. Here was my procedure: * * First I selected a animation clip, for example Idle, by playing it. I use AnimationTester.cs for that * Then look up the clip index and I index it into tranimations[clip index].stateid and logged the stateid * Then I creat a new State(name, logged_stateid, animation_clip_id) * Then assign that State object to a predifined location of statemap[] array. * More animation could be mapped this way. In that case statemap[] should be resized * * Index to statemap[] array is generated by KeyMapper class, for eaxample KeyMapper.Walk * * * * Debug.Log("Anim ID: KeyMapper.Idle" + "103" + " " + "State ID:" + tranimations[103].stateid); //2 * Debug.Log("Anim ID: KeyMapper.Walk" + "1" + " " + "State ID:" + tranimations[1].stateid); //0 * Debug.Log("Anim ID: KeyMapper.Run" + "0" + " " + "State ID:" + tranimations[0].stateid); //1 * Debug.Log("Anim ID: KeyMapper.Run A bit" + "6" + " " + "State ID:" + tranimations[0].stateid); //1 * * Debug.Log("Anim ID: jump start A " + "26" + " " + "State ID:" + tranimations[26].stateid); //19 * Debug.Log("Anim ID: jump start B " + "27" + " " + "State ID:" + tranimations[27].stateid); //28 * Debug.Log("Anim ID: jump start C " + "28" + " " + "State ID:" + tranimations[28].stateid); //28 * * Debug.Log("Anim ID: jump air " + "77" + " " + "State ID:" + tranimations[77].stateid); //3 * Debug.Log("Anim ID: jump Back " + "89" + " " + "State ID:" + tranimations[89].stateid); //5 * Debug.Log("Anim ID: Flip Back " + "75" + " " + "State ID:" + tranimations[75].stateid); //25 * * Debug.Log("Anim ID: Jump Right " + "80" + " " + "State ID:" + tranimations[80].stateid); //26 * Debug.Log("Anim ID: Jump Right " + "78" + " " + "State ID:" + tranimations[78].stateid); //27 * * Debug.Log("Anim ID: KeyMapper.Roll Right " + "81" + " " + "State ID:" + tranimations[81].stateid); //26 * Debug.Log("Anim ID: KeyMapper.Roll KeyMapper.Left " + "79" + " " + "State ID:" + tranimations[79].stateid); //27 * * Debug.Log("Anim ID: Step KeyMapper.Left " + "12" + " " + "State ID:" + tranimations[12].stateid); //6 * Debug.Log("Anim ID: Step Right " + "13" + " " + "State ID:" + tranimations[13].stateid); //7 * * Debug.Log("Anim ID: Throw Flare " + "189" + " " + "State ID:" + tranimations[189].stateid); //0 * Debug.Log("Anim ID: Pickup Flare " + "204" + " " + "State ID:" + tranimations[204].stateid); //67 * Debug.Log("Anim ID: Light Flare " + "257" + " " + "State ID:" + tranimations[204].stateid); // * * Debug.Log("Anim ID: Action " + "11" + " " + "State ID:" + tranimations[11].stateid); // * Debug.Log("Anim ID: Switching " + "197" + " " + "State ID:" + tranimations[197].stateid); // 40 * //Debug.Log("Anim ID: KeyMapper.DrawWeapon " + "218" + " " + "State ID:" + tranimations[218].stateid); // * * Debug.Log("Anim ID: Grab " + "172" + " " + "State ID:" + tranimations[172].stateid); // 56 * Debug.Log("Anim ID: PullUpLow " + "42" + " " + "State ID:" + tranimations[42].stateid); //2 * Debug.Log("Anim ID: PullUpHigh " + "97" + " " + "State ID:" + tranimations[97].stateid); //19 * Debug.Log("Anim ID: PullUpAcrobatic " + "159" + " " + "State ID:" + tranimations[159].stateid); //54 * Debug.Log("Anim ID: WalkUp " + "50" + " " + "State ID:" + tranimations[50].stateid); //2 * * //pull up animations: * //PullUpLow: When Obstackle Height == Lara's Height * //KeyMapper.Walk Up[50]: When Obstackle Height == Lara's heap * //Auto jump and grab[172] + pullup[PullUpHigh]: When Obstackle Height == twice Lara's Height * //Manual jump and grab[172] + pullup[PullUpHigh]: When Obstackle Height > twice Lara's Height * //Manual jump and grab[172] + pullupAcrobatic[PullUpAcrobatic]: When Obstackle Height > twice Lara's Height * //simi left[136]: * //simi right[137]: * //jump grab[150]: * //switching[197] * //61,62 : walk back */ Debug.Log("Anim ID: Wadding " + "177" + " " + "State ID:" + tranimations[177].stateid); //65 Debug.Log("Anim ID: inwater swimming " + "86" + " " + "State ID:" + tranimations[86].stateid); //17 Debug.Log("Anim ID: inwater idle " + "108" + " " + "State ID:" + tranimations[108].stateid); //13 Debug.Log("Anim ID: surface_water swimming " + "116" + " " + "State ID:" + tranimations[116].stateid); //34 Debug.Log("Anim ID: surface idle " + "110" + " " + "State ID:" + tranimations[110].stateid); //33 Debug.Log("Anim ID: surface pullup " + "111" + " " + "State ID:" + tranimations[111].stateid); //33 //build statemap and actions array. //Update add 4 animation layer with each layer size 32 [normal, shallow, inwater, surface ] statemap = new State[128 + 8]; actions = new Action[128 + 8]; //statemap[KeyMapper.Search] = new State ("KeyMapper.Search", -1,-1); //statemap[KeyMapper.Menu] = new State( "KeyMapper.Menu", - 1,-1); //statemap[KeyMapper.PickupFlare] = new State ("Pickup Flare", 67,204); statemap[KeyMapper.PickupFlare].loop = false; statemap[KeyMapper.PickupFlare].moving = false; //statemap[KeyMapper.StepToKeyMapper.Left] = new State ("KeyMapper.StepToKeyMapper.Left", 6,12); statemap[KeyMapper.StepToKeyMapper.Left].moving = true; statemap[KeyMapper.StepToKeyMapper.Left].movedir = Vector3.left; statemap[KeyMapper.StepToKeyMapper.Left].Speed = 0.1f; //statemap[KeyMapper.StepToRight] = new State ("KeyMapper.StepToRight", 7,13); statemap[KeyMapper.StepToRight].moving = true; statemap[KeyMapper.StepToRight].movedir = Vector3.right; statemap[KeyMapper.StepToRight].Speed = 0.1f; statemap[KeyMapper.Jump] = new State("Jump", 28, 28); statemap[KeyMapper.Jump].OnAir = true; statemap[KeyMapper.Jump].movedir = Vector3.up * 0.35f; statemap[KeyMapper.Idle] = new State("KeyMapper.Idle", 2, 103); statemap[KeyMapper.Idle].loop = true; //statemap[1] = new State("KeyMapper.Walk",0,1); //statemap[KeyMapper.PrimaryAction] = new State ("Primary Action", 2,11); statemap[KeyMapper.PrimaryAction] = new State("Primary Action", 2, 103); statemap[KeyMapper.DrawWeapon] = new State("KeyMapper.DrawWeapon", 0, 218); statemap[KeyMapper.Roll] = new State("KeyMapper.Roll", -1, -1); //statemap[10] = new State ("KeyMapper.Run", 1,0); statemap[KeyMapper.Run] = new State("KeyMapper.Run", 1, 0); statemap[KeyMapper.Run].loop = true; statemap[KeyMapper.Run].moving = true; statemap[KeyMapper.Run].Speed = 6; statemap[KeyMapper.Down] = new State("KeyMapper.Down", -1, -1); statemap[KeyMapper.Left] = new State("KeyMapper.Left", -1, -1); statemap[KeyMapper.Right] = new State("Right", -1, -1); statemap[KeyMapper.Walk] = new State("KeyMapper.Walk", 0, 1); statemap[KeyMapper.Walk].loop = true; statemap[KeyMapper.Walk].moving = true; statemap[KeyMapper.Walk].Speed = 2.0f; //Add some sfx to the state run. I'm not sure weather it should be done here or else where statemap[KeyMapper.Run].sfx = new AudioClip[2]; statemap[KeyMapper.Run].sfx[0] = (AudioClip)Resources.Load("sfx/run", typeof(AudioClip)); statemap[KeyMapper.Run].sfx[1] = (AudioClip)Resources.Load("sfx/run", typeof(AudioClip)); statemap[KeyMapper.JumpAir] = new State("Jump Air", 3, 77); statemap[KeyMapper.JumpAir].OnAir = true; statemap[KeyMapper.JumpAir].moving = true; statemap[KeyMapper.JumpAir].Speed = 8; statemap[KeyMapper.JumpAir].movedir = Vector3.forward + Vector3.up * 0.35f; //statemap[jumpBack] = new State("jump Back",5,89); statemap[jumpBack].OnAir = true; statemap[jumpBack].loop = true; statemap[jumpBack].moving = true; statemap[jumpBack].movedir = -Vector3.forward; //statemap[FlipBack] = new State("Flip Back",25,75); statemap[FlipBack].OnAir = true; statemap[FlipBack].moving = true; statemap[FlipBack].movedir = -Vector3.forward; //statemap[JumpRight] = new State("Jump Right",26,81); statemap[JumpRight].OnAir = true; statemap[JumpRight].moving = true; //statemap[JumpKeyMapper.Left] = new State("Jump KeyMapper.Left",27,79); statemap[JumpKeyMapper.Left].OnAir = true; statemap[JumpKeyMapper.Left].moving = true; statemap[KeyMapper.Grab] = new State("Grab", 56, 172); statemap[KeyMapper.PullUpLow] = new State("Grab", 2, 42); statemap[KeyMapper.PullUpLow].moving = false; statemap[KeyMapper.PullUpLow].movedir = Vector3.up * 0.35f; statemap[KeyMapper.PullUpHigh] = new State("PullUpHigh", 19, 97); statemap[KeyMapper.PullUpHigh].moving = false; statemap[KeyMapper.PullUpHigh].movedir = Vector3.up * 0.35f; statemap[KeyMapper.PullUpAcrobatic] = new State("PullUpAcrobatic", 54, 159); statemap[KeyMapper.PullUpAcrobatic].moving = false; statemap[KeyMapper.PullUpAcrobatic].movedir = Vector3.up * 0.35f; statemap[KeyMapper.WalkUp] = new State("WalkUp", 2, 50); statemap[KeyMapper.WalkUp].moving = false; statemap[KeyMapper.WalkUp].movedir = Vector3.up * 0.35f; //Add some sfx to the state pull up. I'm not sure weather it should be done here or else where statemap[KeyMapper.PullUpHigh].sfx = new AudioClip[1]; statemap[KeyMapper.PullUpHigh].sfx[0] = (AudioClip)Resources.Load("sfx/pull_up", typeof(AudioClip)); statemap[KeyMapper.WalkUp].sfx = new AudioClip[1]; statemap[KeyMapper.WalkUp].sfx[0] = (AudioClip)Resources.Load("sfx/pull_up", typeof(AudioClip)); /* * * Now build a array of action, where action stores a list of State objects. Generally * one state is stored in each action but more can be added to build up complex action * */ actions[KeyMapper.Idle] = new Action("KeyMapper.Idle"); actions[KeyMapper.PrimaryAction] = new Action("Primary Action"); actions[KeyMapper.DrawWeapon] = new Action("KeyMapper.DrawWeapon"); actions[KeyMapper.Roll] = new Action("KeyMapper.Roll"); actions[KeyMapper.Run] = new Action("KeyMapper.Run"); actions[KeyMapper.Down] = new Action("KeyMapper.Down"); actions[KeyMapper.Left] = new Action("KeyMapper.Left"); actions[KeyMapper.Right] = new Action("Right"); actions[KeyMapper.Walk] = new Action("KeyMapper.Walk"); actions[KeyMapper.Jump] = new Action("Jump"); actions[KeyMapper.JumpAir] = new Action("Jump Air"); actions[KeyMapper.JumpAirStanding] = new Action("JumpAirStanding"); //actions[KeyMapper.jumpBack] = new Action("jump Back"); // actions[KeyMapper.FlipBack] = new Action("Flip Back"); //actions[KeyMapper.JumpRight] = new Action("Jump Right"); //actions[KeyMapper.Jump.Left] = new Action("Jump Left"); actions[KeyMapper.Grab] = new Action("Grab"); actions[KeyMapper.PullUpLow] = new Action("PullUpLow"); actions[KeyMapper.PullUpHigh] = new Action("PullUpHigh"); actions[KeyMapper.PullUpAcrobatic] = new Action("PullUpAcrobatic"); actions[KeyMapper.WalkUp] = new Action("WalkUp"); //actions[KeyMapper.Search].AddState(statemap[KeyMapper.Search],1,0); //actions[KeyMapper.Menu].AddState(statemap[KeyMapper.Menu],1,0); //actions[KeyMapper.PickupFlare].AddState(statemap[KeyMapper.PickupFlare],1,0); //actions[KeyMapper.StepToLeft].AddState(statemap[KeyMapper.StepToLeft],1,0); //actions[KeyMapper.StepToRight].AddState(statemap[KeyMapper.StepToRight],1,0); actions[KeyMapper.Idle].AddState(statemap[KeyMapper.Idle], 1, 0); actions[KeyMapper.PrimaryAction].AddState(statemap[KeyMapper.PrimaryAction], 1, 0); actions[KeyMapper.DrawWeapon].AddState(statemap[KeyMapper.DrawWeapon], 1, 0); actions[KeyMapper.Roll].AddState(statemap[KeyMapper.Roll], 1, 0); //statemap[10] = new State ("KeyMapper.Run", 1,0); actions[KeyMapper.Run].AddState(statemap[KeyMapper.Run], 1, 0); actions[KeyMapper.Down].AddState(statemap[KeyMapper.Down], 1, 0); actions[KeyMapper.Left].AddState(statemap[KeyMapper.Left], 1, 0); actions[KeyMapper.Right].AddState(statemap[KeyMapper.Right], 1, 0); actions[KeyMapper.Walk].AddState(statemap[KeyMapper.Walk], 1, 0); actions[KeyMapper.Jump].AddState(statemap[KeyMapper.Jump], 1, 0); //actions[KeyMapper.JumpAir].AddState(statemap[KeyMapper.Run],1,0); actions[KeyMapper.JumpAir].AddState(statemap[KeyMapper.JumpAir], 1, 0); actions[KeyMapper.JumpAirStanding].AddState(statemap[KeyMapper.JumpAirStanding], 1, 0); //actions[KeyMapper.jumpBack].AddState(statemap[KeyMapper.jumpBack],1,0); actions[KeyMapper.FlipBack].AddState(statemap[KeyMapper.FlipBack], 1, 0); //actions[KeyMapper.JumpRight].AddState(statemap[KeyMapper.JumpRight],1,0); //actions[KeyMapper.JumpLeft].AddState(statemap[KeyMapper.JumpLeft],1,0); actions[KeyMapper.Grab].AddState(statemap[KeyMapper.Grab], 1, 0); actions[KeyMapper.PullUpLow].AddState(statemap[KeyMapper.PullUpLow], 1, 0); actions[KeyMapper.PullUpHigh].AddState(statemap[KeyMapper.PullUpHigh], 1, 0); actions[KeyMapper.PullUpAcrobatic].AddState(statemap[KeyMapper.PullUpAcrobatic], 1, 0); actions[KeyMapper.WalkUp].AddState(statemap[KeyMapper.WalkUp], 1, 0); /* * Added new states shallow water movment layer (offset 32) * * */ int swimstate = (int)SwimmingState.InShallowWater; statemap[KeyMapper.Idle + swimstate] = new State("KeyMapper.Idle: from shallow water", 2, 103); statemap[KeyMapper.Idle + swimstate].loop = true; statemap[KeyMapper.Run + swimstate] = new State("KeyMapper.Run: from shallow water", 65, 177); statemap[KeyMapper.Run + swimstate].loop = true; statemap[KeyMapper.Run + swimstate].moving = true; statemap[KeyMapper.Run + swimstate].Speed = 3; statemap[KeyMapper.Jump + swimstate] = new State("Jump: from shallow water", 28, 28); statemap[KeyMapper.Jump + swimstate].OnAir = true; statemap[KeyMapper.Jump + swimstate].movedir = Vector3.up * 0.35f; statemap[KeyMapper.WalkUp + swimstate] = new State("WalkUp: from shallow water", 2, 50); statemap[KeyMapper.WalkUp + swimstate].moving = false; statemap[KeyMapper.WalkUp + swimstate].movedir = Vector3.up * 0.35f; statemap[KeyMapper.PullUpHigh + swimstate] = new State("PullUpHigh", 19, 97); statemap[KeyMapper.PullUpHigh].moving = false; statemap[KeyMapper.PullUpHigh].movedir = Vector3.up * 0.35f; actions[KeyMapper.Idle + swimstate] = new Action("KeyMapper.Idle: from shallow water"); actions[KeyMapper.Idle + swimstate].AddState(statemap[KeyMapper.Idle + swimstate], 1, 0); actions[KeyMapper.Run + swimstate] = new Action("KeyMapper.Run: from shallow water"); actions[KeyMapper.Run + swimstate].AddState(statemap[KeyMapper.Run + swimstate], 1, 0); actions[KeyMapper.Jump + swimstate] = new Action("Jump: from shallow water"); actions[KeyMapper.Jump + swimstate].AddState(statemap[KeyMapper.Jump + swimstate], 1, 0); actions[KeyMapper.WalkUp + swimstate] = new Action("WalkUp: from shallow water"); actions[KeyMapper.WalkUp + swimstate].AddState(statemap[KeyMapper.WalkUp + swimstate], 1, 0); //add sfx statemap[KeyMapper.WalkUp + swimstate].sfx = new AudioClip[1]; statemap[KeyMapper.WalkUp + swimstate].sfx[0] = (AudioClip)Resources.Load("sfx/splash2", typeof(AudioClip)); statemap[KeyMapper.PullUpHigh + swimstate].sfx = new AudioClip[1]; statemap[KeyMapper.PullUpHigh + swimstate].sfx[0] = (AudioClip)Resources.Load("sfx/pull_up", typeof(AudioClip)); statemap[KeyMapper.Run + swimstate].sfx = new AudioClip[2]; statemap[KeyMapper.Run + swimstate].sfx[0] = (AudioClip)Resources.Load("sfx/shallow-water", typeof(AudioClip)); statemap[KeyMapper.Run + swimstate].sfx[1] = (AudioClip)Resources.Load("sfx/shallow-water", typeof(AudioClip)); /* * Added new states deep water movment layer (offset 64) * * */ swimstate = (int)SwimmingState.InDeepWater; statemap[KeyMapper.Idle + swimstate] = new State("KeyMapper.Idle", 13, 108); statemap[KeyMapper.Idle + swimstate].loop = true; statemap[KeyMapper.Run + swimstate] = new State("KeyMapper.Run", 17, 86); statemap[KeyMapper.Run + swimstate].loop = true; statemap[KeyMapper.Run + swimstate].moving = true; statemap[KeyMapper.Run + swimstate].Speed = 6; //statemap[KeyMapper.Jump] = new State("Jump",28,28); statemap[KeyMapper.Jump].OnAir = true; statemap[KeyMapper.Jump].movedir = Vector3.up * 0.35f; actions[KeyMapper.Idle + swimstate] = new Action("KeyMapper.Idle"); actions[KeyMapper.Idle + swimstate].AddState(statemap[KeyMapper.Idle + swimstate], 1, 0); actions[KeyMapper.Run + swimstate] = new Action("KeyMapper.Run"); actions[KeyMapper.Run + swimstate].AddState(statemap[KeyMapper.Run + swimstate], 1, 0); //add sfx statemap[KeyMapper.Run + swimstate].sfx = new AudioClip[2]; statemap[KeyMapper.Run + swimstate].sfx[0] = (AudioClip)Resources.Load("sfx/swim", typeof(AudioClip)); statemap[KeyMapper.Run + swimstate].sfx[1] = (AudioClip)Resources.Load("sfx/swim", typeof(AudioClip)); /* * Added new states surface water movment layer (offset 96) * * */ swimstate = (int)SwimmingState.InWaterSurface; statemap[KeyMapper.Idle + swimstate] = new State("Idle Surface", 33, 110); statemap[KeyMapper.Idle + swimstate].loop = true; statemap[KeyMapper.Idle + swimstate].Speed = 3; statemap[KeyMapper.Run + swimstate] = new State("Swim Surface", 34, 116); statemap[KeyMapper.Run + swimstate].loop = true; statemap[KeyMapper.Run + swimstate].moving = true; statemap[KeyMapper.Run + swimstate].Speed = 3; statemap[KeyMapper.Run + swimstate].sfx = new AudioClip[2]; statemap[KeyMapper.Run + swimstate].sfx[0] = (AudioClip)Resources.Load("sfx/treading", typeof(AudioClip)); statemap[KeyMapper.Run + swimstate].sfx[1] = (AudioClip)Resources.Load("sfx/treading", typeof(AudioClip)); statemap[KeyMapper.PullUpHigh + swimstate] = new State("PullUpHigh", 55, 111); statemap[KeyMapper.PullUpHigh + swimstate].moving = false; statemap[KeyMapper.PullUpHigh + swimstate].movedir = Vector3.up * 0.35f; statemap[KeyMapper.PullUpHigh + swimstate].sfx = new AudioClip[1]; statemap[KeyMapper.PullUpHigh + swimstate].sfx[0] = (AudioClip)Resources.Load("sfx/splash2", typeof(AudioClip)); actions[KeyMapper.Idle + swimstate] = new Action("Idle Surface"); actions[KeyMapper.Idle + swimstate].AddState(statemap[KeyMapper.Idle + swimstate], 1, 0); actions[KeyMapper.Run + swimstate] = new Action("Swim Surface"); actions[KeyMapper.Run + swimstate].AddState(statemap[KeyMapper.Run + swimstate], 1, 0); actions[KeyMapper.PullUpHigh + swimstate] = new Action("Pull Out From Water"); actions[KeyMapper.PullUpHigh + swimstate].AddState(statemap[KeyMapper.PullUpHigh + swimstate], 1, 0); actions[KeyMapper.Jump + swimstate] = new Action("Dive Into Water"); actions[KeyMapper.Jump + swimstate].AddState(statemap[KeyMapper.Jump + swimstate], 1, 0); //add sfx statemap[KeyMapper.Run + swimstate].sfx = new AudioClip[2]; statemap[KeyMapper.Run + swimstate].sfx[0] = (AudioClip)Resources.Load("sfx/treading", typeof(AudioClip)); statemap[KeyMapper.Run + swimstate].sfx[1] = (AudioClip)Resources.Load("sfx/treading", typeof(AudioClip)); statemap[KeyMapper.PullUpHigh + swimstate].sfx = new AudioClip[1]; statemap[KeyMapper.PullUpHigh + swimstate].sfx[0] = (AudioClip)Resources.Load("sfx/splash2", typeof(AudioClip)); /* * Added new states for diving (offset 128) * * */ swimstate = (int)SwimmingState.Diving; statemap[KeyMapper.Jump + swimstate] = new State("Dive Into Water", 35, 119); statemap[KeyMapper.Jump + swimstate].OnAir = false; actions[KeyMapper.Jump + swimstate] = new Action("Dive Into Water"); actions[KeyMapper.Jump + swimstate].AddState(statemap[KeyMapper.Jump + swimstate], 1, 0); //state map for dive in air statemap[KeyMapper.DiveInAir] = new State("Dive Air", 52, 156); actions[KeyMapper.DiveInAir] = new Action("Dive in air"); actions[KeyMapper.DiveInAir].AddState(statemap[KeyMapper.DiveInAir], 1, 0); thistransform = transform; SfxSource = gameObject.AddComponent <AudioSource>(); SfxSource.volume = 0.35f; rootanim = (Animation)GetComponent(typeof(Animation)); //initialse states prevkeystate = currentkeystate = KeyMapper.Idle + (int)m_SwimState; current_action = actions[KeyMapper.Idle + (int)m_SwimState]; current_state = actions[KeyMapper.Idle + (int)m_SwimState].state[0]; if (current_state.AnimationID < rootanim.GetClipCount()) { rootanim.Play("" + current_state.AnimationID); } rootanim.wrapMode = WrapMode.Loop; current_action.time = Time.time; crossfading = false; busy = false; Debug.Log(current_state.name); }