LuckyBoxController.cs 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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 = 8;
  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. if (_curTime == _turnTime)
  45. {
  46. _bgIndex = _bgIndex + 1 == _luckyBoxCfg.resArr.Length ? 0 : _bgIndex + 1;
  47. _modelIndex = _modelIndex + 1 == _luckyBoxCfg.suitShowArr.Length ? 0 : _modelIndex + 1;
  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. _dressUpObjUI.ResetSceneObj(0, false, false, null, false);
  67. }
  68. public void Dispose()
  69. {
  70. if (_dressUpObjUI != null)
  71. {
  72. _dressUpObjUI.Dispose();
  73. _dressUpObjUI = null;
  74. }
  75. }
  76. }
  77. }