Exemplo n.º 1
0
    public GameObject CreateBuildingPreview(BuildingDef def)
    {
        GameObject gameObject = CreateBuilding(def, previewTemplate, null);

        Object.DontDestroyOnLoad(gameObject);
        int num = LayerMask.NameToLayer("Place");

        gameObject.transform.SetPosition(new Vector3(0f, 0f, Grid.GetLayerZ(def.SceneLayer)));
        Add2DComponents(def, gameObject, "place", true, num);
        KAnimControllerBase component = gameObject.GetComponent <KAnimControllerBase>();

        if ((Object)component != (Object)null)
        {
            component.fgLayer = Grid.SceneLayer.NoLayer;
        }
        Rotatable rotatable = UpdateComponentRequirement <Rotatable>(gameObject, def.PermittedRotations != PermittedRotations.Unrotatable);

        if ((bool)rotatable)
        {
            rotatable.permittedRotations = def.PermittedRotations;
        }
        KPrefabID kPrefabID = AddID(gameObject, def.PrefabID + "Preview");

        kPrefabID.defaultLayer = num;
        KSelectable component2 = gameObject.GetComponent <KSelectable>();

        component2.SetName(def.Name);
        UpdateComponentRequirement <BuildingCellVisualizer>(gameObject, def.CheckRequiresBuildingCellVisualizer());
        KAnimGraphTileVisualizer component3 = gameObject.GetComponent <KAnimGraphTileVisualizer>();

        if ((Object)component3 != (Object)null)
        {
            Object.DestroyImmediate(component3);
        }
        if (def.RequiresPowerInput)
        {
            GeneratedBuildings.RegisterLogicPorts(gameObject, LogicOperationalController.INPUT_PORTS_0_0);
        }
        gameObject.PreInit();
        Assets.AddPrefab(gameObject.GetComponent <KPrefabID>());
        return(gameObject);
    }
Exemplo n.º 2
0
    public GameObject CreateBuildingUnderConstruction(BuildingDef def)
    {
        GameObject gameObject = CreateBuilding(def, constructionTemplate, null);

        Object.DontDestroyOnLoad(gameObject);
        KSelectable component = gameObject.GetComponent <KSelectable>();

        component.SetName(def.Name);
        for (int i = 0; i < def.Mass.Length; i++)
        {
            gameObject.GetComponent <PrimaryElement>().MassPerUnit += def.Mass[i];
        }
        KPrefabID kPrefabID = AddID(gameObject, def.PrefabID + "UnderConstruction");

        UpdateComponentRequirement <BuildingCellVisualizer>(gameObject, def.CheckRequiresBuildingCellVisualizer());
        Constructable component2 = gameObject.GetComponent <Constructable>();

        component2.SetWorkTime(def.ConstructionTime);
        Rotatable rotatable = UpdateComponentRequirement <Rotatable>(gameObject, def.PermittedRotations != PermittedRotations.Unrotatable);

        if ((bool)rotatable)
        {
            rotatable.permittedRotations = def.PermittedRotations;
        }
        Add2DComponents(def, gameObject, "place", false, kPrefabID.defaultLayer = LayerMask.NameToLayer("Construction"));
        UpdateComponentRequirement <Vent>(gameObject, false);
        bool required = (Object)def.BuildingComplete.GetComponent <AnimTileable>() != (Object)null;

        UpdateComponentRequirement <AnimTileable>(gameObject, required);
        if (def.RequiresPowerInput)
        {
            GeneratedBuildings.RegisterLogicPorts(gameObject, LogicOperationalController.INPUT_PORTS_0_0);
        }
        Assets.AddPrefab(kPrefabID);
        gameObject.PreInit();
        return(gameObject);
    }
Exemplo n.º 3
0
    public GameObject CreateBuildingComplete(GameObject go, BuildingDef def)
    {
        go.name = def.PrefabID + "Complete";
        go.transform.SetPosition(new Vector3(0f, 0f, Grid.GetLayerZ(def.SceneLayer)));
        KSelectable component = go.GetComponent <KSelectable>();

        component.SetName(def.Name);
        PrimaryElement component2 = go.GetComponent <PrimaryElement>();

        component2.MassPerUnit = 0f;
        for (int i = 0; i < def.Mass.Length; i++)
        {
            component2.MassPerUnit += def.Mass[i];
        }
        component2.Temperature = 273.15f;
        BuildingHP buildingHP = go.AddOrGet <BuildingHP>();

        if (def.Invincible)
        {
            buildingHP.invincible = true;
        }
        buildingHP.SetHitPoints(def.HitPoints);
        if (def.Repairable)
        {
            UpdateComponentRequirement <Repairable>(go, true);
        }
        int      defaultLayer = go.layer = LayerMask.NameToLayer("Default");
        Building component3   = go.GetComponent <BuildingComplete>();

        component3.Def = def;
        if (def.InputConduitType != 0 || def.OutputConduitType != 0)
        {
            go.AddComponent <BuildingConduitEndpoints>();
        }
        if (!Add2DComponents(def, go, null, false, -1))
        {
            Debug.Log(def.Name + " is not yet a 2d building!");
        }
        UpdateComponentRequirement <EnergyConsumer>(go, def.RequiresPowerInput);
        Rotatable rotatable = UpdateComponentRequirement <Rotatable>(go, def.PermittedRotations != PermittedRotations.Unrotatable);

        if ((bool)rotatable)
        {
            rotatable.permittedRotations = def.PermittedRotations;
        }
        if (def.Breakable)
        {
            go.AddComponent <Breakable>();
        }
        ConduitConsumer conduitConsumer = UpdateComponentRequirement <ConduitConsumer>(go, def.InputConduitType == ConduitType.Gas || def.InputConduitType == ConduitType.Liquid);

        if ((Object)conduitConsumer != (Object)null)
        {
            conduitConsumer.SetConduitData(def.InputConduitType);
        }
        bool          required      = def.RequiresPowerInput || def.InputConduitType == ConduitType.Gas || def.InputConduitType == ConduitType.Liquid;
        RequireInputs requireInputs = UpdateComponentRequirement <RequireInputs>(go, required);

        if ((Object)requireInputs != (Object)null)
        {
            requireInputs.SetRequirements(def.RequiresPowerInput, def.InputConduitType == ConduitType.Gas || def.InputConduitType == ConduitType.Liquid);
        }
        UpdateComponentRequirement <RequireOutputs>(go, def.OutputConduitType != ConduitType.None);
        UpdateComponentRequirement <Operational>(go, !def.isUtility);
        if (def.Floodable)
        {
            go.AddComponent <Floodable>();
        }
        if (def.Disinfectable)
        {
            go.AddOrGet <AutoDisinfectable>();
            go.AddOrGet <Disinfectable>();
        }
        if (def.Overheatable)
        {
            Overheatable overheatable = go.AddComponent <Overheatable>();
            overheatable.baseOverheatTemp = def.OverheatTemperature;
            overheatable.baseFatalTemp    = def.FatalHot;
        }
        if (def.Entombable)
        {
            go.AddComponent <Structure>();
        }
        if (def.RequiresPowerInput)
        {
            GeneratedBuildings.RegisterLogicPorts(go, LogicOperationalController.INPUT_PORTS_0_0);
            go.AddOrGet <LogicOperationalController>();
        }
        UpdateComponentRequirement <BuildingCellVisualizer>(go, def.CheckRequiresBuildingCellVisualizer());
        if (def.BaseDecor != 0f)
        {
            DecorProvider decorProvider = UpdateComponentRequirement <DecorProvider>(go, true);
            decorProvider.baseDecor  = def.BaseDecor;
            decorProvider.baseRadius = def.BaseDecorRadius;
        }
        if (def.AttachmentSlotTag != Tag.Invalid)
        {
            AttachableBuilding attachableBuilding = UpdateComponentRequirement <AttachableBuilding>(go, true);
            attachableBuilding.attachableToTag = def.AttachmentSlotTag;
        }
        KPrefabID kPrefabID = AddID(go, def.PrefabID);

        kPrefabID.defaultLayer = defaultLayer;
        Assets.AddPrefab(kPrefabID);
        go.PreInit();
        return(go);
    }