备份CatanBuilding瘦身独立工程
This commit is contained in:
150
Assets/Scripts/GampPlay/Fishing/HandController.cs
Normal file
150
Assets/Scripts/GampPlay/Fishing/HandController.cs
Normal file
@@ -0,0 +1,150 @@
|
||||
using asap.core;
|
||||
using cfg;
|
||||
using RootMotion.FinalIK;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public enum EHandState
|
||||
{
|
||||
None,
|
||||
Idle,
|
||||
Hold,
|
||||
Fishing,
|
||||
Catch,
|
||||
Release,
|
||||
End
|
||||
}
|
||||
|
||||
public class HandController : MonoBehaviour
|
||||
{
|
||||
// private Animator anim_hand;
|
||||
//[HideInInspector]
|
||||
//public Animator anim_rightElbowDirection;
|
||||
|
||||
HandPoser poser_l;
|
||||
HandPoser poser_r;
|
||||
|
||||
private FullBodyBipedIK _bodyIK;
|
||||
|
||||
private Transform
|
||||
_leftElbowDireciton,
|
||||
_rightElbowDireciton,
|
||||
_rightHandTargets,
|
||||
_leftHandTargets,
|
||||
Shoulder;
|
||||
|
||||
private bool _isRightHandFollowTarget;
|
||||
private bool _isLeftHandFollowTarget;
|
||||
MMTService mmtService;
|
||||
|
||||
public EHandState EHandState { get; private set; }
|
||||
#region State Method
|
||||
bool isInit;
|
||||
public void ChangeHandState(EHandState state)
|
||||
{
|
||||
}
|
||||
|
||||
public void OnStateEnter(EHandState state)
|
||||
{
|
||||
|
||||
}
|
||||
public void OnStateExit()
|
||||
{
|
||||
|
||||
}
|
||||
public void SetActive(bool value)
|
||||
{
|
||||
if (mmtService == null)
|
||||
{
|
||||
mmtService = GContext.container.Resolve<MMTService>();
|
||||
}
|
||||
if (mmtService.CanShowHand)
|
||||
{
|
||||
gameObject.SetActive(value);
|
||||
}
|
||||
else
|
||||
{
|
||||
gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Component Method
|
||||
void Awake()
|
||||
{
|
||||
Init();
|
||||
}
|
||||
private void Init()
|
||||
{
|
||||
if (isInit)
|
||||
{
|
||||
return;
|
||||
}
|
||||
isInit = true;
|
||||
Shoulder = transform.Find("HandComponent/Shoulder");
|
||||
// anim_hand = transform.Find("Hand").GetComponent<Animator>();
|
||||
_rightElbowDireciton = transform.Find("HandComponent/Elbow/RightElbowDirection");
|
||||
_leftElbowDireciton = transform.Find("HandComponent/Elbow/LeftElbowDirection");
|
||||
//anim_rightElbowDirection = transform.Find("RightElbowDirection").GetComponent<Animator>();
|
||||
_bodyIK = GetComponentInChildren<FullBodyBipedIK>();
|
||||
var posers = GetComponentsInChildren<HandPoser>();
|
||||
if (posers.Length == 2)
|
||||
{
|
||||
poser_l = posers[0];
|
||||
poser_r = posers[1];
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogWarning("HandPoser not found: " + posers.Length);
|
||||
}
|
||||
_bodyIK.solver.rightArmChain.bendConstraint.bendGoal = _rightElbowDireciton;
|
||||
_bodyIK.solver.leftArmChain.bendConstraint.bendGoal = _leftElbowDireciton;
|
||||
}
|
||||
private void OnEnable()
|
||||
{
|
||||
SetShoulderRota(Vector3.zero);
|
||||
}
|
||||
public void SetHandTargets(Transform rightHand, Transform LeftHand, Transform body)
|
||||
{
|
||||
Init();
|
||||
_leftHandTargets = LeftHand;
|
||||
_rightHandTargets = rightHand;
|
||||
|
||||
_bodyIK.solver.leftHandEffector.target = _leftHandTargets;
|
||||
_bodyIK.solver.rightHandEffector.target = _rightHandTargets;
|
||||
|
||||
//_bodyIK.solver.bodyEffector.target = body;
|
||||
if (poser_l != null)
|
||||
{
|
||||
poser_l.poseRoot = _leftHandTargets;
|
||||
}
|
||||
if (poser_r != null)
|
||||
{
|
||||
poser_r.poseRoot = _rightHandTargets;
|
||||
}
|
||||
|
||||
SetAllHandIkTarget(1f);
|
||||
|
||||
}
|
||||
|
||||
private void SetAllHandIkTarget(float weight)
|
||||
{
|
||||
SetHandIKWeight(_bodyIK.solver.leftHandEffector, weight);
|
||||
SetHandIKWeight(_bodyIK.solver.rightHandEffector, weight);
|
||||
}
|
||||
|
||||
private void SetHandIKWeight(IKEffector effector, float weight)
|
||||
{
|
||||
effector.positionWeight = weight;
|
||||
effector.rotationWeight = weight;
|
||||
}
|
||||
public void SetShoulderRota(Vector3 vector)
|
||||
{
|
||||
Quaternion quaternion = Quaternion.Euler(vector);
|
||||
Shoulder.localRotation = quaternion;
|
||||
}
|
||||
#endregion
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user