using CG.Framework;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
/*******************************************************************************
*Create By CG
*Function 零件说明 [部件认知]和[一键拆装]显示
*******************************************************************************/
namespace ZXK.GYJQR
{
public class PartExplainPanel : UIBase
{
protected override void Awake()
{
base.Awake();
}
private void OnEnable()
{
GameManager.Instance._DataBJCJHandler._CurBJRZhandler.OnValueChanged += OnPartInfoChanged;
GameManager.Instance._DataBJCJHandler._CurYJCJhandler.OnValueChanged += OnPartInfoChanged;
}
private void OnDisable()
{
GameManager.Instance._DataBJCJHandler._CurBJRZhandler.OnValueChanged -= OnPartInfoChanged;
GameManager.Instance._DataBJCJHandler._CurYJCJhandler.OnValueChanged -= OnPartInfoChanged;
}
///
/// 实例化数据到说明栏
///
///
public void InitData(BJCJ_INFO partInfo)
{
SetText("PartName_N", partInfo.partName);
SetText("ExplainTxt_N", partInfo.explainTxt);
}
///
/// 选中零件发生变化
///
///
private void OnPartInfoChanged(Dictionary obj)
{
foreach (var item in obj)
{
if (item.Key.Equals(GameManager.Instance._DataBJCJHandler._ShowPartsName.Value))
{
WDebug.Log($"当前主题:{item.Key},零件ID:{item.Value.id}");
InitData(item.Value);
if (UI_Manage.Instance.GetPanel("FirstEnterTrainPanel")==null)
{
if (!string.IsNullOrEmpty(item.Value.sound))
{
string audioPath = System.IO.Path.Combine(Application.streamingAssetsPath, "Audios", GameManager.Instance._CurSystemType.ToString() + "Tips", item.Value.sound + ".mp3");
CG.UTility.UtilitiesMng.LoadAudio(audioPath, (AudioClip clip) =>
{
if (clip)
{
GetComponent().clip = clip;
GetComponent().Play();
}
});
}
}
else
{
StartCoroutine(EnteredPlayAud(item.Value));
}
}
}
}
private IEnumerator EnteredPlayAud(BJCJ_INFO itemInfo)
{
yield return new WaitForSeconds(0.5f);
FirstEnterTrainPanel firstGeo = CG.Framework.UI_Manage.Instance.GetPanel("FirstEnterTrainPanel").GetComponent();
firstGeo.EnteredEvent += () =>
{
if (!string.IsNullOrEmpty(itemInfo.sound))
{
string audioPath = System.IO.Path.Combine(Application.streamingAssetsPath, "Audios", GameManager.Instance._CurSystemType.ToString() + "Tips", itemInfo.sound + ".mp3");
CG.UTility.UtilitiesMng.LoadAudio(audioPath, (AudioClip clip) =>
{
if (clip)
{
GetComponent().clip = clip;
GetComponent().Play();
}
});
}
};
}
}
}