using UnityEngine;
using System.Collections;
using System;
namespace RootMotion.FinalIK {
	/// 
	/// BipedIK solver collection.
	/// 
	[System.Serializable]
	public class BipedIKSolvers {
		/// 
		/// The left foot
		/// 
		public IKSolverLimb leftFoot = new IKSolverLimb(AvatarIKGoal.LeftFoot);
		/// 
		/// The right foot.
		/// 
		public IKSolverLimb rightFoot = new IKSolverLimb(AvatarIKGoal.RightFoot);
		/// 
		/// The left hand.
		/// 
		public IKSolverLimb leftHand = new IKSolverLimb(AvatarIKGoal.LeftHand);
		/// 
		/// The right hand.
		/// 
		public IKSolverLimb rightHand = new IKSolverLimb(AvatarIKGoal.RightHand);
		/// 
		/// The spine.
		/// 
		public IKSolverFABRIK spine = new IKSolverFABRIK();
		/// 
		/// The Look At %IK.
		/// 
		public IKSolverLookAt lookAt = new IKSolverLookAt();
		/// 
		/// The Aim %IK. Rotates the spine to aim a transform's forward towards the target.
		/// 
		public IKSolverAim aim = new IKSolverAim();
		/// 
		/// %Constraints for manipulating the character's pelvis.
		/// 
		public Constraints pelvis = new Constraints();
		/// 
		/// Gets the array containing all the limbs.
		/// 
		public IKSolverLimb[] limbs {
			get {
				if (_limbs == null || (_limbs != null && _limbs.Length != 4)) _limbs = new IKSolverLimb[4] { leftFoot, rightFoot, leftHand, rightHand };
				return _limbs;
			}	
		}
		private IKSolverLimb[] _limbs;
		
		/// 
		/// Gets the array containing all %IK solvers.
		/// 
		public IKSolver[] ikSolvers {
			get {
				if (_ikSolvers == null || (_ikSolvers != null && _ikSolvers.Length != 7)) _ikSolvers = new IKSolver[7] { leftFoot, rightFoot, leftHand, rightHand, spine, lookAt, aim };
				return _ikSolvers;
			}
		}
		private IKSolver[] _ikSolvers;
		
		public void AssignReferences(BipedReferences references) {
			// Assigning limbs from references
			leftHand.SetChain(references.leftUpperArm, references.leftForearm, references.leftHand, references.root);
			rightHand.SetChain(references.rightUpperArm, references.rightForearm, references.rightHand, references.root);
			leftFoot.SetChain(references.leftThigh, references.leftCalf, references.leftFoot, references.root);
			rightFoot.SetChain(references.rightThigh, references.rightCalf, references.rightFoot, references.root);
			// Assigning spine bones from references
			spine.SetChain(references.spine, references.root);
			// Assigning lookAt bones from references
			lookAt.SetChain(references.spine, references.head, references.eyes, references.root);
			// Assigning Aim bones from references
			aim.SetChain(references.spine, references.root);
			leftFoot.goal = AvatarIKGoal.LeftFoot;
			rightFoot.goal = AvatarIKGoal.RightFoot;
			leftHand.goal = AvatarIKGoal.LeftHand;
			rightHand.goal = AvatarIKGoal.RightHand;
		}
	}
}