Survivalcraft API 1.8.2.3 v1.8.2.3
Survivalcraft 2.4
载入中...
搜索中...
未找到
LedElectricElement.cs
浏览该文件的文档.
1using Engine;
2
3namespace Game {
6
7 public float m_voltage;
8
10
11 public Color m_color;
12
13 public LedElectricElement(SubsystemElectricity subsystemElectricity, CellFace cellFace) : base(subsystemElectricity, cellFace) =>
14 m_subsystemGlow = subsystemElectricity.Project.FindSubsystem<SubsystemGlow>(true);
15
16 public override void OnAdded() {
17 m_glowPoint = m_subsystemGlow.AddGlowPoint();
18 CellFace cellFace = CellFaces[0];
19 int data = Terrain.ExtractData(SubsystemElectricity.SubsystemTerrain.Terrain.GetCellValue(cellFace.X, cellFace.Y, cellFace.Z));
20 int mountingFace = LedBlock.GetMountingFace(data);
22 Vector3 v = new(cellFace.X + 0.5f, cellFace.Y + 0.5f, cellFace.Z + 0.5f);
23 m_glowPoint.Position = v - 0.4375f * CellFace.FaceToVector3(mountingFace);
24 m_glowPoint.Forward = CellFace.FaceToVector3(mountingFace);
25 m_glowPoint.Up = mountingFace < 4 ? Vector3.UnitY : Vector3.UnitX;
26 m_glowPoint.Right = Vector3.Cross(m_glowPoint.Forward, m_glowPoint.Up);
27 m_glowPoint.Color = Color.Transparent;
28 m_glowPoint.Size = 0.0324f;
29 m_glowPoint.FarSize = 0.0324f;
30 m_glowPoint.FarDistance = 0f;
31 m_glowPoint.Type = GlowPointType.Square;
32 }
33
34 public override void OnRemoved() {
35 m_subsystemGlow.RemoveGlowPoint(m_glowPoint);
36 }
37
38 public override bool Simulate() {
39 float voltage = m_voltage;
41 if (IsSignalHigh(m_voltage) != IsSignalHigh(voltage)) {
42 m_glowPoint.Color = IsSignalHigh(m_voltage) ? m_color : Color.Transparent;
43 }
44 return false;
45 }
46
47 public float CalculateVoltage() => CalculateHighInputsCount() > 0 ? 1 : 0;
48 }
49}
static bool IsSignalHigh(float voltage)
ReadOnlyList< CellFace > CellFaces
static readonly Color[] LedColors
static int GetMountingFace(int data)
static int GetColor(int data)
LedElectricElement(SubsystemElectricity subsystemElectricity, CellFace cellFace) override void OnAdded()
MountedElectricElement(SubsystemElectricity subsystemElectricity, CellFace cellFace)
virtual int GetCellValue(int x, int y, int z)
static int ExtractData(int value)
static Color Transparent
定义 Color.cs:5
static Vector3 Cross(Vector3 v1, Vector3 v2)
static readonly Vector3 UnitX
static Vector3 FaceToVector3(int face)