更新认知模块

This commit is contained in:
马铖荣 2025-07-01 16:37:26 +08:00
parent bd9b01175b
commit 389579647d
4 changed files with 10978 additions and 1460 deletions

View File

@ -1,4 +1,5 @@
using UnityEngine; using UnityEngine;
using UnityEngine.EventSystems;
public class ZhanShiCameraMove : MonoBehaviour public class ZhanShiCameraMove : MonoBehaviour
{ {
@ -27,7 +28,8 @@ public class ZhanShiCameraMove : MonoBehaviour
instance = this; instance = this;
// transform.LookAt(target); // transform.LookAt(target);
isAutoRotate = false; isAutoRotate = false;
if (isAutoRotate) { if (isAutoRotate)
{
Invoke("SetBool", 2f); Invoke("SetBool", 2f);
@ -47,171 +49,174 @@ public class ZhanShiCameraMove : MonoBehaviour
} }
/// <summary> /// <summary>
/// 更新一下参数 /// 更新一下参数
/// </summary> /// </summary>
/// <param name="x"></param> /// <param name="x"></param>
/// <param name="y"></param> /// <param name="y"></param>
/// <param name="distance"></param> /// <param name="distance"></param>
public void SetData(float x,float y,float distance) public void SetData(float x, float y, float distance)
{ {
isAutoRotate = false; isAutoRotate = false;
//目标物体旋转置空 //目标物体旋转置空
target.transform.rotation=new Quaternion( 0,0,0,0); target.transform.rotation = new Quaternion(0, 0, 0, 0);
//相机参数设置 //相机参数设置
this.x = x; this.x = x;
this.y = y; this.y = y;
this.distance = distance; this.distance = distance;
//根绝XY移动量计算旋转量 //根绝XY移动量计算旋转量
this.y = Mathf.Clamp( this.y, minYangle,maxYangle); this.y = Mathf.Clamp(this.y, minYangle, maxYangle);
Quaternion rot = Quaternion.Euler( this.y, this.x, 0); Quaternion rot = Quaternion.Euler(this.y, this.x, 0);
transform.rotation = rot; transform.rotation = rot;
//对距离进行区间运算,保证距离在最大和最小之间 //对距离进行区间运算,保证距离在最大和最小之间
this.distance = Mathf.Clamp( this.distance, distanceMin, distanceMax); this.distance = Mathf.Clamp(this.distance, distanceMin, distanceMax);
//根据距离值计算摄像机的位置 //根据距离值计算摄像机的位置
Vector3 pos = rot * new Vector3(0, 0, - this.distance) + target.position; Vector3 pos = rot * new Vector3(0, 0, -this.distance) + target.position;
//更改摄像机位置为计算的值 //更改摄像机位置为计算的值
transform.position = pos; transform.position = pos;
//延时旋转2秒后 //延时旋转2秒后
target.transform.localEulerAngles = Vector3.zero; target.transform.localEulerAngles = Vector3.zero;
Invoke("SetBool",2f); Invoke("SetBool", 2f);
} }
// Update is called once per frame // Update is called once per frame
private void Update() private void Update()
{
if (isAutoRotate && !Input.GetMouseButton(1))
{
// Debug.Log("测试到鼠标左键没按下");
{ if (isAutoRotate && !Input.GetMouseButton(1)) RotateModelContinuously(); // 持续旋转模型
{
// Debug.Log("测试到鼠标左键没按下");
RotateModelContinuously(); // 持续旋转模型 } // 如果鼠标左键没按下
else
} // 如果鼠标左键没按下 {
else
{
//target.transform.rotation = Quaternion.identity; //target.transform.rotation = Quaternion.identity;
Drag(); Drag();
}
if (Input.GetAxis("Mouse ScrollWheel") != 0)
{
//根据滚轮的值计算距离
distance = distance - Input.GetAxis("Mouse ScrollWheel") * scrollSpeed;
}
//对距离进行区间运算,保证距离在最大和最小之间
distance = Mathf.Clamp(distance, distanceMin, distanceMax);
//根据距离值计算摄像机的位置
Vector3 pos = transform.rotation * new Vector3(0, 0, -distance) + target.position;
//更改摄像机位置为计算的值
transform.position = pos;
} }
void RotateModelContinuously()
if (Input.GetAxis("Mouse ScrollWheel") != 0)
{ {
if (!isAutoRotatePivot) //根据滚轮的值计算距离
target.transform.Rotate(autoRotateDirection, autoRotationSpeed * Time.deltaTime*speed, Space.World); distance = distance - Input.GetAxis("Mouse ScrollWheel") * scrollSpeed;
else
{
var rotateEuler = autoRotateDirection * autoRotationSpeed * Time.deltaTime*speed;
// 根据模型当前朝向构造一个围绕轴旋转的四元数
Quaternion deltaRotation = Quaternion.Euler(rotateEuler);
// 将新的旋转应用到模型
target.transform.rotation *= deltaRotation;
}
} }
void Drag()
{
if (Input.GetMouseButton(1))
{ //对距离进行区间运算,保证距离在最大和最小之间
distance = Mathf.Clamp(distance, distanceMin, distanceMax);
//获取鼠标X轴移动量 //根据距离值计算摄像机的位置
x = x + Input.GetAxis("Mouse X") * rotSpeed; Vector3 pos = transform.rotation * new Vector3(0, 0, -distance) + target.position;
//获取鼠标Y轴移动量 //更改摄像机位置为计算的值
y = y - Input.GetAxis("Mouse Y") * rotSpeed; transform.position = pos;
//如果滚轮发生滚动
}
//根绝XY移动量计算旋转量
y = Mathf.Clamp(y, minYangle,maxYangle);
Quaternion rot = Quaternion.Euler(y, x, 0);
//根据计算的旋转量旋转计算机
transform.rotation = rot;
if (Input.GetAxis("Mouse ScrollWheel") != 0)
{
//根据滚轮的值计算距离
distance = distance - Input.GetAxis("Mouse ScrollWheel") * scrollSpeed;
}
//对距离进行区间运算,保证距离在最大和最小之间
distance = Mathf.Clamp(distance, distanceMin, distanceMax);
//根据距离值计算摄像机的位置
Vector3 pos = rot * new Vector3(0, 0, -distance) + target.position;
//更改摄像机位置为计算的值
transform.position = pos;
}
[SerializeField][Header("是否自动旋转")]
private bool isAutoRotate;
[SerializeField] [Header("是否按照自身坐标系轴自动旋转")]
private bool isAutoRotatePivot;
[SerializeField][Header("自动旋转方向,例如(0,1,0)按照Y轴旋转")]
private Vector3 autoRotateDirection;
[SerializeField][Header("自动旋转速度")]
private float autoRotationSpeed = 5;
[SerializeField][Header("速度")]
private float speed=5f;
} }
void RotateModelContinuously()
{
if (!isAutoRotatePivot)
target.transform.Rotate(autoRotateDirection, autoRotationSpeed * Time.deltaTime * speed, Space.World);
else
{
var rotateEuler = autoRotateDirection * autoRotationSpeed * Time.deltaTime * speed;
// 根据模型当前朝向构造一个围绕轴旋转的四元数
Quaternion deltaRotation = Quaternion.Euler(rotateEuler);
// 将新的旋转应用到模型
target.transform.rotation *= deltaRotation;
}
}
void Drag()
{
if (Input.GetMouseButton(1))
{
//获取鼠标X轴移动量
x = x + Input.GetAxis("Mouse X") * rotSpeed;
//获取鼠标Y轴移动量
y = y - Input.GetAxis("Mouse Y") * rotSpeed;
//如果滚轮发生滚动
}
//根绝XY移动量计算旋转量
y = Mathf.Clamp(y, minYangle, maxYangle);
Quaternion rot = Quaternion.Euler(y, x, 0);
//根据计算的旋转量旋转计算机
transform.rotation = rot;
if (Input.GetAxis("Mouse ScrollWheel") != 0)
{
//根据滚轮的值计算距离
distance = distance - Input.GetAxis("Mouse ScrollWheel") * scrollSpeed;
}
//对距离进行区间运算,保证距离在最大和最小之间
distance = Mathf.Clamp(distance, distanceMin, distanceMax);
//根据距离值计算摄像机的位置
Vector3 pos = rot * new Vector3(0, 0, -distance) + target.position;
//更改摄像机位置为计算的值
transform.position = pos;
}
[SerializeField]
[Header("是否自动旋转")]
private bool isAutoRotate;
[SerializeField]
[Header("是否按照自身坐标系轴自动旋转")]
private bool isAutoRotatePivot;
[SerializeField]
[Header("自动旋转方向,例如(0,1,0)按照Y轴旋转")]
private Vector3 autoRotateDirection;
[SerializeField]
[Header("自动旋转速度")]
private float autoRotationSpeed = 5;
[SerializeField]
[Header("速度")]
private float speed = 5f;
}

File diff suppressed because it is too large Load Diff

View File

@ -107,14 +107,14 @@ namespace QFramework.Example
btns.Add(btn); btns.Add(btn);
btn.onClick.AddListener(() => btn.onClick.AddListener(() =>
{ {
subContent.SetActive(!subContent.activeSelf); //subContent.SetActive(!subContent.activeSelf);
if (op.freeStep) //if (op.freeStep)
{ //{
if (highIcon.color != highColor) // if (highIcon.color != highColor)
{ // {
TypeEventSystem.Global.Send<StepExecute>(new StepExecute() { index = int.Parse(btn.name) }); // TypeEventSystem.Global.Send<StepExecute>(new StepExecute() { index = int.Parse(btn.name) });
} // }
} //}
}); });
foreach (var sub in item.SubSteps) foreach (var sub in item.SubSteps)
{ {
@ -139,11 +139,11 @@ namespace QFramework.Example
btns.Add(subBtn); btns.Add(subBtn);
subBtn.onClick.AddListener(() => subBtn.onClick.AddListener(() =>
{ {
if (op.freeStep) //if (op.freeStep)
{ //{
subBtn.transform.parent.gameObject.SetActive(true); // subBtn.transform.parent.gameObject.SetActive(true);
TypeEventSystem.Global.Send<StepExecute>(new StepExecute() { index = int.Parse(subBtn.name) }); // TypeEventSystem.Global.Send<StepExecute>(new StepExecute() { index = int.Parse(subBtn.name) });
} //}
}); });
} }

View File

@ -1,21 +1,13 @@
<示例> <示例>
<!--顺序执行完毕--> <!--顺序执行完毕-->
<Action type="Sequence"> <Action type="Sequence">
<Action type="Log" value="进入初始状态"></Action> <Action type="Log" value="进入初始状态"></Action>
<Action type="Log" value="进入初始状态"></Action> <Action type="Log" value="进入初始状态"></Action>
</Action> </Action>
<!--同时执行完毕--> <!--同时执行完毕-->
<Action type="Parallel"> <Action type="Parallel">
<Action type="Log" value="1"></Action> <Action type="Log" value="1"></Action>
<Action type="Log" value="2"></Action> <Action type="Log" value="2"></Action>
</Action> </Action>
<!--只要任意满足就结束这个动作组--> <!--只要任意满足就结束这个动作组-->
<Action type="Any"></Action> <Action type="Any"></Action>