public static DoorConfig GetDoorConfig(DoorPowerState doorPowerState) { if (specificDoors.ContainsKey(doorPowerState.GetPrefabId())) { return(specificDoors[doorPowerState.GetPrefabId()]); } return(null); }
private void FixedUpdate() { if (!GetComponent <ZNetView>()) { return; //wait for network spawn } bool wasPressed = isPressed; bool newPressed = FindPlayerInRange(); if (newPressed) { List <DoorPowerState> doors = DoorPowerState.FindDoorsInPlateRange(transform.position); float?maxTime = doors.Max(i => i.GetDoorConfig()?.openTime); pressCooldown = maxTime ?? Plugin.plateOpenDelay.Value; isPressed = true; } else { if (pressCooldown > 0) { pressCooldown -= Time.fixedDeltaTime; isPressed = true; } else { isPressed = false; } } bool stateChange = isPressed != wasPressed; Vector3 pos = isPressed ? new Vector3(0f, -0.025f, 0f) : new Vector3(0f, 0.05f, 0f); plate.transform.localPosition = pos; if (stateChange) { if (isPressed) { pressEffects.Create(transform.position, Quaternion.identity); } else { releaseEffects.Create(transform.position, Quaternion.identity); } List <DoorPowerState> doors = DoorPowerState.FindDoorsInPlateRange(transform.position); foreach (DoorPowerState door in doors) { if (isPressed) { door.AddPoweringPlate(this); } else { door.RemovePoweringPlate(this); } } } if (lastPlayer == null) { return; } if (stateChange || isPressed) { List <DoorPowerState> doors = DoorPowerState.FindDoorsInPlateRange(transform.position); foreach (DoorPowerState door in doors) { if (isPressed) { // always open the door if the plate is pressed door.Open(lastPlayer); } else { // only close the door if this is the last plate powering it if (door.GetPoweringPlates().Count(i => i != this) > 0) { continue; } door.Close(lastPlayer); } } } }