440 lines
14 KiB
C#
440 lines
14 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using BitStrap;
|
|
using UnityEngine;
|
|
|
|
public class FishingNet : MonoBehaviour
|
|
{
|
|
public FishingNetTrigger fishingNetTrigger;
|
|
|
|
public FishingNetIndicator fishingNetIndicator;
|
|
|
|
public Transform handMountPosition;
|
|
|
|
public Transform fishCatchPosition;
|
|
|
|
[HideInInspector]
|
|
public FishingHands fishingHands;
|
|
|
|
[HideInInspector]
|
|
public Vector3 startPosition = Vector3.zero;
|
|
|
|
[HideInInspector]
|
|
public bool blockMouseInput;
|
|
|
|
public Rigidbody rigidbodyMount;
|
|
|
|
public Rigidbody rigidbodyArm;
|
|
|
|
public Transform rightArm;
|
|
|
|
[ReadOnly]
|
|
public Vector3 rightArmAddRotation = Vector3.zero;
|
|
|
|
[ReadOnly]
|
|
public Vector3 rightArmAddPosition = Vector3.zero;
|
|
|
|
public Vector2 rightArmMoveSpeed = new Vector2(19f, 0.7f);
|
|
|
|
public List<SkinnedMeshRenderer> armsMeshRenderers = new List<SkinnedMeshRenderer>();
|
|
|
|
public MeshRenderer net;
|
|
|
|
public MeshRenderer stick;
|
|
|
|
[ReadOnly]
|
|
public bool canBeUpdated;
|
|
|
|
[ReadOnly]
|
|
public bool isAutomaticUpdate = true;
|
|
|
|
[ReadOnly]
|
|
public float fishCanBePulledTimer;
|
|
|
|
[ReadOnly]
|
|
public Vector3 rightArmPosition = Vector3.zero;
|
|
|
|
[ReadOnly]
|
|
public Vector3 rightArmRotation = Vector3.zero;
|
|
|
|
[ReadOnly]
|
|
public Vector3 rightArmStartPosition = Vector3.zero;
|
|
|
|
[ReadOnly]
|
|
public Vector3 rightArmStartRotation = Vector3.zero;
|
|
|
|
public Vector2 vrPosMinMax = Vector2.zero;
|
|
|
|
private void Awake()
|
|
{
|
|
if (!(base.transform.parent == null))
|
|
{
|
|
}
|
|
}
|
|
|
|
private void Start()
|
|
{
|
|
}
|
|
|
|
public void Initialize()
|
|
{
|
|
rigidbodyMount.useGravity = false;
|
|
rigidbodyMount.isKinematic = false;
|
|
rigidbodyArm.useGravity = false;
|
|
rigidbodyArm.isKinematic = true;
|
|
startPosition = new Vector3(rigidbodyArm.transform.localPosition.x, rigidbodyArm.transform.localPosition.y, 0f);
|
|
rightArmStartPosition = fishingHands.rightArm.transform.localPosition;
|
|
rightArmStartRotation = fishingHands.rightArm.transform.localEulerAngles;
|
|
fishingNetIndicator.Initialize();
|
|
}
|
|
|
|
public void OnCollide(Fish fish)
|
|
{
|
|
if (!isAutomaticUpdate && (bool)fish && (bool)fish.storedBait && !fish.isWatchingFish)
|
|
{
|
|
fishingNetTrigger.gameObject.SetActive(false);
|
|
fishingHands.fishingPlayer.LineBreak(Utilities.GetTranslation("HUD_MESSAGE/FISH_NET_PUSHED") + ".", 1f);
|
|
fish.EnableAI();
|
|
Debug.Log("EnableAI 2");
|
|
fish.BreakFree();
|
|
}
|
|
}
|
|
|
|
public void FishCatch(Fish fish)
|
|
{
|
|
if (!isAutomaticUpdate)
|
|
{
|
|
fishingNetIndicator.meshCollider.enabled = false;
|
|
fishingNetIndicator.renderer.enabled = false;
|
|
fishingHands.fishingPlayer.FishCatch(fish);
|
|
}
|
|
}
|
|
|
|
public void MoveFishToCatchPosition(GameObject fish)
|
|
{
|
|
fish.transform.position = fishCatchPosition.position;
|
|
fish.transform.eulerAngles = fishCatchPosition.eulerAngles;
|
|
if (fish.GetComponent<Fish>().animController.fishAnimSwim.useXAxisForSwim)
|
|
{
|
|
fish.transform.eulerAngles -= Vector3.forward * 90f;
|
|
}
|
|
LeanTween.value(0f, 1f, 0.7f).setOnUpdate((Action<float>)delegate
|
|
{
|
|
fish.transform.position = fishCatchPosition.position;
|
|
fish.transform.eulerAngles = fishCatchPosition.eulerAngles;
|
|
if (fish.GetComponent<Fish>().animController.fishAnimSwim.useXAxisForSwim)
|
|
{
|
|
fish.transform.eulerAngles -= Vector3.forward * 90f;
|
|
}
|
|
});
|
|
}
|
|
|
|
public void ShowNet()
|
|
{
|
|
Debug.Log("Start netting manual: " + GameController.Instance.manualFishingNet);
|
|
fishingHands.HideLeftArm();
|
|
rightArmPosition = fishingHands.rightArm.transform.localPosition;
|
|
rightArmRotation = fishingHands.rightArm.transform.eulerAngles;
|
|
rightArmAddRotation = Vector3.zero;
|
|
rightArmAddPosition = Vector3.zero;
|
|
isAutomaticUpdate = false;
|
|
fishingNetIndicator.meshCollider.enabled = true;
|
|
if ((bool)fishingHands.fishingPlayer.fish)
|
|
{
|
|
Debug.Log("ShowNet 1");
|
|
if (GameController.Instance.manualFishingNet)
|
|
{
|
|
fishingHands.fishingPlayer.CameraLookAt(fishingHands.fishingPlayer.fish.transform.position, new Vector3(0f, 0.2f, 0f), 1f);
|
|
}
|
|
else
|
|
{
|
|
fishingHands.fishingPlayer.CameraLookAt(fishingHands.fishingPlayer.fish.transform.position, new Vector3(0f, 0.2f, 0f), 1f);
|
|
}
|
|
fishingHands.fishingPlayer.fish.animController.squirmTimer = UnityEngine.Random.Range(5f, 8f);
|
|
}
|
|
if (GameController.Instance.manualFishingNet)
|
|
{
|
|
rigidbodyMount.transform.localEulerAngles = new Vector3(0f, -18f, 0f);
|
|
}
|
|
else
|
|
{
|
|
rigidbodyMount.transform.localEulerAngles = new Vector3(-11f, -18f, 0f);
|
|
}
|
|
if (VRManager.IsVROn())
|
|
{
|
|
ToggleVRArmRenderers();
|
|
}
|
|
if (!VRManager.Instance.IsVRFishingNet())
|
|
{
|
|
Debug.Log("ShowNet 2-1");
|
|
rigidbodyArm.transform.localPosition = new Vector3(rigidbodyArm.transform.localPosition.x, rigidbodyArm.transform.localPosition.y, -3.5f);
|
|
LeanTween.moveLocal(rigidbodyArm.gameObject, new Vector3(rigidbodyArm.transform.localPosition.x, rigidbodyArm.transform.localPosition.y, -1.7f), 1f);
|
|
}
|
|
else
|
|
{
|
|
Debug.Log("ShowNet 2-2");
|
|
Transform transform = rigidbodyArm.transform;
|
|
transform.gameObject.SetActive(true);
|
|
transform.parent = VRControllersManager.Instance.GetVRController(VRControllersManager.Instance.GetSecondaryController()).fishingNetHoldTransform;
|
|
transform.localPosition = new Vector3(0.07f, 0.1f, -0.69f);
|
|
transform.localEulerAngles = new Vector3(0f, 0f, 0f);
|
|
transform.localScale = new Vector3(0.8f, 0.8f, 0.8f);
|
|
base.transform.parent.localPosition = new Vector3(-0.037f, 0.051f, -0.035f);
|
|
base.transform.parent.localScale = new Vector3(1.5f, 3.5f, 1.5f);
|
|
net.transform.localScale = new Vector3(1.5f, 1f, 1f);
|
|
}
|
|
if (!VRManager.IsVROn() || GameController.Instance.manualFishingNet)
|
|
{
|
|
Debug.Log("ShowNet no hand");
|
|
rigidbodyMount.gameObject.SetActive(true);
|
|
fishingNetTrigger.gameObject.SetActive(true);
|
|
fishingNetTrigger.GetComponent<MeshRenderer>().enabled = false;
|
|
Utilities.SetLayerRecursively(base.gameObject, "Default");
|
|
Utilities.SetLayerRecursively(stick.gameObject, "Weapon");
|
|
Utilities.SetLayerRecursively(net.gameObject, "Terrain");
|
|
}
|
|
if (UtilitiesInput.isReelingIn)
|
|
{
|
|
blockMouseInput = true;
|
|
}
|
|
StartCoroutine(fishingHands.fishingPlayer.underwaterCamera.TurnOn(false));
|
|
fishingHands.fishingPlayer.Zoom(true, 0.7f);
|
|
if (!VRManager.Instance.IsVRFishingNet())
|
|
{
|
|
Debug.Log("ShowNet 3");
|
|
fishingHands.fishingPlayer.ufpsWeapon.RotationSpringStiffness = 1f;
|
|
fishingHands.fishingPlayer.ufpsWeapon.RotationSpringDamping = 0.7f;
|
|
fishingHands.fishingPlayer.ufpsWeapon.Refresh();
|
|
}
|
|
if ((bool)fishingHands.fishingPlayer.fish)
|
|
{
|
|
fishingHands.fishingLine.RemoveLineOverhead(0f);
|
|
}
|
|
if ((bool)fishingHands.fishingPlayer.boatSimulator)
|
|
{
|
|
fishingHands.fishingPlayer.boatSimulator.PauseFloating(true);
|
|
}
|
|
Debug.Log("ShowNet 4");
|
|
LeanTween.delayedCall(0.3f, (Action)delegate
|
|
{
|
|
Debug.Log("ShowNet 5");
|
|
if (fishingHands.fishingPlayer.currentState == FishingPlayer.PlayerState.FISHING_NET)
|
|
{
|
|
fishingHands.fishingPlayer.LeanForward(1.2f);
|
|
}
|
|
});
|
|
LeanTween.delayedCall(1.3f, (Action)delegate
|
|
{
|
|
Debug.Log("ShowNet 6 fishCanBePulledTimer: " + fishCanBePulledTimer);
|
|
fishCanBePulledTimer = 32f;
|
|
canBeUpdated = true;
|
|
TutorialManager.Instance.ShowTutorial(TutorialManager.TutorialsId.FISHING_NET);
|
|
});
|
|
if (GameController.Instance.manualFishingNet)
|
|
{
|
|
return;
|
|
}
|
|
Debug.Log("ShowNet 7");
|
|
LeanTween.delayedCall(1f, (Action)delegate
|
|
{
|
|
Debug.Log("ShowNet 8");
|
|
if ((bool)fishingHands.fishingPlayer.fish)
|
|
{
|
|
Debug.Log("ShowNet 10");
|
|
isAutomaticUpdate = true;
|
|
fishingHands.fishingPlayer.CameraLookAt(fishingHands.fishingPlayer.fish.transform.position, new Vector3(0f, 0.2f, 0f), 0.8f);
|
|
}
|
|
});
|
|
LeanTween.delayedCall(1.5f, (Action)delegate
|
|
{
|
|
Debug.Log("ShowNet 9");
|
|
if ((bool)fishingHands.fishingPlayer.fish)
|
|
{
|
|
Debug.Log("ShowNet 11");
|
|
fishingHands.fishingPlayer.FishCatch(fishingHands.fishingPlayer.fish);
|
|
}
|
|
});
|
|
}
|
|
|
|
public void HideNet(bool quick = false)
|
|
{
|
|
canBeUpdated = false;
|
|
if (quick)
|
|
{
|
|
rigidbodyMount.gameObject.SetActive(false);
|
|
return;
|
|
}
|
|
if (VRManager.Instance.IsVRFishingNet())
|
|
{
|
|
rigidbodyArm.gameObject.SetActive(false);
|
|
if ((bool)fishingHands.fishingPlayer.boatSimulator)
|
|
{
|
|
fishingHands.fishingPlayer.boatSimulator.PauseFloating(false);
|
|
}
|
|
return;
|
|
}
|
|
if ((bool)fishingHands.fishingPlayer && rigidbodyMount.gameObject.activeSelf)
|
|
{
|
|
fishingHands.fishingPlayer.Zoom(false, 0.7f);
|
|
fishingHands.fishingPlayer.ufpsWeapon.RotationSpringStiffness = 0.02f;
|
|
fishingHands.fishingPlayer.ufpsWeapon.RotationSpringDamping = 0.37f;
|
|
fishingHands.fishingPlayer.ufpsWeapon.Refresh();
|
|
}
|
|
LeanTween.moveLocal(rigidbodyArm.gameObject, new Vector3(rigidbodyArm.transform.localPosition.x, rigidbodyArm.transform.localPosition.y, -3.5f), 0.7f);
|
|
LeanTween.delayedCall(0.7f, (Action)delegate
|
|
{
|
|
rigidbodyMount.gameObject.SetActive(false);
|
|
});
|
|
fishingHands.rightArm.transform.localPosition = rightArmStartPosition;
|
|
fishingHands.rightArm.transform.localEulerAngles = rightArmStartRotation;
|
|
rightArmAddRotation = Vector3.zero;
|
|
rightArmAddPosition = Vector3.zero;
|
|
if ((bool)fishingHands.fishingPlayer.boatSimulator)
|
|
{
|
|
fishingHands.fishingPlayer.boatSimulator.PauseFloating(false);
|
|
}
|
|
}
|
|
|
|
public void UpdateNetInput()
|
|
{
|
|
fishingHands.fishingPlayer.LeanForward(1.2f);
|
|
if (isAutomaticUpdate)
|
|
{
|
|
rigidbodyArm.transform.localPosition += new Vector3(0f, 0f, fishingHands.netMoveSpeed * 2f * Time.deltaTime);
|
|
rigidbodyMount.transform.localEulerAngles = new Vector3(-11f, rigidbodyMount.transform.localEulerAngles.y, 0f);
|
|
}
|
|
if (!canBeUpdated || !GameController.Instance.manualFishingNet)
|
|
{
|
|
return;
|
|
}
|
|
if (fishCanBePulledTimer > 0f)
|
|
{
|
|
fishCanBePulledTimer -= Time.deltaTime;
|
|
if (fishCanBePulledTimer < 15f)
|
|
{
|
|
Debug.LogError("Fish Net Pull hack UpdateNetInput");
|
|
fishingHands.fishingPlayer.FishCatch(fishingHands.fishingPlayer.fish);
|
|
return;
|
|
}
|
|
}
|
|
if (VRManager.Instance.IsVRFishingNet())
|
|
{
|
|
Vector3 localPosition = base.transform.localPosition;
|
|
if (UtilitiesInput.GetButton("NET_UP"))
|
|
{
|
|
localPosition.y += fishingHands.netMoveSpeed * Time.deltaTime * 0.5f;
|
|
}
|
|
else if (UtilitiesInput.GetButton("NET_DOWN"))
|
|
{
|
|
localPosition.y -= fishingHands.netMoveSpeed * Time.deltaTime * 0.5f;
|
|
}
|
|
if (localPosition.y > vrPosMinMax.x)
|
|
{
|
|
localPosition.y = vrPosMinMax.x;
|
|
}
|
|
else if (localPosition.y < vrPosMinMax.y)
|
|
{
|
|
localPosition.y = vrPosMinMax.y;
|
|
}
|
|
base.transform.localPosition = localPosition;
|
|
}
|
|
else
|
|
{
|
|
Vector3 localPosition2 = rigidbodyArm.transform.localPosition;
|
|
if (UtilitiesInput.moveAxis.y > 0.2f)
|
|
{
|
|
localPosition2.z += fishingHands.netMoveSpeed * Time.deltaTime;
|
|
}
|
|
else if (UtilitiesInput.moveAxis.y < -0.2f)
|
|
{
|
|
localPosition2.z -= fishingHands.netMoveSpeed * Time.deltaTime;
|
|
}
|
|
localPosition2.z = Mathf.Clamp(localPosition2.z, startPosition.z - fishingHands.netMoveMaxZ.x, startPosition.z + fishingHands.netMoveMaxZ.y);
|
|
rigidbodyArm.transform.localPosition = localPosition2;
|
|
}
|
|
if ((GlobalSettings.Instance == null || ((bool)GlobalSettings.Instance && GlobalSettings.Instance.turnOnCheats)) && Input.GetKeyDown(KeyCode.N))
|
|
{
|
|
fishingHands.fishingPlayer.ChangeState(FishingPlayer.PlayerState.NORMAL);
|
|
}
|
|
if (UtilitiesInput.GetButtonDown("RESET_THROW"))
|
|
{
|
|
fishingHands.fishingPlayer.fishingController.FinishFishing();
|
|
fishingHands.fishingPlayer.ChangeState(FishingPlayer.PlayerState.NORMAL);
|
|
}
|
|
}
|
|
|
|
public void LateUpdateNetInput()
|
|
{
|
|
}
|
|
|
|
public void FixedUpdateNetInput()
|
|
{
|
|
if (VRManager.Instance.IsVRFishingNet())
|
|
{
|
|
return;
|
|
}
|
|
if (GameController.Instance.manualFishingNet)
|
|
{
|
|
if (UtilitiesInput.lookAxis.x != 0f && !Cursor.visible)
|
|
{
|
|
rightArmAddRotation.y += UtilitiesInput.lookAxis.x * Time.fixedDeltaTime * rightArmMoveSpeed.x;
|
|
rightArmAddRotation = Utilities.GetVectorAngles180Range(rightArmAddRotation);
|
|
rightArmAddRotation.y = Mathf.Clamp(rightArmAddRotation.y, -20f, 25f);
|
|
}
|
|
if (UtilitiesInput.lookAxis.y != 0f && !Cursor.visible)
|
|
{
|
|
rightArmAddPosition.z += UtilitiesInput.lookAxis.y * Time.fixedDeltaTime * rightArmMoveSpeed.y;
|
|
rightArmAddPosition.z = Mathf.Clamp(rightArmAddPosition.z, -0.82f, 0f);
|
|
}
|
|
if (Input.GetAxis("Mouse Y") == 0f)
|
|
{
|
|
}
|
|
}
|
|
fishingHands.rightArm.transform.localPosition = rightArmPosition + rightArmAddPosition;
|
|
fishingHands.rightArm.transform.eulerAngles = rightArmRotation + rightArmAddRotation;
|
|
if (GameController.Instance.manualFishingNet && canBeUpdated)
|
|
{
|
|
Vector3 vectorAngles180Range = Utilities.GetVectorAngles180Range(rigidbodyMount.transform.localEulerAngles);
|
|
if (UtilitiesInput.moveAxis.x < -0.2f && vectorAngles180Range.y > fishingHands.netMoveMaxY.x)
|
|
{
|
|
rigidbodyMount.AddTorque(-fishingHands.transform.up * fishingHands.netRotateSpeed * Time.deltaTime);
|
|
}
|
|
else if (UtilitiesInput.moveAxis.x > 0.2f && vectorAngles180Range.y < fishingHands.netMoveMaxY.y)
|
|
{
|
|
rigidbodyMount.AddTorque(fishingHands.transform.up * fishingHands.netRotateSpeed * Time.deltaTime);
|
|
}
|
|
if (UtilitiesInput.GetButton("NET_UP") && vectorAngles180Range.x > fishingHands.netMoveMaxX.x)
|
|
{
|
|
rigidbodyMount.AddTorque(-rigidbodyMount.transform.right * fishingHands.netRotateSpeed * Time.deltaTime);
|
|
}
|
|
else if (UtilitiesInput.GetButton("NET_DOWN") && vectorAngles180Range.x < fishingHands.netMoveMaxX.y)
|
|
{
|
|
rigidbodyMount.AddTorque(rigidbodyMount.transform.right * fishingHands.netRotateSpeed * Time.deltaTime);
|
|
}
|
|
if (UtilitiesInput.isReelingIn)
|
|
{
|
|
blockMouseInput = false;
|
|
}
|
|
vectorAngles180Range.x = Mathf.Clamp(vectorAngles180Range.x, fishingHands.netMoveMaxX.x, fishingHands.netMoveMaxX.y);
|
|
vectorAngles180Range.y = Mathf.Clamp(vectorAngles180Range.y, fishingHands.netMoveMaxY.x, fishingHands.netMoveMaxY.y);
|
|
vectorAngles180Range.z = 0f;
|
|
rigidbodyMount.transform.localEulerAngles = vectorAngles180Range;
|
|
}
|
|
}
|
|
|
|
public void ToggleVRArmRenderers()
|
|
{
|
|
foreach (SkinnedMeshRenderer armsMeshRenderer in armsMeshRenderers)
|
|
{
|
|
if (armsMeshRenderer.name == "hand_left" || armsMeshRenderer.name == "hand_right")
|
|
{
|
|
armsMeshRenderer.material = fishingHands.vrHandsMaterial;
|
|
}
|
|
else
|
|
{
|
|
armsMeshRenderer.enabled = false;
|
|
}
|
|
}
|
|
}
|
|
}
|