Example #1
0
        private static bool Prefix(BuildingConfigManager __instance, IBuildingConfig config)
        {
            bool result = false;

            if (Hooked)
            {
                return(true);
            }

            //CreateBuildingDef
            BuildingDef buildingDef = config.CreateBuildingDef();

            Hooked = true;
            try
            {
                result = RegisterBuilding(__instance, config, buildingDef);
            }
            catch (Exception e) {
                Debug.Log(" === [BuildingModifier] ERROR registering building [" + buildingDef.PrefabID + "]. Incompatible building config.");
                Debug.Log(e.StackTrace);
                // __instance.RegisterBuilding(config);
                //throw e;
                Application.Quit();
            }
            Hooked = false;
            return(result);
        }
    public void RegisterBuilding(IBuildingConfig config)
    {
        BuildingDef buildingDef = config.CreateBuildingDef();

        configTable[config] = buildingDef;
        GameObject gameObject = UnityEngine.Object.Instantiate(baseTemplate);

        UnityEngine.Object.DontDestroyOnLoad(gameObject);
        gameObject.GetComponent <KPrefabID>().PrefabTag = buildingDef.Tag;
        gameObject.name = buildingDef.PrefabID + "Template";
        gameObject.GetComponent <Building>().Def = buildingDef;
        gameObject.GetComponent <OccupyArea>().OccupiedCellsOffsets = buildingDef.PlacementOffsets;
        if (buildingDef.Deprecated)
        {
            gameObject.GetComponent <KPrefabID>().AddTag(GameTags.DeprecatedContent, false);
        }
        config.ConfigureBuildingTemplate(gameObject, buildingDef.Tag);
        buildingDef.BuildingComplete = BuildingLoader.Instance.CreateBuildingComplete(gameObject, buildingDef);
        bool flag = true;

        for (int i = 0; i < NonBuildableBuildings.Length; i++)
        {
            if (buildingDef.PrefabID == NonBuildableBuildings[i])
            {
                flag = false;
                break;
            }
        }
        if (flag)
        {
            buildingDef.BuildingUnderConstruction      = BuildingLoader.Instance.CreateBuildingUnderConstruction(buildingDef);
            buildingDef.BuildingUnderConstruction.name = GetUnderConstructionName(buildingDef.BuildingUnderConstruction.name);
            buildingDef.BuildingPreview = BuildingLoader.Instance.CreateBuildingPreview(buildingDef);
            GameObject buildingPreview = buildingDef.BuildingPreview;
            buildingPreview.name += "Preview";
        }
        buildingDef.PostProcess();
        config.DoPostConfigureComplete(buildingDef.BuildingComplete);
        if (flag)
        {
            config.DoPostConfigurePreview(buildingDef, buildingDef.BuildingPreview);
            config.DoPostConfigureUnderConstruction(buildingDef.BuildingUnderConstruction);
        }
        Assets.AddBuildingDef(buildingDef);
    }