PlatformDoorController.cs 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using Sirenix.OdinInspector;
  5. using UnityCommon;
  6. namespace DTYJ
  7. {
  8. public class PlatformDoorController : SerializedMonoBehaviour
  9. {
  10. public static PlatformDoorController Instance;
  11. private void Awake()
  12. {
  13. Instance = this;
  14. }
  15. public Dictionary<string, Animation> dicDoors = new Dictionary<string, Animation>();
  16. public void SetDoor(string id, int state)
  17. {
  18. if (state == 1 || state == 0)
  19. {
  20. if (dicDoors.ContainsKey(id))
  21. {
  22. var anim = dicDoors[id];
  23. var animationName = anim.clip.name;
  24. anim[animationName].time = state == 1 ? 0 : anim[animationName].length;
  25. anim[animationName].speed = state == 1 ? 1 : -1;
  26. anim[animationName].wrapMode = WrapMode.Once;
  27. anim.CrossFade(animationName);
  28. }
  29. }
  30. }
  31. //[ContextMenu("´¦Àí")]
  32. public void Handle()
  33. {
  34. var rootSx = GameObject.Find("SceneCommon/Animation/PSDAll_ÏÂÐÐ/psd_animation/psd_total");
  35. var anims = rootSx.GetComponentsInChildren<Animation>();
  36. foreach (var anim in anims)
  37. {
  38. if (anim.gameObject.activeSelf)
  39. dicDoors[anim.name] = anim;
  40. }
  41. var rootXx = GameObject.Find("SceneCommon/Animation/PSDAll_ÉÏÐÐ/psd_animation/psd_total");
  42. anims = rootXx.GetComponentsInChildren<Animation>();
  43. foreach (var anim in anims)
  44. {
  45. if (anim.gameObject.activeSelf)
  46. dicDoors[anim.name] = anim;
  47. }
  48. }
  49. [ContextMenu("´¦Àí")]
  50. public void HandleTemp()
  51. {
  52. Dictionary<string, Animation> dicNew = new Dictionary<string, Animation>();
  53. foreach (var kvp in dicDoors)
  54. {
  55. var animPath = Utility.GetPathInHierichy(kvp.Value.transform, null);
  56. dicNew["1_" + kvp.Key] = GameObject.Find("StationOthers/1/" + animPath).GetComponent<Animation>();
  57. dicNew["2_" + kvp.Key] = GameObject.Find("StationOthers/2/" + animPath).GetComponent<Animation>();
  58. }
  59. foreach (var kvp in dicNew)
  60. {
  61. dicDoors[kvp.Key] = kvp.Value;
  62. }
  63. }
  64. }
  65. }