LuckyBoxController.cs 4.7 KB

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