Exemplo n.º 1
0
    private static bool Add2DComponents(BuildingDef def, GameObject go, string initialAnimState = null, bool no_collider = false, int layer = -1)
    {
        bool flag = def.AnimFiles != null && def.AnimFiles.Length > 0;

        if (layer == -1)
        {
            layer = LayerMask.NameToLayer("Default");
        }
        go.layer = layer;
        KBatchedAnimController[] components = go.GetComponents <KBatchedAnimController>();
        if (components.Length > 1)
        {
            for (int i = 2; i < components.Length; i++)
            {
                Object.DestroyImmediate(components[i]);
            }
        }
        if ((Object)def.BlockTileAtlas == (Object)null)
        {
            KBatchedAnimController kBatchedAnimController = UpdateComponentRequirement <KBatchedAnimController>(go, flag);
            if ((Object)kBatchedAnimController != (Object)null)
            {
                kBatchedAnimController.AnimFiles = def.AnimFiles;
                if (def.isKAnimTile)
                {
                    kBatchedAnimController.initialAnim = null;
                }
                else
                {
                    if (def.isUtility && initialAnimState == null)
                    {
                        initialAnimState = "idle";
                    }
                    else if ((Object)go.GetComponent <Door>() != (Object)null)
                    {
                        initialAnimState = "closed";
                    }
                    kBatchedAnimController.initialAnim = ((initialAnimState == null) ? def.DefaultAnimState : initialAnimState);
                }
                kBatchedAnimController.SetFGLayer(def.ForegroundLayer);
                kBatchedAnimController.materialType = KAnimBatchGroup.MaterialType.Default;
            }
        }
        KBoxCollider2D kBoxCollider2D = UpdateComponentRequirement <KBoxCollider2D>(go, flag && !no_collider);

        if ((Object)kBoxCollider2D != (Object)null)
        {
            kBoxCollider2D.offset = new Vector3(0f, 0.5f * (float)def.HeightInCells, 0f);
            kBoxCollider2D.size   = new Vector3((float)def.WidthInCells, (float)def.HeightInCells, 0f);
        }
        if (def.AnimFiles == null)
        {
            Debug.LogError(def.Name + " Def missing anim files");
        }
        return(flag);
    }