12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- using EPOOutline;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.EventSystems;
- public class CameraRayCastManager : MonoSingleton<CameraRayCastManager>
- {
- //活跃状态检测物体
- public static int RayCastActivelayer = 25;
- private Camera mainCamera;
- public RayCastItem currentRayCastItem;
- private void Awake()
- {
- Camera[] camera = FindObjectsOfType<Camera>();
- for (int i = 0; i < camera.Length; i++)
- {
- if (camera[i].isActiveAndEnabled && camera[i].tag == "MainCamera")
- {
- mainCamera = camera[i];
- break;
- }
- }
- if (mainCamera == null) Debug.LogError("未查找到主摄像机");
- }
- private void Update()
- {
- if (mainCamera == null) return;
- //if (EventSystem.current.IsPointerOverGameObject()) return;
- RaycastHit hit;
- //活跃状态RaycastItem检测
- if (Physics.Raycast(mainCamera.ScreenPointToRay(Input.mousePosition), out hit, 50, 1 << RayCastActivelayer))
- {
- CheckRayCastItem(hit);
- }
- //非活跃状态检测
- else if (Physics.Raycast(mainCamera.ScreenPointToRay(Input.mousePosition), out hit, 50))
- {
- CheckRayCastItem(hit);
- }
- else if (currentRayCastItem)
- {
- currentRayCastItem.CloseHighlighter();
- currentRayCastItem = null;
- }
- }
- private void CheckRayCastItem(RaycastHit hit)
- {
- if (hit.collider.GetComponentInParent<RayCastItem>() != null)
- {
- if (currentRayCastItem)
- {
- currentRayCastItem.CloseHighlighter();
- }
- currentRayCastItem = hit.collider.GetComponentInParent<RayCastItem>();
- currentRayCastItem.InitRayCastParents();
- //考核模式关闭划过高亮
- if (OperateSetting.Instance.m_CurrentOperationMode == OperationMode.Exam)
- {
- return;
- }
- currentRayCastItem.OpenHighlighter(OutLineType.hover);
- }
- else if (currentRayCastItem)
- { //考核模式关闭划过高亮
- if (OperateSetting.Instance.m_CurrentOperationMode == OperationMode.Exam)
- {
- currentRayCastItem = null;
- return;
- }
- currentRayCastItem.CloseHighlighter();
- currentRayCastItem = null;
- }
- }
- public bool CheckCurrentHoverItem(RayCastItem item)
- {
- if (currentRayCastItem == null)
- return false;
- else
- return currentRayCastItem.Contains(item);
- }
- }
|