123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128 |
- using UI.LuckyBox;
- using FairyGUI;
- using ET;
- using System.Collections.Generic;
- using System;
- using UnityEngine;
- using System.Collections;
- namespace GFGGame
- {
- public class LuckyBoxController
- {
- private GComponent _com;
- // private UI_ComModel _comModel;
- private DressUpObjUI _dressUpObjUI;
- private LuckyBoxCfg _luckyBoxCfg;
- private const int _turnTime = 8;
- private int _curTime = _turnTime;
- private int _bgIndex = 0;
- private int _modelIndex = 0;
- public LuckyBoxController(GComponent comModel)
- {
- _dressUpObjUI = new DressUpObjUI("SceneDressUp");
- _com = comModel;
- }
- public void OnShown(int luckyBoxId)
- {
- // _comModel = UI_ComModel.Proxy(_com);
- _curTime = _turnTime;
- _luckyBoxCfg = LuckyBoxCfgArray.Instance.GetCfg(luckyBoxId);
- _com.GetChild("loaMask").asLoader.url = ResPathUtil.GetBgImgPath(_luckyBoxCfg.bgResArr[_bgIndex]);
- ChangeRes();
- Timers.inst.Remove(UpdateTime);
- if (_luckyBoxCfg.resArr.Length > 1 || _luckyBoxCfg.suitIdArr.Length > 1)
- {
- Timers.inst.Add(_turnTime, 0, UpdateTime);
- }
- }
- private void UpdateTime(object param)
- {
- _com.GetChild("loaMask").asLoader.url = ResPathUtil.GetBgImgPath(_luckyBoxCfg.bgResArr[_bgIndex]);
- _bgIndex = _bgIndex + 1 == _luckyBoxCfg.bgResArr.Length ? 0 : _bgIndex + 1;
- if (_luckyBoxCfg.resArr.Length > 0)
- {
- _modelIndex = _modelIndex + 1 == _luckyBoxCfg.resArr.Length ? 0 : _modelIndex + 1;
- }
- else
- {
- _modelIndex = _modelIndex + 1 == _luckyBoxCfg.suitIdArr.Length ? 0 : _modelIndex + 1;
- }
- _com.GetTransition("t0").Play(ChangeRes);
- // ChangeRes();
- }
- // private void UpdateRes()
- // {
- // Timers.inst.StartCoroutine(ChangeRes());
- // }
- private void ChangeRes()
- {
- UI_ComModel _comModel = UI_ComModel.Proxy(_com);
- _comModel.m_loaBg.url = ResPathUtil.GetBgImgPath(_luckyBoxCfg.bgResArr[_bgIndex]);
- if (_luckyBoxCfg.resArr.Length > 0)
- {
- int direction = _luckyBoxCfg.scaleArr[_modelIndex] >= 0 ? 1 : -1;
- float scale = _luckyBoxCfg.scaleArr.Length > 0 ? Math.Abs(_luckyBoxCfg.scaleArr[_modelIndex]) / 10000f : 1;
- _comModel.m_comModelRes.m_loaRes.url = string.Format("ui://LuckyBox/{0}", _luckyBoxCfg.resArr[_modelIndex]);
- _comModel.m_comModelRes.m_loaRes.SetPosition(_luckyBoxCfg.posArr[_modelIndex][0], _luckyBoxCfg.posArr[_modelIndex][1], 1);
- _comModel.m_comModelRes.m_loaRes.SetScale(direction * scale, scale);
- }
- else if (_luckyBoxCfg.suitIdArr.Length > 0)
- {
- int direction = 1;
- if (_luckyBoxCfg.scaleArr.Length > 0)
- {
- direction = _luckyBoxCfg.scaleArr[_modelIndex] >= 0 ? 1 : -1;
- }
- if (_luckyBoxCfg.isAni == 0)
- {
- SuitCfg suitCfg = SuitCfgArray.Instance.GetCfg(_luckyBoxCfg.suitIdArr[_modelIndex]);
- _comModel.m_comModelRes.m_loaRes.url = ResPathUtil.GetDressUpPath(suitCfg.aniRes);
- float scale = _luckyBoxCfg.scaleArr.Length > 0 ? Math.Abs(_luckyBoxCfg.scaleArr[_modelIndex]) / 10000f : 1;
- _comModel.m_comModelRes.m_loaRes.SetScale(direction * scale, scale);
- _comModel.m_comModelRes.m_loaRes.SetPosition(_luckyBoxCfg.posArr[_modelIndex][0], _luckyBoxCfg.posArr[_modelIndex][1], 1);
- }
- else
- {
- _comModel.m_comModelRes.m_loaRes.url = "";
- _comModel.m_loaMask.alpha = 1;
- // yield return null;
- int scale = _luckyBoxCfg.scaleArr.Length > 0 ? Math.Abs(_luckyBoxCfg.scaleArr[_modelIndex]) / 10000 : 100;
- _dressUpObjUI.ResetSceneObj(scale, false, false, null, false);
- _dressUpObjUI.dressUpObj.PutOnSuitCfg(_luckyBoxCfg.suitIdArr[_modelIndex], true, new int[] { ConstDressUpItemType.BEI_JING }, false, false);
- _dressUpObjUI.UpdateWrapper(_comModel.m_comModelRes.m_holder);
- _dressUpObjUI.sceneObject.transform.localScale = new Vector3(direction * scale, scale, scale);
- _comModel.m_comModelRes.m_holder.SetPosition(_luckyBoxCfg.posArr[_modelIndex][0], _luckyBoxCfg.posArr[_modelIndex][1], 1);
- // yield return null;
- }
- }
- _comModel.m_t1.Play();
- UI_ComModel.ProxyEnd();
- }
- public void OnHide()
- {
- _bgIndex = 0;
- _modelIndex = 0;
- _dressUpObjUI.dressUpObj.TakeOffAll();
- UI_ComModel _comModel = UI_ComModel.Proxy(_com);
- _comModel.m_comModelRes.m_loaRes.url = "";
- UI_ComModel.ProxyEnd();
- Timers.inst.Remove(UpdateTime);
- }
- public void Dispose()
- {
- if (_dressUpObjUI != null)
- {
- _dressUpObjUI.Dispose();
- _dressUpObjUI = null;
- }
- }
- }
- }
|