194 lines
4.7 KiB
C#
Raw Normal View History

2025-02-12 17:36:00 +08:00
using QFramework;
using QFramework.Example;
using System;
using System.Collections;
using System.Collections.Generic;
2025-02-13 11:02:16 +08:00
using System.Drawing;
2025-02-12 17:36:00 +08:00
using UnityEngine;
using UnityEngine.EventSystems;
using XMLTool;
using static UnityEditor.Progress;
2025-02-13 11:02:16 +08:00
using static XMLTool.Body3D;
2025-02-12 17:36:00 +08:00
public class Body3DController : MonoSingleton<Body3DController>
{
Body3DController() { }
Dictionary<GameObject, Body3DOjbItem> objs = new Dictionary<GameObject, Body3DOjbItem>();
bool selectIsGroup = false;
public List<GameObject> isOnList = new List<GameObject>();
2025-02-13 11:02:16 +08:00
public bool allowDrag = false;
2025-02-12 17:36:00 +08:00
public override void OnSingletonInit()
{
base.OnSingletonInit();
TypeEventSystem.Global.Register<OnBody3DStart>((arg) =>
{
Refresh();
}).UnRegisterWhenGameObjectDestroyed(gameObject);
TypeEventSystem.Global.Register<OnModuleQuit>(OnClear);
TypeEventSystem.Global.Register<OnBody3DGroupTypeChanged>(OnToggleSelectType);
TypeEventSystem.Global.Register<OnBody3DSelected>(OnBody3DSelectedHandler);
}
private void OnBody3DSelectedHandler(OnBody3DSelected selected)
{
if (selected.isOn)
{
if (isOnList.Contains(selected.obj) == false)
{
if (selectIsGroup == false)
{
ClearObjectToggle();
}
isOnList.Add(selected.obj);
2025-02-13 11:02:16 +08:00
UI3DBodyInfoData data = new UI3DBodyInfoData();
data.body = selected.obj.GetComponent<Body3DOjbItem>().body;
UIKit.OpenPanelAsync<UI3DBodyInfo>(UILevel.PopUI, data).ToAction().Start(this);
2025-02-12 17:36:00 +08:00
}
}
else
{
if (isOnList.Contains(selected.obj))
{
isOnList.Remove(selected.obj);
selected.obj.GetComponent<ObjectToggle>().Set(false);
}
2025-02-13 11:02:16 +08:00
if (isOnList.Count <= 0)
{
UIKit.HidePanel<UI3DBodyInfo>();
}
2025-02-12 17:36:00 +08:00
}
}
2025-02-13 11:02:16 +08:00
public void Active(bool isActive)
{
foreach (var item in objs)
{
if (isOnList.Contains(item.Key) == false)
{
item.Key.SetActive(isActive);
}
}
}
2025-02-12 17:36:00 +08:00
public void Active(GameObject obj, bool isActive, bool isOther)
{
if (isOther)
{
foreach (var item in objs)
{
if (item.Key != obj)
{
2025-02-13 11:02:16 +08:00
item.Key.SetActive(isActive);
2025-02-12 17:36:00 +08:00
}
}
}
else
{
obj.SetActive(isActive);
}
}
public void Transparent(GameObject obj, bool isTransparent, bool isOther)
{
if (isOther)
{
foreach (var item in objs)
{
if (item.Key != obj)
{
Utility.SetSurfaceType(item.Key.GetComponent<MeshRenderer>().material, isTransparent);
}
}
}
else
{
Utility.SetSurfaceType(obj.GetComponent<MeshRenderer>().material, isTransparent);
}
}
private void OnToggleSelectType(OnBody3DGroupTypeChanged type)
{
selectIsGroup = type.isGroup;
}
private void OnClear(OnModuleQuit quit)
{
Clear();
}
public void Refresh()
{
Parser(Global.Instance.cur3DPart);
}
public void Parser(Body3D.Body body)
{
2025-02-13 11:02:16 +08:00
if (body.subBody != null && body.subBody.Count > 0)
2025-02-12 17:36:00 +08:00
{
foreach (var item in body.subBody)
{
Parser(item.Value);
}
}
2025-02-13 11:02:16 +08:00
else
{
GameObject obj = Utility.FindObj(body.Path);
var bodyObjItem = obj.GetOrAddComponent<Body3DOjbItem>();
bodyObjItem.Init(body);
objs.Add(obj, bodyObjItem);
}
2025-02-12 17:36:00 +08:00
}
private void Update()
{
if (Input.GetMouseButtonDown(0) && EventSystem.current.IsPointerOverGameObject() == false)
{
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD>ߵ<EFBFBD><DFB5><EFBFBD>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD>λ<EFBFBD><CEBB>
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
if (Physics.Raycast(ray, out hit))
{
GameObject obj = hit.collider.gameObject;
}
else
{
if (selectIsGroup == false)
{
ClearObjectToggle();
}
}
}
}
public void ClearObjectToggle()
{
for (int i = isOnList.Count - (1); i >= 0; i--)
{
isOnList[i].GetComponent<ObjectToggle>().Set(false);
}
}
public void Clear()
{
objs.Clear();
}
}