void Awake() { if (!initialized) { Debug.LogError(name+": Locomotion System has not been initialized.",this); return; } // Put regular and backwards motions into one array m_Motions = new IMotionAnalyzer[sourceAnimations.Length + sourceAnimationsBackwards.Length]; for (int i=0; i<sourceAnimations.Length; i++) { motions[i] = sourceAnimations[i]; } for (int i=0; i<sourceAnimationsBackwards.Length; i++) { motions[sourceAnimations.Length+i] = sourceAnimationsBackwards[i]; } // Get number of walk cycle motions and put them in an array int cycleMotionAmount = 0; for (int i=0; i<motions.Length; i++) { if (motions[i].motionType == MotionType.WalkCycle) cycleMotionAmount++; } m_CycleMotions = new IMotionAnalyzer[cycleMotionAmount]; int index = 0; for (int i=0; i<motions.Length; i++) { if (motions[i].motionType == MotionType.WalkCycle) { cycleMotions[index] = motions[i]; index++; } } // Setup motion groups List<string> motionGroupNameList = new List<string>(); List<MotionGroupInfo> motionGroupList = new List<MotionGroupInfo>(); List<List<IMotionAnalyzer>> motionGroupMotionLists = new List<List<IMotionAnalyzer>>(); List<IMotionAnalyzer> nonGroupMotionList = new List<IMotionAnalyzer>(); for (int i=0; i<motions.Length; i++) { if (motions[i].motionGroup == "") { nonGroupMotionList.Add(motions[i]); } else { string groupName = motions[i].motionGroup; if ( !motionGroupNameList.Contains(groupName) ) { // Name is new so create a new motion group MotionGroupInfo m = new MotionGroupInfo(); // Use it as controller for our new motion group m.name = groupName; motionGroupList.Add(m); motionGroupNameList.Add(groupName); motionGroupMotionLists.Add(new List<IMotionAnalyzer>()); } motionGroupMotionLists[motionGroupNameList.IndexOf(groupName)].Add(motions[i]); } } m_NonGroupMotions = nonGroupMotionList.ToArray(); m_MotionGroups = motionGroupList.ToArray(); for (int g=0; g<motionGroups.Length; g++) { motionGroups[g].motions = motionGroupMotionLists[g].ToArray(); } // Set up parameter space (for each motion group) used for automatic blending for (int g=0; g<motionGroups.Length; g++) { MotionGroupInfo group = motionGroups[g]; Vector3[] motionVelocities = new Vector3[group.motions.Length]; float[][] motionParameters = new float[group.motions.Length][]; for (int i=0; i<group.motions.Length; i++) { motionVelocities[i] = group.motions[i].cycleVelocity; motionParameters[i] = new float[] {motionVelocities[i].x, motionVelocities[i].y, motionVelocities[i].z}; } group.interpolator = new PolarGradientBandInterpolator(motionParameters); } // Calculate offset time values for each walk cycle motion CalculateTimeOffsets(); }
void Awake() { if (!initialized) { Debug.LogError(name + ": Locomotion System has not been initialized.", this); return; } // Put regular and backwards motions into one array m_Motions = new IMotionAnalyzer[sourceAnimations.Length + sourceAnimationsBackwards.Length]; for (int i = 0; i < sourceAnimations.Length; i++) { motions[i] = sourceAnimations[i]; } for (int i = 0; i < sourceAnimationsBackwards.Length; i++) { motions[sourceAnimations.Length + i] = sourceAnimationsBackwards[i]; } // Get number of walk cycle motions and put them in an array int cycleMotionAmount = 0; for (int i = 0; i < motions.Length; i++) { if (motions[i].motionType == MotionType.WalkCycle) { cycleMotionAmount++; } } m_CycleMotions = new IMotionAnalyzer[cycleMotionAmount]; int index = 0; for (int i = 0; i < motions.Length; i++) { if (motions[i].motionType == MotionType.WalkCycle) { cycleMotions[index] = motions[i]; index++; } } // Setup motion groups List <string> motionGroupNameList = new List <string>(); List <MotionGroupInfo> motionGroupList = new List <MotionGroupInfo>(); List <List <IMotionAnalyzer> > motionGroupMotionLists = new List <List <IMotionAnalyzer> >(); List <IMotionAnalyzer> nonGroupMotionList = new List <IMotionAnalyzer>(); for (int i = 0; i < motions.Length; i++) { if (motions[i].motionGroup == "") { nonGroupMotionList.Add(motions[i]); } else { string groupName = motions[i].motionGroup; if (!motionGroupNameList.Contains(groupName)) { // Name is new so create a new motion group MotionGroupInfo m = new MotionGroupInfo(); // Use it as controller for our new motion group m.name = groupName; motionGroupList.Add(m); motionGroupNameList.Add(groupName); motionGroupMotionLists.Add(new List <IMotionAnalyzer>()); } motionGroupMotionLists[motionGroupNameList.IndexOf(groupName)].Add(motions[i]); } } m_NonGroupMotions = nonGroupMotionList.ToArray(); m_MotionGroups = motionGroupList.ToArray(); for (int g = 0; g < motionGroups.Length; g++) { motionGroups[g].motions = motionGroupMotionLists[g].ToArray(); } // Set up parameter space (for each motion group) used for automatic blending for (int g = 0; g < motionGroups.Length; g++) { MotionGroupInfo group = motionGroups[g]; Vector3[] motionVelocities = new Vector3[group.motions.Length]; float[][] motionParameters = new float[group.motions.Length][]; for (int i = 0; i < group.motions.Length; i++) { motionVelocities[i] = group.motions[i].cycleVelocity; motionParameters[i] = new float[] { motionVelocities[i].x, motionVelocities[i].y, motionVelocities[i].z }; } group.interpolator = new PolarGradientBandInterpolator(motionParameters); } // Calculate offset time values for each walk cycle motion CalculateTimeOffsets(); }