193 lines
6.6 KiB
C#
193 lines
6.6 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
//using ARWLSpace;
|
|
using DG.Tweening;
|
|
//using QFramework;
|
|
using Unity.VisualScripting;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class GetXiangQing : MonoBehaviour
|
|
{
|
|
public Button likeButton;
|
|
public GameObject uiElement;
|
|
public GameObject findGameObject;
|
|
public GameObject previousGameObject = null;
|
|
public bool isDown = false;
|
|
public bool isDown2 = false;
|
|
|
|
public Transform mainCameraTran;
|
|
|
|
private float doubleClickTime = 0.3f; // 双击的时间间隔
|
|
private float lastClickTime = 0f;
|
|
// 在类中添加状态变量
|
|
private bool isAnimating = false;
|
|
|
|
public ParticleSystem yanHuaParticleSystem;
|
|
void Start()
|
|
{
|
|
uiElement.SetActive(false);
|
|
sequence = DOTween.Sequence();
|
|
mainCameraTran = GameObject.Find("MyCamera").transform.GetChild(0);
|
|
}
|
|
//Renderer myRenderer;
|
|
Material material;
|
|
RaycastHit hit;
|
|
DG.Tweening.Sequence sequence;
|
|
private void Update()
|
|
{
|
|
doubleClick();
|
|
if (findGameObject != null)
|
|
{
|
|
uiElement.GetComponent<Image>().color = Color.red;
|
|
}
|
|
else
|
|
{
|
|
uiElement.GetComponent<Image>().color = Color.white;
|
|
}
|
|
Vector3 screenCenter = new Vector3(Screen.width / 2, Screen.height / 2, 0);
|
|
|
|
Ray ray = UnityEngine.Camera.main.ScreenPointToRay(screenCenter);
|
|
|
|
Debug.DrawRay(ray.origin, ray.direction * 1000, Color.red);
|
|
|
|
if (Physics.Raycast(ray, out hit))
|
|
{
|
|
findGameObject = hit.collider.gameObject;
|
|
}
|
|
else
|
|
{
|
|
// ChangeMaterial(findGameObject); // 红色
|
|
findGameObject = null;
|
|
}
|
|
|
|
previousGameObject = findGameObject;
|
|
}
|
|
|
|
public void doubleClick() // 检查双击
|
|
{
|
|
if (isAnimating) return; // 动画期间禁止新点击
|
|
|
|
if (Input.GetMouseButtonDown(0)) // 检测左键点击
|
|
{
|
|
//float currentTime = Time.time;
|
|
//if (currentTime - lastClickTime <= doubleClickTime)
|
|
//{
|
|
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); // 从鼠标位置发射射线
|
|
if (Physics.Raycast(ray, out hit)) // 检测射线碰撞
|
|
{
|
|
if (hit.collider.name != "Cube")
|
|
{
|
|
findGameObject = hit.collider.gameObject; // 设置被双击的物体
|
|
yanHuaParticleSystem.transform.position = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, 10f)); // 设置粒子系统位置为屏幕位置
|
|
yanHuaParticleSystem.Play();
|
|
OnDoubleClick(); // 调用双击方法
|
|
}
|
|
}
|
|
else
|
|
{
|
|
Debug.Log("射线检测失败");
|
|
}
|
|
//}
|
|
//lastClickTime = currentTime; // 更新上一次点击时间
|
|
}
|
|
}
|
|
private void OnDoubleClick()
|
|
{
|
|
// 在这里执行双击时的逻辑
|
|
Debug.Log("双击事件触发!"); // 示例:输出双击事件
|
|
OnPointerUp(); // 也可以调用OnPointerUp()方法
|
|
}
|
|
|
|
public void OnPointerDown()
|
|
{
|
|
//highlightUser.SetGameObject(findGameObject);
|
|
isDown = true;
|
|
uiElement.SetActive(true);
|
|
}
|
|
|
|
|
|
public void OnPointerUp()
|
|
{
|
|
// 如果已有动画运行则直接返回
|
|
if (isAnimating) return;
|
|
isDown = false;
|
|
|
|
uiElement.SetActive(false);
|
|
if (findGameObject.name == "ShuiDI")
|
|
{
|
|
//findGameObject.GetComponent<ShuiDiRen>().PlayAnim();
|
|
}
|
|
else
|
|
{
|
|
//findGameObject.transform.GetComponent<MyPlane>().rawImageKuang.gameObject.SetActive(false);
|
|
DG.Tweening.Sequence moveSequence = DOTween.Sequence();
|
|
Debug.Log("findGameObject" + findGameObject + "+" + findGameObject.transform);
|
|
|
|
// 添加动画开始标记
|
|
isAnimating = true;
|
|
|
|
moveSequence.OnStart(() =>
|
|
{
|
|
// 禁用所有点击
|
|
likeButton.interactable = false;
|
|
isAnimating = true;
|
|
})
|
|
.OnComplete(() =>
|
|
{
|
|
// 恢复点击
|
|
likeButton.interactable = true;
|
|
isAnimating = false;
|
|
});
|
|
if (findGameObject.transform.name.Contains("Big"))
|
|
{
|
|
//findGameObject.transform.localScale = new Vector3(3.5f, 1f, 4.6f); // 设置物体缩放比例为5:8
|
|
findGameObject.transform.GetComponent<MyPlane>().OnMoveInvisible();
|
|
// moveSequence.AppendInterval(0.5f); // 等待0.5秒
|
|
// moveSequence.Append(findGameObject.transform.DOMove(mainCameraTran.position, 0.5f).SetEase(Ease.InOutQuad));
|
|
// moveSequence.AppendCallback(() =>
|
|
// {
|
|
|
|
// findGameObject.transform.rotation = mainCameraTran.transform.rotation;
|
|
// findGameObject.transform.SetParent(mainCameraTran);
|
|
// findGameObject.transform.position = mainCameraTran.position;
|
|
|
|
// });
|
|
}
|
|
else
|
|
{
|
|
//findGameObject.transform.localScale = new Vector3(0.7f, 1f, 1.12f); // 设置物体缩放比例为5:8
|
|
findGameObject.transform.GetComponent<MyPlane>().OnMoveInvisible();
|
|
// moveSequence.AppendInterval(0.5f); // 等待0.5秒
|
|
// moveSequence.Append(findGameObject.transform.DOMove(mainCameraTran.parent.GetChild(1).position, 0.5f).SetEase(Ease.InOutQuad));
|
|
// moveSequence.AppendCallback(() =>
|
|
// {
|
|
// Vector3 originalScale = findGameObject.transform.lossyScale;
|
|
// Transform newParent = mainCameraTran.parent.GetChild(1);
|
|
// // 设置旋转和父物体
|
|
// Vector3 newRotation = newParent.transform.rotation.eulerAngles;
|
|
// findGameObject.transform.rotation = Quaternion.Euler(newRotation);
|
|
// findGameObject.transform.SetParent(newParent);
|
|
|
|
// findGameObject.transform.position = newParent.position;
|
|
// });
|
|
}
|
|
|
|
if (findGameObject.GetComponent<MyPlane>().isMP4)
|
|
{
|
|
findGameObject.GetComponent<MyPlane>().StartPlay();
|
|
}
|
|
}
|
|
}
|
|
public void OnPointerDown2()
|
|
{
|
|
isDown2 = true;
|
|
}
|
|
|
|
|
|
public void OnPointerUp2()
|
|
{
|
|
isDown2 = false;
|
|
}
|
|
}
|