Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Network segment and node reorder scripts. Refreshes UI automatically.
// Network segment and node reorder scripts. Refreshes UI automatically.
// SEGMENTS
var asset = ToolsModifierControl.toolController.m_editPrefabInfo as NetInfo;
var ai = asset.m_netAI as TrainTrackAI; // RoadAI / TrainTrackAI / PedestrianPathAI
var elevation = "basic"; // basic / elevated / bridge / slope / tunnel
int[] order = new int[] { 2, 1, 3, 4, 5, 6, 7 }; // new order
if(elevation=="elevated") asset = ai.m_elevatedInfo; if(elevation=="bridge") asset = ai.m_bridgeInfo;
if(elevation=="slope") asset = ai.m_slopeInfo; if(elevation=="tunnel") asset = ai.m_tunnelInfo;
if(order.Max() > order.Length) {
Debug.LogWarning("SEGMENT_REORDER: Failed. Order array contains a value which is too high."); return; }
if(order.GroupBy(x => x).Any(g => g.Count() > 1)) {
Debug.LogWarning("SEGMENT_REORDER: Failed. Order array uses same value multiple times."); return; }
if(asset.m_segments.Length != order.Length) {
Debug.LogWarning("SEGMENT_REORDER: Failed. Segment array and order array item count mismatch."); return; }
NetInfo.Segment[] segments = new NetInfo.Segment[order.Length];
for (int i = 0; i < order.Length; i++) segments[i] = asset.m_segments[order[i]-1];
asset.m_segments = segments; var panel = UnityEngine.Object.FindObjectOfType<RoadEditorMainPanel>();
panel.GetType().GetMethod("Clear", BindingFlags.NonPublic | BindingFlags.Instance).Invoke(panel, null);
panel.GetType().GetMethod("Initialize", BindingFlags.NonPublic | BindingFlags.Instance).Invoke(panel, null);
// NODES
var asset = ToolsModifierControl.toolController.m_editPrefabInfo as NetInfo;
var ai = asset.m_netAI as TrainTrackAI; // RoadAI / TrainTrackAI / PedestrianPathAI
var elevation = "basic"; // basic / elevated / bridge / slope / tunnel
int[] order = new int[] { 2, 1, 3, 4, 5, 6, 7, 8 }; // new order
if(elevation=="elevated") asset = ai.m_elevatedInfo; if(elevation=="bridge") asset = ai.m_bridgeInfo;
if(elevation=="slope") asset = ai.m_slopeInfo; if(elevation=="tunnel") asset = ai.m_tunnelInfo;
if(order.Max() > order.Length) {
Debug.LogWarning("NODE_REORDER: Failed. Order array contains a value which is too high."); return; }
if(order.GroupBy(x => x).Any(g => g.Count() > 1)) {
Debug.LogWarning("NODE_REORDER: Failed. Order array uses same value multiple times."); return; }
if(asset.m_nodes.Length != order.Length) {
Debug.LogWarning("NODE_REORDER: Failed. Node array and order array item count mismatch."); return; }
NetInfo.Node[] nodes = new NetInfo.Node[order.Length];
for (int i = 0; i < order.Length; i++) nodes[i] = asset.m_nodes[order[i]-1];
asset.m_nodes = nodes; var panel = UnityEngine.Object.FindObjectOfType<RoadEditorMainPanel>();
panel.GetType().GetMethod("Clear", BindingFlags.NonPublic | BindingFlags.Instance).Invoke(panel, null);
panel.GetType().GetMethod("Initialize", BindingFlags.NonPublic | BindingFlags.Instance).Invoke(panel, null);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.