You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
61 lines
2.0 KiB
61 lines
2.0 KiB
4 years ago
|
using AX.MessageSystem;
|
||
|
using System;
|
||
|
using System.Collections;
|
||
|
using System.Collections.Generic;
|
||
|
using UnityEngine;
|
||
|
|
||
|
public class BurnTimer : MonoBehaviour {
|
||
|
private static string burnTime = "";
|
||
|
private static float burnHours = 0;
|
||
|
public static bool isBurning=false;
|
||
|
public Transform p_firenormal;
|
||
|
public Transform p_fireliquid;
|
||
|
void Start()
|
||
|
{
|
||
|
if(p_firenormal ==null)
|
||
|
{
|
||
|
p_firenormal = transform.Find("P_FireNormal").transform;
|
||
|
}
|
||
|
if (p_fireliquid == null)
|
||
|
{
|
||
|
p_fireliquid=GameObject.Find("P_FireLiquidLevel").transform;
|
||
|
}
|
||
|
MessageDispatcher.AddListener("BurnTimeSet", BurnTimeSet);
|
||
|
}
|
||
|
void OnDestroy()
|
||
|
{
|
||
|
MessageDispatcher.RemoveListener("BurnTimeSet", BurnTimeSet);
|
||
|
}
|
||
|
void BurnTimeSet(IMessage obj)
|
||
|
{
|
||
|
if(p_fireliquid !=null && p_firenormal != null)
|
||
|
{
|
||
|
//如果没有火了,以当前时间为结束时间计算燃烧时间
|
||
|
if (p_firenormal.childCount == 0 && p_fireliquid.childCount == 0)
|
||
|
{
|
||
|
isBurning = false;
|
||
|
burnTime = TIME_SYNC.time;
|
||
|
DateTime time = Convert.ToDateTime(burnTime);
|
||
|
TimeSpan duration = time.TimeOfDay;
|
||
|
burnHours = (float)duration.TotalHours;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
public static float BurnTime
|
||
|
{
|
||
|
get
|
||
|
{
|
||
|
if (isBurning) //如果还在燃烧,就以当前时间为结束计算燃烧时间
|
||
|
{
|
||
|
burnTime = TIME_SYNC.time;
|
||
|
DateTime time = Convert.ToDateTime(burnTime);
|
||
|
TimeSpan duration = time.TimeOfDay;
|
||
|
burnHours = (float)duration.TotalHours;
|
||
|
}
|
||
|
//如果没有燃烧,一种情况是没有设置火,此时burnHours返回初始值0
|
||
|
//另一情况是火全灭,burnHours已在BurnTimeSet方法中赋值
|
||
|
return burnHours;
|
||
|
}
|
||
|
}
|
||
|
}
|