103 lines
3.5 KiB
C#
103 lines
3.5 KiB
C#
using System;
|
|
using Cysharp.Threading.Tasks;
|
|
using Stary.Evo;
|
|
using Stary.Evo.AudioCore;
|
|
using Stary.Evo.InformationSave;
|
|
using Stary.Evo.UIFarme;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using YooAsset;
|
|
|
|
namespace Main
|
|
{
|
|
public class IntroPanel : BasePanel
|
|
{
|
|
static readonly string path = "IntroPanel";
|
|
|
|
private Image intro;
|
|
|
|
private LocalTransformInfo transformInfo;
|
|
|
|
public IntroPanel()
|
|
{
|
|
}
|
|
|
|
|
|
public override void Initialize(GameObject panelGo)
|
|
{
|
|
base.Initialize(panelGo);
|
|
|
|
intro = activePanel.transform.Find("Intro").GetComponent<Image>();
|
|
transformInfo = activePanel.transform.GetComponent<LocalTransformInfo>();
|
|
intro.gameObject.SetActive(false);
|
|
}
|
|
|
|
public override void OnEnter()
|
|
{
|
|
base.OnEnter();
|
|
|
|
this.RegisterEvent<IntroType, string, string>(IntroType.IntroSpriteName, OnClickPreviousIntro);
|
|
this.RegisterEvent<IntroType, RuntimeAnimatorController, string>(IntroType.IntroAnimation, OnAddAnimation);
|
|
this.RegisterEvent<IntroType, string, string>(IntroType.IntroAudio, OnClickPreviousIntroAudio);
|
|
this.RegisterEvent<IntroType, Sprite, string>(IntroType.IntroSprite, SetIntroSprite);
|
|
}
|
|
|
|
public override void OnExit(float delay = 0)
|
|
{
|
|
base.OnExit(delay);
|
|
intro.sprite = null;
|
|
intro.gameObject.SetActive(false);
|
|
this.UnRegisterEvent<IntroType, string, string>(IntroType.IntroSpriteName, OnClickPreviousIntro);
|
|
this.UnRegisterEvent<IntroType, string, string>(IntroType.IntroAudio, OnClickPreviousIntroAudio);
|
|
this.UnRegisterEvent<IntroType, RuntimeAnimatorController, string>(IntroType.IntroAnimation, OnAddAnimation);
|
|
this.UnRegisterEvent<IntroType, Sprite, string>(IntroType.IntroSprite, SetIntroSprite);
|
|
var animator = intro.transform.GetComponent<Animator>();
|
|
if (animator != null)
|
|
{
|
|
GameObject.Destroy(animator);
|
|
}
|
|
}
|
|
|
|
public async void OnAddAnimation(RuntimeAnimatorController animatorController, string desc)
|
|
{
|
|
var animator = intro.transform.GetOrAddComponent<Animator>();
|
|
animator.runtimeAnimatorController = animatorController;
|
|
|
|
intro.SetNativeSize();
|
|
intro.gameObject.SetActive(true);
|
|
transformInfo.Set(desc);
|
|
}
|
|
|
|
public async void OnClickPreviousIntro(string spriteName, string desc)
|
|
{
|
|
var handle= YooAssets.LoadAssetAsync<Sprite>(spriteName);
|
|
await handle.Task;
|
|
SetIntroSprite(handle.GetAssetObject<Sprite>(), desc);
|
|
}
|
|
|
|
public async void OnClickPreviousIntroAudio(string auid, string desc)
|
|
{
|
|
var info = await this.GetData<IAudioTableData>().GetAudioClipToUISprite(auid);
|
|
AudioCoreManager.PlayVoice(new AudioData()
|
|
{
|
|
clip = info.audioClip,
|
|
});
|
|
SetIntroSprite(info.sprite, desc);
|
|
}
|
|
public void SetIntroSprite(Sprite sprite, string desc)
|
|
{
|
|
|
|
intro.sprite = sprite;
|
|
intro.SetNativeSize();
|
|
intro.gameObject.SetActive(true);
|
|
transformInfo.Set(desc);
|
|
}
|
|
public enum IntroType
|
|
{
|
|
IntroSpriteName,
|
|
IntroSprite,
|
|
IntroAudio,
|
|
IntroAnimation
|
|
}
|
|
}
|
|
} |