2022-11-01 15:30:13 +08:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using SHADE;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace SHADE_Scripting
|
|
|
|
|
{
|
2022-11-21 00:12:09 +08:00
|
|
|
|
public class ThirdPersonCamera : Script
|
|
|
|
|
{
|
2022-11-01 15:30:13 +08:00
|
|
|
|
|
2022-11-21 00:12:09 +08:00
|
|
|
|
public float armLength = 2.0f;
|
|
|
|
|
public float turnSpeedPitch = 0.3f;
|
|
|
|
|
public float turnSpeedYaw = 0.5f;
|
2022-11-25 16:23:26 +08:00
|
|
|
|
public bool inverseXControls = false;
|
|
|
|
|
public bool inverseYControls = false;
|
2023-02-20 19:53:22 +08:00
|
|
|
|
public float pitchUpperClamp = 45.0f;
|
|
|
|
|
public float pitchLowerClamp = 5.0f;
|
2022-11-01 15:30:13 +08:00
|
|
|
|
|
2022-11-21 00:12:09 +08:00
|
|
|
|
protected override void awake()
|
|
|
|
|
{
|
|
|
|
|
AddComponent<Transform>();
|
|
|
|
|
|
|
|
|
|
if (!GetComponent<Camera>())
|
|
|
|
|
{
|
|
|
|
|
AddComponent<Camera>();
|
|
|
|
|
}
|
2023-03-05 15:35:57 +08:00
|
|
|
|
|
2022-11-21 00:12:09 +08:00
|
|
|
|
if (!GetComponent<CameraArm>())
|
|
|
|
|
{
|
|
|
|
|
AddComponent<CameraArm>();
|
|
|
|
|
}
|
2022-11-23 13:44:03 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void start()
|
|
|
|
|
{
|
2022-11-21 00:12:09 +08:00
|
|
|
|
GetComponent<CameraArm>().ArmLength = armLength;
|
2023-03-08 17:00:43 +08:00
|
|
|
|
GetComponent<Camera>().FOV = Settings.cameraFOV;
|
2022-11-21 00:12:09 +08:00
|
|
|
|
}
|
2022-11-01 15:30:13 +08:00
|
|
|
|
|
2022-11-02 17:31:57 +08:00
|
|
|
|
protected override void update()
|
|
|
|
|
{
|
2023-03-02 17:33:02 +08:00
|
|
|
|
if (GameManager.Instance.GamePause || !GameManager.Instance.stealFoodPopUpDone)
|
2023-02-21 19:31:50 +08:00
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-21 00:12:09 +08:00
|
|
|
|
CameraArm arm = GetComponent<CameraArm>();
|
|
|
|
|
if (arm)
|
2022-11-02 17:31:57 +08:00
|
|
|
|
{
|
2022-11-21 00:12:09 +08:00
|
|
|
|
Vector2 vel = Input.GetMouseVelocity();
|
2022-11-25 16:23:26 +08:00
|
|
|
|
if(inverseYControls)
|
|
|
|
|
arm.Pitch -= vel.y * turnSpeedPitch * Time.DeltaTimeF;
|
|
|
|
|
else
|
|
|
|
|
arm.Pitch += vel.y * turnSpeedPitch * Time.DeltaTimeF;
|
|
|
|
|
|
|
|
|
|
if (inverseXControls)
|
2023-02-20 19:53:22 +08:00
|
|
|
|
arm.Yaw -= vel.x * turnSpeedYaw * Time.DeltaTimeF;
|
2023-02-25 21:56:49 +08:00
|
|
|
|
else
|
|
|
|
|
arm.Yaw += vel.x * turnSpeedYaw * Time.DeltaTimeF;
|
2022-11-21 00:12:09 +08:00
|
|
|
|
|
2023-02-20 19:53:22 +08:00
|
|
|
|
if (arm.Pitch > pitchUpperClamp)
|
2022-11-21 00:12:09 +08:00
|
|
|
|
{
|
2023-02-20 19:53:22 +08:00
|
|
|
|
arm.Pitch = pitchUpperClamp;
|
2022-11-21 00:12:09 +08:00
|
|
|
|
}
|
2023-02-20 19:53:22 +08:00
|
|
|
|
else if (arm.Pitch < pitchLowerClamp)
|
2022-11-21 00:12:09 +08:00
|
|
|
|
{
|
2023-02-20 19:53:22 +08:00
|
|
|
|
arm.Pitch = pitchLowerClamp;
|
2022-11-01 15:30:13 +08:00
|
|
|
|
}
|
2022-11-02 17:31:57 +08:00
|
|
|
|
}
|
2022-11-01 15:30:13 +08:00
|
|
|
|
}
|
2022-11-21 00:12:09 +08:00
|
|
|
|
|
|
|
|
|
}
|
2022-11-01 15:30:13 +08:00
|
|
|
|
}
|