136 lines
4.2 KiB
C#
136 lines
4.2 KiB
C#
// ***********************************************************************
|
|
// Assembly : Game
|
|
// Author : Kimch
|
|
// Created : 2022-02-23
|
|
// Description :
|
|
// Last Modified By :
|
|
// Last Modified On :
|
|
// ***********************************************************************
|
|
// <copyright file= "ChaWidget" company="Kunpo"></copyright>
|
|
// <summary></summary>
|
|
// ***********************************************************************
|
|
|
|
using UnityEngine;
|
|
using UnityEngine.ResourceManagement.AsyncOperations;
|
|
using UnityEngine.UI;
|
|
|
|
namespace G.UI
|
|
{
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
public class ChaWidget : KUIWidget
|
|
{
|
|
#region Auto Generate
|
|
|
|
#pragma warning disable CS0649 // 从未对字段赋值,字段将一直保持其默认值 null
|
|
|
|
#pragma warning restore CS0649 // 从未对字段赋值,字段将一直保持其默认值 null
|
|
|
|
#endregion
|
|
|
|
#region Field
|
|
|
|
string _lastChaAsset;
|
|
string _lastWeaponAsset;
|
|
AsyncOperationHandle<GameObject> _chaHandle;
|
|
AsyncOperationHandle<WeaponSpineData> _weaponHandle;
|
|
|
|
#endregion
|
|
|
|
#region Method
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="chaSkinAsset"></param>
|
|
/// <param name="weaponSkinAsset"></param>
|
|
/// <param name="callback"></param>
|
|
public void Show(string chaSkinAsset, string weaponSkinAsset, Callback2 callback)
|
|
{
|
|
StartCoroutine(ShowSkinCO(chaSkinAsset, weaponSkinAsset, callback));
|
|
}
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="kind"></param>
|
|
/// <param name="assets"></param>
|
|
/// <returns></returns>
|
|
private System.Collections.IEnumerator ShowSkinCO(string chaAsset, string weaponAsset, Callback2 callback)
|
|
{
|
|
Sprite mainWeaponSprite = null;
|
|
Sprite subWeaponSprite = null;
|
|
|
|
AsyncOperationHandle<WeaponSpineData> lastWeaponHandle = default;
|
|
if (!_weaponHandle.IsValid() || _weaponHandle.Result.name != weaponAsset)
|
|
{
|
|
//if (_weaponHandle.IsValid())
|
|
//{
|
|
// AssetProxy.Instance.Release(_weaponHandle);
|
|
//}
|
|
lastWeaponHandle = _weaponHandle;
|
|
if (!string.IsNullOrEmpty(weaponAsset))
|
|
{
|
|
_weaponHandle = AssetProxy.Instance.GetAssetAsync<WeaponSpineData>(weaponAsset);
|
|
yield return _weaponHandle;
|
|
if (_weaponHandle.Status == AsyncOperationStatus.Succeeded)
|
|
{
|
|
mainWeaponSprite = _weaponHandle.Result.mainHand;
|
|
subWeaponSprite = _weaponHandle.Result.subHand;
|
|
}
|
|
}
|
|
}
|
|
|
|
if (!_chaHandle.IsValid() || _chaHandle.Result.name != chaAsset)
|
|
{
|
|
if (_chaHandle.IsValid())
|
|
{
|
|
AssetProxy.Instance.ReleaseInstance(_chaHandle);
|
|
}
|
|
|
|
_chaHandle = AssetProxy.Instance.InstantiateAsync(chaAsset, this.transform);
|
|
yield return _chaHandle;
|
|
_chaHandle.Result.name = chaAsset;
|
|
|
|
if (_weaponHandle.IsValid())
|
|
{
|
|
mainWeaponSprite = _weaponHandle.Result.mainHand;
|
|
subWeaponSprite = _weaponHandle.Result.subHand;
|
|
}
|
|
}
|
|
|
|
if (_chaHandle.IsValid() && mainWeaponSprite != null)
|
|
{
|
|
var es = _chaHandle.Result.GetComponent<EquipSystem>();
|
|
es.Equip(mainWeaponSprite, EquipSystem.EquipType.MainWp);
|
|
if (subWeaponSprite != null)
|
|
{
|
|
es.Equip(subWeaponSprite, EquipSystem.EquipType.SubWp);
|
|
}
|
|
}
|
|
|
|
if (lastWeaponHandle.IsValid())
|
|
{
|
|
AssetProxy.Instance.Release(lastWeaponHandle);
|
|
}
|
|
|
|
callback?.Invoke(0, "");
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Unity
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
private void Awake()
|
|
{
|
|
SetViewData();
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
}
|