DogSide.cs 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. namespace DuckHunter
  6. {
  7. public class DogSide : MonoBehaviour
  8. {
  9. public static DogSide Instance;
  10. DragonBones.UnityArmatureComponent armature;
  11. public Action onExit;
  12. void Start()
  13. {
  14. Instance = this;
  15. armature = GetComponentInChildren<DragonBones.UnityArmatureComponent>();
  16. armature.AddEventListener(DragonBones.EventObject.FRAME_EVENT, OnAnimationEventHandler);
  17. armature.AddEventListener(DragonBones.EventObject.COMPLETE, OnAnimationEventHandler);
  18. armature.animation.Play("enter", 1);
  19. }
  20. private void OnAnimationEventHandler(string type, DragonBones.EventObject eventObject)
  21. {
  22. if (eventObject.type == DragonBones.EventObject.FRAME_EVENT)
  23. {
  24. if (eventObject.name == "layer")
  25. transform.SetSiblingIndex(transform.parent.Find("BGFront").GetSiblingIndex());
  26. }
  27. else if (eventObject.type == DragonBones.EventObject.COMPLETE)
  28. {
  29. Destroy(gameObject);
  30. onExit?.Invoke();
  31. }
  32. // Debug.Log(string.Format("animationName:{0},eventType:{1},eventName:{2}", eventObject.animationState.name, type, eventObject.name));
  33. }
  34. void OnDestroy()
  35. {
  36. if (Instance == this) Instance = null;
  37. }
  38. }
  39. }