-
Notifications
You must be signed in to change notification settings - Fork 2
/
ScrapTrack.cs
92 lines (80 loc) · 4.13 KB
/
ScrapTrack.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
using UnityEngine;
using System.Collections.Generic;
public class ScrapTrack : MachineEntity
{
public static ushort ScrapTrackType = ModManager.mModMappings.CubesByKey["steveman0.ScrapTrack"].CubeType;
public static ushort ScrapStraightVal = ModManager.mModMappings.CubesByKey["steveman0.ScrapTrack"].ValuesByKey["steveman0.ScrapTrackStraight"].Value;
public static ushort ScrapCornerVal = ModManager.mModMappings.CubesByKey["steveman0.ScrapTrack"].ValuesByKey["steveman0.ScrapTrackCorner"].Value;
public static ushort ScrapSlopeVal = ModManager.mModMappings.CubesByKey["steveman0.ScrapTrack"].ValuesByKey["steveman0.ScrapTrackSlope"].Value;
public static Dictionary<ushort, Mesh> TrackMeshes = new Dictionary<ushort, Mesh>();
public static Dictionary<ushort, Material> TrackMaterials = new Dictionary<ushort, Material>();
public static Mesh StraightTrackMesh; //Initialized at Mod level
public static Mesh CornerTrackMesh;
public static Mesh SlopeTrackMesh;
public static Material StraightTrackMaterial;
public static Material CornerTrackMaterial;
public static Material SlopeTrackMaterial; //Initialized at Mod level
public bool DoRender;
public Vector3 position;
public Quaternion rotation;
public static bool Initialized;
public ScrapTrack(ModCreateSegmentEntityParameters parameters)
: base(parameters)
{
mbNeedsUnityUpdate = true;
Vector3 lUnityPos = WorldScript.instance.mPlayerFrustrum.GetCoordsToUnity(this.mnX, this.mnY, this.mnZ);
lUnityPos.x += 0.5f;
lUnityPos.y += 0.5f;
lUnityPos.z += 0.5f;
this.position = lUnityPos;
this.rotation = SegmentCustomRenderer.GetRotationQuaternion(this.mFlags);
//Stupid corner mirroring...
if (this.mValue == ScrapCornerVal)
this.rotation *= Quaternion.Euler(Vector3.up * 180);
if (this.mValue == ScrapSlopeVal)
this.position.y += 0.46f;
}
public override void SpawnGameObject()
{
this.DoRender = true;
}
public override void UnitySuspended()
{
this.DoRender = false;
}
public override void OnUpdateRotation(byte newFlags)
{
this.rotation = SegmentCustomRenderer.GetRotationQuaternion(newFlags);
//Stupid corner mirroring...
if (this.mValue == ScrapCornerVal)
this.rotation *= Quaternion.Euler(Vector3.up * 180);
base.OnUpdateRotation(newFlags);
}
public override void UnityUpdate()
{
if (!Initialized)
{
if (SpawnableObjectManagerScript.instance == null)
return;
GameObject obj = SpawnableObjectManagerScript.instance.maSpawnableObjects[(int)SpawnableObjectEnum.Minecart_Track_Corner].transform.gameObject;
CornerTrackMesh = obj.GetComponentInChildren<MeshFilter>().mesh;
Material mat = obj.GetComponentInChildren<Renderer>().material;
CornerTrackMaterial = new Material(mat);
CornerTrackMaterial.SetColor("_Color", new Color(200/256f, 117/256f, 51/256f));
obj = SpawnableObjectManagerScript.instance.maSpawnableObjects[(int)SpawnableObjectEnum.Minecart_Track_Slope].transform.gameObject;
SlopeTrackMesh = obj.GetComponentInChildren<MeshFilter>().mesh;
Material mat2 = obj.GetComponentInChildren<Renderer>().material;
SlopeTrackMaterial = new Material(mat);
SlopeTrackMaterial.SetColor("_Color", new Color(200/256f, 117/256f, 51/256f));
TrackMeshes.Add(ScrapStraightVal, StraightTrackMesh);
TrackMeshes.Add(ScrapCornerVal, CornerTrackMesh);
TrackMeshes.Add(ScrapSlopeVal, SlopeTrackMesh);
TrackMaterials.Add(ScrapStraightVal, StraightTrackMaterial);
TrackMaterials.Add(ScrapCornerVal, CornerTrackMaterial);
TrackMaterials.Add(ScrapSlopeVal, SlopeTrackMaterial);
Initialized = true;
}
else if (DoRender)
Graphics.DrawMesh(TrackMeshes[this.mValue], position, rotation, TrackMaterials[this.mValue], 0);
}
}