public override void InitializePrefab() { base.InitializePrefab(); this.m_trafficLights = true; this.m_noiseAccumulation = 24; this.m_noiseRadius = 50; this.m_constructionCost = 24000; this.m_maintenanceCost = 1980; this.m_elevationCost = 2000; if (name == "Large Road Bridge With Bus Lanes") { this.m_middlePillarOffset = 43.5f; this.m_doubleLength = true; this.m_canModify = false; } else { this.m_doubleLength = false; this.m_canModify = true; } try { NetInfo largeRoad = PrefabCollection <NetInfo> .FindLoaded("Large Road With Bus Lanes"); if (largeRoad == null) { throw new KeyNotFoundException("Can't find LargeRoad in PrefabCollection."); } LargeRoadWithBusLanesAI largeRoadWithBusLanes = largeRoad.GetComponent <LargeRoadWithBusLanesAI>(); if (largeRoadWithBusLanes == null) { throw new KeyNotFoundException("Large Road With Bus Lanes prefab does not have a LargeRoadWithBusLanesAI."); } if (name == "Large Road Bridge With Bus Lanes") { largeRoadWithBusLanes.m_bridgeInfo = this.m_info; } else { largeRoadWithBusLanes.m_elevatedInfo = this.m_info; } if (name == "Large Road Bridge With Bus Lanes") { GameObject pillarPrefab = Resources.FindObjectsOfTypeAll <GameObject>().Where(g => g.name == "LargeRoadBridgeSuspensionPillar").FirstOrDefault(); if (pillarPrefab == null) { throw new KeyNotFoundException("Can't find LargeRoadBridgeSuspensionPillar."); } this.m_middlePillarInfo = pillarPrefab.GetComponent <BuildingInfo>(); } else { GameObject pillarPrefab = Resources.FindObjectsOfTypeAll <GameObject>().Where(g => g.name == "HighwayBridgePillar").FirstOrDefault(); if (pillarPrefab == null) { throw new KeyNotFoundException("Can't find HighwayBridgePillar."); } this.m_bridgePillarInfo = pillarPrefab.GetComponent <BuildingInfo>(); } Debug.Log("Traffic++: " + name + " initialized."); } catch (KeyNotFoundException knf) { Debug.Log("Traffic++: Error initializing Large Road Bridge AI: " + knf.Message + "\n"); } catch (Exception e) { Debug.Log("Traffic++: Unexpected " + e.GetType().Name + " initializing Large Road Bridge AI: " + e.Message + "\n" + e.StackTrace + "\n"); } }
/* * In here I'm changing the prefabs to have my classes. This way, every time the game instantiates * a prefab that I've changed, that object will run my code. * The prefabs aren't available at the moment of creation of this class, that's why I keep trying to * run it on update. I want to make sure I make the switch as soon as they exist to prevent the game * from instantianting objects without my code. */ void TryReplacePrefabs() { NetCollection beautificationNetCollection = null; NetCollection roadsNetCollection = null; NetCollection publicTansportNetCollection = null; VehicleCollection garbageVehicleCollection = null; VehicleCollection policeVehicleCollection = null; VehicleCollection publicTansportVehicleCollection = null; VehicleCollection healthCareVehicleCollection = null; VehicleCollection fireDepartmentVehicleCollection = null; VehicleCollection industrialVehicleCollection = null; TransportCollection publicTransportTransportCollection = null; ToolController toolController = null; try { // NetCollections beautificationNetCollection = TryGetComponent <NetCollection>("Beautification"); if (beautificationNetCollection == null) { return; } roadsNetCollection = TryGetComponent <NetCollection>("Road"); if (roadsNetCollection == null) { return; } publicTansportNetCollection = TryGetComponent <NetCollection>("Public Transport"); if (publicTansportNetCollection == null) { return; } // VehicleCollections garbageVehicleCollection = TryGetComponent <VehicleCollection>("Garbage"); if (garbageVehicleCollection == null) { return; } policeVehicleCollection = TryGetComponent <VehicleCollection>("Police Department"); if (policeVehicleCollection == null) { return; } publicTansportVehicleCollection = TryGetComponent <VehicleCollection>("Public Transport"); if (publicTansportVehicleCollection == null) { return; } healthCareVehicleCollection = TryGetComponent <VehicleCollection>("Health Care"); if (healthCareVehicleCollection == null) { return; } fireDepartmentVehicleCollection = TryGetComponent <VehicleCollection>("Fire Department"); if (fireDepartmentVehicleCollection == null) { return; } industrialVehicleCollection = TryGetComponent <VehicleCollection>("Industrial"); if (industrialVehicleCollection == null) { return; } // Transports publicTransportTransportCollection = TryGetComponent <TransportCollection>("Public Transport"); if (publicTransportTransportCollection == null) { return; } // Tools toolController = TryGetComponent <ToolController>("Tool Controller"); if (toolController == null) { return; } } catch (Exception e) { Debug.Log("Traffic++: Unexpected " + e.GetType().Name + " getting required components: " + e.Message + "\n" + e.StackTrace + "\n"); return; } Debug.Log("Traffic++: Queueing prefabs for loading..."); Singleton <LoadingManager> .instance.QueueLoadingAction(ActionWrapper(() => { try { // roads ZonablePedestrianPathAI.Initialize(beautificationNetCollection, transform); ZonablePedestrianBridgeAI.Initialize(beautificationNetCollection, transform); LargeRoadWithBusLanesAI.Initialize(roadsNetCollection, transform); LargeRoadWithBusLanesBridgeAI.Initialize(roadsNetCollection, transform); if ((CSLTraffic.Options & OptionsManager.ModOptions.GhostMode) != OptionsManager.ModOptions.GhostMode) { // Transports BusTransportLineAI.Initialize(publicTansportNetCollection, publicTansportVehicleCollection, publicTransportTransportCollection, transform); // vehicles CustomAmbulanceAI.Initialize(healthCareVehicleCollection, transform); CustomBusAI.Initialize(publicTansportVehicleCollection, transform); CustomCargoTruckAI.Initialize(industrialVehicleCollection, transform); CustomFireTruckAI.Initialize(fireDepartmentVehicleCollection, transform); CustomGarbageTruckAI.Initialize(garbageVehicleCollection, transform); CustomHearseAI.Initialize(healthCareVehicleCollection, transform); CustomPoliceCarAI.Initialize(policeVehicleCollection, transform); //Tools CustomTransportTool.Initialize(toolController); } // Localization UpdateLocalization(); AddQueuedActionsToLoadingQueue(); } catch (KeyNotFoundException knf) { Debug.Log("Traffic++: Error initializing a prefab: " + knf.Message + "\n" + knf.StackTrace + "\n"); } catch (Exception e) { Debug.Log("Traffic++: Unexpected " + e.GetType().Name + " initializing prefabs: " + e.Message + "\n" + e.StackTrace + "\n"); } })); m_initialized = true; Debug.Log("Traffic++: Prefabs queued for loading."); }