LuckyBoxController.cs 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. using UI.LuckyBox;
  2. using FairyGUI;
  3. using ET;
  4. using System.Collections.Generic;
  5. using System;
  6. using UnityEngine;
  7. using System.Collections;
  8. namespace GFGGame
  9. {
  10. public class LuckyBoxController
  11. {
  12. private GComponent _com;
  13. // private UI_ComModel _comModel;
  14. private DressUpObjUI _dressUpObjUI;
  15. private LuckyBoxCfg _luckyBoxCfg;
  16. private const int _turnTime = 8;
  17. private int _curTime = _turnTime;
  18. private int _bgIndex = 0;
  19. private int _modelIndex = 0;
  20. public LuckyBoxController(GComponent comModel)
  21. {
  22. _dressUpObjUI = new DressUpObjUI("SceneDressUp");
  23. _com = comModel;
  24. }
  25. public void OnShown(int luckyBoxId)
  26. {
  27. // _comModel = UI_ComModel.Proxy(_com);
  28. _curTime = _turnTime;
  29. _luckyBoxCfg = LuckyBoxCfgArray.Instance.GetCfg(luckyBoxId);
  30. _com.GetChild("loaMask").asLoader.url = ResPathUtil.GetBgImgPath(_luckyBoxCfg.bgResArr[_bgIndex]);
  31. ChangeRes();
  32. Timers.inst.Remove(UpdateTime);
  33. if (_luckyBoxCfg.resArr.Length > 1 || _luckyBoxCfg.suitIdArr.Length > 1)
  34. {
  35. Timers.inst.Add(_turnTime, 0, UpdateTime);
  36. }
  37. }
  38. private void UpdateTime(object param)
  39. {
  40. _com.GetChild("loaMask").asLoader.url = ResPathUtil.GetBgImgPath(_luckyBoxCfg.bgResArr[_bgIndex]);
  41. _bgIndex = _bgIndex + 1 == _luckyBoxCfg.bgResArr.Length ? 0 : _bgIndex + 1;
  42. if (_luckyBoxCfg.resArr.Length > 0)
  43. {
  44. _modelIndex = _modelIndex + 1 == _luckyBoxCfg.resArr.Length ? 0 : _modelIndex + 1;
  45. }
  46. else
  47. {
  48. _modelIndex = _modelIndex + 1 == _luckyBoxCfg.suitIdArr.Length ? 0 : _modelIndex + 1;
  49. }
  50. _com.GetTransition("t0").Play(ChangeRes);
  51. // ChangeRes();
  52. }
  53. // private void UpdateRes()
  54. // {
  55. // Timers.inst.StartCoroutine(ChangeRes());
  56. // }
  57. private void ChangeRes()
  58. {
  59. UI_ComModel _comModel = UI_ComModel.Proxy(_com);
  60. _comModel.m_loaBg.url = ResPathUtil.GetBgImgPath(_luckyBoxCfg.bgResArr[_bgIndex]);
  61. if (_luckyBoxCfg.resArr.Length > 0)
  62. {
  63. int direction = _luckyBoxCfg.scaleArr[_modelIndex] >= 0 ? 1 : -1;
  64. float scale = _luckyBoxCfg.scaleArr.Length > 0 ? Math.Abs(_luckyBoxCfg.scaleArr[_modelIndex]) / 10000f : 1;
  65. _comModel.m_comModelRes.m_loaRes.url = string.Format("ui://LuckyBox/{0}", _luckyBoxCfg.resArr[_modelIndex]);
  66. _comModel.m_comModelRes.m_loaRes.SetPosition(_luckyBoxCfg.posArr[_modelIndex][0], _luckyBoxCfg.posArr[_modelIndex][1], 1);
  67. _comModel.m_comModelRes.m_loaRes.SetScale(direction * scale, scale);
  68. }
  69. else if (_luckyBoxCfg.suitIdArr.Length > 0)
  70. {
  71. int direction = 1;
  72. if (_luckyBoxCfg.scaleArr.Length > 0)
  73. {
  74. direction = _luckyBoxCfg.scaleArr[_modelIndex] >= 0 ? 1 : -1;
  75. }
  76. if (_luckyBoxCfg.isAni == 0)
  77. {
  78. SuitCfg suitCfg = SuitCfgArray.Instance.GetCfg(_luckyBoxCfg.suitIdArr[_modelIndex]);
  79. _comModel.m_comModelRes.m_loaRes.url = ResPathUtil.GetDressUpPath(suitCfg.aniRes);
  80. float scale = _luckyBoxCfg.scaleArr.Length > 0 ? Math.Abs(_luckyBoxCfg.scaleArr[_modelIndex]) / 10000f : 1;
  81. _comModel.m_comModelRes.m_loaRes.SetScale(direction * scale, scale);
  82. _comModel.m_comModelRes.m_loaRes.SetPosition(_luckyBoxCfg.posArr[_modelIndex][0], _luckyBoxCfg.posArr[_modelIndex][1], 1);
  83. }
  84. else
  85. {
  86. _comModel.m_comModelRes.m_loaRes.url = "";
  87. _comModel.m_loaMask.alpha = 1;
  88. // yield return null;
  89. int scale = _luckyBoxCfg.scaleArr.Length > 0 ? Math.Abs(_luckyBoxCfg.scaleArr[_modelIndex]) / 10000 : 100;
  90. _dressUpObjUI.ResetSceneObj(scale, false, false, null, false);
  91. _dressUpObjUI.dressUpObj.PutOnSuitCfg(_luckyBoxCfg.suitIdArr[_modelIndex], true, new int[] { ConstDressUpItemType.BEI_JING }, false, false);
  92. _dressUpObjUI.UpdateWrapper(_comModel.m_comModelRes.m_holder);
  93. _dressUpObjUI.sceneObject.transform.localScale = new Vector3(direction * scale, scale, scale);
  94. _comModel.m_comModelRes.m_holder.SetPosition(_luckyBoxCfg.posArr[_modelIndex][0], _luckyBoxCfg.posArr[_modelIndex][1], 1);
  95. // yield return null;
  96. }
  97. }
  98. _comModel.m_t1.Play();
  99. UI_ComModel.ProxyEnd();
  100. }
  101. public void OnHide()
  102. {
  103. _bgIndex = 0;
  104. _modelIndex = 0;
  105. _dressUpObjUI.ResetSceneObj(0, false, false, null, false);
  106. UI_ComModel _comModel = UI_ComModel.Proxy(_com);
  107. _comModel.m_comModelRes.m_loaRes.url = "";
  108. UI_ComModel.ProxyEnd();
  109. Timers.inst.Remove(UpdateTime);
  110. }
  111. public void Dispose()
  112. {
  113. if (_dressUpObjUI != null)
  114. {
  115. _dressUpObjUI.Dispose();
  116. _dressUpObjUI = null;
  117. }
  118. }
  119. }
  120. }