[정영민] 공통 기능 스크립트 정리 작업
26.01.20 천일 공장 최적화 진행 중인 프로젝트에서 공통 기능 스크립트 정리 후 데이터 업로드
This commit is contained in:
105
Assets/Scripts/Manager/MachineClickManager.cs
Normal file
105
Assets/Scripts/Manager/MachineClickManager.cs
Normal file
@@ -0,0 +1,105 @@
|
||||
using UnityEngine;
|
||||
using WI;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace CHN
|
||||
{
|
||||
public class MachineClickManager : MonoBehaviour, ISingle
|
||||
{
|
||||
OrbitalController controller;
|
||||
public List<Machine> machines = new List<Machine>();
|
||||
public Machine currentClickMachine;
|
||||
|
||||
RaycastHit[] hitInfo = new RaycastHit[16];
|
||||
|
||||
RaycastHit hit;
|
||||
|
||||
public event Action<Machine> onLeftClickMachine;
|
||||
public event Action onLeftClickArea;
|
||||
|
||||
public LayerMask floorLayers;
|
||||
public int hitFloorIndex;
|
||||
|
||||
public override void AfterAwake()
|
||||
{
|
||||
controller = FindSingle<OrbitalController>();
|
||||
}
|
||||
public override void AfterStart()
|
||||
{
|
||||
var building = FindSingle<Building>();
|
||||
machines = building.floors.SelectMany(f => f.machines).ToList();
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
RaycastOnClickArea();
|
||||
RaycastOnClickMachine();
|
||||
}
|
||||
|
||||
private void RaycastOnClickMachine()
|
||||
{
|
||||
var floorMachines = FindSingle<Building>().currentFloor.machines;
|
||||
|
||||
bool leftClick = Input.GetMouseButtonDown(0);
|
||||
|
||||
if (!leftClick)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (controller.IsClickUI)
|
||||
return;
|
||||
|
||||
LayerMask exceptionLayer = LayerMask.GetMask("Floor", "Floor Ground");
|
||||
LayerMask layerMask = floorLayers & ~exceptionLayer;
|
||||
|
||||
Ray ray = controller.camera.ScreenPointToRay(Input.mousePosition);
|
||||
hitInfo = Physics.RaycastAll(ray, Mathf.Infinity, layerMask);
|
||||
|
||||
if (hitInfo.Length == 0)
|
||||
return;
|
||||
|
||||
Array.Sort(hitInfo, (hit1, hit2) => hit1.distance.CompareTo(hit2.distance));
|
||||
var hitColider = hitInfo[0].collider;
|
||||
|
||||
hitColider.TryGetComponent<Machine>(out var machine);
|
||||
|
||||
foreach (var floorMachine in floorMachines)
|
||||
{
|
||||
if(floorMachine == machine)
|
||||
{
|
||||
if (leftClick)
|
||||
{
|
||||
onLeftClickMachine?.Invoke(machine);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void RaycastOnClickArea()
|
||||
{
|
||||
bool leftClick = Input.GetMouseButtonDown(0);
|
||||
|
||||
if (controller.IsClickUI)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
LayerMask exceptionLayer = LayerMask.GetMask("Machine");
|
||||
LayerMask layerMask = floorLayers & ~exceptionLayer;
|
||||
|
||||
var ray = controller.camera.ScreenPointToRay(Input.mousePosition);
|
||||
hitInfo = Physics.RaycastAll(ray, Mathf.Infinity, layerMask);
|
||||
|
||||
if (hitInfo.Length == 0)
|
||||
return;
|
||||
|
||||
if (leftClick)
|
||||
{
|
||||
onLeftClickArea?.Invoke();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user