修改了锅炉的ui
This commit is contained in:
parent
e48847f10d
commit
bc0da5d66b
File diff suppressed because it is too large
Load Diff
|
|
@ -5,15 +5,16 @@ using UnityEngine;
|
|||
public class GuoLuAnLi : MonoBehaviour
|
||||
{
|
||||
public GameObject ViewPage;
|
||||
public int MoiveNum;
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
ToOpenSelectMoive(1);
|
||||
ToOpenSelectMoive(MoiveNum);
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
GuoLuManager.Instance.ToEndVideo(1);
|
||||
GuoLuManager.Instance.ToEndVideo(MoiveNum);
|
||||
}
|
||||
|
||||
// Start is called before the first frame update
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ public class GuoLuBaoZhang : MonoBehaviour
|
|||
//是否开始爆发
|
||||
public bool IsStartBao = false;
|
||||
|
||||
private Animator animator;
|
||||
public Animator animator;
|
||||
private AnimationClip clip;
|
||||
|
||||
[Header("UI 控制")]
|
||||
|
|
@ -30,6 +30,44 @@ public class GuoLuBaoZhang : MonoBehaviour
|
|||
[Header("Canvas 管理")]
|
||||
public GameObject[] AllCanvas;
|
||||
|
||||
public bool IsCanMove = false;
|
||||
[Header("旋转设置")]
|
||||
[Tooltip("旋转灵敏度")]
|
||||
public float rotationSensitivityX = 3f;
|
||||
public float rotationSensitivityY = 3f;
|
||||
[Tooltip("垂直旋转限制 - 最小角度")]
|
||||
public float minVerticalAngle = -60f;
|
||||
[Tooltip("垂直旋转限制 - 最大角度")]
|
||||
public float maxVerticalAngle = 60f;
|
||||
[Tooltip("旋转平滑度")]
|
||||
public float rotationSmoothness = 10f;
|
||||
|
||||
[Header("缩放设置")]
|
||||
[Tooltip("缩放灵敏度")]
|
||||
public float scaleSensitivity = 0.1f;
|
||||
[Tooltip("最小缩放比例")]
|
||||
public Vector3 minScale = new Vector3(0.5f, 0.5f, 0.5f);
|
||||
[Tooltip("最大缩放比例")]
|
||||
public Vector3 maxScale = new Vector3(3f, 3f, 3f);
|
||||
[Tooltip("缩放平滑度")]
|
||||
public float scaleSmoothness = 10f;
|
||||
|
||||
[Tooltip("重置动画的平滑度")]
|
||||
public float resetSmoothness = 15f;
|
||||
|
||||
// 初始状态变量
|
||||
private Vector3 initialPosition;
|
||||
private Quaternion initialRotation;
|
||||
private Vector3 initialScale;
|
||||
|
||||
// 当前目标状态变量
|
||||
private Vector3 targetScale;
|
||||
private float currentXRotation;
|
||||
private float currentYRotation;
|
||||
private float targetXRotation;
|
||||
private float targetYRotation;
|
||||
private Vector3 targetPosition;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
Instance = this;
|
||||
|
|
@ -45,10 +83,24 @@ public class GuoLuBaoZhang : MonoBehaviour
|
|||
void Start()
|
||||
{
|
||||
// 获取Animator组件(确保挂载在目标物体上)
|
||||
animator = GetComponent<Animator>();
|
||||
//animator = GetComponent<Animator>();
|
||||
clip = GetCurrentAnimationClip(animator);
|
||||
|
||||
animator.speed = 0;
|
||||
|
||||
// 保存初始状态
|
||||
initialPosition = transform.localPosition;
|
||||
initialRotation = transform.localRotation;
|
||||
initialScale = transform.localScale;
|
||||
|
||||
// 初始化当前状态为初始状态
|
||||
targetPosition = initialPosition;
|
||||
|
||||
Vector3 initialRotationAngles = initialRotation.eulerAngles;
|
||||
currentXRotation = targetXRotation = initialRotationAngles.y;
|
||||
currentYRotation = targetYRotation = initialRotationAngles.x;
|
||||
|
||||
targetScale = initialScale;
|
||||
}
|
||||
|
||||
private void Update()
|
||||
|
|
@ -106,6 +158,116 @@ public class GuoLuBaoZhang : MonoBehaviour
|
|||
}
|
||||
}
|
||||
|
||||
void LateUpdate()
|
||||
{
|
||||
// 处理旋转和缩放输入
|
||||
if (IsCanMove) // 重置时忽略其他输入
|
||||
{
|
||||
HandleRotationInput();
|
||||
HandleScaleInput();
|
||||
}
|
||||
|
||||
|
||||
// 应用平滑变换
|
||||
ApplySmoothRotation();
|
||||
ApplySmoothScaling();
|
||||
ApplySmoothPosition();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 重置物体到初始状态(位置、旋转、缩放)
|
||||
/// </summary>
|
||||
public void ResetToInitialState()
|
||||
{
|
||||
// 设置目标状态为初始状态
|
||||
targetPosition = initialPosition;
|
||||
targetScale = initialScale;
|
||||
|
||||
Vector3 initialRotationAngles = initialRotation.eulerAngles;
|
||||
targetXRotation = initialRotationAngles.y;
|
||||
targetYRotation = initialRotationAngles.x;
|
||||
}
|
||||
|
||||
void HandleRotationInput()
|
||||
{
|
||||
// 当按住指定的鼠标按钮时处理旋转
|
||||
if (Input.GetMouseButton(1))
|
||||
{
|
||||
float mouseX = Input.GetAxis("Mouse X") * rotationSensitivityX;
|
||||
float mouseY = Input.GetAxis("Mouse Y") * rotationSensitivityY;
|
||||
|
||||
targetXRotation += mouseX;
|
||||
targetYRotation -= mouseY;
|
||||
|
||||
// 限制垂直旋转角度
|
||||
targetYRotation = Mathf.Clamp(targetYRotation, minVerticalAngle, maxVerticalAngle);
|
||||
}
|
||||
}
|
||||
|
||||
void HandleScaleInput()
|
||||
{
|
||||
//if (useMouseWheelForScale)
|
||||
//{
|
||||
float scrollInput = Input.GetAxis("Mouse ScrollWheel");
|
||||
if (scrollInput != 0)
|
||||
{
|
||||
Vector3 scaleChange = Vector3.one * (scrollInput > 0 ? 1 : -1) * scaleSensitivity;
|
||||
Vector3 newScale = targetScale + scaleChange;
|
||||
|
||||
targetScale = new Vector3(
|
||||
Mathf.Clamp(newScale.x, minScale.x, maxScale.x),
|
||||
Mathf.Clamp(newScale.y, minScale.y, maxScale.y),
|
||||
Mathf.Clamp(newScale.z, minScale.z, maxScale.z)
|
||||
);
|
||||
}
|
||||
//}
|
||||
//else
|
||||
//{
|
||||
// // 备选方案:使用左右键同时按下缩放(如果不使用滚轮)
|
||||
// if (Input.GetMouseButton(0) && Input.GetMouseButton(1))
|
||||
// {
|
||||
// float mouseY = Input.GetAxis("Mouse Y") * scaleSensitivity;
|
||||
// Vector3 newScale = targetScale + Vector3.one * (mouseY > 0 ? 1 : -1) * scaleSensitivity;
|
||||
|
||||
// targetScale = new Vector3(
|
||||
// Mathf.Clamp(newScale.x, minScale.x, maxScale.x),
|
||||
// Mathf.Clamp(newScale.y, minScale.y, maxScale.y),
|
||||
// Mathf.Clamp(newScale.z, minScale.z, maxScale.z)
|
||||
// );
|
||||
// }
|
||||
//}
|
||||
}
|
||||
|
||||
void ApplySmoothRotation()
|
||||
{
|
||||
currentXRotation = Mathf.Lerp(currentXRotation, targetXRotation,
|
||||
rotationSmoothness * Time.deltaTime);
|
||||
currentYRotation = Mathf.Lerp(currentYRotation, targetYRotation,
|
||||
rotationSmoothness * Time.deltaTime);
|
||||
|
||||
transform.rotation = Quaternion.Euler(currentYRotation, currentXRotation, 0);
|
||||
}
|
||||
|
||||
void ApplySmoothScaling()
|
||||
{
|
||||
transform.localScale = Vector3.Lerp(
|
||||
transform.localScale,
|
||||
targetScale,
|
||||
scaleSmoothness * Time.deltaTime
|
||||
);
|
||||
}
|
||||
|
||||
void ApplySmoothPosition()
|
||||
{
|
||||
// 处理位置平滑过渡(主要用于重置时)
|
||||
transform.localPosition = Vector3.Lerp(
|
||||
transform.localPosition,
|
||||
targetPosition,
|
||||
resetSmoothness * Time.deltaTime
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 动画开始正常播放
|
||||
/// </summary>
|
||||
|
|
@ -200,9 +362,9 @@ public class GuoLuBaoZhang : MonoBehaviour
|
|||
// 上下浮动动画
|
||||
Vector3 pos = CanvasObj.transform.position;
|
||||
if (shouldShow)
|
||||
CanvasObj.transform.position = new Vector3(pos.x, pos.y + 0.5f, pos.z);
|
||||
CanvasObj.transform.position = new Vector3(pos.x, pos.y + 0.8f, pos.z);
|
||||
else
|
||||
CanvasObj.transform.position = new Vector3(pos.x, pos.y - 0.5f, pos.z);
|
||||
CanvasObj.transform.position = new Vector3(pos.x, pos.y - 0.8f, pos.z);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,27 +9,19 @@ public class GuoLuGongNeng : MonoBehaviour
|
|||
/// 功能页面
|
||||
/// </summary>
|
||||
|
||||
[Header("页面")]
|
||||
public GameObject[] Pages;
|
||||
|
||||
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
//动画结束
|
||||
GuoLuBaoZhang.Instance.EndPlayAnim();
|
||||
|
||||
for (int i = 0; i < Pages.Length; i++) {
|
||||
Pages[i].gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
Pages[0].SetActive(true);
|
||||
|
||||
//锅炉开始爆炸
|
||||
GuoLuBaoZhang.Instance.StartPlayAnim();
|
||||
GuoLuBaoZhang.Instance.IsCanMove = true;
|
||||
MultiSubCanvasClickHandler.Instance.IsUse=true;
|
||||
}
|
||||
|
||||
// Start is called before the first frame update
|
||||
|
|
@ -38,14 +30,14 @@ public class GuoLuGongNeng : MonoBehaviour
|
|||
|
||||
}
|
||||
|
||||
public void SwitchPage(int pageNum)
|
||||
public void EndPage()
|
||||
{
|
||||
Pages[pageNum].SetActive(true);
|
||||
Pages[1 - pageNum].SetActive(false);
|
||||
//动画结束
|
||||
GuoLuBaoZhang.Instance.EndPlayAnim();
|
||||
GuoLuBaoZhang.Instance.IsCanMove = false;
|
||||
|
||||
if (pageNum == 0)
|
||||
{
|
||||
GuoLuManager.Instance.ToEndVideo(0);
|
||||
}
|
||||
//位置旋转还原
|
||||
GuoLuBaoZhang.Instance.ResetToInitialState();
|
||||
MultiSubCanvasClickHandler.Instance.IsUse = false;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,59 @@
|
|||
using DG.Tweening;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class GuoLuHowMsgs : MonoBehaviour
|
||||
{
|
||||
public static GuoLuHowMsgs Instance;
|
||||
|
||||
//ËùÓÐÎï¼þ½éÉÜ
|
||||
public Transform[] AllCoreMsgs;
|
||||
public List<string> CoreNames;
|
||||
private int m_nowShowNum = 0;
|
||||
|
||||
public Vector3 ShowPos;
|
||||
public Vector3 YinPos;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
Instance = this;
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
CoreNames = new List<string>();
|
||||
|
||||
for (int i = 0; i < AllCoreMsgs.Length; i++)
|
||||
{
|
||||
CoreNames.Add(AllCoreMsgs[i].name);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void ShowCoreMsg(string name)
|
||||
{
|
||||
|
||||
if (CoreNames.Contains(name))
|
||||
{
|
||||
int num = CoreNames.IndexOf(name);
|
||||
if (m_nowShowNum != num)
|
||||
{
|
||||
if (m_nowShowNum > -1)
|
||||
{
|
||||
AllCoreMsgs[m_nowShowNum].localPosition=YinPos;
|
||||
}
|
||||
|
||||
m_nowShowNum = num;
|
||||
}
|
||||
AllCoreMsgs[num].localPosition = ShowPos;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
//if (m_nowShowNum > -1)
|
||||
// AllCoreMsgs[m_nowShowNum].DOLocalMove(YinPos, 2f);
|
||||
//m_nowShowNum = -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 3b6a755e8a06dbd43b62e27e29f1bf97
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -0,0 +1,49 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
/// <summary>
|
||||
/// 模拟操作
|
||||
/// 1,材质替换
|
||||
/// 2,粒子控制
|
||||
/// </summary>
|
||||
public class GuoLuMoLi : MonoBehaviour
|
||||
{
|
||||
[Tooltip("烟雾物体")]
|
||||
public MeshRenderer YanRender;
|
||||
public Material[] Materials;
|
||||
[Tooltip("喷火粒子")]
|
||||
public ParticleSystem HuoParticle;
|
||||
|
||||
private Material m_yanMat;
|
||||
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
m_yanMat = YanRender.material;
|
||||
}
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
HuoParticle.Stop();
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void StartToChange()
|
||||
{
|
||||
YanRender.material = Materials[1];
|
||||
HuoParticle.Play();
|
||||
}
|
||||
|
||||
public void EndToChange()
|
||||
{
|
||||
YanRender.material = Materials[0];
|
||||
HuoParticle.Stop();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 10e8dc049ac141e439a205721cb8c0f9
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -4,74 +4,84 @@ using UnityEngine.UI;
|
|||
|
||||
public class MultiSubCanvasClickHandler : MonoBehaviour
|
||||
{
|
||||
public static MultiSubCanvasClickHandler Instance;
|
||||
|
||||
public Camera targetCamera; // 目标相机,用于发射射线
|
||||
public RawImage rawImage; // 需要判断点击位置的 RawImage
|
||||
public float maxRaycastDistance = 100f; // 射线最大检测距离
|
||||
public bool IsUse=false;
|
||||
|
||||
public string[] AllCoreName;
|
||||
private void Awake()
|
||||
{
|
||||
Instance = this;
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
// 检测鼠标左键按下事件
|
||||
if (Input.GetMouseButtonDown(0))
|
||||
if(IsUse)
|
||||
{
|
||||
// 获取鼠标点击位置
|
||||
Vector2 mousePosition = Input.mousePosition;
|
||||
|
||||
// 将鼠标点击位置转换为 RawImage 的局部坐标
|
||||
RectTransformUtility.ScreenPointToLocalPointInRectangle(
|
||||
rawImage.rectTransform,
|
||||
mousePosition,
|
||||
null,
|
||||
out Vector2 localPoint//返回的局部坐标
|
||||
);
|
||||
|
||||
// 将局部坐标转换为归一化坐标,通过RawImage的长宽比
|
||||
Rect rect = rawImage.rectTransform.rect;
|
||||
float normalizedX = (localPoint.x - rect.x) / rect.width;
|
||||
float normalizedY = (localPoint.y - rect.y) / rect.height;
|
||||
|
||||
// 打印归一化坐标
|
||||
Debug.Log($"Click Position: ({normalizedX}, {normalizedY})");
|
||||
|
||||
// 判断点击位置是否在 RawImage 范围内
|
||||
if (normalizedX >= 0 && normalizedX <= 1 && normalizedY >= 0 && normalizedY <= 1)
|
||||
// 检测鼠标左键按下事件
|
||||
if (Input.GetMouseButtonDown(0))
|
||||
{
|
||||
Debug.Log("Click is within RawImage bounds.");
|
||||
// 获取鼠标点击位置
|
||||
Vector2 mousePosition = Input.mousePosition;
|
||||
|
||||
// 将归一化坐标转换为目标相机画面的屏幕坐标
|
||||
Vector3 screenPoint = new Vector3(
|
||||
normalizedX * targetCamera.pixelWidth,
|
||||
normalizedY * targetCamera.pixelHeight,
|
||||
targetCamera.nearClipPlane
|
||||
// 将鼠标点击位置转换为 RawImage 的局部坐标
|
||||
RectTransformUtility.ScreenPointToLocalPointInRectangle(
|
||||
rawImage.rectTransform,
|
||||
mousePosition,
|
||||
null,
|
||||
out Vector2 localPoint//返回的局部坐标
|
||||
);
|
||||
|
||||
// 从目标相机发射射线
|
||||
Ray ray = targetCamera.ScreenPointToRay(screenPoint);
|
||||
RaycastHit hit;
|
||||
// 将局部坐标转换为归一化坐标,通过RawImage的长宽比
|
||||
Rect rect = rawImage.rectTransform.rect;
|
||||
float normalizedX = (localPoint.x - rect.x) / rect.width;
|
||||
float normalizedY = (localPoint.y - rect.y) / rect.height;
|
||||
|
||||
// 绘制射线,无论是否击中物体
|
||||
if (Physics.Raycast(ray, out hit, maxRaycastDistance))
|
||||
// 打印归一化坐标
|
||||
//Debug.Log($"Click Position: ({normalizedX}, {normalizedY})");
|
||||
|
||||
// 判断点击位置是否在 RawImage 范围内
|
||||
if (normalizedX >= 0 && normalizedX <= 1 && normalizedY >= 0 && normalizedY <= 1)
|
||||
{
|
||||
// 如果射线打中了某个物体
|
||||
Debug.Log("Hit: " + hit.transform.gameObject.name);
|
||||
//Debug.Log("Click is within RawImage bounds.");
|
||||
|
||||
GuoLuShowCoreMsg.Instance.ShowCoreMsg(hit.transform.gameObject.name);
|
||||
// 将归一化坐标转换为目标相机画面的屏幕坐标
|
||||
Vector3 screenPoint = new Vector3(
|
||||
normalizedX * targetCamera.pixelWidth,
|
||||
normalizedY * targetCamera.pixelHeight,
|
||||
targetCamera.nearClipPlane
|
||||
);
|
||||
|
||||
// 从目标相机发射射线
|
||||
Ray ray = targetCamera.ScreenPointToRay(screenPoint);
|
||||
RaycastHit hit;
|
||||
|
||||
// 绘制射线,无论是否击中物体
|
||||
if (Physics.Raycast(ray, out hit, maxRaycastDistance))
|
||||
{
|
||||
// 如果射线打中了某个物体
|
||||
//Debug.Log("Hit: " + hit.transform.gameObject.name);
|
||||
|
||||
GuoLuHowMsgs.Instance.ShowCoreMsg(hit.transform.gameObject.name);
|
||||
|
||||
// 绘制射线到击中点
|
||||
//Debug.DrawRay(ray.origin, ray.direction * hit.distance, Color.red, 5);
|
||||
}
|
||||
else
|
||||
{
|
||||
// 如果射线没有击中任何物体,绘制射线到最大距离
|
||||
//Debug.Log("Hit: Nothing");
|
||||
|
||||
//GuoLuHowMsgs.Instance.ShowCoreMsg("Nothing");
|
||||
// 绘制射线到最大距离
|
||||
//Debug.DrawRay(ray.origin, ray.direction * maxRaycastDistance, Color.red, 5);
|
||||
}
|
||||
|
||||
// 绘制射线到击中点
|
||||
//Debug.DrawRay(ray.origin, ray.direction * hit.distance, Color.red, 5);
|
||||
}
|
||||
else
|
||||
{
|
||||
// 如果射线没有击中任何物体,绘制射线到最大距离
|
||||
Debug.Log("Hit: Nothing");
|
||||
|
||||
GuoLuShowCoreMsg.Instance.ShowCoreMsg("Nothing");
|
||||
// 绘制射线到最大距离
|
||||
//Debug.DrawRay(ray.origin, ray.direction * maxRaycastDistance, Color.red, 5);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue