Survivalcraft API 1.8.2.3 v1.8.2.3
Survivalcraft 2.4
载入中...
搜索中...
未找到
OneLedElectricElement.cs
浏览该文件的文档.
1using Engine;
2
3namespace Game {
6
7 public float m_voltage;
8
9 public Color m_color;
10
12
13 public OneLedElectricElement(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 Vector3 v = new(cellFace.X + 0.5f, cellFace.Y + 0.5f, cellFace.Z + 0.5f);
22 Vector3 vector = CellFace.FaceToVector3(mountingFace);
23 Vector3 vector2 = mountingFace < 4 ? Vector3.UnitY : Vector3.UnitX;
24 Vector3 right = Vector3.Cross(vector, vector2);
25 m_glowPoint = m_subsystemGlow.AddGlowPoint();
26 m_glowPoint.Position = v - 0.4375f * CellFace.FaceToVector3(mountingFace);
27 m_glowPoint.Forward = vector;
28 m_glowPoint.Up = vector2;
29 m_glowPoint.Right = right;
30 m_glowPoint.Color = Color.Transparent;
31 m_glowPoint.Size = 0.52f;
32 m_glowPoint.FarSize = 0.52f;
33 m_glowPoint.FarDistance = 1f;
34 m_glowPoint.Type = GlowPointType.Square;
35 }
36
37 public override void OnRemoved() {
38 m_subsystemGlow.RemoveGlowPoint(m_glowPoint);
39 }
40
41 public override bool Simulate() {
42 float voltage = m_voltage;
43 m_voltage = 0f;
44 foreach (ElectricConnection connection in Connections) {
45 if (connection.ConnectorType != ElectricConnectorType.Output
46 && connection.NeighborConnectorType != 0) {
48 }
49 }
50 if (m_voltage != voltage) {
51 int num = (int)MathF.Round(m_voltage * 15f);
52 m_glowPoint.Color = num >= 8 ? LedBlock.LedColors[Math.Clamp(num - 8, 0, 7)] : Color.Transparent;
53 }
54 return false;
55 }
56 }
57}
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)
static readonly Color[] LedColors
MountedElectricElement(SubsystemElectricity subsystemElectricity, CellFace cellFace)
OneLedElectricElement(SubsystemElectricity subsystemElectricity, CellFace cellFace) override void OnAdded()
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)