VirtualFramework/Assets/Scripts/Item/Body3DOjbItem.cs

68 lines
1.9 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;
using UnityEngine;
using XMLTool;
public class Body3DOjbItem : MonoBehaviour
{
2025-02-13 11:02:16 +08:00
public Body3D.Body body;
2025-02-12 17:36:00 +08:00
2025-02-13 11:02:16 +08:00
ObjectToggle objToggle;
ObjDrag objDrag;
private void Awake()
2025-02-12 17:36:00 +08:00
{
}
public void Init(Body3D.Body body)
{
this.body = body;
if (body.subBody == null || body.subBody.Count == 0)
{
if (body.toggle != null)
{
2025-02-13 11:02:16 +08:00
objToggle = gameObject.GetOrAddComponent<ObjectToggle>();
2025-02-12 17:36:00 +08:00
ObjectColorToggle colorToggle = null;
if (body.toggle.color != null)
{
colorToggle = gameObject.GetOrAddComponent<ObjectColorToggle>();
colorToggle.Init(Utility.ToColor(body.toggle.color.isOn), Utility.ToColor(body.toggle.color.isOff));
}
objToggle.OnValueChanged.AddListener(isOn =>
{
colorToggle?.SetColor(isOn);
2025-02-13 11:02:16 +08:00
objDrag = gameObject.GetOrAddComponent<ObjDrag>();
RefreshDrag();
TypeEventSystem.Global.Send<OnBody3DSelected>(new OnBody3DSelected() { isOn = isOn, obj = gameObject });
2025-02-12 17:36:00 +08:00
if (isOn)
{
2025-02-13 11:02:16 +08:00
TypeEventSystem.Global.Register<OnBody3DDragChanged>(OnBody3DDragHandler);
}
else
{
TypeEventSystem.Global.UnRegister<OnBody3DDragChanged>(OnBody3DDragHandler);
2025-02-12 17:36:00 +08:00
}
});
}
}
}
2025-02-13 11:02:16 +08:00
private void OnBody3DDragHandler(OnBody3DDragChanged drag)
{
RefreshDrag();
}
2025-02-12 17:36:00 +08:00
2025-02-13 11:02:16 +08:00
public void RefreshDrag()
{
if (objToggle != null && objDrag != null)
{
objDrag.isOn = objToggle.isOn && Body3DController.Instance.allowDrag;
}
}
2025-02-12 17:36:00 +08:00
}