private void Awake()
        {
            foreach (Transform childd in transform)
            {
                if (childd)
                {
                    child = childd;
                    child.gameObject.AddComponent <SpringBone>();
                }
            }

            trs           = transform;
            localRotation = transform.localRotation;

            managerRef = GetParentSpringManager(transform);

            if (child == null)
            {
                DestroyImmediate(this);
            }

            if (managerRef != null & this != null)
            {
                managerRef.springBones[indexBones++] = this;
            }
        }
예제 #2
0
        private void Awake()
        {
            trs           = transform;
            localRotation = transform.localRotation;

            managerRef = GetParentSpringManager(transform);
        }
예제 #3
0
 private void Awake()
 {
     trs = transform;
     //Kobayashi:Reference for "SpringManager" component with unitychan
     // GameObject.Find("unitychan_dynamic").GetComponent<SpringManager>();
     managerRef = GetParentSpringManager(transform);
 }
예제 #4
0
		private void Awake ()
		{
			trs = transform;
			localRotation = transform.localRotation;
			//Kobayashi:Reference for "SpringManager" component with unitychan
			// GameObject.Find("unitychan_dynamic").GetComponent<SpringManager>();
			managerRef = GetParentSpringManager (transform);
		}
예제 #5
0
 private void Awake()
 {
     springForce   = baseSpringForce;
     trs           = transform;
     localRotation = transform.localRotation;
     //Kobayashi:Reference for "SpringManager" component with unitychan
     // GameObject.Find("unitychan_dynamic").GetComponent<SpringManager>();
     managerRef = GetParentSpringManager(transform);
 }
예제 #6
0
        private void Awake()
        {
            trs           = transform;
            localRotation = transform.localRotation;
            //Kobayashi:Reference for "SpringManager" component with unitychan
            // GameObject.Find("unitychan_dynamic").GetComponent<SpringManager>();
            managerRef = GetParentSpringManager(transform);

            if (transform.childCount > 0)
            {
                child = transform.GetChild(0);
            }
        }
예제 #7
0
        public void Cal()
        {
            //先拿localEuler
            //设置localRotation 获取 rotation 和 position 和transformfromdirection
            //设置managerRef
            CalEnd();
            Vector3 localEuler = trs.localEulerAngles;

            trs.localRotation = Quaternion.identity * localRotation;
            var rotation  = trs.rotation;
            var position  = trs.position;
            var direction = trs.TransformDirection(boneAxis);

            if (managerRef == null)
            {
                managerRef = GetParentSpringManager(trs);
            }
            NewUpdateSpring(localEuler, rotation, position, direction);
        }
예제 #8
0
        public void UpdateSpring()
        {
            Vector3 localEulerAngles = trs.localEulerAngles;

            //UnityEngine.Debug.Log("计算前:" + localEulerAngles.Json());

            //Kobayashi
            //org = trs;
            //回転をリセット
            trs.localRotation = Quaternion.identity * localRotation;

            float sqrDt = Time.deltaTime * Time.deltaTime;

            //stiffness
            Vector3 force = trs.rotation * (boneAxis * stiffnessForce) / sqrDt;

            //drag
            force += (prevTipPos - currTipPos) * dragForce / sqrDt;

            force += springForce / sqrDt;

            //前フレームと値が同じにならないように
            Vector3 temp = currTipPos;

            //verlet
            currTipPos = (currTipPos - prevTipPos) + currTipPos + (force * sqrDt);

            //長さを元に戻す
            currTipPos = ((currTipPos - trs.position).normalized * springLength) + trs.position;

            //衝突判定
            for (int i = 0; i < colliders.Length; i++)
            {
                if (colliders[i] == null)
                {
                    continue;
                }

                Vector3 collisionCenterPos;
                if (colliders[i].CheckCollision(currTipPos, radius, out collisionCenterPos))
                {
                    Vector3 normal = (currTipPos - collisionCenterPos).normalized;
                    currTipPos = collisionCenterPos + (normal * (radius + colliders[i].radius));
                    currTipPos = ((currTipPos - trs.position).normalized * springLength) + trs.position;
                }
            }

            prevTipPos = temp;

            //回転を適用;
            Vector3 aimVector = trs.TransformDirection(boneAxis);

            Quaternion aimRotation = Quaternion.FromToRotation(aimVector, currTipPos - trs.position);
            //original
            //trs.rotation = aimRotation * trs.rotation;
            //Kobayahsi:Lerp with mixWeight
            Quaternion secondaryRotation = aimRotation * trs.rotation;

            if (managerRef == null)
            {
                managerRef = GetParentSpringManager(trs);
            }
            trs.rotation = Quaternion.Lerp(trs.rotation, secondaryRotation, managerRef.dynamicRatio);
            //if (isRang) {
            //    Quaternion old = trs.rotation;
            //    trs.rotation = secondaryRotation;
            //    Vector3 oldV = trs.localEulerAngles;
            //    if (oldV != localEulerAngles) {
            //        UnityEngine.Debug.Log("确实不同");
            //    } else {
            //        UnityEngine.Debug.Log("其实相同");
            //    }
            //    Check(ref oldV.x, localEulerAngles.x, rangAngle.x);
            //    Check(ref oldV.y, localEulerAngles.y, rangAngle.y);
            //    Check(ref oldV.z, localEulerAngles.z, rangAngle.z);

            //    trs.localEulerAngles = oldV;
            //    secondaryRotation = trs.rotation;

            //    trs.rotation = lastRotaion = Quaternion.Lerp(lastRotaion, secondaryRotation, managerRef.dynamicRatio);
            //} else {
            //    trs.rotation = Quaternion.Lerp(trs.rotation, secondaryRotation, managerRef.dynamicRatio);
            //}
        }
예제 #9
0
 public void SetManager(SpringManager mgr)
 {
     managerRef = mgr;
 }