You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

89 lines
2.4 KiB

using System;
using System.Collections;
using System.Collections.Generic;
using DG.Tweening;
using UnityEngine;
using UnityEngine.EventSystems;
/// <summary>
/// 交互的ui
/// </summary>
public class InteractiveUI : MonoBehaviour, IBeginDragHandler, IDragHandler, IEndDragHandler, IPointerDownHandler,
IPointerUpHandler
{
public Progress progress;
private Vector3 birthPos;
private float distance;
private RaycastHit[] rayInfos;
private void Awake()
{
birthPos = transform.GetComponent<RectTransform>().localPosition;
}
public void OnBeginDrag(PointerEventData eventData)
{
distance = Camera.main.GetComponent<GetCameraDistance>().GetDistance(transform);
}
public void OnDrag(PointerEventData eventData)
{
transform.position = Input.mousePosition;
InteractJudge();
}
public void OnEndDrag(PointerEventData eventData)
{
}
public void OnSelect(BaseEventData eventData)
{
}
public void OnPointerDown(PointerEventData eventData)
{
GameStageManager.Instance.currentStage = GameStage.;
transform.DOScale(Vector3.one * 1.3f, 0.2f);
}
public void OnPointerUp(PointerEventData eventData)
{
EffectManager.Instance.DisableInteractEffect();
GameStageManager.Instance.currentStage = GameStage.;
Invoke("Return",0.5f);
transform.DOLocalMove(birthPos, 0.4f);
}
void Return()
{
transform.DOScale(Vector3.one, 0.2f);
}
/// <summary>
/// 交互判断
/// </summary>
void InteractJudge()
{
Vector3 screenMouse = new Vector3(Input.mousePosition.x, Input.mousePosition.y, distance);
Vector3 worldPos = Camera.main.ScreenToWorldPoint(screenMouse);
Ray ray = new Ray(Camera.main.transform.position, Camera.main.transform.position - worldPos);
Debug.DrawRay(Camera.main.transform.position,Camera.main.transform.position - worldPos,Color.cyan);
rayInfos = Physics.RaycastAll(ray);
if (rayInfos != null && rayInfos.Length != 0)
{
foreach (var rayinfo in rayInfos)
{
if (rayinfo.collider.tag == "Action")
{
rayinfo.collider.gameObject.GetComponent<ProgressInstance>().StartInteractEffect(progress);
return;
}
}
}
EffectManager.Instance.DisableInteractEffect();
}
}