LuckyBoxController.cs 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. _comModel.m_loaBg.url = ResPathUtil.GetBgImgPath(_luckyBoxCfg.resArr[_bgIndex]);
  30. if (_luckyBoxCfg.suitShowArr.Length > 0)
  31. {
  32. int scale = 100;
  33. int direction = 1;
  34. if (_luckyBoxCfg.scaleArr.Length > 0)
  35. {
  36. scale = Math.Abs(_luckyBoxCfg.scaleArr[_modelIndex]);
  37. direction = _luckyBoxCfg.scaleArr[_modelIndex] >= 0 ? 1 : -1;
  38. }
  39. _dressUpObjUI.ResetSceneObj(scale, false, false, null, false);
  40. _dressUpObjUI.dressUpObj.PutOnSuitCfg(_luckyBoxCfg.suitShowArr[_modelIndex][0], true, new int[] { ConstDressUpItemType.BEI_JING }, false, false);
  41. _dressUpObjUI.UpdateWrapper(_comModel.m_holder);
  42. _dressUpObjUI.sceneObject.transform.localPosition = new Vector3(_luckyBoxCfg.suitShowArr[_modelIndex][1], _luckyBoxCfg.suitShowArr[_modelIndex][2], 0);
  43. _dressUpObjUI.sceneObject.transform.localScale = new Vector3(direction * scale, scale, scale);
  44. }
  45. if (_luckyBoxCfg.resArr.Length > 1 || _luckyBoxCfg.suitShowArr.Length > 1)
  46. {
  47. Timers.inst.Remove(UpdateTime);
  48. Timers.inst.Add(1, 0, UpdateTime);
  49. }
  50. }
  51. private void UpdateTime(object param)
  52. {
  53. _curTime = _curTime - 1 == 0 ? _turnTime : _curTime - 1;
  54. if (_curTime == _turnTime)
  55. {
  56. _bgIndex = _bgIndex + 1 == _luckyBoxCfg.resArr.Length ? 0 : _bgIndex + 1;
  57. _modelIndex = _modelIndex + 1 == _luckyBoxCfg.suitShowArr.Length ? 0 : _modelIndex + 1;
  58. if (_luckyBoxCfg.resArr.Length > 1)
  59. {
  60. _comModel.m_loaBg.url = ResPathUtil.GetBgImgPath(_luckyBoxCfg.resArr[_bgIndex]);
  61. }
  62. if (_luckyBoxCfg.suitShowArr.Length > 0)
  63. {
  64. int scale = 100;
  65. int direction = 1;
  66. if (_luckyBoxCfg.scaleArr.Length > 0)
  67. {
  68. scale = Math.Abs(_luckyBoxCfg.scaleArr[_modelIndex]);
  69. direction = _luckyBoxCfg.scaleArr[_modelIndex] >= 0 ? 1 : -1;
  70. }
  71. _dressUpObjUI.ResetSceneObj(scale, false, false, null, false);
  72. _dressUpObjUI.dressUpObj.PutOnSuitCfg(_luckyBoxCfg.suitShowArr[_modelIndex][0], true, new int[] { ConstDressUpItemType.BEI_JING }, false, false);
  73. _dressUpObjUI.UpdateWrapper(_comModel.m_holder);
  74. _dressUpObjUI.sceneObject.transform.localPosition = new Vector3(_luckyBoxCfg.suitShowArr[_modelIndex][1], _luckyBoxCfg.suitShowArr[_modelIndex][2], 0);
  75. _dressUpObjUI.sceneObject.transform.localScale = new Vector3(direction * scale, scale, scale);
  76. }
  77. }
  78. }
  79. public void OnHide()
  80. {
  81. UI_ComModel.ProxyEnd();
  82. Timers.inst.Remove(UpdateTime);
  83. _bgIndex = 0;
  84. _modelIndex = 0;
  85. _dressUpObjUI.ResetSceneObj(0, false, false, null, false);
  86. }
  87. public void Dispose()
  88. {
  89. if (_dressUpObjUI != null)
  90. {
  91. _dressUpObjUI.Dispose();
  92. _dressUpObjUI = null;
  93. }
  94. }
  95. }
  96. }