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
|
|
|
|
|
{
|
|
|
|
|
public class ThirdPersonCamera: Script
|
|
|
|
|
{
|
|
|
|
|
|
2022-11-03 01:50:02 +08:00
|
|
|
|
public float armLength = 2.0f;
|
2022-11-01 15:30:13 +08:00
|
|
|
|
public float turnSpeedPitch = 0.3f;
|
|
|
|
|
public float turnSpeedYaw = 0.5f;
|
|
|
|
|
public float pitchClamp = 45.0f;
|
|
|
|
|
public ThirdPersonCamera(GameObject go) : base(go) { }
|
|
|
|
|
|
|
|
|
|
protected override void awake()
|
|
|
|
|
{
|
2022-11-02 17:31:57 +08:00
|
|
|
|
AddComponent<Transform>();
|
|
|
|
|
|
2022-11-01 15:30:13 +08:00
|
|
|
|
if(!GetComponent<Camera>())
|
|
|
|
|
{
|
|
|
|
|
AddComponent<Camera>();
|
|
|
|
|
}
|
2022-11-02 17:31:57 +08:00
|
|
|
|
GetComponent<Camera>().SetMainCamera();
|
2022-11-01 15:30:13 +08:00
|
|
|
|
if (!GetComponent<CameraArm>())
|
|
|
|
|
{
|
|
|
|
|
AddComponent<CameraArm>();
|
|
|
|
|
}
|
|
|
|
|
GetComponent<CameraArm>().ArmLength = armLength;
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-02 17:31:57 +08:00
|
|
|
|
protected override void update()
|
|
|
|
|
{
|
|
|
|
|
if (Input.GetMouseButton(Input.MouseCode.RightButton))
|
|
|
|
|
{
|
|
|
|
|
CameraArm arm = GetComponent<CameraArm>();
|
|
|
|
|
if (arm)
|
|
|
|
|
{
|
|
|
|
|
Vector2 vel = Input.GetMouseVelocity();
|
|
|
|
|
arm.Pitch -= vel.y * turnSpeedPitch * Time.DeltaTimeF;
|
|
|
|
|
arm.Yaw += vel.x * turnSpeedYaw * Time.DeltaTimeF;
|
|
|
|
|
|
|
|
|
|
if (arm.Pitch > pitchClamp)
|
2022-11-01 15:30:13 +08:00
|
|
|
|
{
|
2022-11-02 17:31:57 +08:00
|
|
|
|
arm.Pitch = pitchClamp;
|
2022-11-01 15:30:13 +08:00
|
|
|
|
}
|
2022-11-02 17:31:57 +08:00
|
|
|
|
else if (arm.Pitch < 0)
|
|
|
|
|
{
|
|
|
|
|
arm.Pitch = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
2022-11-01 15:30:13 +08:00
|
|
|
|
}
|
2022-11-02 17:31:57 +08:00
|
|
|
|
}
|
2022-11-01 15:30:13 +08:00
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|