Files
UltimateFishing2020/Assets/Scripts/Assembly-CSharp/ItemsViewer.cs
2026-03-04 10:03:45 +08:00

137 lines
3.7 KiB
C#

using UnityEngine;
using UnityEngine.UI;
using UnityStandardAssets.CrossPlatformInput;
public class ItemsViewer : MonoBehaviour
{
public GameObject viewItemCamera;
public Camera viewCamera;
public Transform envBoxContainer;
public Transform itemContainer;
public GameObject assignItemView;
private GameObject currentItemView;
public Text nameText;
public Image logoBrand;
public float rotationSensitivity = 1f;
private float currentFieldOfView;
private Vector2 cursorPositionToRotate = Vector2.zero;
private bool isUserRotation;
private void Start()
{
}
private void Update()
{
if ((bool)assignItemView)
{
if ((bool)currentItemView)
{
Object.Destroy(currentItemView);
currentItemView = null;
}
currentItemView = Object.Instantiate(assignItemView, itemContainer);
currentItemView.transform.localPosition = Vector3.zero;
currentItemView.transform.localEulerAngles = Vector3.zero;
assignItemView = null;
}
if (GameManager.Instance.player.GetButtonDown("B"))
{
Object.Destroy(base.gameObject);
}
AutoRotateEnv();
}
private void AutoRotateEnv()
{
if (!currentItemView)
{
return;
}
if (isUserRotation)
{
envBoxContainer.Rotate(new Vector3(0f, 0f - cursorPositionToRotate.y, 0f));
itemContainer.Rotate(new Vector3(0f - cursorPositionToRotate.x, 0f, 0f));
}
else
{
envBoxContainer.Rotate(new Vector3(0f, 0.5f, 0f));
}
if (GameManager.Instance.controllerType == GameManager.ControllerType.GamePad)
{
if (GameManager.Instance.player.GetAxis("cameraVerticalGamepad") != 0f || GameManager.Instance.player.GetAxis("cameraHorizontalGamepad") != 0f)
{
isUserRotation = true;
cursorPositionToRotate += new Vector2(GameManager.Instance.player.GetAxis("cameraHorizontalGamepad") * Time.unscaledDeltaTime, GameManager.Instance.player.GetAxis("cameraVerticalGamepad") * Time.unscaledDeltaTime);
}
else
{
cursorPositionToRotate = Vector2.MoveTowards(cursorPositionToRotate, Vector2.zero, Time.unscaledDeltaTime * 5f);
}
}
else if (Input.GetMouseButton(0))
{
isUserRotation = true;
cursorPositionToRotate += new Vector2(CrossPlatformInputManager.GetAxis("Mouse Y"), CrossPlatformInputManager.GetAxis("Mouse X")) * rotationSensitivity;
}
else
{
cursorPositionToRotate = Vector2.MoveTowards(cursorPositionToRotate, Vector2.zero, Time.unscaledDeltaTime * 5f);
}
if (GameManager.Instance.controllerType == GameManager.ControllerType.GamePad)
{
if (GameManager.Instance.player.GetButtonDown("MouseClick"))
{
envBoxContainer.localPosition = new Vector3(0f, 0.22f, 0f);
currentFieldOfView = 0f;
cursorPositionToRotate = Vector2.zero;
isUserRotation = false;
}
if (GameManager.Instance.player.GetButtonDown("jumping"))
{
Exit();
}
}
else if (Input.GetMouseButton(1))
{
envBoxContainer.localPosition = new Vector3(0f, 0.22f, 0f);
currentFieldOfView = 0f;
cursorPositionToRotate = Vector2.zero;
isUserRotation = false;
}
if (GameManager.Instance.controllerType == GameManager.ControllerType.GamePad)
{
currentFieldOfView -= GameManager.Instance.player.GetAxis("CameraVerticalGamepadUI") * Time.unscaledDeltaTime;
currentFieldOfView = Mathf.Clamp(currentFieldOfView, -1f, 5f);
}
else if (Input.mouseScrollDelta.y != 0f)
{
currentFieldOfView -= Input.mouseScrollDelta.y * (Time.unscaledDeltaTime * 5f);
currentFieldOfView = Mathf.Clamp(currentFieldOfView, -1f, 5f);
}
envBoxContainer.localPosition = new Vector3(0f, 0.22f, currentFieldOfView);
}
public void Exit()
{
if (!(GameManager.Instance.addectiveSceneLoaded == "FishPedia"))
{
GameManager.Instance.PlayOnClickSound();
Debug.Log("Viewer exit");
GameManager.Instance.currentItemsViewer = null;
Object.Destroy(base.gameObject);
}
}
}