using System; using RootMotion.FinalIK; using UnityEngine; public class InteractionControl : MonoBehaviour { public enum LeftHandPoster { None = 0, Reel = 1, HandFish = 2, HandPodbierak = 3, HandChwytak = 4 } private InteractionSystem interactionSystem; private FullBodyBipedIK fullBodyBipedIK; private Transform fps_Camera; public Transform rightHandPointer; public Transform leftHandPointer; public Transform headTransform; public Transform headCameraPointTransform; private float rHandPositionWeight = 0.9f; private float rHandRotationWeight = 0.9f; public LeftHandPoster leftHandPoster; public InteractionObject LeftHandFish; public InteractionObject LeftHandPodbierak; public InteractionObject LeftHandChwytak; public bool LeftHandInteractionWithReel; public bool LeftHandInteractionWithPodbierak; public bool LeftHandInteractionWithChwytak; private Vector3 positionStartCameraOfHead; private Vector3 positionStartCamera; private Vector3 positionStartLookingHead; private LookAtIK _lookAtIK; private PlayerMain _playerMain; private void Start() { fullBodyBipedIK = GetComponent(); fps_Camera = base.transform.GetComponent().m_Camera.transform; interactionSystem = base.transform.GetComponent(); _lookAtIK = base.transform.GetComponent(); _playerMain = base.transform.GetComponent(); positionStartCameraOfHead = fps_Camera.position - headTransform.position; positionStartCamera = fps_Camera.localPosition; InteractionSystem obj = interactionSystem; obj.OnInteractionPickUp = (InteractionSystem.InteractionDelegate)Delegate.Combine(obj.OnInteractionPickUp, new InteractionSystem.InteractionDelegate(OnInteractionPickUp)); InteractionSystem obj2 = interactionSystem; obj2.OnInteractionStop = (InteractionSystem.InteractionDelegate)Delegate.Combine(obj2.OnInteractionStop, new InteractionSystem.InteractionDelegate(OnInteractionStop)); InteractionSystem obj3 = interactionSystem; obj3.OnInteractionPause = (InteractionSystem.InteractionDelegate)Delegate.Combine(obj3.OnInteractionPause, new InteractionSystem.InteractionDelegate(OnInteractionPause)); InteractionSystem obj4 = interactionSystem; obj4.OnInteractionResume = (InteractionSystem.InteractionDelegate)Delegate.Combine(obj4.OnInteractionResume, new InteractionSystem.InteractionDelegate(OnInteractionResume)); } private void FixedUpdate() { CheckRightHandInteractionRaycast(); } private void Update() { if (ScriptsHandler.Instance.m_PlayerMain.m_CameraTypeView == PlayerMain.CameraTypeView.FirstPerson) { AnimatorClipInfo[] currentAnimatorClipInfo = ScriptsHandler.Instance.m_PlayerMain.animator.GetCurrentAnimatorClipInfo(0); Debug.Log(_playerMain.m_Jumping); if (interactionSystem.IsInInteraction(FullBodyBipedEffector.RightHand) || _playerMain.m_Jumping || currentAnimatorClipInfo[0].clip.name == "RunFwdLoop" || (InputManager.isRunning && !ScriptsHandler.Instance.m_PlayerMain.currentRod) || LeftHandInteractionWithPodbierak) { fps_Camera.position = Vector3.MoveTowards(fps_Camera.position, headCameraPointTransform.position, Time.deltaTime * 5f); Debug.Log("dasfdsf"); } else { fps_Camera.localPosition = Vector3.MoveTowards(fps_Camera.localPosition, positionStartCamera, Time.deltaTime * 2f); } } if (interactionSystem.IsInInteraction(FullBodyBipedEffector.RightHand)) { _lookAtIK.solver.target = fullBodyBipedIK.solver.rightHandEffector.target; _lookAtIK.solver.SetLookAtWeight(0.7f); } else if (_playerMain.currentRod != null) { if (_playerMain.currentRod.fishingLine.currentLineHandler.EndLineRigidbody_1 != null) { if (!_playerMain.currentRod.fishingLine.fishObject) { _lookAtIK.solver.target = _playerMain.currentRod.fishingLine.currentLineHandler.EndLineRigidbody_1.transform; } else { _lookAtIK.solver.target = _playerMain.currentRod.fishingLine.fishObject.transform; } _lookAtIK.solver.SetLookAtWeight(0.9f); } } else { _lookAtIK.solver.target = null; _lookAtIK.solver.SetLookAtWeight(0f); } if (!interactionSystem.IsInInteraction(FullBodyBipedEffector.RightHand)) { fullBodyBipedIK.solver.rightHandEffector.target = rightHandPointer; if (ScriptsHandler.Instance.m_PlayerMain.currentRightHandObject != null) { fullBodyBipedIK.solver.SetEffectorWeights(FullBodyBipedEffector.RightHand, Mathf.MoveTowards(fullBodyBipedIK.solver.rightHandEffector.positionWeight, rHandPositionWeight, Time.deltaTime), Mathf.MoveTowards(fullBodyBipedIK.solver.rightHandEffector.rotationWeight, rHandRotationWeight, Time.deltaTime)); } else { fullBodyBipedIK.solver.SetEffectorWeights(FullBodyBipedEffector.RightHand, Mathf.MoveTowards(fullBodyBipedIK.solver.rightHandEffector.positionWeight, 0f, Time.deltaTime), Mathf.MoveTowards(fullBodyBipedIK.solver.rightHandEffector.rotationWeight, 0f, Time.deltaTime)); } } else { fullBodyBipedIK.solver.rightHandEffector.target = null; } LeftHandController(); } private void LeftHandController() { switch (leftHandPoster) { case LeftHandPoster.None: if (interactionSystem.IsPaused(FullBodyBipedEffector.LeftHand)) { interactionSystem.ResumeInteraction(FullBodyBipedEffector.LeftHand); fullBodyBipedIK.solver.leftHandEffector.target = null; fullBodyBipedIK.solver.SetEffectorWeights(FullBodyBipedEffector.LeftHand, 0f, 0f); } break; case LeftHandPoster.HandFish: if (!interactionSystem.IsPaused(FullBodyBipedEffector.LeftHand) && !interactionSystem.IsInInteraction(FullBodyBipedEffector.LeftHand)) { interactionSystem.StartInteraction(FullBodyBipedEffector.LeftHand, LeftHandFish, interrupt: false); fullBodyBipedIK.solver.leftHandEffector.target = leftHandPointer; fullBodyBipedIK.solver.SetEffectorWeights(FullBodyBipedEffector.LeftHand, 1f, 0.1f); } break; case LeftHandPoster.HandPodbierak: if (!interactionSystem.IsPaused(FullBodyBipedEffector.LeftHand) && !interactionSystem.IsInInteraction(FullBodyBipedEffector.LeftHand)) { interactionSystem.StartInteraction(FullBodyBipedEffector.LeftHand, LeftHandPodbierak, interrupt: false); fullBodyBipedIK.solver.leftHandEffector.target = leftHandPointer; fullBodyBipedIK.solver.SetEffectorWeights(FullBodyBipedEffector.LeftHand, 1f, 0.1f); } break; case LeftHandPoster.HandChwytak: if (!interactionSystem.IsPaused(FullBodyBipedEffector.LeftHand) && !interactionSystem.IsInInteraction(FullBodyBipedEffector.LeftHand)) { interactionSystem.StartInteraction(FullBodyBipedEffector.LeftHand, LeftHandChwytak, interrupt: false); fullBodyBipedIK.solver.leftHandEffector.target = leftHandPointer; fullBodyBipedIK.solver.SetEffectorWeights(FullBodyBipedEffector.LeftHand, 1f, 0.1f); } break; case LeftHandPoster.Reel: break; } } private void CheckRightHandInteractionRaycast() { if (!fps_Camera.gameObject.activeSelf || !Camera.main) { return; } Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); float maxDistance = 1f; LayerMask layerMask = LayerMask.NameToLayer("Player"); if (Physics.Raycast(ray, out var hitInfo, maxDistance, layerMask)) { Transform transform = hitInfo.transform; ScriptsHandler.Instance.m_CanvasManager.ShowHideCanvasInfoInteractionPanel(transform, visable: true); if (transform.tag == "Rod") { if (InputManager.isGetUpRod) { InteractionObject component = transform.GetComponent(); if (component != null && ScriptsHandler.Instance.m_PlayerMain.currentRod == null) { fullBodyBipedIK.solver.SetEffectorWeights(FullBodyBipedEffector.RightHand, 0.6f, 0.6f); interactionSystem.StartInteraction(FullBodyBipedEffector.RightHand, component, interrupt: false); } } } else if (transform.tag == "Stojak") { if (InputManager.isGetUpRod) { InteractionObject component2 = transform.GetComponent(); if (component2 != null && ScriptsHandler.Instance.m_PlayerMain.currentRod != null) { StopReelInteractionWithLeftHand(); fullBodyBipedIK.solver.SetEffectorWeights(FullBodyBipedEffector.RightHand, 0.6f, 0.6f); interactionSystem.StartInteraction(FullBodyBipedEffector.RightHand, component2, interrupt: false); } } } else { ScriptsHandler.Instance.m_CanvasManager.ShowHideCanvasInfoInteractionPanel(null, visable: false); } } else { ScriptsHandler.Instance.m_CanvasManager.ShowHideCanvasInfoInteractionPanel(null, visable: false); } } public void StartReelUnlockInteractionWithLeftHand() { if (!(ScriptsHandler.Instance.m_PlayerMain.currentRightHandObject == null) && !interactionSystem.IsInInteraction(FullBodyBipedEffector.LeftHand)) { if (ScriptsHandler.Instance.m_PlayerMain.currentRightHandObject.GetComponent().GetReelUnlockInteraction() != null) { interactionSystem.StartInteraction(FullBodyBipedEffector.LeftHand, ScriptsHandler.Instance.m_PlayerMain.currentRightHandObject.GetComponent().GetReelUnlockInteraction(), interrupt: false); } ScriptsHandler.Instance.m_PlayerMain.currentRightHandObject.GetComponent().fishingLine.reel.UnlockKablag(val: true); leftHandPoster = LeftHandPoster.Reel; } } public void StartReelInteractionWithLeftHand() { if (!(ScriptsHandler.Instance.m_PlayerMain.currentRightHandObject == null) && !interactionSystem.IsInInteraction(FullBodyBipedEffector.LeftHand)) { if (ScriptsHandler.Instance.m_PlayerMain.currentRightHandObject.GetComponent().GetReelInteraction() != null) { interactionSystem.StartInteraction(FullBodyBipedEffector.LeftHand, ScriptsHandler.Instance.m_PlayerMain.currentRightHandObject.GetComponent().GetReelInteraction(), interrupt: false); } leftHandPoster = LeftHandPoster.Reel; } } public void StopReelInteractionWithLeftHand() { if (LeftHandInteractionWithReel) { leftHandPoster = LeftHandPoster.None; } } public void StopPodbierakInteractionWithLeftHand() { interactionSystem.StopInteraction(FullBodyBipedEffector.LeftHand); fullBodyBipedIK.solver.leftHandEffector.target = null; fullBodyBipedIK.solver.SetEffectorWeights(FullBodyBipedEffector.LeftHand, 0f, 0f); leftHandPoster = LeftHandPoster.None; LeftHandInteractionWithPodbierak = false; } public void StopChwytakInteractionWithLeftHand() { interactionSystem.StopInteraction(FullBodyBipedEffector.LeftHand); fullBodyBipedIK.solver.leftHandEffector.target = null; fullBodyBipedIK.solver.SetEffectorWeights(FullBodyBipedEffector.LeftHand, 0f, 0f); leftHandPoster = LeftHandPoster.None; LeftHandInteractionWithChwytak = false; } private void OnInteractionPickUp(FullBodyBipedEffector effectorType, InteractionObject interactionObject) { if (effectorType == FullBodyBipedEffector.RightHand && interactionObject.tag == "Rod") { ScriptsHandler.Instance.m_PlayerMain.currentRightHandObject = interactionObject.gameObject; } } private void OnInteractionStop(FullBodyBipedEffector effectorType, InteractionObject interactionObject) { } private void OnInteractionResume(FullBodyBipedEffector effectorType, InteractionObject interactionObject) { if (effectorType == FullBodyBipedEffector.LeftHand && interactionObject.tag == "Reel") { LeftHandInteractionWithReel = false; } } private void OnInteractionPause(FullBodyBipedEffector effectorType, InteractionObject interactionObject) { if (effectorType == FullBodyBipedEffector.LeftHand && interactionObject.tag == "Reel") { LeftHandInteractionWithReel = true; } if (effectorType == FullBodyBipedEffector.LeftHand && interactionObject.name == "PodbierakHand") { ScriptsHandler.Instance.m_PlayerMain.CreatePodbierak(); LeftHandInteractionWithPodbierak = true; } if (effectorType == FullBodyBipedEffector.LeftHand && interactionObject.name == "ChwytakHand") { ScriptsHandler.Instance.m_PlayerMain.CreateChwytak(); LeftHandInteractionWithChwytak = true; } } }