修改框架
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
/// <summary>
|
||||
/// 相机控制器
|
||||
/// </summary>
|
||||
public abstract class CameraController : MonoBehaviour {
|
||||
/// <summary> 位置 </summary>
|
||||
public abstract Vector3 Position { get; set; }
|
||||
/// <summary> 正向 </summary>
|
||||
public abstract Vector3 Forward { get; set; }
|
||||
/// <summary> 右向 </summary>
|
||||
public abstract Vector3 Right { get; set; }
|
||||
/// <summary> 旋转 </summary>
|
||||
public abstract Vector3 EulerAngles { get; set; }
|
||||
/// <summary> 距离 </summary>
|
||||
public abstract float Distance { get; set; }
|
||||
|
||||
/// <summary> 初始化 </summary>
|
||||
public abstract void Initialize();
|
||||
/// <summary> 重置相机 </summary>
|
||||
public abstract void ResetCamera();
|
||||
|
||||
/// <summary> 屏幕坐标转换世界坐标 </summary>
|
||||
public virtual Vector3 ScreenToWorldPosition(Vector3 screenPosition) {
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 96a98904bc59dd9468543e99e52f3d94
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2408eae033f1fe54ebf17cdc3530f985
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,47 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
/// <summary>
|
||||
/// 默认相机
|
||||
/// </summary>
|
||||
public class CameraDefault : CameraController {
|
||||
|
||||
public override Vector3 Position {
|
||||
get => throw new System.NotImplementedException();
|
||||
set => throw new System.NotImplementedException();
|
||||
}
|
||||
public override Vector3 Forward {
|
||||
get => throw new System.NotImplementedException();
|
||||
set => throw new System.NotImplementedException();
|
||||
}
|
||||
public override Vector3 Right {
|
||||
get => throw new System.NotImplementedException();
|
||||
set => throw new System.NotImplementedException();
|
||||
}
|
||||
public override Vector3 EulerAngles {
|
||||
get => throw new System.NotImplementedException();
|
||||
set => throw new System.NotImplementedException();
|
||||
}
|
||||
public override float Distance {
|
||||
get => throw new System.NotImplementedException();
|
||||
set => throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
public override void Initialize() {
|
||||
ModuleCamera.OnCameraMode += ModuleCamera_OnCameraMode;
|
||||
}
|
||||
|
||||
private void ModuleCamera_OnCameraMode(EnumCameraMode mode) {
|
||||
#if UNITY_STANDALONE_WIN && !UNITY_EDITOR
|
||||
return;
|
||||
#endif
|
||||
gameObject.SetActive(mode == EnumCameraMode.None);
|
||||
if (mode == EnumCameraMode.None) { ModuleCamera.CurrentCamera = this; }
|
||||
}
|
||||
|
||||
public override void ResetCamera() {
|
||||
// transform.position = HotUpdateScene.I.StartPoint.position;
|
||||
// transform.eulerAngles = HotUpdateScene.I.StartPoint.eulerAngles;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0f6f4a232485de9439914dc14b7df5a7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,68 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
/// <summary>
|
||||
/// 移轴相机
|
||||
/// </summary>
|
||||
public class CameraMoveAxis : CameraController {
|
||||
|
||||
public Camera mainCamera;
|
||||
public LayerMask layerMask;
|
||||
|
||||
private RaycastHit hitInfo;
|
||||
|
||||
public override Vector3 Position {
|
||||
get => transform.position;
|
||||
set => transform.position = value;
|
||||
}
|
||||
public override Vector3 Forward {
|
||||
get => throw new System.NotImplementedException();
|
||||
set => throw new System.NotImplementedException();
|
||||
}
|
||||
public override Vector3 Right {
|
||||
get => throw new System.NotImplementedException();
|
||||
set => throw new System.NotImplementedException();
|
||||
}
|
||||
public override Vector3 EulerAngles {
|
||||
get => transform.eulerAngles;
|
||||
set => transform.eulerAngles = value;
|
||||
}
|
||||
public override float Distance {
|
||||
get => GetVisualField();
|
||||
set => SetVisualField(value);
|
||||
}
|
||||
|
||||
private float GetVisualField() {
|
||||
return Vector3.Distance(mainCamera.transform.localPosition, Vector3.zero);
|
||||
}
|
||||
private void SetVisualField(float value) {
|
||||
value = Mathf.Clamp(value, 10, 30);
|
||||
Vector3 direction = mainCamera.transform.localPosition - Vector3.zero;
|
||||
mainCamera.transform.localPosition = direction.normalized * value;
|
||||
// if (!Volume.profile.TryGet(out DepthOfField depthOfField)) { return; }
|
||||
// depthOfField.focusDistance.SetValue(new FloatParameter(value));
|
||||
}
|
||||
|
||||
public override void Initialize() {
|
||||
ModuleCamera.OnCameraMode += ModuleCamera_OnCameraMode;
|
||||
}
|
||||
|
||||
private void ModuleCamera_OnCameraMode(EnumCameraMode mode) {
|
||||
gameObject.SetActive(mode == EnumCameraMode.MoveAxis);
|
||||
if (mode == EnumCameraMode.MoveAxis) { ModuleCamera.CurrentCamera = this; }
|
||||
}
|
||||
|
||||
public override void ResetCamera() {
|
||||
// transform.position = HotUpdateScene.I.StartPoint.position;
|
||||
// transform.eulerAngles = HotUpdateScene.I.StartPoint.eulerAngles;
|
||||
}
|
||||
|
||||
public override Vector3 ScreenToWorldPosition(Vector3 screenPosition) {
|
||||
Ray ray = mainCamera.ScreenPointToRay(screenPosition);
|
||||
Physics.Raycast(ray, out hitInfo, 200f, layerMask);
|
||||
Vector3 position = Vector3.zero;
|
||||
if (hitInfo.transform != null) { position = hitInfo.point; }
|
||||
return position;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cc9103ac1c158bb41af1ba45de4f9d08
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,49 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using MuHua;
|
||||
|
||||
/// <summary>
|
||||
/// 相机模块
|
||||
/// </summary>
|
||||
public class ModuleCamera : ModuleSingle<ModuleCamera> {
|
||||
/// <summary> 当前相机 </summary>
|
||||
public static CameraController CurrentCamera;
|
||||
/// <summary> 相机模式事件 </summary>
|
||||
public static event Action<EnumCameraMode> OnCameraMode;
|
||||
/// <summary> 设置相机模式 </summary>
|
||||
public static void Mode(EnumCameraMode mode, bool isReset = true) {
|
||||
OnCameraMode?.Invoke(mode);
|
||||
if (isReset) { I.ResetCamera(); }
|
||||
}
|
||||
|
||||
public List<CameraController> cameras;
|
||||
|
||||
protected override void Awake() => NoReplace();
|
||||
|
||||
private void Start() => cameras.ForEach(obj => obj.Initialize());
|
||||
|
||||
/// <summary> 重置相机 </summary>
|
||||
public void ResetCamera() => cameras.ForEach(obj => obj.ResetCamera());
|
||||
|
||||
/// <summary>
|
||||
/// 转换方向
|
||||
/// </summary>
|
||||
/// <param name="forward">相机的前方</param>
|
||||
/// <param name="right">相机的右方</param>
|
||||
/// <param name="moveInput">输入的移动方向</param>
|
||||
/// <returns>Y轴向上的平面移动方向</returns>
|
||||
public static Vector3 TransferDirection(Vector3 forward, Vector3 right, Vector2 moveInput) {
|
||||
// 确保前方和右方方向在水平面上
|
||||
forward.y = 0;
|
||||
right.y = 0;
|
||||
|
||||
// 归一化方向向量
|
||||
forward.Normalize();
|
||||
right.Normalize();
|
||||
|
||||
// 计算移动方向
|
||||
return (forward * moveInput.y + right * moveInput.x).normalized;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d436e33934b1feb4d8a3909ffb5292a2
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user