//-------------------------------------------------------- // [Author]: 第二世界 // [ Date ]: Monday, November 27, 2017 //-------------------------------------------------------- using System; using System.Collections; using System.Collections.Generic; using System.Text; using UnityEngine; using UnityEngine.UI; //战斗力增加 namespace vnxbqy.UI { public class PowerAddWin : Window { [SerializeField] Text m_PowerText;//用来获取战斗力 private int prowNum = 0; #region Built-in private int Length = 0;//所需长度 private ulong Finalvalue = 0;//最终值 ulong Default = 0; int Value = -1; private float lastTime = 0; [Header("停留速度")] public float StaySpeed = 1.5f; [Header("滚动速度")] public double RollingSpeed = 0.1f; private float lastTime1 = 0; [SerializeField] RectTransform m_ContainerDisplay; [SerializeField] List powerUpPositions; PlayerMainDate m_MainModel; PlayerMainDate onMainModel { get { return m_MainModel ?? (m_MainModel = ModelCenter.Instance.GetModel()); } } protected override void BindController() { } protected override void AddListeners() { } protected override void OnPreOpen() { onMainModel.AddPowerEvent += Init; Init(); } void Init() { lastTime = 0; lastTime1 = 0; Default = Finalvalue; //直接变成上一次未结束的值 Finalvalue += onMainModel.ProwNumAdd; Length = Finalvalue.ToString().Length; BFairyAuRewards(Finalvalue); CheckPosition(); } protected override void OnAfterOpen() { } protected override void OnPreClose() { onMainModel.AddPowerEvent -= Init; Finalvalue = 0; } protected override void OnAfterClose() { } StringBuilder theTarget = new StringBuilder();//目标值 StringBuilder variation = new StringBuilder();//变化值 void BFairyAuRewards(ulong Number) { Finalvalue = Number; Value = Length - 1; int length = 0; length = Finalvalue.ToString().Length; theTarget.Length = 0; theTarget.Append('0', Length - length); theTarget.Append(Finalvalue); theTarget.ToString(); variation.Length = 0; variation.Append('0', Length); } protected override void LateUpdate() { if (Value < 0) { lastTime += Time.deltaTime; if (lastTime >= StaySpeed) { Close(); } return; } lastTime1 += Time.deltaTime; if (lastTime1>= RollingSpeed) { if (theTarget[Value] != variation[Value]) { Default += (ulong)Mathf.Pow(10, Length - 1 - Value); variation.Length = 0; int length = Default.ToString().Length; variation.Append('0', Length - length); variation.Append(Default); variation.ToString(); m_PowerText.text = "+" + variation.ToString(); } else Value--; lastTime1 = 0; } } #endregion void CheckPosition() { var type = WindowType.None; if (WindowCenter.Instance.IsOpen()) { type = WindowType.TreasureLevelUp; } else if (WindowCenter.Instance.IsOpen()) { type = WindowType.Realm; } var _index = powerUpPositions.FindIndex((x)=> { return x.windowType == type; }); if (_index != -1) { m_ContainerDisplay.transform.localPosition = powerUpPositions[_index].position; } } [Serializable] public struct PowerUpPosition { public WindowType windowType; public Vector3 position; } public enum WindowType { None, TreasureLevelUp, Realm, } } }