LuckyBoxController.cs 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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[0]);
  29. if (_luckyBoxCfg.suitShowArr.Length > 0)
  30. {
  31. _dressUpObjUI.ResetSceneObj(100, false, false, null, false);
  32. _dressUpObjUI.dressUpObj.PutOnSuitCfg(_luckyBoxCfg.suitShowArr[0][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.Add(1, 0, UpdateTime);
  38. }
  39. }
  40. private void UpdateTime(object param)
  41. {
  42. _curTime = _curTime - 1 == 0 ? _turnTime : _curTime - 1;
  43. _bgIndex = _bgIndex + 1 == _luckyBoxCfg.resArr.Length ? 0 : _bgIndex + 1;
  44. _modelIndex = _modelIndex + 1 == _luckyBoxCfg.suitShowArr.Length ? 0 : _modelIndex + 1;
  45. if (_curTime == _turnTime)
  46. {
  47. if (_luckyBoxCfg.resArr.Length > 1)
  48. {
  49. _comModel.m_loaBg.url = ResPathUtil.GetBgImgPath(_luckyBoxCfg.resArr[_bgIndex]);
  50. }
  51. if (_luckyBoxCfg.suitShowArr.Length > 0)
  52. {
  53. _dressUpObjUI.ResetSceneObj(100, false, false, null, false);
  54. _dressUpObjUI.dressUpObj.PutOnSuitCfg(_luckyBoxCfg.suitShowArr[_modelIndex][0], true, new int[] { ConstDressUpItemType.BEI_JING }, false, false);
  55. _dressUpObjUI.UpdateWrapper(_comModel.m_holder);
  56. }
  57. }
  58. }
  59. public void OnHide()
  60. {
  61. UI_ComModel.ProxyEnd();
  62. Timers.inst.Remove(UpdateTime);
  63. }
  64. public void Dispose()
  65. {
  66. if (_dressUpObjUI != null)
  67. {
  68. _dressUpObjUI.Dispose();
  69. _dressUpObjUI = null;
  70. }
  71. }
  72. }
  73. }