Example #1
0
        public override void InitializePrefab()
        {
            base.InitializePrefab();

            this.m_constructionCost = 2000;
            this.m_maintenanceCost  = 250;

            try
            {
                NetInfo zonablePath = PrefabCollection <NetInfo> .FindLoaded("Zonable Pedestrian Pavement");

                if (zonablePath == null)
                {
                    throw new KeyNotFoundException("Can't find Zonable Pedestrian Pavement in PrefabCollection.");
                }
                ZonablePedestrianPathAI zonablePathAI = zonablePath.GetComponent <ZonablePedestrianPathAI>();
                if (zonablePathAI == null)
                {
                    throw new KeyNotFoundException("Zonable Pedestrian Pavement prefab does not have a ZonablePedestrianPathAI.");
                }
                zonablePathAI.m_elevatedInfo = this.m_info;
                zonablePathAI.m_bridgeInfo   = this.m_info;

                GameObject pillarPrefab = Resources.FindObjectsOfTypeAll <GameObject>().Where(g => g.name == "Pedestrian Elevated Pillar").FirstOrDefault();
                if (pillarPrefab == null)
                {
                    throw new KeyNotFoundException("Can't find Pedestrian Elevated Pillar.");
                }
                this.m_bridgePillarInfo = pillarPrefab.GetComponent <BuildingInfo>();

                Debug.Log("Traffic++: " + name + " initialized.");
            }
            catch (KeyNotFoundException knf)
            {
                Debug.Log("Traffic++: Error initializing Zonable Pedestrian Bridge AI: " + knf.Message + "\n");
            }
            catch (Exception e)
            {
                Debug.Log("Traffic++: Unexpected " + e.GetType().Name + " initializing Zonable Pedestrian Bridge AI: " + e.Message + "\n" + e.StackTrace + "\n");
            }
        }
Example #2
0
        /*
         * 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.");
        }