ReleaseYourEffect.cs 963 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. using System;
  2. using UnityEngine;
  3. using Xft;
  4. public class ReleaseYourEffect : MonoBehaviour
  5. {
  6. private void Start()
  7. {
  8. this.YourEffect.Initialize();
  9. }
  10. private void InstantiateEffect()
  11. {
  12. GameObject gameObject = UnityEngine.Object.Instantiate<GameObject>(this.YourEffect.gameObject, Vector3.zero, Quaternion.identity);
  13. XffectComponent component = gameObject.GetComponent<XffectComponent>();
  14. component.Active();
  15. }
  16. private void ReleasePooledEffect(string effectName)
  17. {
  18. XffectComponent effect = this.EffectPool.GetEffect(effectName);
  19. effect.Active();
  20. }
  21. private void OnGUI()
  22. {
  23. if (GUI.Button(new Rect(0f, 0f, 350f, 30f), "instantiate a new effect"))
  24. {
  25. this.InstantiateEffect();
  26. }
  27. if (GUI.Button(new Rect(0f, 30f, 350f, 30f), "instantiate effect from EffectCache"))
  28. {
  29. this.ReleasePooledEffect("sample_effect");
  30. }
  31. }
  32. public XffectComponent YourEffect;
  33. public XffectCache EffectPool;
  34. }