using System.Collections; using System.Collections.Generic; using TMPro; using UnityEngine; using UnityEngine.UI; using UnityEngine.UIElements; using Button = UnityEngine.UI.Button; using Image = UnityEngine.UI.Image; using Toggle = UnityEngine.UI.Toggle; using Framework; using Cysharp.Threading.Tasks; using Gameplay; using cfg.CharacterCfg; using PhxhSDK; using System.Threading.Tasks; using UnityEngine.EventSystems; using Gameplay.Performance; using cfg.ActorCfg; using Gameplay.Utils; using UnityEngine.Playables; using Gameplay.Net; using static CriWare.CriAtomExBeatSync; using Gameplay.Emoji; public class SkinChangeController : UIWindow { //UI GameObj ///Auto Gen Start/// public Image Image_BG; //public Button Button_Back; public Button Button_back; public TMP_Text Text_Back; public Button Button_Home; public Image Image_Dark; public Image Image_LeftBG; public Image Image_ModelPosition; public Image Image_Poster; public Image Image_PosterPreview; public Image Image_MidBG; public Button Button_ShowAllPic; public TMP_Text Text_Name; public TMP_Text Text_SkinName; public TMP_Text Text_Info; public TMP_Text Text_GetWay; public Button Button_Buy; public TMP_Text Text_Buy; public Button Button_Wear; public TMP_Text Text_Wear; public GameObject UpperUI; private RawImage rawImageGaussianBlurMask; ///Auto Gen End/// private PinchZoomModule PinchZoom; private DragForUI Drag; private PhxhSDK.PhxhScrollView ScrollView; SkinScrollView skinScrollView = new SkinScrollView(); GameObject _sampleModel; GameObject _instModel; private UnitEmojiManager _emojiManager; private bool isShowPosterPic = false; private CharacterDataInfo curCharacterInfo; private int curSelectSkinId; private int curUsingSkinId; List characterSkinList; Dictionary posterLargePics = new(); Dictionary posterHalfPics = new(); PosterFader fader = new PosterFader(); public static async UniTask Open(CharacterDataInfo characterData) { CommonUtils.CaptureScreenshot(); return await UIManager.Instance.CreateAndOpenWindow(UINameConst.UI_SkinChange, characterData); } // deal with input data public override void PreLoad(object data = null) { curCharacterInfo = data as CharacterDataInfo; curSelectSkinId = (int)curCharacterInfo.SkinID;// + 1; if(curSelectSkinId == 0) { DebugUtil.LogError("当前角色数据内皮肤ID为0,已设置为默认皮肤ID"); curSelectSkinId = 1; } curUsingSkinId = curSelectSkinId; characterSkinList = CommonUtils.GetCharacterSkinCfgList((int)curCharacterInfo.ID); PreLoadSpritesAsync(); } void refreshCharacterInfo() { curCharacterInfo = CharacterDataInfoManager.Instance.GetCharacterInfo(curCharacterInfo.ID); curSelectSkinId = (int)curCharacterInfo.SkinID; if (curSelectSkinId == 0) { DebugUtil.LogError("当前角色数据内皮肤ID为0,已设置为默认皮肤ID"); curSelectSkinId = 1; } curUsingSkinId = curSelectSkinId; } async void PreLoadSpritesAsync() { foreach (var dataCharacter in characterSkinList) { string path = CommonUtils.GetCharacterPicPath((int)curCharacterInfo.ID, CommonUtils.ECharacterPicPathType.Poster, dataCharacter.SkinID); var sprite = await LoadAssetAsync(path); if (!posterLargePics.ContainsKey(dataCharacter.SkinID)) posterLargePics.Add(dataCharacter.SkinID, sprite); else posterLargePics[dataCharacter.SkinID] = sprite; //TODO 目前半身图使用好感度图片路径 path = CommonUtils.GetCharacterPicPath((int)curCharacterInfo.ID, CommonUtils.ECharacterPicPathType.Favorable, dataCharacter.SkinID); DebugUtil.Log("目前半身图暂用使用路径为:" + path + ",请待补充相关资源与更新配置表后在此处更新相关代码"); var halfSprite = await LoadAssetAsync(path); if (!posterHalfPics.ContainsKey(dataCharacter.SkinID)) posterHalfPics.Add(dataCharacter.SkinID, halfSprite); else posterHalfPics[dataCharacter.SkinID] = halfSprite; } } async void LoadModel() { //TODO 加载不同皮肤的模型的路径 var prefabPath = PathEx.GetCharacterDisplayModelPath(curCharacterInfo.Cfg.NameID); _sampleModel = await LoadAssetAsync(prefabPath); GameObject model = Object.Instantiate(_sampleModel, Image_ModelPosition.transform, true); _instModel = model; model.transform.localPosition = new Vector3(0, -200, -300); model.transform.localRotation = new(0, 180, 0, 1); model.transform.localScale = 300 * Vector3.one; model.gameObject.SetLayerEx(5); var pd = model.GetComponentInChildren(); if (pd != null) { pd.enabled = false; } var animator = model.GetComponentInChildren(); if (animator != null) { animator.Play("standready001"); } _InitEmoji(); } private void _InitEmoji() { if (_emojiManager != null) { _emojiManager.Dispose(); _emojiManager = null; } var charSingleData = curCharacterInfo.Cfg; _emojiManager = new UnitEmojiManager(_instModel, charSingleData.EmojiEyesColor, charSingleData.EmojiEyeBowsType, charSingleData.EmojiEyeBowsColor, true); _emojiManager.SwitchEmoji(charSingleData.DefaultDisplayEmojiId); } // Use this for initialization public override void OnInit() { //bind UI GameObj SkinChangeBinder.GetComponents(this); UpperUI = FindObj("Image_BG/UpperUI"); rawImageGaussianBlurMask = GetComponent("GaussianBlurMask"); rawImageGaussianBlurMask.texture = CommonUtils.screenTexture; Image_Poster.GetComponent().sizeDelta = Vector2.zero; PinchZoom = GetComponent("Image_BG/Image_Poster"); Drag = GetComponent("Image_BG/Image_Poster"); ScrollView = GetComponent("Image_BG/UpperUI/ChangeSkin/ScrollView"); skinScrollView.SetScrollRect(ScrollView); skinScrollView.SetItemCountFunc(() => characterSkinList.Count + 2);//列表上下各加一个空白item作为padding skinScrollView.SetItemSizeFunc((index) => skinScrollView.GetItemSizeFromList(index)); skinScrollView.SetUpdateFunc(_RefreshSkinItem); skinScrollView.InitItemCellList(characterSkinList.Count); BindButton(Button_ShowAllPic, OnShowPicButton); BindButton(Button_back, OnReturnButton); BindButton(Button_Wear, OnChangeSkinClick); LoadModel(); Drag.OnDragStarted += OnDragBegin; Drag.OnDraging += OnDrag; Drag.OnDragCompleted += OnDragEnd; EventManager.Instance.Register(EventManager.EventName.CharacterInfoRefresh, CharacterInfoRefreshListener); _SetSkinPosYListData(); skinScrollView.UpdateData(); skinScrollView.ScrollTo(curSelectSkinId); } void CharacterInfoRefreshListener() { refreshCharacterInfo(); SetSkinInfoAndButton(); } //invoke when open window protected override void OnShowWindow(object data = null) { base.OnShowWindow(data); if (PinchZoom != null) PinchZoom.enabled = false; isShowPosterPic = false; SetSkinInfoAndButton(); SetPosterSkinPic(); } //invoke when reload window protected override void OnReloadWindow(object data = null) { } //invoke when close window protected override void OnHideWindow() { base.OnHideWindow(); EventManager.Instance.Send(EventManager.EventName.EN_UIControllCultivateMainInput, true); } //invoke when destroy public override void OnRelease() { base.OnRelease(); EventManager.Instance.Unregister(EventManager.EventName.CharacterInfoRefresh, CharacterInfoRefreshListener); } #region Button Event void OnShowPicButton() { ShowAllPic(true); } void OnReturnButton() { if(isShowPosterPic) { ShowAllPic(false); SetSkinInfoAndButton(); } else { CloseWindow(); } } void _OnClickSkinItem(int to) { if (curSelectSkinId == to) { return; } int from = curSelectSkinId; curSelectSkinId = to; //_RefreshPosterButton(); skinScrollView.DoTwoItemScale(to - 1, from - 1, skinScrollView.ItemFullRectTrans.rect.size, skinScrollView.ItemRectTrans.rect.size, 0.1f, () => { _SetSkinPosYListData(false); }, () => { skinScrollView.AnimScrollTo(to); SetSkinInfoAndButton(); }); fader.DoFade(Image_Poster, 0f, 0.12f, () => { SetPosterSkinPic(); fader.DoFade(Image_Poster, 1f, 0.12f); }); } #endregion #region drag event float scaleFactor; void OnDragBegin(PointerEventData data) { if(!isShowPosterPic) { return; } scaleFactor = UIRoot.Instance.RootCanvas.GetComponent().sizeDelta.x / PerformanceManager.instance.fullScreenWidth; } void OnDrag(PointerEventData data) { if(!isShowPosterPic) { return; } Drag.GetComponent().anchoredPosition += data.delta * scaleFactor; //drag.transform.position = GoRoot.transform.position; } void OnDragEnd(PointerEventData data) { if (!isShowPosterPic) { return; } } #endregion private void _SetSkinPosYListData(bool setSize = true) { if (setSize) { for (int i = 0; i < characterSkinList.Count; i++) { Vector2 size = skinScrollView.SkinItemSize(i + 1, curSelectSkinId); skinScrollView._itemCells[i].size = size; } } var posY = -skinScrollView.SkinItemSize(-1, curSelectSkinId).y; for (int i = 0; i < characterSkinList.Count; i++) { Vector2 size = skinScrollView._itemCells[i].size; posY -= size.y / 2; skinScrollView._itemCells[i].localPosY = posY; posY -= size.y / 2; } } private async void _RefreshSkinItem(int index, RectTransform item) { if (index <= 0 || index >= characterSkinList.Count + 1) { item.gameObject.SetActive(false); return; } var go = item.gameObject; go.SetActive(true); var posterPic = CommonUtils.GetCharacterPicPath((int)curCharacterInfo.ID, CommonUtils.ECharacterPicPathType.Favorable, index); var imgSkin = CommonUtils.GetComponent(go, "ButtonChange/ImageSkin"); var imgSelect = CommonUtils.GetGameObject(go, "ButtonChange/ImageChooseRect"); var imgDoSelect = CommonUtils.GetGameObject(go, "ButtonChange/ImageCover"); var btnChange = CommonUtils.GetComponent