Survivalcraft API 1.8.2.3 v1.8.2.3
Survivalcraft 2.4
载入中...
搜索中...
未找到
FourLedElectricElement.cs
浏览该文件的文档.
1using Engine;
2
3namespace Game {
6
7 public float m_voltage;
8
9 public Color m_color;
10
11 public GlowPoint[] m_glowPoints = new GlowPoint[4];
12
13 public FourLedElectricElement(SubsystemElectricity subsystemElectricity, CellFace cellFace) : base(subsystemElectricity, cellFace) =>
14 m_subsystemGlow = subsystemElectricity.Project.FindSubsystem<SubsystemGlow>(true);
15
16 public override void OnAdded() {
17 CellFace cellFace = CellFaces[0];
18 int data = Terrain.ExtractData(SubsystemElectricity.SubsystemTerrain.Terrain.GetCellValue(cellFace.X, cellFace.Y, cellFace.Z));
19 int mountingFace = FourLedBlock.GetMountingFace(data);
21 for (int i = 0; i < 4; i++) {
22 int num = i % 2 == 0 ? 1 : -1;
23 int num2 = i / 2 == 0 ? 1 : -1;
24 Vector3 v = new(cellFace.X + 0.5f, cellFace.Y + 0.5f, cellFace.Z + 0.5f);
25 Vector3 vector = CellFace.FaceToVector3(mountingFace);
26 Vector3 vector2 = mountingFace < 4 ? Vector3.UnitY : Vector3.UnitX;
27 Vector3 vector3 = Vector3.Cross(vector, vector2);
28 m_glowPoints[i] = m_subsystemGlow.AddGlowPoint();
29 m_glowPoints[i].Position = v - 0.4375f * CellFace.FaceToVector3(mountingFace) + 0.25f * vector3 * num + 0.25f * vector2 * num2;
30 m_glowPoints[i].Forward = vector;
31 m_glowPoints[i].Up = vector2;
32 m_glowPoints[i].Right = vector3;
34 m_glowPoints[i].Size = 0.26f;
35 m_glowPoints[i].FarSize = 0.26f;
36 m_glowPoints[i].FarDistance = 1f;
37 m_glowPoints[i].Type = GlowPointType.Square;
38 }
39 }
40
41 public override void OnRemoved() {
42 for (int i = 0; i < 4; i++) {
43 m_subsystemGlow.RemoveGlowPoint(m_glowPoints[i]);
44 }
45 }
46
47 public override bool Simulate() {
48 float voltage = m_voltage;
49 m_voltage = 0f;
50 foreach (ElectricConnection connection in Connections) {
51 if (connection.ConnectorType != ElectricConnectorType.Output
52 && connection.NeighborConnectorType != 0) {
54 }
55 }
56 if (m_voltage != voltage) {
57 int num = (int)MathF.Round(m_voltage * 15f);
58 for (int i = 0; i < 4; i++) {
59 m_glowPoints[i].Color = (num & (1 << i)) != 0 ? m_color : Color.Transparent;
60 }
61 }
62 return false;
63 }
64 }
65}
static int Max(int x1, int x2)
ElectricConnectorType ConnectorType
ElectricConnectorType NeighborConnectorType
virtual float GetOutputVoltage(int face)
List< ElectricConnection > Connections
ReadOnlyList< CellFace > CellFaces
static int GetColor(int data)
static int GetMountingFace(int data)
FourLedElectricElement(SubsystemElectricity subsystemElectricity, CellFace cellFace) override void OnAdded()
static readonly Color[] LedColors
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)