|
@@ -5,6 +5,8 @@ using System.Collections.Generic;
|
|
|
using System;
|
|
|
using UnityEngine;
|
|
|
using System.Collections;
|
|
|
+using Live2D.Cubism.Rendering;
|
|
|
+using DG.Tweening;
|
|
|
|
|
|
namespace GFGGame
|
|
|
{
|
|
@@ -13,25 +15,44 @@ namespace GFGGame
|
|
|
private GComponent _com;
|
|
|
// private UI_ComModel _comModel;
|
|
|
private DressUpObjUI _dressUpObjUI;
|
|
|
+ private DressUpObjUI _dressUpObjUI2;
|
|
|
+
|
|
|
private LuckyBoxCfg _luckyBoxCfg;
|
|
|
- private const int _turnTime = 8;
|
|
|
+ private const int _turnTime = 7;
|
|
|
private int _curTime = _turnTime;
|
|
|
private int _bgIndex = 0;
|
|
|
private int _modelIndex = 0;
|
|
|
+ private List<DressUpObjUI> _dressUpObjUIs = new List<DressUpObjUI>(2);
|
|
|
+ private ModelInfo[] modelInfos = new ModelInfo[2];
|
|
|
+
|
|
|
+ private class ModelInfo
|
|
|
+ {
|
|
|
+ public CubismRenderController[] cubismModels;
|
|
|
+ public List<SpriteRenderer> spriteRenderers = new List<SpriteRenderer>();
|
|
|
+ }
|
|
|
|
|
|
public LuckyBoxController(GComponent comModel)
|
|
|
{
|
|
|
_dressUpObjUI = new DressUpObjUI("SceneDressUp");
|
|
|
+ _dressUpObjUI2 = new DressUpObjUI("SceneDressUp");
|
|
|
+
|
|
|
+ _dressUpObjUIs.Add(_dressUpObjUI);
|
|
|
+ _dressUpObjUIs.Add(_dressUpObjUI2);
|
|
|
+
|
|
|
_com = comModel;
|
|
|
}
|
|
|
|
|
|
+ private bool showNoAnim;
|
|
|
public void OnShown(int luckyBoxId)
|
|
|
{
|
|
|
+ showNoAnim = true;
|
|
|
// _comModel = UI_ComModel.Proxy(_com);
|
|
|
_curTime = _turnTime;
|
|
|
_luckyBoxCfg = LuckyBoxCfgArray.Instance.GetCfg(luckyBoxId);
|
|
|
_com.GetChild("loaMask").asLoader.url = ResPathUtil.GetBgImgPath(_luckyBoxCfg.bgResArr[_bgIndex]);
|
|
|
+ InitDressUpObj();
|
|
|
ChangeRes();
|
|
|
+
|
|
|
Timers.inst.Remove(UpdateTime);
|
|
|
if (_luckyBoxCfg.resArr.Length > 1 || _luckyBoxCfg.suitIdArr.Length > 1)
|
|
|
{
|
|
@@ -52,24 +73,33 @@ namespace GFGGame
|
|
|
_modelIndex = _modelIndex + 1 == _luckyBoxCfg.suitIdArr.Length ? 0 : _modelIndex + 1;
|
|
|
}
|
|
|
|
|
|
- _com.GetTransition("t0").Play(ChangeRes);
|
|
|
- // ChangeRes();
|
|
|
+ if(_luckyBoxCfg.isAni == 0)
|
|
|
+ {
|
|
|
+ _com.GetTransition("t0").Play(ChangeRes);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ HideModel();
|
|
|
+ UpdateIndex();
|
|
|
+ ChangeRes();
|
|
|
+ }
|
|
|
}
|
|
|
- // private void UpdateRes()
|
|
|
- // {
|
|
|
- // Timers.inst.StartCoroutine(ChangeRes());
|
|
|
- // }
|
|
|
+
|
|
|
+ private int _index = 0;
|
|
|
+
|
|
|
private void ChangeRes()
|
|
|
{
|
|
|
UI_ComModel _comModel = UI_ComModel.Proxy(_com);
|
|
|
+
|
|
|
+ UI_ComModelRes comRes = _comModel.m_comModelRes;
|
|
|
_comModel.m_loaBg.url = ResPathUtil.GetBgImgPath(_luckyBoxCfg.bgResArr[_bgIndex]);
|
|
|
if (_luckyBoxCfg.resArr.Length > 0)
|
|
|
{
|
|
|
int direction = _luckyBoxCfg.scaleArr[_modelIndex] >= 0 ? 1 : -1;
|
|
|
float scale = _luckyBoxCfg.scaleArr.Length > 0 ? Math.Abs(_luckyBoxCfg.scaleArr[_modelIndex]) / 10000f : 1;
|
|
|
- _comModel.m_comModelRes.m_loaRes.url = string.Format("ui://LuckyBox/{0}", _luckyBoxCfg.resArr[_modelIndex]);
|
|
|
- _comModel.m_comModelRes.m_loaRes.SetPosition(_luckyBoxCfg.posArr[_modelIndex][0], _luckyBoxCfg.posArr[_modelIndex][1], 1);
|
|
|
- _comModel.m_comModelRes.m_loaRes.SetScale(direction * scale, scale);
|
|
|
+ comRes.m_loaRes.url = string.Format("ui://LuckyBox/{0}", _luckyBoxCfg.resArr[_modelIndex]);
|
|
|
+ comRes.m_loaRes.SetPosition(_luckyBoxCfg.posArr[_modelIndex][0], _luckyBoxCfg.posArr[_modelIndex][1], 1);
|
|
|
+ comRes.m_loaRes.SetScale(direction * scale, scale);
|
|
|
}
|
|
|
else if (_luckyBoxCfg.suitIdArr.Length > 0)
|
|
|
{
|
|
@@ -80,36 +110,76 @@ namespace GFGGame
|
|
|
}
|
|
|
if (_luckyBoxCfg.isAni == 0)
|
|
|
{
|
|
|
+ _comModel.m_loaMask.visible = true;
|
|
|
SuitCfg suitCfg = SuitCfgArray.Instance.GetCfg(_luckyBoxCfg.suitIdArr[_modelIndex]);
|
|
|
- _comModel.m_comModelRes.m_loaRes.url = ResPathUtil.GetDressUpPath(suitCfg.aniRes);
|
|
|
-
|
|
|
+ comRes.m_loaRes.url = ResPathUtil.GetDressUpPath(suitCfg.aniRes);
|
|
|
float scale = _luckyBoxCfg.scaleArr.Length > 0 ? Math.Abs(_luckyBoxCfg.scaleArr[_modelIndex]) / 10000f : 1;
|
|
|
- _comModel.m_comModelRes.m_loaRes.SetScale(direction * scale, scale);
|
|
|
- _comModel.m_comModelRes.m_loaRes.SetPosition(_luckyBoxCfg.posArr[_modelIndex][0], _luckyBoxCfg.posArr[_modelIndex][1], 1);
|
|
|
+ comRes.m_loaRes.SetScale(direction * scale, scale);
|
|
|
+ comRes.m_loaRes.SetPosition(_luckyBoxCfg.posArr[_modelIndex][0], _luckyBoxCfg.posArr[_modelIndex][1], 1);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- _comModel.m_comModelRes.m_loaRes.url = "";
|
|
|
- _comModel.m_loaMask.alpha = 1;
|
|
|
- // yield return null;
|
|
|
+ _comModel.m_loaMask.visible = false;
|
|
|
+ comRes = (_index == 0 ? _comModel.m_comModelRes : _comModel.m_comModelRes2);
|
|
|
int scale = _luckyBoxCfg.scaleArr.Length > 0 ? Math.Abs(_luckyBoxCfg.scaleArr[_modelIndex]) / 10000 : 100;
|
|
|
- _dressUpObjUI.ResetSceneObj(scale, false, false, null, false);
|
|
|
- _dressUpObjUI.dressUpObj.PutOnSuitCfg(_luckyBoxCfg.suitIdArr[_modelIndex], true, new int[] { ConstDressUpItemType.BEI_JING }, false, false);
|
|
|
- _dressUpObjUI.UpdateWrapper(_comModel.m_comModelRes.m_holder);
|
|
|
- _dressUpObjUI.sceneObject.transform.localScale = new Vector3(direction * scale, scale, scale);
|
|
|
- _comModel.m_comModelRes.m_holder.SetPosition(_luckyBoxCfg.posArr[_modelIndex][0], _luckyBoxCfg.posArr[_modelIndex][1], 1);
|
|
|
- // yield return null;
|
|
|
+ _comModel.m_loaMask.alpha = 1;
|
|
|
+ comRes.m_loaRes.url = "";
|
|
|
+ _dressUpObjUIs[_index].UpdateWrapper(comRes.m_holder);
|
|
|
+ comRes.m_holder.SetPosition(_luckyBoxCfg.posArr[_modelIndex][0], _luckyBoxCfg.posArr[_modelIndex][1], 1);
|
|
|
+ _dressUpObjUIs[_index].ResetSceneObj(scale, false, false, null, false);
|
|
|
+ _dressUpObjUIs[_index].dressUpObj.PutOnSuitCfg(_luckyBoxCfg.suitIdArr[_modelIndex], true, new int[] { ConstDressUpItemType.BEI_JING }, false, false);
|
|
|
+ Timers.inst.StartCoroutine(DelayShowModel(direction));
|
|
|
+
|
|
|
}
|
|
|
}
|
|
|
- _comModel.m_t1.Play();
|
|
|
+ if (_luckyBoxCfg.isAni == 0)
|
|
|
+ {
|
|
|
+ _com.GetTransition("t1").Play();
|
|
|
+ }
|
|
|
UI_ComModel.ProxyEnd();
|
|
|
}
|
|
|
|
|
|
+ private IEnumerator DelayShowModel(int direction)
|
|
|
+ {
|
|
|
+ _dressUpObjUIs[_index].sceneObject.transform.localScale = Vector3.zero;
|
|
|
+
|
|
|
+ // 未加载到live2D之前,不做显示
|
|
|
+ while (!InitModel(_index))
|
|
|
+ {
|
|
|
+ yield return new WaitForEndOfFrame();
|
|
|
+ }
|
|
|
+
|
|
|
+ int scale = _luckyBoxCfg.scaleArr.Length > 0 ? Math.Abs(_luckyBoxCfg.scaleArr[_modelIndex]) / 10000 : 100;
|
|
|
+ _dressUpObjUIs[_index].sceneObject.transform.localScale = new Vector3(direction * scale, scale, scale);
|
|
|
+ //if (showNoAnim)
|
|
|
+ //{
|
|
|
+ // ChangeModelAlpha(_index, 1);
|
|
|
+ // showNoAnim = false;
|
|
|
+ //}
|
|
|
+ //else
|
|
|
+ //{
|
|
|
+ // ShowModel();
|
|
|
+ //}
|
|
|
+ ShowModel();
|
|
|
+ }
|
|
|
+
|
|
|
public void OnHide()
|
|
|
{
|
|
|
+ DOTween.Kill("fade");
|
|
|
_bgIndex = 0;
|
|
|
_modelIndex = 0;
|
|
|
- _dressUpObjUI.ResetSceneObj(0, false, false, null, false);
|
|
|
+ _dressUpObjUI.dressUpObj.TakeOffAll();
|
|
|
+
|
|
|
+ // 隐藏另一个模型
|
|
|
+ if (_dressUpObjUIs[0].sceneObject != null)
|
|
|
+ {
|
|
|
+ _dressUpObjUIs[0].sceneObject.transform.localScale = Vector3.zero;
|
|
|
+ }
|
|
|
+ if (_dressUpObjUIs[1].sceneObject != null)
|
|
|
+ {
|
|
|
+ _dressUpObjUIs[1].sceneObject.transform.localScale = Vector3.zero;
|
|
|
+ }
|
|
|
+
|
|
|
UI_ComModel _comModel = UI_ComModel.Proxy(_com);
|
|
|
_comModel.m_comModelRes.m_loaRes.url = "";
|
|
|
UI_ComModel.ProxyEnd();
|
|
@@ -123,6 +193,108 @@ namespace GFGGame
|
|
|
_dressUpObjUI.Dispose();
|
|
|
_dressUpObjUI = null;
|
|
|
}
|
|
|
+
|
|
|
+ if (_dressUpObjUI2 != null)
|
|
|
+ {
|
|
|
+ _dressUpObjUI2.Dispose();
|
|
|
+ _dressUpObjUI2 = null;
|
|
|
+ }
|
|
|
+
|
|
|
+ _dressUpObjUIs.Clear();
|
|
|
+ }
|
|
|
+
|
|
|
+ private void UpdateIndex()
|
|
|
+ {
|
|
|
+ _index ^= 1;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private bool InitModel(int index)
|
|
|
+ {
|
|
|
+ if (_dressUpObjUIs[index].sceneObject == null)
|
|
|
+ {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ Transform model = _dressUpObjUIs[index].sceneObject.transform.Find("Role");
|
|
|
+ modelInfos[index].cubismModels = model.GetComponentsInChildren<CubismRenderController>();
|
|
|
+ modelInfos[index].spriteRenderers = new List<SpriteRenderer>(model.GetComponentsInChildren<SpriteRenderer>());
|
|
|
+ return modelInfos[index].cubismModels.Length > 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void ShowModel()
|
|
|
+ {
|
|
|
+ ChangeModelAlphaAnim(_index, 0, 1);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void HideModel()
|
|
|
+ {
|
|
|
+ InitModel(_index);
|
|
|
+ ChangeModelAlphaAnim(_index, 1, 0);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void ChangeComResLayer()
|
|
|
+ {
|
|
|
+ UI_ComModel _comModel = UI_ComModel.Proxy(_com);
|
|
|
+ int index = _comModel.target.GetChildIndex(_comModel.m_comModelRes.target);
|
|
|
+ int index2 = _comModel.target.GetChildIndex(_comModel.m_comModelRes2.target);
|
|
|
+ _comModel.target.SetChildIndex(_comModel.m_comModelRes.target, index2);
|
|
|
+ _comModel.target.SetChildIndex(_comModel.m_comModelRes2.target, index);
|
|
|
+
|
|
|
+ UI_ComModel.ProxyEnd();
|
|
|
+ }
|
|
|
+
|
|
|
+ private void ChangeModelAlpha(int index, float value)
|
|
|
+ {
|
|
|
+ if(modelInfos[index].cubismModels == null)
|
|
|
+ {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ for (int j = 0; j < modelInfos[index].cubismModels.Length; j++)
|
|
|
+ {
|
|
|
+ modelInfos[index].cubismModels[j].Opacity = value;
|
|
|
+ }
|
|
|
+
|
|
|
+ for (int i = 0; i < modelInfos[index].spriteRenderers.Count; i++)
|
|
|
+ {
|
|
|
+ if (modelInfos[index].spriteRenderers[i] == null)
|
|
|
+ {
|
|
|
+ modelInfos[index].spriteRenderers.RemoveAt(i);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ Color color = modelInfos[index].spriteRenderers[i].color;
|
|
|
+ color.a = value;
|
|
|
+ modelInfos[index].spriteRenderers[i].color = color;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void ChangeModelAlphaAnim(int index, float start, float end, Action action = null)
|
|
|
+ {
|
|
|
+ Ease ease = start < end ? Ease.InQuad : Ease.OutQuad;
|
|
|
+ DOTween.To(() => start, (value) =>
|
|
|
+ {
|
|
|
+ ChangeModelAlpha(index, value);
|
|
|
+ }, end, 0.75f).SetEase(ease).OnComplete(() =>
|
|
|
+ {
|
|
|
+ action?.Invoke();
|
|
|
+ }).SetAutoKill().SetId("fade");
|
|
|
+ }
|
|
|
+
|
|
|
+ private void InitDressUpObj()
|
|
|
+ {
|
|
|
+ modelInfos[0] = new ModelInfo();
|
|
|
+ modelInfos[1] = new ModelInfo();
|
|
|
+
|
|
|
+ UI_ComModel _comModel = UI_ComModel.Proxy(_com);
|
|
|
+ _dressUpObjUI.UpdateWrapper(_comModel.m_comModelRes.m_holder);
|
|
|
+ _dressUpObjUI2.UpdateWrapper(_comModel.m_comModelRes2.m_holder);
|
|
|
+
|
|
|
+ UI_ComModel.ProxyEnd();
|
|
|
+
|
|
|
+ //int temp = 1 - _index;
|
|
|
+ //InitModel(temp);
|
|
|
+ //ChangeModelAlpha(temp, 0);
|
|
|
}
|
|
|
}
|
|
|
}
|