VirtualFramework/Assets/Scripts/UI/UIBody3DInfo.cs
2025-05-21 10:31:52 +08:00

214 lines
6.4 KiB
C#

using UnityEngine;
using UnityEngine.UI;
using QFramework;
using XMLTool;
using DG.Tweening;
using TMPro;
using System;
namespace QFramework.Example
{
public class UIBody3DInfoData : UIPanelData
{
public Body3D.Body body;
}
public partial class UIBody3DInfo : UIPanel
{
GameObject obj;
ResLoader loader;
protected override void OnInit(IUIData uiData = null)
{
AudioKit.Settings.VoiceVolume.Value = 1;
TypeEventSystem.Global.Register<OnModuleQuit>(OnModuleQuithandler).UnRegisterWhenGameObjectDestroyed(this);
loader = ResLoader.Allocate();
Group.onValueChanged.AddListener(isOn =>
{
var text = Group.transform.Find("Label").GetComponent<TextMeshProUGUI>();
TypeEventSystem.Global.Send<OnBody3DGroupTypeChanged>(new OnBody3DGroupTypeChanged() { isGroup = isOn });
if (isOn)
{
text.color = Color.white;
text.text = "¶àÑ¡";
}
else
{
text.color = new Color(1f / 255f, 103f / 255f, 206f / 255f);
text.text = "µ¥Ñ¡";
}
});
Transparent.onValueChanged.AddListener(isOn =>
{
if (isOn)
{
Transparent.transform.Find("Label").GetComponent<TextMeshProUGUI>().text = "ʵÌå";
}
else
{
Transparent.transform.Find("Label").GetComponent<TextMeshProUGUI>().text = "͸Ã÷";
}
Utility.SetSurfaceType(obj.GetComponent<MeshRenderer>().material, isOn);
});
Single.onValueChanged.AddListener((isOn) =>
{
Body3DController.Instance.Active(!isOn);
});
TransparentOther.onValueChanged.AddListener(isOn =>
{
if (isOn)
{
TransparentOther.transform.Find("Label").GetComponent<TextMeshProUGUI>().text = "ʵÌåÆäËû";
}
else
{
TransparentOther.transform.Find("Label").GetComponent<TextMeshProUGUI>().text = "͸Ã÷ÆäËû";
}
Body3DController.Instance.Transparent(obj, isOn, true);
});
//BackBtn.onClick.AddListener(() =>
//{
// Body3DController.Instance.Active(true);
// BackBtn.gameObject.SetActive(false);
// Active.gameObject.SetActive(true);
// Single.gameObject.SetActive(true);
// Transparent.gameObject.SetActive(true);
// TransparentOther.gameObject.SetActive(true);
//});
ShowTip.onValueChanged.AddListener(isOn =>
{
Center.gameObject.SetActive(isOn);
});
AudioBtn.onValueChanged.AddListener(isOn =>
{
if (isOn)
{
string audioName = mData.body.Audio;
if (string.IsNullOrEmpty(audioName) == false)
{
string path = Global.audioPath + audioName;
loader.Add2Load(path.ToLocalAudioResName(), (success, res) =>
{
if (success)
{
AudioKit.PlayVoice(res.Asset.As<AudioClip>(), false, onEndedCallback: () =>
{
AudioBtn.isOn = false;
});
}
});
loader.LoadAsync();
}
}
else
{
AudioKit.StopVoice();
}
});
AudioSpeed.onValueChanged.AddListener((isOn) =>
{
});
FontAdd.onClick.AddListener(() =>
{
if (Des.fontSize <= 31)
{
Des.fontSize++;
}
});
FontSub.onClick.AddListener(() =>
{
if (Des.fontSize > 1)
{
Des.fontSize--;
}
});
}
private void OnModuleQuithandler(OnModuleQuit quit)
{
Hide();
}
public void RefreshTipPath()
{
ListContent.RemoveAllChildren();
ListItemFacotry(mData.body);
}
public void Refresh()
{
PartName.text = mData.body.Name;
EnglishName.text = mData.body.EnglishName;
obj = Utility.FindObj(mData.body.Path);
Des.text = mData.body.Tip;
RefreshTipPath();
Active.onValueChanged.RemoveAllListeners();
Active.isOn = false;
Active.transform.Find("Label").GetComponent<TextMeshProUGUI>().text = "Òþ²Ø";
Active.onValueChanged.AddListener(isOn =>
{
obj.SetActive(!isOn);
if (isOn)
{
Body3DController.Instance.AddActiveObj(obj);
Active.transform.Find("Label").GetComponent<TextMeshProUGUI>().text = "ÏÔʾ";
}
else
{
Body3DController.Instance.PopActiveObj();
Active.transform.Find("Label").GetComponent<TextMeshProUGUI>().text = "Òþ²Ø";
}
});
}
public void ListItemFacotry(Body3D.Body body)
{
GameObject obj = GameObject.Instantiate(ListItem.gameObject, ListContent);
obj.transform.Find("Label").GetComponent<TextMeshProUGUI>().text = body.Name + "/";
obj.transform.SetAsFirstSibling();
if (body.parent != null)
{
ListItemFacotry(body.parent);
}
}
protected override void OnOpen(IUIData uiData = null)
{
mData = uiData as UIBody3DInfoData ?? new UIBody3DInfoData();
Refresh();
}
protected override void OnShow()
{
}
protected override void OnHide()
{
}
protected override void OnClose()
{
}
}
}