LuckyBoxController.cs 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. using UI.LuckyBox;
  2. using FairyGUI;
  3. using ET;
  4. using System.Collections.Generic;
  5. using System;
  6. namespace GFGGame
  7. {
  8. public class LuckyBoxController
  9. {
  10. private GComponent _com;
  11. private UI_ComModel _comModel;
  12. private DressUpObjUI _dressUpObjUI;
  13. private LuckyBoxCfg _luckyBoxCfg;
  14. private const int _turnTime = 3;
  15. private int _curTime = _turnTime;
  16. private int _bgIndex = 0;
  17. private int _modelIndex = 0;
  18. public LuckyBoxController(GComponent comModel)
  19. {
  20. _dressUpObjUI = new DressUpObjUI("SceneDressUp");
  21. _com = comModel;
  22. }
  23. public void OnShown(int luckyBoxId)
  24. {
  25. _comModel = UI_ComModel.Proxy(_com);
  26. _curTime = _turnTime;
  27. _luckyBoxCfg = LuckyBoxCfgArray.Instance.GetCfg(luckyBoxId);
  28. _comModel.m_loaBg.url = ResPathUtil.GetBgImgPath(_luckyBoxCfg.resArr[_bgIndex]);
  29. if (_luckyBoxCfg.suitShowArr.Length > 0)
  30. {
  31. _dressUpObjUI.ResetSceneObj(100, false, false, null, false);
  32. _dressUpObjUI.dressUpObj.PutOnSuitCfg(_luckyBoxCfg.suitShowArr[_modelIndex][0], true, new int[] { ConstDressUpItemType.BEI_JING }, false, false);
  33. _dressUpObjUI.UpdateWrapper(_comModel.m_holder);
  34. }
  35. if (_luckyBoxCfg.resArr.Length > 1 || _luckyBoxCfg.suitShowArr.Length > 1)
  36. {
  37. Timers.inst.Remove(UpdateTime);
  38. Timers.inst.Add(1, 0, UpdateTime);
  39. }
  40. }
  41. private void UpdateTime(object param)
  42. {
  43. _curTime = _curTime - 1 == 0 ? _turnTime : _curTime - 1;
  44. _bgIndex = _bgIndex + 1 == _luckyBoxCfg.resArr.Length ? 0 : _bgIndex + 1;
  45. _modelIndex = _modelIndex + 1 == _luckyBoxCfg.suitShowArr.Length ? 0 : _modelIndex + 1;
  46. if (_curTime == _turnTime)
  47. {
  48. if (_luckyBoxCfg.resArr.Length > 1)
  49. {
  50. _comModel.m_loaBg.url = ResPathUtil.GetBgImgPath(_luckyBoxCfg.resArr[_bgIndex]);
  51. }
  52. if (_luckyBoxCfg.suitShowArr.Length > 0)
  53. {
  54. _dressUpObjUI.ResetSceneObj(100, false, false, null, false);
  55. _dressUpObjUI.dressUpObj.PutOnSuitCfg(_luckyBoxCfg.suitShowArr[_modelIndex][0], true, new int[] { ConstDressUpItemType.BEI_JING }, false, false);
  56. _dressUpObjUI.UpdateWrapper(_comModel.m_holder);
  57. }
  58. }
  59. }
  60. public void OnHide()
  61. {
  62. UI_ComModel.ProxyEnd();
  63. Timers.inst.Remove(UpdateTime);
  64. _bgIndex = 0;
  65. _modelIndex = 0;
  66. }
  67. public void Dispose()
  68. {
  69. if (_dressUpObjUI != null)
  70. {
  71. _dressUpObjUI.Dispose();
  72. _dressUpObjUI = null;
  73. }
  74. }
  75. }
  76. }