protected virtual void OnEnable() { if (animatorStateInfos != null) { animatorStateInfos.RegisterListener(); } }
protected override void Start() { base.Start(); animatorStateInfos = new vAnimatorStateInfos(GetComponent <Animator>()); animatorStateInfos.RegisterListener(); }
protected virtual void Start() { character = GetComponent <vIControlAI>(); animator = GetComponent <Animator>(); animatorStateInfos = new vAnimatorStateInfos(animator); animatorStateInfos.RegisterListener(); if (animator.isHuman) { head = animator.GetBoneTransform(HumanBodyBones.Head); var spine1 = animator.GetBoneTransform(HumanBodyBones.Spine); var spine2 = animator.GetBoneTransform(HumanBodyBones.Chest); spine = new List <Transform>(); if (spine1) { spine.Add(spine1); } if (spine2) { spine.Add(spine2); } var neck = animator.GetBoneTransform(HumanBodyBones.Neck); if (!hips) { hips = animator.GetBoneTransform(HumanBodyBones.Hips); } if (neck && spine2 && neck.parent && neck.parent != spine2) { spine.Add(neck.parent); } } if (head) { headHeight = Vector3.Distance(transform.position, head.position); } ResetOffseLookHeight(); GetLookPoint(); lookAroundProgress = 0.5f; }
void Start() { if (!sensor) { var sensorObj = new GameObject("HeadTrackSensor"); sensor = sensorObj.AddComponent <vHeadTrackSensor>(); } // updates the headtrack using the late update of the tpinput so we don't need to create another one var tpInput = GetComponent <vThirdPersonInput>(); if (tpInput) { tpInput.onLateUpdate -= UpdateHeadTrack; tpInput.onLateUpdate += UpdateHeadTrack; } vchar = GetComponent <vICharacter>(); sensor.headTrack = this; animator = GetComponentInChildren <Animator>(); if (animator) { animatorStateInfos = new vAnimatorStateInfos(animator); animatorStateInfos.RegisterListener(); } if (autoFindBones) { head = animator.GetBoneTransform(HumanBodyBones.Head); if (head) { forwardReference = new GameObject("FWRF").transform; forwardReference.SetParent(head); forwardReference.transform.localPosition = Vector3.zero; forwardReference.transform.rotation = transform.rotation; var hips = animator.GetBoneTransform(HumanBodyBones.Hips); if (hips) { var target = head; for (int i = 0; i < 4; i++) { if (target.parent && target.parent.gameObject != hips.gameObject) { spine.Add(target.parent); target = target.parent; } else { break; } } } } } cameraMain = Camera.main; if (head) { headHeight = Vector3.Distance(transform.position, head.position); sensor.transform.position = head.transform.position; } else { headHeight = 1f; sensor.transform.position = transform.position; } if (spine.Count == 0) { Debug.Log("Headtrack Spines missing"); } var layer = LayerMask.NameToLayer("HeadTrack"); sensor.transform.parent = transform; sensor.gameObject.layer = layer; sensor.gameObject.tag = transform.tag; spine.Reverse(); GetLookPoint(); }