414 lines
12 KiB
C#
414 lines
12 KiB
C#
using cfg.CharacterCfg;
|
|
using Framework;
|
|
using System.Collections.Generic;
|
|
using Gameplay;
|
|
using Gameplay.Utils;
|
|
using PhxhSDK;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using Button = UnityEngine.UI.Button;
|
|
using Constants = Framework.Constants;
|
|
using Image = UnityEngine.UI.Image;
|
|
using Cysharp.Threading.Tasks;
|
|
using Gameplay.Emoji;
|
|
using UnityEngine.Playables;
|
|
using UnityEngine.UI;
|
|
using System.Security.Cryptography.X509Certificates;
|
|
|
|
public class UIPosterController : UIWindow
|
|
{
|
|
//UI GameObj
|
|
///Auto Gen Start///
|
|
public Image Image_BG;
|
|
public Button Button_Back;
|
|
public Button Button_Home;
|
|
public Image Image_Poster;
|
|
public Button Button_Poster;
|
|
public TMP_Text Text_Poster;
|
|
public Image Image_LightBar;
|
|
public Button Button_Poster_Default;
|
|
public TMP_Text Text_Poster_Default;
|
|
public Button Button_Model;
|
|
public TMP_Text Text_Model;
|
|
public Image Image_LightBar01;
|
|
public Button Button_Model_Default;
|
|
public TMP_Text Text_Model_Default;
|
|
|
|
private CharacterDataInfo _characterData;
|
|
private EshowType mCurShowType = EshowType.Pic;
|
|
|
|
private Sprite ui2Dpic;
|
|
private CharacterAttri characterAttri;
|
|
private GameObject _sampleModel;
|
|
private GameObject _instModel;
|
|
private Vector3 PosterScale = Vector3.one;
|
|
private float scaleXiShu = 1;
|
|
private GameObject modelParent;
|
|
private UnitEmojiManager _emojiManager;
|
|
|
|
private const string DEFAULT_ANIMATION = "standready001";
|
|
private const float SCALE_XISHU = 0.5f;
|
|
private const float SCALE_XISHU_DELTA = 0.05f;
|
|
|
|
private readonly Vector3 _imgPosterScale = new (0.5f, 0.5f, 0.5f);
|
|
private readonly Vector3 _modelPos = new (0,-309,-247);
|
|
private readonly Quaternion _modelRotate = new (0,180,0,1);
|
|
private readonly Vector3 _modelScale = new (540,540,540);
|
|
private enum EshowType
|
|
{
|
|
Pic,
|
|
Model,
|
|
}
|
|
|
|
|
|
///Auto Gen End///
|
|
|
|
public static async UniTask<UIWindow> Open(CharacterDataInfo characterDataInfo)
|
|
{
|
|
await CommonUtils.CaptureScreenshot();
|
|
|
|
return await UIManager.Instance.CreateAndOpenWindow(UINameConst.UIPoster, characterDataInfo);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 高斯模糊遮罩
|
|
/// </summary>
|
|
private RawImage rawImageGaussianBlurMask;
|
|
|
|
public override void OnInit()
|
|
{
|
|
//bind UI GameObj
|
|
UIPosterBinder.GetComponents(this);
|
|
|
|
rawImageGaussianBlurMask = GetComponent<RawImage>("GaussianBlurMask");
|
|
|
|
rawImageGaussianBlurMask.texture = CommonUtils.GetScreenTexture2D();
|
|
|
|
BindButton(Button_Back, OnButton_BackClick);
|
|
BindButton(Button_Poster, OnButton_Poster);
|
|
BindButton(Button_Model, OnButton_Model);
|
|
BindButton(Button_Poster_Default, OnButton_Poster);
|
|
BindButton(Button_Model_Default, OnButton_Model);
|
|
BindButton(Button_Home, OnClickHome);
|
|
|
|
modelParent = FindObj("Model");
|
|
|
|
}
|
|
private void OnClickHome()
|
|
{
|
|
UIManager.Instance.CloseAllNormalExcept(UINameConst.UI_MainPanel);
|
|
}
|
|
|
|
//float xoffset = 0;
|
|
//float yoffset = 0;
|
|
//Vector3 curPostion = Vector3.zero;
|
|
//private void OnFingerDrag(Vector2 delta)
|
|
//{
|
|
|
|
// if (mCurShowType == EshowType.Pic)
|
|
// {
|
|
|
|
|
|
// // Image_Poster.transform.localPosition = new Vector3(Image_Poster.transform.localPosition.x+delta.x, Image_Poster.transform.localPosition.y + delta.y, 0);
|
|
|
|
|
|
// if ((Image_Poster.transform.localPosition.x + delta.x) >= (Screen.width/2- (500*Image_Poster.transform.localScale.x)))
|
|
// {
|
|
// xoffset = Screen.width / 2 - (500 * Image_Poster.transform.localScale.x);
|
|
// }
|
|
// else if (((Image_Poster.transform.localPosition.x + delta.x) <=(-Screen.width/2+(500*Image_Poster.transform.localScale.x))))
|
|
// {
|
|
// xoffset = -Screen.width / 2 + (500* Image_Poster.transform.localScale.x);
|
|
// }
|
|
// else
|
|
// {
|
|
// xoffset = Image_Poster.transform.localPosition.x + delta.x;
|
|
// }
|
|
// if ((Image_Poster.transform.localPosition.y + delta.y) >= ((Screen.height/2)- Image_Poster.rectTransform.sizeDelta.y/2 * Image_Poster.transform.localScale.x))
|
|
// {
|
|
// yoffset = ((Screen.height / 2) - (Image_Poster.rectTransform.sizeDelta.y / 2 * Image_Poster.transform.localScale.x));
|
|
// }
|
|
// else if (((Image_Poster.transform.localPosition.y + delta.y) <= ((-Screen.height / 2)+ (Image_Poster.rectTransform.sizeDelta.y/2* Image_Poster.transform.localScale.x))))
|
|
// {
|
|
// yoffset = -Screen.height / 2+(Image_Poster.rectTransform.sizeDelta.y / 2 * Image_Poster.transform.localScale.x);
|
|
// }
|
|
// else
|
|
// {
|
|
// yoffset = Image_Poster.transform.localPosition.y + delta.y;
|
|
// }
|
|
// Image_Poster.transform.localPosition = new Vector3(xoffset, yoffset, 0);
|
|
|
|
// }
|
|
//}
|
|
|
|
private void OnFingersZoom(float delta)
|
|
{
|
|
if (mCurShowType != EshowType.Pic) return;
|
|
if (delta > 0)
|
|
{
|
|
if (scaleXiShu >= SCALE_XISHU)
|
|
{
|
|
scaleXiShu = SCALE_XISHU;
|
|
}else
|
|
{
|
|
scaleXiShu += SCALE_XISHU_DELTA;
|
|
}
|
|
Image_Poster.transform.localScale = PosterScale * scaleXiShu;
|
|
|
|
}
|
|
else
|
|
{
|
|
if (scaleXiShu <= SCALE_XISHU/2)
|
|
{
|
|
scaleXiShu = SCALE_XISHU/2;
|
|
}
|
|
else
|
|
{
|
|
scaleXiShu -= SCALE_XISHU_DELTA;
|
|
}
|
|
Image_Poster.transform.localScale = PosterScale * scaleXiShu;
|
|
|
|
|
|
}
|
|
}
|
|
|
|
private void OnButton_Model()
|
|
{
|
|
if(mCurShowType==EshowType.Model)
|
|
{
|
|
return;
|
|
}
|
|
RefreshModel();
|
|
}
|
|
|
|
private void RefreshModel()
|
|
{
|
|
modelParent.SetActive(true);
|
|
Image_Poster.gameObject.SetActive(false);
|
|
mCurShowType = EshowType.Model;
|
|
RefreshChangeBtn();
|
|
|
|
if (_sampleModel == null)
|
|
{
|
|
DebugUtil.LogError("加载的模型为空");
|
|
return;
|
|
}
|
|
|
|
if (_instModel != null)
|
|
{
|
|
// 做显示处理
|
|
_InitAnim();
|
|
return;
|
|
}
|
|
|
|
_instModel = Object.Instantiate(_sampleModel, modelParent.transform, true);
|
|
_instModel.transform.localPosition = _modelPos;
|
|
_instModel.transform.localScale = _modelScale;
|
|
_instModel.transform.localRotation= _modelRotate;
|
|
_instModel.gameObject.SetLayerEx(5);
|
|
|
|
var pd = _instModel.GetComponentInChildren<PlayableDirector>();
|
|
if (pd != null)
|
|
{
|
|
pd.enabled = false;
|
|
}
|
|
|
|
_InitEmoji();
|
|
_InitAnim();
|
|
}
|
|
|
|
private void _InitEmoji()
|
|
{
|
|
if (_emojiManager != null)
|
|
{
|
|
_emojiManager.Dispose();
|
|
_emojiManager = null;
|
|
}
|
|
var charSingleData = _characterData.Cfg;
|
|
_emojiManager = new UnitEmojiManager(_instModel, charSingleData.EmojiEyesColor,
|
|
charSingleData.EmojiEyeBowsType, charSingleData.EmojiEyeBowsColor, true);
|
|
_emojiManager.SwitchEmoji(charSingleData.DefaultDisplayEmojiId);
|
|
}
|
|
|
|
private void _InitAnim()
|
|
{
|
|
var animator = _instModel.GetComponentInChildren<Animator>();
|
|
if (animator != null)
|
|
{
|
|
int ran = UnityEngine.Random.Range(0, 2);
|
|
if(ran == 0)
|
|
{
|
|
animator.Play(DEFAULT_ANIMATION);
|
|
DebugUtil.Log("当前随机播放动作: " + DEFAULT_ANIMATION);
|
|
}
|
|
else
|
|
{
|
|
animator.Play("standready002");
|
|
DebugUtil.Log("当前随机播放动作: standready002");
|
|
}
|
|
//RuntimeAnimatorController runtimeAnimatorController = animator.runtimeAnimatorController;
|
|
//if (runtimeAnimatorController != null)
|
|
//{
|
|
// AnimationClip[] clips = runtimeAnimatorController.animationClips;
|
|
// int ran = UnityEngine.Random.Range(0, clips.Length);
|
|
// string stateName = clips[ran].name.Substring(10);
|
|
// DebugUtil.Log("角色动画机clips数: " + clips.Length + ",当前随机播放: " + stateName);
|
|
// animator.Play(stateName);
|
|
// return;
|
|
//}
|
|
//animator.Play(DEFAULT_ANIMATION);
|
|
}
|
|
}
|
|
|
|
private void OnButton_Poster()
|
|
{
|
|
if (mCurShowType == EshowType.Pic)
|
|
{
|
|
return;
|
|
|
|
}
|
|
|
|
Refresh2DPic();
|
|
}
|
|
private void RefreshChangeBtn()
|
|
{
|
|
Button_Poster.gameObject.SetActive(mCurShowType == EshowType.Pic);
|
|
Button_Model_Default.gameObject.SetActive(mCurShowType !=EshowType.Model);
|
|
Button_Poster_Default.gameObject.SetActive(mCurShowType != EshowType.Pic);
|
|
Button_Model.gameObject.SetActive(mCurShowType == EshowType.Model);
|
|
}
|
|
private void Refresh2DPic()
|
|
{
|
|
modelParent.SetActive(false);
|
|
Image_Poster.gameObject.SetActive(true);
|
|
Image_Poster.sprite = ui2Dpic;
|
|
Image_Poster.SetNativeSize();
|
|
Image_Poster.transform.localScale = _imgPosterScale;
|
|
mCurShowType = EshowType.Pic;
|
|
RefreshChangeBtn();
|
|
}
|
|
|
|
private void LoadCfg()
|
|
{
|
|
OnLoadPostCfg();
|
|
_LoadPic();
|
|
_LoadModel();
|
|
}
|
|
|
|
|
|
private void ResetModel()
|
|
{
|
|
if (_instModel != null)
|
|
{
|
|
_instModel.Destroy();
|
|
_instModel = null;
|
|
}
|
|
}
|
|
|
|
|
|
private void OnLoadPostCfg()
|
|
{
|
|
characterAttri=TableManager.Instance.Tables.CharacterAttri;
|
|
}
|
|
private async void _LoadModel()
|
|
{
|
|
var prefabPath = PathEx.GetCharacterDisplayModelPath(_characterData.Cfg.NameID);
|
|
_sampleModel = await LoadAssetAsync<GameObject>(prefabPath);
|
|
if (mCurShowType != EshowType.Model)
|
|
{
|
|
return;
|
|
}
|
|
RefreshModel();
|
|
}
|
|
|
|
private void OnButton_BackClick()
|
|
{
|
|
CloseWindow();
|
|
}
|
|
//invoke when open window
|
|
protected override void OnShowWindow(object tempInfo)
|
|
{
|
|
|
|
InputManager.Instance.OnFingersMove += OnFingersZoom;
|
|
//InputManager.Instance.OnFingerMoveUI += OnFingerDrag;
|
|
InputManager.Instance.OnFingerMoveUI += RotateMonster;
|
|
mCurShowType = EshowType.Pic;
|
|
ResetModel();
|
|
_characterData = tempInfo as CharacterDataInfo;
|
|
Image_Poster.gameObject.SetActive(false);
|
|
LoadCfg();
|
|
}
|
|
|
|
private void RotateMonster(Vector2 delta)
|
|
{
|
|
if (delta == Vector2.zero) return;
|
|
if (_instModel != null)
|
|
{
|
|
_instModel.transform.Rotate(Vector3.up, -delta.x);
|
|
}
|
|
}
|
|
|
|
|
|
private void RefreshUI()
|
|
{
|
|
if(mCurShowType==EshowType.Pic)
|
|
{
|
|
Refresh2DPic();
|
|
}else
|
|
{
|
|
RefreshModel();
|
|
}
|
|
}
|
|
|
|
private async void _LoadPic()
|
|
{
|
|
var picPath = CommonUtils.GetCharacterPicPath(_characterData.Cfg.RoleID, CommonUtils.ECharacterPicPathType.Poster);
|
|
ui2Dpic = await LoadAssetAsync<Sprite>(picPath);
|
|
if (mCurShowType != EshowType.Pic)
|
|
{
|
|
return;
|
|
}
|
|
RefreshUI();
|
|
Image_Poster.gameObject.SetActive(true);
|
|
}
|
|
|
|
//invoke when reload window
|
|
protected override void OnReloadWindow(object data = null)
|
|
{
|
|
|
|
}
|
|
private void UnLoad()
|
|
{
|
|
AssetManager.Instance.Unload(CommonUtils.GetCharacterPicPath(_characterData.Cfg.RoleID, CommonUtils.ECharacterPicPathType.Poster));
|
|
var prefabPath = PathEx.GetCharacterDisplayModelPath(_characterData.Cfg.NameID);
|
|
AssetManager.Instance.Unload(prefabPath);
|
|
|
|
}
|
|
//invoke when close window
|
|
protected override void OnHideWindow()
|
|
{
|
|
//UnLoad();
|
|
InputManager.Instance.OnFingersMove -= OnFingersZoom;
|
|
// InputManager.Instance.OnFingerMoveUI -= OnFingerDrag;
|
|
InputManager.Instance.OnFingerMoveUI -= RotateMonster;
|
|
EventManager.Instance.Send(EventManager.EventName.EN_UIControllCultivateMainInput, true);
|
|
|
|
if (_emojiManager != null)
|
|
{
|
|
_emojiManager.Dispose();
|
|
_emojiManager = null;
|
|
}
|
|
|
|
if (_instModel != null)
|
|
{
|
|
Object.Destroy(_instModel);
|
|
_instModel = null;
|
|
}
|
|
|
|
}
|
|
|
|
public override void OnRelease()
|
|
{
|
|
base.OnRelease();
|
|
}
|
|
} |