コード例 #1
0
        public static void Initialize(ToolController toolController)
        {
            if (sm_initialized)
            {
                return;
            }

            Debug.Log("Traffic++: Initializing Transport Tool.\n");

            TransportTool       originalTransportTool = toolController.GetComponent <TransportTool>();
            CustomTransportTool customTransportTool   = toolController.gameObject.AddComponent <CustomTransportTool>();

            // contributed by Japa
            FieldInfo toolControllerField = typeof(ToolController).GetField("m_tools", BindingFlags.Instance | BindingFlags.NonPublic);

            if (toolControllerField != null)
            {
                toolControllerField.SetValue(toolController, toolController.GetComponents <ToolBase>());
            }
            FieldInfo toolModifierDictionary = typeof(ToolsModifierControl).GetField("m_Tools", BindingFlags.Static | BindingFlags.NonPublic);

            if (toolModifierDictionary != null)
            {
                toolModifierDictionary.SetValue(null, null);
            }

            sm_initialized = true;

            Debug.Log("Traffic++: Transport Tool initialized.\n");
        }
コード例 #2
0
        void Update()
        {
            if (!m_initialized)
            {
                TryReplacePrefabs();
                return;
            }

            // contributed by Japa
            if (CustomTransportTool.sm_initialized && Singleton <LoadingManager> .instance.m_loadingComplete)
            {
                TransportTool transportTool = ToolsModifierControl.GetCurrentTool <TransportTool>();
                if (transportTool != null)
                {
                    CustomTransportTool customTransportTool = ToolsModifierControl.SetTool <CustomTransportTool>();
                    if (customTransportTool != null)
                    {
                        customTransportTool.m_prefab = transportTool.m_prefab;
                    }
                }
            }
        }
コード例 #3
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.");
        }