Esempio n. 1
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()
        {
            try {
                NetCollection     beautificationNetCollection = GameObject.Find("Beautification").GetComponent <NetCollection>();
                VehicleCollection garbageVehicleCollection    = GameObject.Find("Garbage").GetComponent <VehicleCollection>();
                VehicleCollection policeVehicleCollection     = GameObject.Find("Police Department").GetComponent <VehicleCollection>();
                //VehicleCollection publicTansportVehicleCollection = GameObject.Find("Public Transport").GetComponent<VehicleCollection>();
                VehicleCollection healthCareVehicleCollection     = GameObject.Find("Health Care").GetComponent <VehicleCollection>();
                VehicleCollection fireDepartmentVehicleCollection = GameObject.Find("Fire Department").GetComponent <VehicleCollection>();

                // Localization
                UpdateLocalization();

                // roads
                PedestrianZoningPathAI.Initialize(beautificationNetCollection, transform);
                PedestrianZoningBridgeAI.Initialize(beautificationNetCollection, transform);

                // vehicles
                CustomGarbageTruckAI.Initialize(garbageVehicleCollection, transform);
                CustomAmbulanceAI.Initialize(healthCareVehicleCollection, transform);
                //CustomBusAI.Initialize(publicTansportVehicleCollection, transform);
                CustomFireTruckAI.Initialize(fireDepartmentVehicleCollection, transform);
                CustomHearseAI.Initialize(healthCareVehicleCollection, transform);
                CustomPoliceCarAI.Initialize(policeVehicleCollection, transform);

                m_initialized = true;
            } catch (KeyNotFoundException knf) {
#if DEBUG
                System.IO.File.AppendAllText("Debug.txt", "Error trying to initialize custom prefabs: " + knf.Message + "\n");
                m_initialized = true;
#endif
            } catch (Exception) {}
        }
Esempio n. 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.");
        }