using System.Collections; using System.Collections.Generic; using UnityEngine; using Sirenix.OdinInspector; using UnityCommon; namespace DTYJ { public class PlatformDoorController : SerializedMonoBehaviour { public static PlatformDoorController Instance; private void Awake() { Instance = this; } public Dictionary dicDoors = new Dictionary(); public void SetDoor(string id, int state) { if (state == 1 || state == 0) { if (dicDoors.ContainsKey(id)) { var anim = dicDoors[id]; var animationName = anim.clip.name; anim[animationName].time = state == 1 ? 0 : anim[animationName].length; anim[animationName].speed = state == 1 ? 1 : -1; anim[animationName].wrapMode = WrapMode.Once; anim.CrossFade(animationName); } } } //[ContextMenu("处理")] public void Handle() { var rootSx = GameObject.Find("SceneCommon/Animation/PSDAll_下行/psd_animation/psd_total"); var anims = rootSx.GetComponentsInChildren(); foreach (var anim in anims) { if (anim.gameObject.activeSelf) dicDoors[anim.name] = anim; } var rootXx = GameObject.Find("SceneCommon/Animation/PSDAll_上行/psd_animation/psd_total"); anims = rootXx.GetComponentsInChildren(); foreach (var anim in anims) { if (anim.gameObject.activeSelf) dicDoors[anim.name] = anim; } } [ContextMenu("处理")] public void HandleTemp() { Dictionary dicNew = new Dictionary(); foreach (var kvp in dicDoors) { var animPath = Utility.GetPathInHierichy(kvp.Value.transform, null); dicNew["1_" + kvp.Key] = GameObject.Find("StationOthers/1/" + animPath).GetComponent(); dicNew["2_" + kvp.Key] = GameObject.Find("StationOthers/2/" + animPath).GetComponent(); } foreach (var kvp in dicNew) { dicDoors[kvp.Key] = kvp.Value; } } } }