using UnityEngine;
using System.Collections;
using Engine.Component;
using System;
public class RevertComponent : BaseComponent
{
/// 使用时间
public float FUseTime = 3f;
/// 激活时间
private float fEnableTime = 0f;
private bool isOnEnable = false;
private AudioSource m_source;
private Action ResetCallBackFun;
/// 组件被激活时
void OnEnable()
{
fEnableTime = Time.realtimeSinceStartup;
isOnEnable = true;
m_source = this.GetComponent ();
if(m_source != null)
GameSoundManager.Instance.Register (m_source, this.gameObject);
}
void OnDisable()
{
if(m_source != null)
GameSoundManager.Instance.UnRegister (m_source);
}
public void SetCallBack(Action callBack)
{
ResetCallBackFun = callBack;
}
/// 帧函数
void Update()
{
if (Time.realtimeSinceStartup - fEnableTime >= FUseTime)
{
Revert();
}
}
public void Revert()
{
isOnEnable = false;
if (ResetCallBackFun != null)
{
ResetCallBackFun.Invoke(this);
ResetCallBackFun = null;
}
PrefabManager.Instance.RevertPrefab(this.gameObject, this.gameObject.name);
this.transform.parent = null;
}
}