Skip to content

Commit

Permalink
Merged in changes made by Klyte45
Browse files Browse the repository at this point in the history
  • Loading branch information
andreharv committed Mar 29, 2020
2 parents 85442d6 + 555979c commit 2b46ef8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
7 changes: 5 additions & 2 deletions TrainTrackBridgeAIMetro.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using ColossalFramework;
using MetroOverhaul;
using MetroOverhaul.NEXT.Extensions;
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
Expand Down Expand Up @@ -40,7 +41,7 @@ public override void GetNodeBuilding(ushort nodeID, ref NetNode data, out Buildi
{
if (m_NetTool == null)
{
m_NetTool = FindObjectOfType<NetTool>();
m_NetTool = GetExactTool<NetTool>();
}
if (m_NetTool?.Prefab != null)
{
Expand Down Expand Up @@ -110,6 +111,8 @@ public override void GetNodeBuilding(ushort nodeID, ref NetNode data, out Buildi
base.GetNodeBuilding(nodeID, ref data, out building, out heightOffset);
}

private T GetExactTool<T>() where T : UnityEngine.Object => FindObjectsOfType<T>().Where(x => x.GetType() == typeof(T)).FirstOrDefault();

public override void UpdateNodeFlags(ushort nodeID, ref NetNode data)
{
base.UpdateNodeFlags(nodeID, ref data);
Expand Down Expand Up @@ -184,7 +187,7 @@ private void GetSegmentPillarProps(float elevation)
// prop.m_probability = 100;
// prop.m_repeatDistance = thePillarPropInfo.RepeatDistance;
// prop.m_segmentOffset = thePillarPropInfo.SegmentOffset;
// var prefab = FindObjectOfType<NetTool>().Prefab;
// var prefab = GetExactTool<NetTool>().Prefab;
// var centerLane = prefab.m_lanes.FirstOrDefault(l => l != null && l.m_laneType == NetInfo.LaneType.None);
// if (centerLane == null)
// {
Expand Down
10 changes: 6 additions & 4 deletions UI/MetroCustomizerBaseUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ public override void Update()
}
public override void Start()
{
m_netTool = FindObjectOfType<NetTool>();
m_netTool = GetExactTool<NetTool>();
if (m_netTool == null)
{
#if DEBUG
Expand All @@ -220,7 +220,7 @@ public override void Start()
enabled = false;
return;
}
m_buildingTool = FindObjectOfType<BuildingTool>();
m_buildingTool = GetExactTool<BuildingTool>();
if (m_buildingTool == null)
{
#if DEBUG
Expand All @@ -229,8 +229,8 @@ public override void Start()
enabled = false;
return;
}
m_buildingTool = FindObjectOfType<BuildingTool>();
if (m_buildingTool == null)
m_bulldozeTool = GetExactTool<BulldozeTool>();
if (m_bulldozeTool == null)
{
#if DEBUG
Next.Debug.Log("BuildingTool Not Found");
Expand All @@ -252,6 +252,8 @@ public override void Start()
SubStart();
}

private T GetExactTool<T>() where T : UnityEngine.Object => FindObjectsOfType<T>().Where(x => x.GetType() == typeof(T)).FirstOrDefault();

private float m_SetWidth = 250;
protected virtual void CreateUI()
{
Expand Down

0 comments on commit 2b46ef8

Please sign in to comment.