245 lines
6.1 KiB
C#
Raw Permalink Normal View History

2025-05-18 01:04:31 +08:00
// ***********************************************************************
// Assembly : Game
// Author : Kimch
// Created : 2021-04-12
// Description :
// Last Modified By :
// Last Modified On :
// ***********************************************************************
// <copyright file= "BeautyDetailPanel" company="Kunpo"></copyright>
// <summary></summary>
// ***********************************************************************
using DG.Tweening;
using Spine.Unity;
using System.Collections;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
namespace G.UI
{
/// <summary>
///
/// </summary>
public class BeautyDetailPanel : KUIWidget
{
#region Field
#pragma warning disable CS0649 // 从未对字段赋值,字段将一直保持其默认值 null
[KUIFlag]
Button _btnMeet;
[KUIFlag]
Button _btnGift;
[KUIFlag]
Button _btnSkill;
[KUIFlag]
Button _btnSkin;
[KUIFlag]
TextMeshProUGUI _tmpName;
[KUIFlag]
Image _imgPicture;
[KUIFlag]
TextMeshProUGUI _tmpDescription;
[KUIFlag]
TextMeshProUGUI _tmpTalk;
[KUIFlag]
TextMeshProUGUI _tmpLevel;
[KUIFlag]
TextMeshProUGUI _tmpExp;
[KUIFlag]
GameObject _goSkeleton;
#pragma warning restore CS0649 // 从未对字段赋值,字段将一直保持其默认值 null
//[KUIFlag]
SkeletonGraphic _skeleton;
#endregion
#region Method
public override void Refresh()
{
if (this.data is BeautyProxy.BeautyInfo beautyInfo)
{
_tmpName.text = beautyInfo.item.name;
_tmpDescription.text = beautyInfo.item.description;
_tmpTalk.text = beautyInfo.item.talk;
_tmpLevel.text = "亲密度:" + beautyInfo.level;
_tmpExp.text = "红颜经验:" + beautyInfo.exp;
StartCoroutine(LoadBeautySkin2(beautyInfo.skinItem, _imgPicture, _goSkeleton));
//_skeleton.raycastTarget = true;
_clicking = false;
}
}
private void Refresh2()
{
if (this.data is BeautyProxy.BeautyInfo beautyInfo)
{
_tmpLevel.text = beautyInfo.level.ToString();
_tmpExp.text = beautyInfo.exp.ToString();
}
}
public IEnumerator LoadBeautySkin2(ItemBeautySkin skin, Image picture, GameObject skeletonRoot)
{
if (string.IsNullOrEmpty(skin.asset))
{
picture.gameObject.SetActive(true);
skeletonRoot.SetActive(false);
var handle = AssetProxy.Instance.TryGetTemporaryAssetAsync<Sprite>($"{skin.picture}/pic.png");
yield return handle;
if (handle.Status == UnityEngine.ResourceManagement.AsyncOperations.AsyncOperationStatus.Succeeded)
picture.sprite = handle.Result;
}
else
{
picture.gameObject.SetActive(false);
skeletonRoot.SetActive(true);
var skinAsset = skin.asset;
var rootTr = skeletonRoot.transform;
if (rootTr.childCount > 0)
{
var child = rootTr.GetChild(0);
if (child.name == skinAsset)
{
skinAsset = "";
yield break;
}
AssetProxy.Instance.ReleaseInstance(child.gameObject);
}
if (!string.IsNullOrEmpty(skinAsset))
{
var handle = AssetProxy.Instance.InstantiateAsync(skin.asset, rootTr);
yield return handle;
handle.Result.name = skin.asset;
_skeleton = handle.Result.GetComponent<SkeletonGraphic>();
}
}
}
private void OnMeetBtnClick()
{
PostNotification(GlobalDefine.EVENT_BEAUTY_WINDOW, this.data, "gift1");
SoundProxy.PlayFxAsync(GlobalDefine.BUTTON_CLICK_SOUND);
}
private void OnGiftBtnClick()
{
PostNotification(GlobalDefine.EVENT_BEAUTY_WINDOW, this.data, "gift1");
SoundProxy.PlayFxAsync(GlobalDefine.BUTTON_CLICK_SOUND);
}
private void OnEffectBtnClick()
{
PostNotification(GlobalDefine.EVENT_BEAUTY_WINDOW, this.data, "skill");
SoundProxy.PlayFxAsync(GlobalDefine.BUTTON_CLICK_SOUND);
}
private void OnSkinBtnClick()
{
PostNotification(GlobalDefine.EVENT_BEAUTY_WINDOW, this.data, "skin");
SoundProxy.PlayFxAsync(GlobalDefine.BUTTON_CLICK_SOUND);
}
private bool _clicking;
private void OnSkinClick()
{
if (_clicking)
return;
_clicking = true;
_skeleton.AnimationState.Complete += OnAnimComp;
_skeleton.AnimationState.SetAnimation(0, "haixiu", false);
if (this.data is BeautyProxy.BeautyInfo beautyInfo)
{
_tmpTalk.transform.parent.gameObject.SetActive(true);
_tmpTalk.text = "";
if (!string.IsNullOrEmpty(beautyInfo.skinItem.talk))
_tmpTalk.DOText(beautyInfo.skinItem.talk, 2f);
if (!string.IsNullOrEmpty(beautyInfo.skinItem.sound))
SoundProxy.PlayFxAsync(beautyInfo.skinItem.sound + ".mp3");
//StartCoroutine(PlaySound(beautyInfo.skinItem.sound));
}
}
private void OnAnimComp(Spine.TrackEntry trackEntry)
{
_tmpTalk.transform.parent.gameObject.SetActive(false);
_skeleton.AnimationState.Complete -= OnAnimComp;
if (trackEntry.Animation.Name == "haixiu")
{
Debug.Log("OnAnimComp");
_skeleton.AnimationState.SetAnimation(0, "idle", true);
}
_clicking = false;
}
#endregion
#region Unity
/// <summary>
///
/// </summary>
private void Awake()
{
SetViewData();
_btnMeet.onClick.AddListener(this.OnMeetBtnClick);
_btnGift.onClick.AddListener(this.OnGiftBtnClick);
_btnSkill.onClick.AddListener(this.OnEffectBtnClick);
_btnSkin.onClick.AddListener(this.OnSkinBtnClick);
_goSkeleton.GetComponent<Button>().onClick.AddListener(this.OnSkinClick);
_btnMeet.gameObject.SetActive(false);
_btnSkill.gameObject.SetActive(false);
}
private void OnEnable()
{
RegisterThis();
}
private void OnDisable()
{
UnregisterThis();
}
#endregion
#region Mediator
readonly int[] _notificationInterests = new int[]
{
GlobalDefine.EVENT_BEAUTY_GIFT,
GlobalDefine.EVENT_BEAUTY_SKIN
};
public override System.Collections.Generic.IList<int> ListNotificationInterests()
{
return _notificationInterests;
}
public override void HandleNotification(PureMVC.Interfaces.INotification notification)
{
if (notification.Name == GlobalDefine.EVENT_BEAUTY_GIFT)
Refresh2();
else if (notification.Name == GlobalDefine.EVENT_BEAUTY_SKIN)
{
StartCoroutine(LoadBeautySkin2((ItemBeautySkin)notification.Body, _imgPicture, _goSkeleton));
}
}
#endregion
}
}