Exemplo 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) {}
        }
Exemplo n.º 2
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.");
                }
                PedestrianZoningPathAI zonablePathAI = zonablePath.GetComponent <PedestrianZoningPathAI>();
                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>();
            }
            catch (KeyNotFoundException knf)
            {
#if DEBUG
                System.IO.File.AppendAllText("Debug.txt", "Error initializing Zonable Pedestrian Bridge AI: " + knf.Message + "\n");
#endif
            }
        }