123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using XRTool.Util;
- namespace ShadowStudio.Model
- {
- /// <summary>
- /// 用户角色控制器
- /// </summary>
- public class PlayerAnimatorController : MonoBehaviour
- {
- private Animator playerAni;
- public Transform playerHead;
- private Transform t_renMAN;
- private Transform leftHand;
- private Transform rightHand;
- private Transform handLeft;
- private Transform handRight;
- private Animator leftHandAnim;
- private Animator rightHandAnim;
- private int leftState;
- private int rightState;
- public void SetHands(Transform leftHand, Transform rightHand)
- {
- this.leftHand = leftHand;
- this.rightHand = rightHand;
- }
- private void Start()
- {
- if (HandLeft)
- {
- HandLeft.gameObject.SetActive(false);
- }
- if (HandRight)
- {
- HandRight.gameObject.SetActive(false);
- }
- if(CScript.App.AppManager.Instance.isRunHolographic)
- {
- HandLeft.gameObject.SetActive(false);
- HandRight.gameObject.SetActive(false);
- T_renMAN.gameObject.SetActive(false);
- }
- }
- public Animator PlayerAni
- {
- get
- {
- if (!playerAni)
- {
- playerAni = GetComponent<Animator>();
- }
- return playerAni;
- }
- }
- public Transform T_renMAN
- {
- get
- {
- if (!t_renMAN)
- {
- t_renMAN = UnityUtil.GetBreadthChild<Transform>(transform, "T_renMAN");
- }
- return T_renMAN;
- }
- }
- public Transform HandLeft
- {
- get
- {
- if (!handLeft)
- {
- handLeft = UnityUtil.GetBreadthChild<Transform>(transform, "HandLeft");
- }
- return handLeft;
- }
- }
- public Transform HandRight
- {
- get
- {
- if (!handRight)
- {
- handRight = UnityUtil.GetBreadthChild<Transform>(transform, "HandRight");
- }
- return handRight;
- }
- }
- public Animator LeftHandAnim
- {
- get
- {
- if (!leftHandAnim && HandLeft)
- {
- leftHandAnim = HandLeft.GetComponent<Animator>();
- }
- return leftHandAnim;
- }
- }
- public Animator RightHandAnim
- {
- get
- {
- if (!rightHandAnim && HandRight)
- {
- rightHandAnim = HandRight.GetComponent<Animator>();
- }
- return rightHandAnim;
- }
- }
- /// <summary>
- /// 角色IK动画设置
- /// </summary>
- /// <param name="layerIndex"></param>
- //private void OnAnimatorIK(int layerIndex)
- //{
- // if (PlayerAni)
- // {
- // if (leftHand)
- // {
- // SetPlayerIKWeight(AvatarIKGoal.LeftHand);
- // SetPlayerIK(AvatarIKGoal.LeftHand, leftHand);
- // }
- // if (rightHand)
- // {
- // SetPlayerIKWeight(AvatarIKGoal.RightHand);
- // SetPlayerIK(AvatarIKGoal.RightHand, rightHand);
- // }
- // }
- //}
- public void SetPlayerIK(AvatarIKGoal goal, Vector3 pos, Quaternion rotation)
- {
- PlayerAni.SetIKPosition(goal, pos);
- PlayerAni.SetIKRotation(goal, rotation);
- }
- public void SetPlayerIK(AvatarIKGoal goal, Transform target)
- {
- SetPlayerIK(goal, target.position, target.rotation);
- }
- /// <summary>
- /// 设置头部信息
- /// </summary>
- /// <param name="goal"></param>
- public void SetPlayerIKWeight(AvatarIKGoal goal)
- {
- PlayerAni.SetIKPositionWeight(goal, 1f);
- PlayerAni.SetIKRotationWeight(goal, 1f);
- }
- public void SetAnimInt(Animator animator, string stateName, int state)
- {
- if (animator)
- {
- animator.SetInteger(stateName, state);
- }
- }
- public int LeftHandState
- {
- get
- {
- return leftState;
- }
- set
- {
- if (LeftHandAnim)
- {
- SetAnimInt(LeftHandAnim, "State", leftState = value);
- }
- }
- }
- public int RightHandState
- {
- get
- {
- return rightState;
- }
- set
- {
- if (RightHandAnim)
- {
- SetAnimInt(RightHandAnim, "State", rightState = value);
- }
- }
- }
- }
- }
|