Survivalcraft API 1.8.2.3 v1.8.2.3
Survivalcraft 2.4
载入中...
搜索中...
未找到
ButtonElectricElement.cs
浏览该文件的文档.
1using Engine;
2
3namespace Game {
5 public float m_pressedVoltage;
6
7 public float m_voltage;
8
9 public bool m_wasPressed;
10
11 public ButtonElectricElement(SubsystemElectricity subsystemElectricity, CellFace cellFace, int value) : base(subsystemElectricity, cellFace) {
12 int voltageLevel = ButtonBlock.GetVoltageLevel(Terrain.ExtractData(value));
13 m_pressedVoltage = voltageLevel / 15f;
14 }
15
16 public void Press() {
17 if (!m_wasPressed
18 && m_voltage == 0f) {
19 m_wasPressed = true;
20 CellFace cellFace = CellFaces[0];
21 SubsystemElectricity.SubsystemAudio.PlaySound("Audio/Click", 1f, 0f, new Vector3(cellFace.X, cellFace.Y, cellFace.Z), 2f, true);
23 }
24 }
25
26 public override float GetOutputVoltage(int face) => m_voltage;
27
28 public override bool Simulate() {
29 float voltage = m_voltage;
30 if (m_wasPressed) {
31 m_wasPressed = false;
34 }
35 else {
36 m_voltage = 0f;
37 }
38 return m_voltage != voltage;
39 }
40
41 public override bool OnInteract(TerrainRaycastResult raycastResult, ComponentMiner componentMiner) {
42 Press();
43 return true;
44 }
45
46 public override void OnHitByProjectile(CellFace cellFace, WorldItem worldItem) {
47 Press();
48 }
49 }
50}
Engine.Vector3 Vector3
static int GetVoltageLevel(int data)
override bool OnInteract(TerrainRaycastResult raycastResult, ComponentMiner componentMiner)
ButtonElectricElement(SubsystemElectricity subsystemElectricity, CellFace cellFace, int value)
override void OnHitByProjectile(CellFace cellFace, WorldItem worldItem)
override float GetOutputVoltage(int face)
ReadOnlyList< CellFace > CellFaces
MountedElectricElement(SubsystemElectricity subsystemElectricity, CellFace cellFace)
void PlaySound(string name, float volume, float pitch, float pan, float delay)
void QueueElectricElementForSimulation(ElectricElement electricElement, int circuitStep)
static int ExtractData(int value)