Exemplo n.º 1
0
 private bool IsReadyToInitiateLegs(IK[] ikComponents)
 {
     for (int i = 0; i < ikComponents.Length; i++)
     {
         IK iK = ikComponents[i];
         if (iK == null)
         {
             return(false);
         }
         if (iK is FullBodyBipedIK)
         {
             base.LogWarning("GrounderIK does not support FullBodyBipedIK, use CCDIK, FABRIK, LimbIK or TrigonometricIK instead. If you want to use FullBodyBipedIK, use the GrounderFBBIK component.");
             return(false);
         }
         if (iK is FABRIKRoot)
         {
             base.LogWarning("GrounderIK does not support FABRIKRoot, use CCDIK, FABRIK, LimbIK or TrigonometricIK instead.");
             return(false);
         }
         if (iK is AimIK)
         {
             base.LogWarning("GrounderIK does not support AimIK, use CCDIK, FABRIK, LimbIK or TrigonometricIK instead.");
             return(false);
         }
     }
     return(true);
 }
Exemplo n.º 2
0
        public bool Initiate()
        {
            if (defaultPose == null)
            {
                return(false);
            }
            if (!defaultPose.poseStored)
            {
                return(false);
            }
            if (bones.Length == 0)
            {
                return(false);
            }

            if (ik == null)
            {
                ik = GetComponent <IK>();
            }
            if (ik == null)
            {
                Debug.LogError("EditorIK can not find an IK component.", transform);
                return(false);
            }

            defaultPose.Restore(bones);

            ik.GetIKSolver().executedInEditor = false;
            ik.GetIKSolver().Initiate(ik.transform);
            ik.GetIKSolver().executedInEditor = true;
            return(true);
        }
        void Start()
        {
            // Find the ik component
            ik = GetComponent<IK>();

            // Store the default rest position of the leg
            defaultDirection = mechSpider.transform.TransformDirection(position + offset - mechSpider.transform.position);
        }
Exemplo n.º 4
0
 private void DestroyLegs(IK[] ikComponents)
 {
     for (int i = 0; i < ikComponents.Length; i++)
     {
         IK iK = ikComponents[i];
         if (iK != null)
         {
             IKSolver expr_1F = iK.GetIKSolver();
             expr_1F.OnPreUpdate = (IKSolver.UpdateDelegate)Delegate.Remove(expr_1F.OnPreUpdate, new IKSolver.UpdateDelegate(this.OnSolverUpdate));
             IKSolver expr_46 = iK.GetIKSolver();
             expr_46.OnPostUpdate = (IKSolver.UpdateDelegate)Delegate.Remove(expr_46.OnPostUpdate, new IKSolver.UpdateDelegate(this.OnPostSolverUpdate));
         }
     }
 }
Exemplo n.º 5
0
		void Start() {
			// Find the ik component
			ik = GetComponent<IK>();

			// Workaround for Unity Win Store/Phone serialization bug
			stepProgress = 1f;
			
			hit = new RaycastHit();
			
			var points = ik.GetIKSolver().GetPoints();
			position = points[points.Length - 1].transform.position;
			
			hit.point = position;

			// Store the default rest position of the leg
			defaultPosition = mechSpider.transform.InverseTransformPoint(position + offset);
		}
Exemplo n.º 6
0
 // OnStateExit is called before OnStateExit is called on any state inside this state machine
 override public void OnStateExit(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
 {
     if (stateInfo.IsName("Leg F Kick"))
     {
         animator.SetBool("LegFKick", false);
     }
     else if (stateInfo.IsName("LowJump 1"))
     {
         animator.SetBool("LowJump", false);
         RootMotion.Demos.MechSpiderController ctl = animator.gameObject.GetComponent <RootMotion.Demos.MechSpiderController>();
         if (ctl != null)
         {
             ctl.enabled = true;
         }
         RootMotion.Demos.MechSpider obj = animator.gameObject.GetComponent <RootMotion.Demos.MechSpider>();
         if (obj != null)
         {
             foreach (RootMotion.Demos.MechSpiderLeg leg in obj.legs)
             {
                 RootMotion.FinalIK.IK ik = leg.GetComponentInParent <RootMotion.FinalIK.IK>();
                 if (ik != null)
                 {
                     ik.enabled = true;
                 }
                 leg.enabled = true;
             }
             obj.enabled = true;
             animator.gameObject.transform.position = obj.body.position;
         }
     }
     else if (stateInfo.IsName("VictoryDance"))
     {
         animator.SetBool("VictoryDance", false);
         RootMotion.Demos.MechSpider obj = animator.gameObject.GetComponent <RootMotion.Demos.MechSpider>();
         if (obj != null)
         {
             obj.enabled = true;
         }
         RootMotion.Demos.MechSpiderController ctl = animator.gameObject.GetComponent <RootMotion.Demos.MechSpiderController>();
         if (ctl != null)
         {
             ctl.enabled = true;
         }
     }
 }
Exemplo n.º 7
0
 private void OnDestroy()
 {
     if (this.initiated)
     {
         IK[] array = this.legs;
         for (int i = 0; i < array.Length; i++)
         {
             IK iK = array[i];
             if (iK != null)
             {
                 IKSolver expr_2F = iK.GetIKSolver();
                 expr_2F.OnPreUpdate = (IKSolver.UpdateDelegate)Delegate.Remove(expr_2F.OnPreUpdate, new IKSolver.UpdateDelegate(this.OnSolverUpdate));
                 IKSolver expr_56 = iK.GetIKSolver();
                 expr_56.OnPostUpdate = (IKSolver.UpdateDelegate)Delegate.Remove(expr_56.OnPostUpdate, new IKSolver.UpdateDelegate(this.OnPostSolverUpdate));
             }
         }
     }
 }
Exemplo n.º 8
0
 private void OnEnable()
 {
     if (Application.isPlaying)
     {
         return;
     }
     if (ik == null)
     {
         ik = GetComponent <IK>();
     }
     if (ik == null)
     {
         Debug.LogError("EditorIK needs to have an IK component on the same GameObject.", transform);
         return;
     }
     if (bones.Length == 0)
     {
         bones = ik.transform.GetComponentsInChildren <Transform>();
     }
 }
Exemplo n.º 9
0
 // OnStateEnter is called before OnStateEnter is called on any state inside this state machine
 override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
 {
     if (stateInfo.IsName("LowJump 1"))
     {
         RootMotion.Demos.MechSpider obj = animator.gameObject.GetComponent <RootMotion.Demos.MechSpider>();
         if (obj != null)
         {
             obj.enabled = false;
             foreach (RootMotion.Demos.MechSpiderLeg leg in obj.legs)
             {
                 leg.enabled = false;
                 RootMotion.FinalIK.IK ik = leg.GetComponentInParent <RootMotion.FinalIK.IK>();
                 if (ik != null)
                 {
                     ik.enabled = false;
                 }
             }
         }
         RootMotion.Demos.MechSpiderController ctl = animator.gameObject.GetComponent <RootMotion.Demos.MechSpiderController>();
         if (ctl != null)
         {
             ctl.enabled = false;
         }
     }
     else if (stateInfo.IsName("VictoryDance"))
     {
         RootMotion.Demos.MechSpider obj = animator.gameObject.GetComponent <RootMotion.Demos.MechSpider>();
         if (obj != null)
         {
             obj.enabled = false;
         }
         RootMotion.Demos.MechSpiderController ctl = animator.gameObject.GetComponent <RootMotion.Demos.MechSpiderController>();
         if (ctl != null)
         {
             ctl.enabled = false;
         }
     }
 }
Exemplo n.º 10
0
 private bool IsReadyToInitiate()
 {
     if (this.pelvis == null)
     {
         return(false);
     }
     if (this.legs.Length == 0)
     {
         return(false);
     }
     IK[] array = this.legs;
     for (int i = 0; i < array.Length; i++)
     {
         IK iK = array[i];
         if (iK == null)
         {
             return(false);
         }
         if (iK is FullBodyBipedIK)
         {
             base.LogWarning("GrounderIK does not support FullBodyBipedIK, use CCDIK, FABRIK, LimbIK or TrigonometricIK instead. If you want to use FullBodyBipedIK, use the GrounderFBBIK component.");
             return(false);
         }
         if (iK is FABRIKRoot)
         {
             base.LogWarning("GrounderIK does not support FABRIKRoot, use CCDIK, FABRIK, LimbIK or TrigonometricIK instead.");
             return(false);
         }
         if (iK is AimIK)
         {
             base.LogWarning("GrounderIK does not support AimIK, use CCDIK, FABRIK, LimbIK or TrigonometricIK instead.");
             return(false);
         }
     }
     return(true);
 }
Exemplo n.º 11
0
		// Cleaning up the delegates
		private void DestroyLegs(IK[] ikComponents) {
			foreach (IK leg in ikComponents) {
				if (leg != null) {
					leg.GetIKSolver().OnPreUpdate -= OnSolverUpdate;
					leg.GetIKSolver().OnPostUpdate -= OnPostSolverUpdate;
				}
			}
		}
Exemplo n.º 12
0
		// Initiate the feet
		private Transform[] InitiateFeet(IK[] ikComponents, ref Foot[] f, int indexOffset) {
			Transform[] bones = new Transform[ikComponents.Length];
			
			for (int i = 0; i < ikComponents.Length; i++) {
				IKSolver.Point[] points = ikComponents[i].GetIKSolver().GetPoints();
				
				f[i + indexOffset] = new Foot(ikComponents[i].GetIKSolver(), points[points.Length - 1].transform);
				bones[i] = f[i + indexOffset].transform;
				
				// Add to the update delegates of each ik solver
				f[i + indexOffset].solver.OnPreUpdate += OnSolverUpdate;
				f[i + indexOffset].solver.OnPostUpdate += OnPostSolverUpdate;
			}
			
			return bones;
		}
Exemplo n.º 13
0
		// Are the leg IK components valid for initiation?
		private bool IsReadyToInitiateLegs(IK[] ikComponents) {
			foreach (IK leg in ikComponents) {
				if (leg == null) return false;
				
				if (leg is FullBodyBipedIK) {
					LogWarning("GrounderIK does not support FullBodyBipedIK, use CCDIK, FABRIK, LimbIK or TrigonometricIK instead. If you want to use FullBodyBipedIK, use the GrounderFBBIK component.");
					return false;
				}
				
				if (leg is FABRIKRoot) {
					LogWarning("GrounderIK does not support FABRIKRoot, use CCDIK, FABRIK, LimbIK or TrigonometricIK instead.");
					return false;
				}
				
				if (leg is AimIK) {
					LogWarning("GrounderIK does not support AimIK, use CCDIK, FABRIK, LimbIK or TrigonometricIK instead.");
					return false;
				}
			}
			
			return true;
		}
Exemplo n.º 14
0
        void Start()
        {
            ik = GetComponent <IK>();

            ik.GetIKSolver().Initiate(ik.transform);
        }