public GameObject CreatePrefab()
    {
        string    iD          = ID;
        string    name        = ITEMS.INDUSTRIAL_PRODUCTS.BASIC_FABRIC.NAME;
        string    desc        = ITEMS.INDUSTRIAL_PRODUCTS.BASIC_FABRIC.DESC;
        float     mass        = 1f;
        bool      unitMass    = true;
        KAnimFile anim        = Assets.GetAnim("swampreedwool_kanim");
        string    initialAnim = "object";

        Grid.SceneLayer sceneLayer = Grid.SceneLayer.BuildingBack;
        EntityTemplates.CollisionShape collisionShape = EntityTemplates.CollisionShape.RECTANGLE;
        float      width        = 0.8f;
        float      height       = 0.45f;
        bool       isPickupable = true;
        int        sortOrder    = SORTORDER.BUILDINGELEMENTS + BasicFabricTuning.SORTORDER;
        List <Tag> list         = new List <Tag>();

        list.Add(GameTags.IndustrialIngredient);
        list.Add(GameTags.BuildingFiber);
        list = list;
        GameObject gameObject = EntityTemplates.CreateLooseEntity(iD, name, desc, mass, unitMass, anim, initialAnim, sceneLayer, collisionShape, width, height, isPickupable, sortOrder, SimHashes.Creature, list);

        gameObject.AddOrGet <EntitySplitter>();
        PrefabAttributeModifiers prefabAttributeModifiers = gameObject.AddOrGet <PrefabAttributeModifiers>();

        prefabAttributeModifiers.AddAttributeDescriptor(decorModifier);
        return(gameObject);
    }
Пример #2
0
    protected override void OnSpawn()
    {
        base.OnSpawn();
        KBatchedAnimController component = GetComponent <KBatchedAnimController>();
        Rotatable component2             = GetComponent <Rotatable>();

        if ((Object)component != (Object)null && (Object)component2 == (Object)null)
        {
            component.Offset = Def.GetVisualizerOffset() + Def.placementPivot;
        }
        KBoxCollider2D component3 = GetComponent <KBoxCollider2D>();

        if ((Object)component3 != (Object)null)
        {
            Vector3 visualizerOffset = Def.GetVisualizerOffset();
            component3.offset += new Vector2(visualizerOffset.x, visualizerOffset.y);
        }
        int cell = Grid.PosToCell(base.transform.GetPosition());

        if (Def.IsFoundation)
        {
            int[] placementCells = base.PlacementCells;
            foreach (int num in placementCells)
            {
                Grid.Foundation[num] = true;
                Game.Instance.roomProber.SolidChangedEvent(num, false);
            }
        }
        Vector3 position = Grid.CellToPosCBC(cell, Def.SceneLayer);

        base.transform.SetPosition(position);
        PrimaryElement component4 = GetComponent <PrimaryElement>();

        if ((Object)component4 != (Object)null && component4.Mass == 0f)
        {
            component4.Mass = Def.Mass[0];
        }
        Def.MarkArea(cell, base.Orientation, Def.ObjectLayer, base.gameObject);
        if (Def.IsTilePiece)
        {
            Def.MarkArea(cell, base.Orientation, Def.TileLayer, base.gameObject);
            Def.RunOnArea(cell, base.Orientation, delegate(int c)
            {
                TileVisualizer.RefreshCell(c, Def.TileLayer, Def.ReplacementLayer);
            });
        }
        RegisterBlockTileRenderer();
        if (Def.PreventIdleTraversalPastBuilding)
        {
            for (int j = 0; j < base.PlacementCells.Length; j++)
            {
                Grid.PreventIdleTraversal[base.PlacementCells[j]] = true;
            }
        }
        KSelectable component5 = GetComponent <KSelectable>();

        if ((Object)component5 != (Object)null)
        {
            component5.SetStatusIndicatorOffset(Def.placementPivot);
        }
        Components.BuildingCompletes.Add(this);
        BuildingConfigManager.Instance.AddBuildingCompleteKComponents(base.gameObject, Def.Tag);
        hasSpawnedKComponents = true;
        scenePartitionerEntry = GameScenePartitioner.Instance.Add(base.name, this, GetExtents(), GameScenePartitioner.Instance.completeBuildings, null);
        Attributes attributes = this.GetAttributes();

        if (attributes != null)
        {
            Deconstructable component6 = GetComponent <Deconstructable>();
            if ((Object)component6 != (Object)null)
            {
                for (int k = 1; k < component6.constructionElements.Length; k++)
                {
                    Tag     tag     = component6.constructionElements[k];
                    Element element = ElementLoader.GetElement(tag);
                    if (element != null)
                    {
                        foreach (AttributeModifier attributeModifier in element.attributeModifiers)
                        {
                            attributes.Add(attributeModifier);
                        }
                    }
                    else
                    {
                        GameObject gameObject = Assets.TryGetPrefab(tag);
                        if ((Object)gameObject != (Object)null)
                        {
                            PrefabAttributeModifiers component7 = gameObject.GetComponent <PrefabAttributeModifiers>();
                            if ((Object)component7 != (Object)null)
                            {
                                foreach (AttributeModifier descriptor in component7.descriptors)
                                {
                                    attributes.Add(descriptor);
                                }
                            }
                        }
                    }
                }
            }
        }
    }
Пример #3
0
 private void SetDescription(BuildingDef def)
 {
     if (!((UnityEngine.Object)def == (UnityEngine.Object)null) && !((UnityEngine.Object)productFlavourText == (UnityEngine.Object)null))
     {
         string text = def.Desc;
         Dictionary <Klei.AI.Attribute, float> dictionary  = new Dictionary <Klei.AI.Attribute, float>();
         Dictionary <Klei.AI.Attribute, float> dictionary2 = new Dictionary <Klei.AI.Attribute, float>();
         foreach (Klei.AI.Attribute attribute in def.attributes)
         {
             if (!dictionary.ContainsKey(attribute))
             {
                 dictionary[attribute] = 0f;
             }
         }
         foreach (AttributeModifier attributeModifier in def.attributeModifiers)
         {
             float             value = 0f;
             Klei.AI.Attribute key   = Db.Get().BuildingAttributes.Get(attributeModifier.AttributeId);
             dictionary.TryGetValue(key, out value);
             value = (dictionary[key] = value + attributeModifier.Value);
         }
         if (materialSelectionPanel.CurrentSelectedElement != (Tag)null)
         {
             Element element = ElementLoader.GetElement(materialSelectionPanel.CurrentSelectedElement);
             if (element != null)
             {
                 foreach (AttributeModifier attributeModifier2 in element.attributeModifiers)
                 {
                     float             value2 = 0f;
                     Klei.AI.Attribute key2   = Db.Get().BuildingAttributes.Get(attributeModifier2.AttributeId);
                     dictionary2.TryGetValue(key2, out value2);
                     value2 = (dictionary2[key2] = value2 + attributeModifier2.Value);
                 }
             }
             else
             {
                 GameObject gameObject = Assets.TryGetPrefab(materialSelectionPanel.CurrentSelectedElement);
                 PrefabAttributeModifiers component = gameObject.GetComponent <PrefabAttributeModifiers>();
                 if ((UnityEngine.Object)component != (UnityEngine.Object)null)
                 {
                     foreach (AttributeModifier descriptor in component.descriptors)
                     {
                         float             value3 = 0f;
                         Klei.AI.Attribute key3   = Db.Get().BuildingAttributes.Get(descriptor.AttributeId);
                         dictionary2.TryGetValue(key3, out value3);
                         value3 = (dictionary2[key3] = value3 + descriptor.Value);
                     }
                 }
             }
         }
         if (dictionary.Count > 0)
         {
             text += "\n\n";
             foreach (KeyValuePair <Klei.AI.Attribute, float> item in dictionary)
             {
                 float value4 = 0f;
                 dictionary.TryGetValue(item.Key, out value4);
                 float  value5 = 0f;
                 string text2  = string.Empty;
                 if (dictionary2.TryGetValue(item.Key, out value5))
                 {
                     value5 = Mathf.Abs(value4 * value5);
                     text2  = "(+" + value5 + ")";
                 }
                 string text3 = text;
                 text = text3 + "\n" + item.Key.Name + ": " + (value4 + value5) + text2;
             }
         }
         productFlavourText.text = text;
     }
 }