using UnityEngine; using System.Collections; using Newtonsoft.Json.Linq; using System; public class TiliTime : MonoSingleton { private Player player = null; /// /// 间隔计数用. /// private int mIntx = 0; /// /// 上一次计算的时间 /// private long mLastTime = 0; /// /// 单键初始化 /// protected override void OnAwake() { player = UserProxy.Instance.player; mLastTime = player.PrivateState.TiliTime; base.OnAwake(); } public void Init() { player = UserProxy.Instance.player; mLastTime = player.PrivateState.TiliTime; } // Use this for initialization void Start() { player = UserProxy.Instance.player; mLastTime = player.PrivateState.TiliTime; } // Update is called once per frame void Update() { if (mIntx > 10) { mIntx = 0; long tempTime = GetTimeStamp() - mLastTime; if (tempTime > 300) { int temptili = (int)( (int)(tempTime / 300)); mLastTime = GetTimeStamp(); if (!CheckTiliIsFull()) { AddTili(temptili); } } } mIntx++; } /// /// 检测体力值是否已经满了 /// /// private bool CheckTiliIsFull() { if (player.baseInfo.tili > 119) { return true; } return false; } private void AddTili(int temptili) { player.baseInfo.tili += temptili; // LogHelper.Log("检测溢出"+ player.curPower); if (player.baseInfo.tili > 120) { player.baseInfo.tili = 120; } player.myAccountChangedDelegate?.Invoke(); } /// /// 发送获取体力的请求 /// public void SendTili() { } public void InitTili() { } public void SetTiliTime(long temptime) { mLastTime = temptime; if (null != UserProxy.Instance.player.myAccountChangedDelegate) { UserProxy.Instance.player.myAccountChangedDelegate.Invoke(); } } public long GetTiliTime() { return mLastTime; } /// /// 获取当前时间戳 /// /// 为真时获取10位时间戳,为假时获取13位时间戳. /// public static long GetTimeStamp() => UserProxy.Instance.GetCurrentUnixTimeStamp(); }