123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122 |
- using UnityEngine;
- using System.Collections;
- using Newtonsoft.Json.Linq;
- using System;
- public class TiliTime : MonoSingleton<TiliTime>
- {
- private Player player = null;
-
- /// <summary>
- /// 间隔计数用.
- /// </summary>
- private int mIntx = 0;
- /// <summary>
- /// 上一次计算的时间
- /// </summary>
- private long mLastTime = 0;
- /// <summary>
- /// 单键初始化
- /// </summary>
- 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++;
- }
- /// <summary>
- /// 检测体力值是否已经满了
- /// </summary>
- /// <returns></returns>
- 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();
- }
-
- /// <summary>
- /// 发送获取体力的请求
- /// </summary>
- 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;
- }
- /// <summary>
- /// 获取当前时间戳
- /// </summary>
- /// <param name="bflag">为真时获取10位时间戳,为假时获取13位时间戳.</param>
- /// <returns></returns>
- public static long GetTimeStamp() => UserProxy.Instance.GetCurrentUnixTimeStamp();
- }
|