123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- using UnityEngine;
- using System.Collections;
- using Engine.Component;
- using System;
- public class RevertComponent : BaseComponent
- {
- /// <summary>使用时间</summary>
- public float FUseTime = 3f;
- /// <summary>激活时间</summary>
- private float fEnableTime = 0f;
- private bool isOnEnable = false;
- private AudioSource m_source;
- private Action<RevertComponent> ResetCallBackFun;
- /// <summary>组件被激活时</summary>
- void OnEnable()
- {
- fEnableTime = Time.realtimeSinceStartup;
- isOnEnable = true;
- m_source = this.GetComponent<AudioSource> ();
- 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<RevertComponent> callBack)
- {
- ResetCallBackFun = callBack;
- }
- /// <summary>帧函数</summary>
- 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;
- }
- }
|