新相机控制逻辑脚本

This commit is contained in:
Afeijia 2023-08-28 19:07:34 +08:00
parent c859428031
commit 4e8cb1535c
5 changed files with 108471 additions and 6 deletions

View File

@ -14,6 +14,7 @@ MonoBehaviour:
m_EditorClassIdentifier:
useSafeMode: 1
safeModeOptions:
logBehaviour: 2
nestedTweenFailureBehaviour: 0
timeScale: 1
useSmoothDeltaTime: 0
@ -31,6 +32,8 @@ MonoBehaviour:
defaultEasePeriod: 0
defaultAutoKill: 1
defaultLoopType: 0
debugMode: 0
debugStoreTargetId: 1
showPreviewPanel: 1
storeSettingsLocation: 0
modules:
@ -42,5 +45,9 @@ MonoBehaviour:
uiEnabled: 1
textMeshProEnabled: 0
tk2DEnabled: 0
deAudioEnabled: 0
deUnityExtendedEnabled: 0
epoOutlineEnabled: 0
createASMDEF: 0
showPlayingTweens: 0
showPausedTweens: 0

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 0184bb96ccf7b4948b004e3adcad11f3
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -5,6 +5,9 @@ using UnityEditor;
#endif
using UnityEngine;
using UnityEngine.EventSystems;
using DG.Tweening;
using System;
using static WebInteraction;
/// <summary>
/// 相机控制
@ -65,6 +68,23 @@ public class CameraRT : MonoBehaviour
//动态调节相机缩放的灵敏度
float tempSpeed;
private void Awake()
{
BoolMonitor.ValueChanged += BoolMonitor_ValueChanged;
}
private static void BoolMonitor_ValueChanged(object sender, EventArgs e)
{
//Debug.Log("当前是否不动" + BoolMonitor.Value);
if (!BoolMonitor.Value)
{
if (!string.IsNullOrEmpty(WebInteraction.Inst.current_videoNumber) && WebInteraction.Inst.isVideoPlay)
{
WebInteraction.Inst.CloseVideo(WebInteraction.Inst.current_videoNumber);
}
}
}
private void Start()
{
if (cam == null)
@ -72,16 +92,110 @@ public class CameraRT : MonoBehaviour
cam = Camera.main;
}
cameraTransform = cam.transform;
// 初始化上一帧的位置和旋转
lastPosition = cameraTransform.position;
lastRotation = cameraTransform.rotation;
target = transform.GetChild(0);
target.gameObject.AddComponent<CameraTargetFollowCam>();
x = cam.transform.localEulerAngles.y;
y = cam.transform.localEulerAngles.x;
target_init_position = target.position;
//target_init_rotation = target.rotation;
target_init_eulerAngles = target.eulerAngles;
camera_init_position = cam.transform.position;
//camera_init_rotation = cam.transform.rotation;
camera_init_eulerAngles = cam.transform.eulerAngles;
init_x = x = cam.transform.localEulerAngles.y;
init_y = y = cam.transform.localEulerAngles.x;
tempSpeed = xSpeed_move;
rotateTimer_temp = rotateTimer;
}
Vector3 target_init_position;
//Quaternion target_init_rotation;
Vector3 target_init_eulerAngles;
Vector3 camera_init_position;
//Quaternion camera_init_rotation;
Vector3 camera_init_eulerAngles;
float init_x;
float init_y;
bool auto_move;
/// <summary>
/// 全景视角
/// </summary>
public void InitPanoramic()
{
auto_move = true;
//target.position = target_init_position;
//target.rotation = target_init_rotation;
//cam.transform.position = camera_init_position;
//cam.transform.rotation = camera_init_rotation;
//x = cam.transform.localEulerAngles.y;
//y = cam.transform.localEulerAngles.x;
Array.ForEach(GameObject.FindObjectsOfType<ClickEvent>(), itme =>
{
itme.My_magnifyState = false;
});
//Array.ForEach(GameObject.FindObjectsOfType<TransparentGlow>(), itme =>
//{
// itme.F2();
//});
PatternChoose.Inst.transform.Find("设备类/设备配置").gameObject.SetActive(false);
PatternChoose.Inst.transform.Find("设备类/设备新增").gameObject.SetActive(false);
PatternChoose.Inst.transform.Find("端口类/端口配置").gameObject.SetActive(false);
PatternChoose.Inst.transform.Find("端口类/端口新增").gameObject.SetActive(false);
GameManager.Inst.magnifyState = false;
distance = 20;
DOTween.To(() => x, (v) => x = v, init_x, 0.5f);
DOTween.To(() => y, (v) => y = v, init_y, 0.5f);
DOTween.To(() => cam.transform.position, (v) => cam.transform.position = v, camera_init_position, 0.5f);
DOTween.To(() => cam.transform.eulerAngles, v => cam.transform.eulerAngles = v, camera_init_eulerAngles, 0.5f);
DOTween.To(() => target.position, v => target.position = v, target_init_position, 0.5f);
DOTween.To(() => target.eulerAngles, v => target.eulerAngles = v, target_init_eulerAngles, 0.5f).OnComplete(() => { auto_move = false; });
}
/// <summary>
/// 鸟瞰视角
/// </summary>
public void InitBirds_Eye()
{
auto_move = true;
Array.ForEach(GameObject.FindObjectsOfType<ClickEvent>(), itme =>
{
itme.My_magnifyState = false;
});
PatternChoose.Inst.transform.Find("设备类/设备配置").gameObject.SetActive(false);
PatternChoose.Inst.transform.Find("设备类/设备新增").gameObject.SetActive(false);
PatternChoose.Inst.transform.Find("端口类/端口配置").gameObject.SetActive(false);
PatternChoose.Inst.transform.Find("端口类/端口新增").gameObject.SetActive(false);
GameManager.Inst.magnifyState = true;
distance = 10;
DOTween.To(() => x, (v) => x = v, 110, 0.5f);
DOTween.To(() => y, (v) => y = v, 15, 0.5f);
DOTween.To(() => cam.transform.position, (v) => cam.transform.position = v, new Vector3(1, 2.8f, -7.5f), 0.5f);
DOTween.To(() => cam.transform.eulerAngles, v => cam.transform.eulerAngles = v, new Vector3(15, 110, 0), 0.5f);
DOTween.To(() => target.position, v => target.position = v, new Vector3(10.2f, 0.2f, -11), 0.5f);
DOTween.To(() => target.eulerAngles, v => target.eulerAngles = v, new Vector3(0, 110, 0), 0.5f).OnComplete(() => { auto_move = false; });
}
public void SetTarget(Transform _target)
{
target.position = _target.position;
@ -113,6 +227,10 @@ public class CameraRT : MonoBehaviour
Vector3 oldMousePos;
void Update()
{
BoolMonitor.Value = ismove();
if (auto_move)
return;
if (!autoRotate)
return;
@ -146,8 +264,10 @@ public class CameraRT : MonoBehaviour
void LateUpdate()
{
if (auto_move)
return;
if (isAutoRotating)
return;
return;
if (target)
{
@ -173,12 +293,32 @@ public class CameraRT : MonoBehaviour
}
}
private Transform cameraTransform;
private Vector3 lastPosition;
private Quaternion lastRotation;
//检测相机是否移动
public bool ismove()
{
// 检查当前帧的位置和旋转是否与上一帧不同
if (cameraTransform.position != lastPosition || cameraTransform.rotation != lastRotation)
{
// 相机移动了,可以在这里执行相应的操作
//Debug.Log("相机移动了"+ BoolMonitor.Value);
// 更新上一帧的位置和旋转
lastPosition = cameraTransform.position;
lastRotation = cameraTransform.rotation;
return false;
}
return true;
}
void Move()
{
if (EventSystem.current.IsPointerOverGameObject())
return;
if (Input.GetMouseButton(0))
if (Input.GetMouseButton(2))
{
float h = Input.GetAxis("Mouse X") * Time.deltaTime * xSpeed_move;
float v = Input.GetAxis("Mouse Y") * Time.deltaTime * ySpeed_move;

View File

@ -230,11 +230,26 @@ public class ExtendedFlycam : MonoBehaviour
rotationY = 0;
}
public CameraRT CameraRT;
public void CameraRtEnable()
{
CameraRT.enabled = true;
}
public void CameraRtDisable()
{
CameraRT.enabled = false;
}
/// <summary>
/// 镜头全景
/// </summary>
public void QuanJing()
{
CameraRtEnable();
CameraRT.InitPanoramic();
return;
Array.ForEach(GameObject.FindObjectsOfType<ClickEvent>(), itme =>
{
itme.My_magnifyState = false;
@ -263,6 +278,9 @@ public class ExtendedFlycam : MonoBehaviour
/// </summary>
public void NiaoKan()
{
CameraRtEnable();
CameraRT.InitBirds_Eye();
return;
Array.ForEach(GameObject.FindObjectsOfType<ClickEvent>(), itme =>
{
itme.My_magnifyState = false;
@ -277,8 +295,8 @@ public class ExtendedFlycam : MonoBehaviour
Inst.transform.DOLocalMove(new Vector3(18.35136f, 2.717596f, -10.86447f), 1);
Inst.transform.DORotateQuaternion(Quaternion.Euler(Inst.ClampAngle(22.6f, -91.1f, 0, Vector3.zero)), 1f).OnComplete(() =>
{
//更新相机初始旋转角度
Inst.initialRotationEulerAngles = new Vector3(22.6f, -91.1f, 0);
//更新相机初始旋转角度
Inst.initialRotationEulerAngles = new Vector3(22.6f, -91.1f, 0);
});
}