示例#1
0
    internal void UpdateImprovement(RemoteFortressReader.ItemImprovement improvement)
    {
        Color matColor     = ContentLoader.GetColor(improvement.material);
        float textureIndex = ContentLoader.GetPatternIndex(improvement.material);

        image = improvement.image;

        if (actualModel != null)
        {
            Destroy(actualModel);
            actualModel = null;
        }


        GameObject prefab = null;

        switch (improvement.type)
        {
        case ImprovementType.ART_IMAGE:
            prefab = DecorationManager.Instance.Image;
            break;

        case ImprovementType.BANDS:
        case ImprovementType.COVERED:
            prefab = DecorationManager.Instance.GetShape(improvement.shape);
            break;

        case ImprovementType.RINGS_HANGING:
            prefab = DecorationManager.Instance.Ring;
            break;

        case ImprovementType.SPIKES:
            prefab = DecorationManager.Instance.Spike;
            break;

        default:
            break;
        }

        if (prefab == null)
        {
            gameObject.SetActive(false);
            return;
        }

        actualModel = Instantiate(prefab, transform, false);

        meshRenderer = actualModel.GetComponentInChildren <MeshRenderer>();
        if (improvement.type == ImprovementType.ART_IMAGE)
        {
            meshRenderer.material.SetTexture("_TileIndex", ImageManager.Instance.CreateImage(improvement.image));
        }
        else
        {
            originalMaterial            = meshRenderer.sharedMaterial;
            meshRenderer.sharedMaterial = ContentLoader.getFinalMaterial(originalMaterial, matColor.a);
        }

        MaterialPropertyBlock prop = new MaterialPropertyBlock();

        prop.SetColor("_MatColor", matColor);
        prop.SetFloat("_MatIndex", textureIndex);
        meshRenderer.SetPropertyBlock(prop);
    }
示例#2
0
    /// <summary>
    /// This is the function that actually decides what mesh and texture each tile gets
    /// </summary>
    /// <param name="buffer">Buffer to put the chosen meshes into for combining</param>
    /// <param name="layer">layer currently being worked on</param>
    /// <param name="tile">The tile to get all the needed info from.</param>
    void FillMeshBuffer(out MeshCombineUtility.MeshInstance buffer, MeshLayer layer, MapDataStore.Tile tile, Vector3 pos)
    {
        buffer = new MeshCombineUtility.MeshInstance();
        Vector2     index1      = Vector2.zero;
        Vector2     index2      = Vector2.zero;
        MeshContent meshContent = null;

        buffer.color = Color.grey;
        if (layer == MeshLayer.Collision)
        {
            if (!ContentLoader.Instance.CollisionMeshConfiguration.GetValue(tile, layer, out meshContent))
            {
                buffer.meshData = null;
                return;
            }
            if (meshContent.MeshData.ContainsKey(MeshLayer.Collision))
            {
                buffer.meshData = meshContent.MeshData[MeshLayer.Collision];
            }
            else if (meshContent.MeshData.ContainsKey(MeshLayer.StaticMaterial))
            {
                buffer.meshData = meshContent.MeshData[MeshLayer.StaticMaterial];
            }
            else
            {
                buffer.meshData = null;
                return;
            }
            buffer.transform   = Matrix4x4.TRS(pos, meshContent.GetRotation(tile), Vector3.one);
            buffer.hiddenFaces = CalculateHiddenFaces(tile, meshContent.Rotation);
            return;
        }
        if (ContentLoader.Instance.DesignationMeshConfiguration.GetValue(tile, layer, out meshContent))
        {
            if (!meshContent.MeshData.ContainsKey(layer))
            {
                buffer.meshData = null;
                return;
            }
            buffer.meshData  = meshContent.MeshData[layer];
            buffer.transform = Matrix4x4.TRS(pos, meshContent.GetRotation(tile), Vector3.one);

            index1.x     = ContentLoader.GetPatternIndex(tile.DesignationMat) / ContentLoader.Instance.PatternTextureDepth;
            buffer.color = ContentLoader.GetColor(tile.DesignationMat);
            if (meshContent.ShapeTexture != null)
            {
                index1.y = meshContent.ShapeTexture.ArrayIndex;
            }
            else
            {
                index1.y = ContentLoader.Instance.DefaultShapeTexArrayIndex;
            }
            if (meshContent.SpecialTexture != null)
            {
                index2.x = meshContent.SpecialTexture.ArrayIndex;
            }
            else
            {
                index2.x = ContentLoader.Instance.DefaultSpecialTexArrayIndex;
            }

            buffer.uv1Transform = Matrix4x4.identity;
            buffer.uv2Force     = index1;
            buffer.uv3Force     = index2;
            buffer.hiddenFaces  = CalculateHiddenFaces(tile, meshContent.Rotation);
            return;
        }

        var matColor        = ContentLoader.GetColor(tile.GetMaterial(layer));
        var matPatternIndex = ContentLoader.GetPatternIndex(tile.GetMaterial(layer));

        switch (layer)
        {
        case MeshLayer.GrowthMaterial:
        case MeshLayer.GrowthCutout:
        case MeshLayer.GrowthTransparent:
            matColor = ContentLoader.GetColor(new MatPairStruct(55, 0), tile.GetMaterial(layer));
            break;

        case MeshLayer.GrowthMaterial1:
        case MeshLayer.GrowthCutout1:
        case MeshLayer.GrowthTransparent1:
            matColor = ContentLoader.GetColor(new MatPairStruct(55, 1), tile.GetMaterial(layer));
            break;

        case MeshLayer.GrowthMaterial2:
        case MeshLayer.GrowthCutout2:
        case MeshLayer.GrowthTransparent2:
            matColor = ContentLoader.GetColor(new MatPairStruct(55, 2), tile.GetMaterial(layer));
            break;

        case MeshLayer.GrowthMaterial3:
        case MeshLayer.GrowthCutout3:
        case MeshLayer.GrowthTransparent3:
            matColor = ContentLoader.GetColor(new MatPairStruct(55, 3), tile.GetMaterial(layer));
            break;

        default:
            break;
        }

        switch (layer)
        {
        case MeshLayer.GrowthMaterial:
        case MeshLayer.GrowthMaterial1:
        case MeshLayer.GrowthMaterial2:
        case MeshLayer.GrowthMaterial3:
        case MeshLayer.GrowthCutout:
        case MeshLayer.GrowthCutout1:
        case MeshLayer.GrowthCutout2:
        case MeshLayer.GrowthCutout3:
        case MeshLayer.GrowthTransparent:
        case MeshLayer.GrowthTransparent1:
        case MeshLayer.GrowthTransparent2:
        case MeshLayer.GrowthTransparent3:
        {
            switch (tile.tiletypeMaterial)
            {
            case TiletypeMaterial.PLANT:
            case TiletypeMaterial.ROOT:
            case TiletypeMaterial.TREE_MATERIAL:
            case TiletypeMaterial.MUSHROOM:
                if (!ContentLoader.Instance.GrowthMeshConfiguration.GetValue(tile, layer, out meshContent))
                {
                    buffer.meshData = null;
                    return;
                }
                break;

            default:
                buffer.meshData = null;
                return;
            }
        }
        break;

        default:
        {
            if (layer == MeshLayer.NaturalTerrain)
            {
                if (VoxelGenerator.IsNatural(tile) && !VoxelGenerator.HandleShape(tile) && !VoxelGenerator.UseBoth(tile))
                {
                    layer = MeshLayer.StaticMaterial;
                }
                else
                {
                    buffer.meshData = null;
                    return;
                }
            }
            else if (VoxelGenerator.IsNatural(tile) && !VoxelGenerator.UseBoth(tile))
            {
                buffer.meshData = null;
                return;
            }
            if (!ContentLoader.Instance.TileMeshConfiguration.GetValue(tile, layer, out meshContent))
            {
                buffer.meshData = null;
                return;
            }
        }
        break;
        }

        //Use the transparent shader instead of the opaque shader if the material is transparent.
        if (matColor.a < 0.5f)
        {
            switch (layer)
            {
            case MeshLayer.StaticMaterial:
            case MeshLayer.BaseMaterial:
            case MeshLayer.LayerMaterial:
            case MeshLayer.VeinMaterial:
                buffer.meshData = null;
                return;

            case MeshLayer.StaticTransparent:
                layer = MeshLayer.StaticMaterial;
                break;

            case MeshLayer.BaseTransparent:
                layer = MeshLayer.BaseMaterial;
                break;

            case MeshLayer.LayerTransparent:
                layer = MeshLayer.LayerMaterial;
                break;

            case MeshLayer.VeinTransparent:
                layer = MeshLayer.VeinMaterial;
                break;

            default:
                break;
            }
        }

        if (!meshContent.MeshData.ContainsKey(layer))
        {
            buffer.meshData = null;
            return;
        }
        buffer.meshData  = meshContent.MeshData[layer];
        buffer.transform = Matrix4x4.TRS(pos, meshContent.GetRotation(tile), Vector3.one);
        Matrix4x4 shapeTextTransform  = ContentLoader.Instance.DefaultShapeTexTransform;
        Matrix4x4 specialTexTransform = Matrix4x4.identity;

        NormalContent tileTexContent;

        if (meshContent.ShapeTexture == null)
        {
            if (ContentLoader.Instance.ShapeTextureConfiguration.GetValue(tile, layer, out tileTexContent))
            {
                shapeTextTransform = tileTexContent.UVTransform;
                index1.y           = tileTexContent.ArrayIndex;
            }
        }
        else
        {
            shapeTextTransform = meshContent.ShapeTexture.UVTransform;
            index1.y           = meshContent.ShapeTexture.ArrayIndex;
        }

        index1.x = matPatternIndex / ContentLoader.Instance.PatternTextureDepth;



        if (meshContent.SpecialTexture != null)
        {
            specialTexTransform = meshContent.SpecialTexture.UVTransform;
            index2.x            = meshContent.SpecialTexture.ArrayIndex;
        }
        else
        {
            specialTexTransform = ContentLoader.Instance.DefaultSpecialTexTransform;
            index2.x            = ContentLoader.Instance.DefaultSpecialTexArrayIndex;
        }

        buffer.color = matColor;

        buffer.uv1Transform = Matrix4x4.identity;
        buffer.uv2Force     = index1;
        buffer.uv3Force     = index2;

        buffer.hiddenFaces = CalculateHiddenFaces(tile, meshContent.Rotation);
    }
示例#3
0
    internal void UpdateItems(UnitDefinition unit)
    {
        var heldItemIndex = inventory.FindLastIndex(x => x.item.mode == InventoryMode.Hauled || x.item.mode == InventoryMode.Weapon);

        if (heldItemIndex >= 0)
        {
            var heldItem = inventory[heldItemIndex];
            if (heldItem.item.item.type != heldItemType)
            {
                if (heldItemModel != null)
                {
                    Destroy(heldItemModel);
                }
                var point = heldItemPoint;
                if (point == null)
                {
                    point = transform;
                }
                heldItemModel = ItemManager.InstantiateItem(heldItem.item.item, transform, false);
                heldItemModel.transform.position    = point.transform.position;
                heldItemModel.transform.rotation    = point.transform.rotation;
                heldItemModel.transform.localScale *= 1.0f / transform.lossyScale.magnitude;
                heldItemType = heldItem.item.item.type;
            }
        }
        else
        {
            if (heldItemModel != null)
            {
                Destroy(heldItemModel);
            }
            heldItemModel = null;
        }
        if (modeledPart != null)
        {
            modeledPart.ApplyEquipment(inventory, unit);
        }
        else
        {
            foreach (var item in inventory)
            {
                if (item.item.mode != InventoryMode.Worn)
                {
                    continue;
                }
                if (flags.head)
                {
                    continue;
                }
                MaterialPropertyBlock propertyBlock = new MaterialPropertyBlock();
                var color = ContentLoader.GetColor(item.item.item);
                var index = ContentLoader.GetPatternIndex(item.item.item.material);
                propertyBlock.SetColor("_MatColor", color);
                propertyBlock.SetFloat("_MatIndex", index);
                propertyBlock.SetColor("_JobColor", unit.profession_color);
                foreach (var layerModel in layerModels)
                {
                    if (layerModel == null)
                    {
                        continue;
                    }
                    var renderer = layerModel.GetComponentInChildren <MeshRenderer>();
                    if (renderer != null)
                    {
                        renderer.SetPropertyBlock(propertyBlock);
                    }
                }
            }
        }
    }
示例#4
0
    void GenerateMesh()
    {
        if (width == 1 && height == 1)
        {
            return;
        }
        int            length    = width * height * 4;
        List <Vector3> vertices  = new List <Vector3>(length);
        List <Color>   colors    = new List <Color>(length);
        List <Vector2> uvs       = new List <Vector2>(length);
        List <Vector2> uv2s      = new List <Vector2>(length);
        List <Vector2> uv3s      = new List <Vector2>(length);
        List <int>     triangles = new List <int>(length);

        List <Vector3> waterVerts = new List <Vector3>();
        List <Vector2> waterUvs   = new List <Vector2>();
        List <int>     waterTris  = new List <int>();

        foreach (MeshFilter mf in terrainChunks)
        {
            if (mf.mesh != null)
            {
                mf.mesh.Clear();
            }
        }
        foreach (MeshFilter mf in waterChunks)
        {
            if (mf.mesh != null)
            {
                mf.mesh.Clear();
            }
        }

        chunkIndex      = 0;
        waterChunkIndex = 0;
        for (int x = 0; x < width; x++)
        {
            for (int y = 0; y < height; y++)
            {
                if (DetailRegions.ContainsKey(new DFCoord2d(x, y)))
                {
                    continue;
                }


                //If the vertex lists are already full, make a chunk with what we have, and keep going
                if (vertices.Count >= (65535 - 20))
                {
                    FinalizeGeometryChunk(vertices, colors, uvs, uv2s, uv3s, triangles);
                }

                //If the vertex lists are already full, make a chunk with what we have, and keep going
                if (waterVerts.Count >= (65535 - 20))
                {
                    FinalizeWaterGeometryChunk(waterVerts, waterUvs, waterTris);
                }


                Color terrainColor = ContentLoader.GetColor(regionTiles[x, y].surface_material);

                Color plantColor   = Color.black;
                float grassPercent = Mathf.Pow(regionTiles[x, y].vegetation / 100.0f, 0.25F);
                float treePercent  = Mathf.Pow(regionTiles[x, y].vegetation / 100.0f, 0.5F);

                foreach (var item in regionTiles[x, y].plant_materials)
                {
                    plantColor += ContentLoader.GetColor(item);
                }
                if (regionTiles[x, y].plant_materials.Count == 0)
                {
                    grassPercent = 0;
                }
                else
                {
                    plantColor /= regionTiles[x, y].plant_materials.Count;
                }

                Color treeColor = Color.black;
                int   treeCount = 0;
                foreach (var tree in regionTiles[x, y].tree_materials)
                {
                    int plantIndex = tree.mat_index;
                    if (tree.mat_type != 419 ||
                        DFConnection.Instance.NetPlantRawList == null ||
                        DFConnection.Instance.NetPlantRawList.plant_raws.Count <= plantIndex)
                    {
                        continue;
                    }
                    var treeMat = tree;
                    foreach (var growth in DFConnection.Instance.NetPlantRawList.plant_raws[plantIndex].growths)
                    {
                        int currentTicks = TimeHolder.DisplayedTime.CurrentYearTicks;
                        if ((growth.timing_start != -1 && growth.timing_start > currentTicks) || (growth.timing_end != -1 && growth.timing_end < currentTicks))
                        {
                            continue;
                        }
                        treeMat = growth.mat;
                        break;
                    }
                    treeColor += ContentLoader.GetColor(treeMat);
                    treeCount++;
                }
                if (treeCount == 0)
                {
                    treePercent = 0;
                }
                else
                {
                    treeColor /= treeCount;
                }



                terrainColor = Color.Lerp(terrainColor, plantColor, grassPercent);
                terrainColor = Color.Lerp(terrainColor, treeColor, treePercent);

                Vector2 biome = new Vector2(regionTiles[x, y].rainfall, 100 - regionTiles[x, y].drainage) / 100;

                Vector3 vert1 = RegionToUnityCoords(x, y, regionTiles[x, y].elevation);
                Vector3 vert2 = RegionToUnityCoords(x + 1, y + 1, regionTiles[x, y].elevation);

                bool snow = regionTiles[x, y].snow > 0;

                RegionMaker.AddHorizontalQuad(vert1, vert2, biome, terrainColor, vertices, colors, uvs, uv2s, uv3s, triangles, snow);

                if (regionTiles[x, y].elevation < regionTiles[x, y].water_elevation)
                {
                    vert1 = RegionToUnityCoords(x, y, regionTiles[x, y].water_elevation);
                    vert2 = RegionToUnityCoords(x + 1, y + 1, regionTiles[x, y].water_elevation);

                    RegionMaker.AddHorizontalQuad(vert1, vert2, biome, terrainColor, waterVerts, null, waterUvs, null, null, waterTris, false);
                }

                int north = 0;
                if (y > 0 && !DetailRegions.ContainsKey(new DFCoord2d(x, y - 1)))
                {
                    north = regionTiles[x, y - 1].elevation;
                }
                if (north < regionTiles[x, y].elevation)
                {
                    vert1 = (new Vector3(x * 48 * 16 * GameMap.tileWidth, regionTiles[x, y].elevation * GameMap.tileHeight, -y * 48 * 16 * GameMap.tileWidth)) * scale;
                    vert2 = (new Vector3((x + 1) * 48 * 16 * GameMap.tileWidth, north * GameMap.tileHeight, -y * 48 * 16 * GameMap.tileWidth)) * scale;

                    RegionMaker.AddVerticalQuad(vert1, vert2, biome, terrainColor, vertices, colors, uvs, uv2s, uv3s, triangles, snow);
                }

                int south = 0;
                if (y < height - 1 && !DetailRegions.ContainsKey(new DFCoord2d(x, y + 1)))
                {
                    south = regionTiles[x, y + 1].elevation;
                }
                if (south < regionTiles[x, y].elevation)
                {
                    vert1 = (new Vector3((x + 1) * 48 * 16 * GameMap.tileWidth, regionTiles[x, y].elevation * GameMap.tileHeight, -(y + 1) * 48 * 16 * GameMap.tileWidth)) * scale;
                    vert2 = (new Vector3(x * 48 * 16 * GameMap.tileWidth, south * GameMap.tileHeight, -(y + 1) * 48 * 16 * GameMap.tileWidth)) * scale;

                    RegionMaker.AddVerticalQuad(vert1, vert2, biome, terrainColor, vertices, colors, uvs, uv2s, uv3s, triangles, snow);
                }

                int east = 0;
                if (x < width - 1 && !DetailRegions.ContainsKey(new DFCoord2d(x + 1, y)))
                {
                    east = regionTiles[x + 1, y].elevation;
                }
                if (east < regionTiles[x, y].elevation)
                {
                    vert1 = (new Vector3((x + 1) * 48 * 16 * GameMap.tileWidth, regionTiles[x, y].elevation * GameMap.tileHeight, -y * 48 * 16 * GameMap.tileWidth)) * scale;
                    vert2 = (new Vector3((x + 1) * 48 * 16 * GameMap.tileWidth, east * GameMap.tileHeight, -(y + 1) * 48 * 16 * GameMap.tileWidth)) * scale;

                    RegionMaker.AddVerticalQuad(vert1, vert2, biome, terrainColor, vertices, colors, uvs, uv2s, uv3s, triangles, snow);
                }
                int west = 0;
                if (x > 0 && !DetailRegions.ContainsKey(new DFCoord2d(x - 1, y)))
                {
                    west = regionTiles[x - 1, y].elevation;
                }
                if (west < regionTiles[x, y].elevation)
                {
                    vert1 = (new Vector3(x * 48 * 16 * GameMap.tileWidth, regionTiles[x, y].elevation * GameMap.tileHeight, -(y + 1) * 48 * 16 * GameMap.tileWidth)) * scale;
                    vert2 = (new Vector3(x * 48 * 16 * GameMap.tileWidth, west * GameMap.tileHeight, -y * 48 * 16 * GameMap.tileWidth)) * scale;

                    RegionMaker.AddVerticalQuad(vert1, vert2, biome, terrainColor, vertices, colors, uvs, uv2s, uv3s, triangles, snow);
                }
            }
        }

        FinalizeGeometryChunk(vertices, colors, uvs, uv2s, uv3s, triangles);

        FinalizeWaterGeometryChunk(waterVerts, waterUvs, waterTris);
    }
示例#5
0
        public void UpdatePart(BuildingInstance buildingInput)
        {
            Color partColor    = new Color32(128, 128, 128, 128);
            float textureIndex = 0;

            if (string.IsNullOrEmpty(item) || ItemTokenList.ItemLookup == null)
            {
                if (index < 0)
                {
                    partColor    = ContentLoader.GetColor(buildingInput.material);
                    textureIndex = ContentLoader.GetPatternIndex(buildingInput.material);
                }
                else if (index >= buildingInput.items.Count - endOffset)
                {
                    gameObject.SetActive(false);
                    return;
                }
                else
                {
                    var buildingItem = buildingInput.items[index];
                    //skip items that are just stored in the building.
                    //though they should be later in the list anyway.
                    if ((buildingItem.mode == 0) != storedItem)
                    {
                        gameObject.SetActive(false);
                        return;
                    }
                    partColor    = ContentLoader.GetColor(buildingItem.item);
                    textureIndex = ContentLoader.GetPatternIndex(buildingItem.item.material);
                    ItemModel.UpdateImprovements(gameObject, buildingItem.item);
                }
            }
            else if (!ItemTokenList.ItemLookup.ContainsKey(item))
            {
                gameObject.SetActive(false);
                return;
            }
            else
            {
                MatPairStruct itemCode = ItemTokenList.ItemLookup[item].mat_pair;
                bool          set      = false;
                foreach (var buildingItem in buildingInput.items)
                {
                    //skip items that are just stored in the building.
                    //though they should be later in the list anyway.
                    if (buildingItem.mode == 0 && !storedItem)
                    {
                        continue;
                    }
                    //if our setting is a generic item, like any weapon, then any subtype can match.
                    if ((itemCode.mat_index == -1 && itemCode.mat_type == buildingItem.item.type.mat_type) ||
                        (buildingItem.item.type == itemCode))
                    {
                        partColor    = ContentLoader.GetColor(buildingItem.item);
                        textureIndex = ContentLoader.GetPatternIndex(buildingItem.item.material);
                        ItemModel.UpdateImprovements(gameObject, buildingItem.item);
                        set = true;
                        break;
                    }
                }
                if (!set)
                {
                    gameObject.SetActive(false);
                    return;
                }
            }
            gameObject.SetActive(true);


            if (meshRenderer == null)
            {
                meshRenderer = GetComponent <MeshRenderer>();
            }

            if (originalMaterial == null)
            {
                originalMaterial = meshRenderer.sharedMaterial;
            }

            meshRenderer.sharedMaterial = ContentLoader.getFinalMaterial(originalMaterial, partColor.a);

            MaterialPropertyBlock prop = new MaterialPropertyBlock();

            prop.SetColor("_MatColor", partColor);
            prop.SetFloat("_MatIndex", textureIndex);
            meshRenderer.SetPropertyBlock(prop);
        }
示例#6
0
    void GenerateSpatterTexture(int blockX, int blockY, int blockZ)
    {
        UnityEngine.Profiling.Profiler.BeginSample("GenerateSpatterTexture", this);
        if (spatterColor[blockZ] == null || spatterColor[blockZ].Length != MapDataStore.MapSize.x * MapDataStore.MapSize.y)
        {
            spatterColor[blockZ] = new Color[MapDataStore.MapSize.x * MapDataStore.MapSize.y];
        }

        var textureColors = spatterColor[blockZ];

        for (int y = blockY * GameMap.blockSize; y < (blockY + 1) * GameMap.blockSize; y++)
        {
            for (int x = blockX * GameMap.blockSize; x < (blockX + 1) * GameMap.blockSize; x++)
            {
                Color totalColor = new Color(0, 0, 0, 0);
                int   index      = x + (y * MapDataStore.MapSize.x);

                var tile = MapDataStore.Main[x, y, blockZ];
                if (tile == null)
                {
                    textureColors[index] = totalColor;
                    continue;
                }
                if (tile.spatters == null || tile.spatters.Count == 0)
                {
                    textureColors[index] = totalColor;
                    continue;
                }

                if (tile.Hidden)
                {
                    textureColors[index] = totalColor;
                    continue;
                }
                float totalAmount = 0;

                foreach (var spatter in tile.spatters)
                {
                    if (spatter.amount == 0)
                    {
                        continue;
                    }

                    Color color = Color.white;

                    if (spatter.material.mat_type == (int)MatBasic.ICE && spatter.state == MatterState.Powder)
                    {
                        color = Color.white;
                    }
                    else
                    {
                        if (spatter.item != null)
                        {
                            color = ContentLoader.GetGrowthColor(ContentLoader.GrowthPeriod.Stale, spatter.item.mat_index, spatter.material);
                        }
                        else
                        {
                            color = ContentLoader.GetColor(spatter.material);
                        }
                    }

                    float amount = spatter.amount;
                    if (spatter.item != null)
                    {
                        amount /= 3000;
                    }
                    else
                    {
                        amount /= 100;
                    }
                    //amount = Mathf.Clamp01(amount);

                    color *= amount;

                    color.a = amount;

                    totalColor  += color;
                    totalAmount += amount;
                }
                if (totalAmount > 1)
                {
                    totalColor /= totalAmount;
                }
                textureColors[index] = totalColor;
            }
        }

        UnityEngine.Profiling.Profiler.EndSample();
    }
示例#7
0
    void GenerateTerrainTexture(int blockX, int blockY, int blockZ)
    {
        if (ContentLoader.Instance == null)
        {
            return;
        }
        UnityEngine.Profiling.Profiler.BeginSample("GenerateTerrainTexture", this);

        if (terrainSplatColor[blockZ] == null || terrainTintColor[blockZ] == null || terrainSplatColor[blockZ].Length != MapDataStore.MapSize.x * MapDataStore.MapSize.y)
        {
            CreateBlankTerrainTextures(blockZ);
        }

        var terrainIndices = terrainSplatColor[blockZ];
        var terrainColors  = terrainTintColor[blockZ];

        UnityEngine.Profiling.Profiler.BeginSample("Update Terrain Color Array", this);
        for (int y = blockY * GameMap.blockSize; y < (blockY + 1) * GameMap.blockSize; y++)
        {
            for (int x = blockX * GameMap.blockSize; x < (blockX + 1) * GameMap.blockSize; x++)
            {
                int index = x + (y * MapDataStore.MapSize.x);
                var tile  = MapDataStore.Main[x, y, blockZ];
                if (IsNullOrEmpty(tile))
                {
                    if (!IsNullOrEmpty(MapDataStore.Main[x - 1, y, blockZ]))
                    {
                        tile = MapDataStore.Main[x - 1, y, blockZ];
                    }
                    else if (!IsNullOrEmpty(MapDataStore.Main[x, y - 1, blockZ]))
                    {
                        tile = MapDataStore.Main[x, y - 1, blockZ];
                    }
                    else if (!IsNullOrEmpty(MapDataStore.Main[x + 1, y, blockZ]))
                    {
                        tile = MapDataStore.Main[x + 1, y, blockZ];
                    }
                    else if (!IsNullOrEmpty(MapDataStore.Main[x, y + 1, blockZ]))
                    {
                        tile = MapDataStore.Main[x, y + 1, blockZ];
                    }
                    else if (!IsNullOrEmpty(MapDataStore.Main[x - 1, y - 1, blockZ]))
                    {
                        tile = MapDataStore.Main[x - 1, y - 1, blockZ];
                    }
                    else if (!IsNullOrEmpty(MapDataStore.Main[x - 1, y + 1, blockZ]))
                    {
                        tile = MapDataStore.Main[x - 1, y + 1, blockZ];
                    }
                    else if (!IsNullOrEmpty(MapDataStore.Main[x + 1, y - 1, blockZ]))
                    {
                        tile = MapDataStore.Main[x + 1, y - 1, blockZ];
                    }
                    else if (!IsNullOrEmpty(MapDataStore.Main[x + 1, y + 1, blockZ]))
                    {
                        tile = MapDataStore.Main[x + 1, y + 1, blockZ];
                    }
                    else
                    {
                        continue;
                    }
                }
                if (tile.shape == TiletypeShape.RAMP_TOP && tile.Down != null)
                {
                    tile = tile.Down;
                }

                var layer = MeshLayer.BaseMaterial;
                if (tile.tiletypeMaterial == TiletypeMaterial.GRASS_DARK ||
                    tile.tiletypeMaterial == TiletypeMaterial.GRASS_DEAD ||
                    tile.tiletypeMaterial == TiletypeMaterial.GRASS_DRY ||
                    tile.tiletypeMaterial == TiletypeMaterial.GRASS_LIGHT ||
                    tile.tiletypeMaterial == TiletypeMaterial.PLANT
                    )
                {
                    layer = MeshLayer.LayerMaterial;
                }
                if (tile.special == TiletypeSpecial.NORMAL || layer == MeshLayer.LayerMaterial)
                {
                    //If it's natural terrain or grass, use the material normal maps.
                    terrainIndices[index].g = ContentLoader.GetShapeIndex(tile.GetMaterial(layer)) / 255f;
                }
                else
                {
                    NormalContent norms;
                    ContentLoader.Instance.ShapeTextureConfiguration.GetValue(tile, layer, out norms);
                    terrainIndices[index].g = norms.StorageIndex / 255f;
                }
                terrainIndices[index].r = ContentLoader.GetPatternIndex(tile.GetMaterial(layer)) / 255f;
                terrainColors[index]    = ContentLoader.GetColor(tile.GetMaterial(layer));
            }
        }
        UnityEngine.Profiling.Profiler.EndSample();
        UnityEngine.Profiling.Profiler.EndSample();
    }
示例#8
0
    internal void UpdateLayers(UnitDefinition unit, CreatureRaw creatureRaw, CasteRaw casteRaw)
    {
        for (int i = 0; i < spriteList.Count; i++)
        {
            var spriteLayerDef = SpriteCollection.spriteLayers[i];
            var sprite         = spriteList[i];
            switch (spriteLayerDef.spriteSource)
            {
            case CreatureSpriteLayer.SpriteSource.Static:
                sprite.gameObject.SetActive(true);
                switch (spriteLayerDef.colorSource)
                {
                case CreatureSpriteLayer.ColorSource.Fixed:
                    sprite.color = spriteLayerDef.color;
                    break;

                case CreatureSpriteLayer.ColorSource.Job:
                    sprite.color = new Color(unit.profession_color.red / 255.0f, unit.profession_color.green / 255.0f, unit.profession_color.blue / 255.0f, 0.5f);
                    break;

                default:
                    sprite.color = new Color32(128, 128, 128, 128);
                    break;
                }
                break;

            case CreatureSpriteLayer.SpriteSource.Bodypart:
                sprite.gameObject.SetActive(true);
                switch (spriteLayerDef.colorSource)
                {
                case CreatureSpriteLayer.ColorSource.Fixed:
                    sprite.color = spriteLayerDef.color;
                    break;

                case CreatureSpriteLayer.ColorSource.Material:
                    ColorDefinition unitColor     = new ColorDefinition();
                    int             colorModIndex = casteRaw.color_modifiers.FindIndex(x => x.part == spriteLayerDef.token && x.start_date == 0);
                    if (colorModIndex >= 0 && unit.appearance != null)
                    {
                        unitColor    = casteRaw.color_modifiers[colorModIndex].patterns[unit.appearance.colors[colorModIndex]].colors[spriteLayerDef.patternIndex];
                        sprite.color = new Color32((byte)unitColor.red, (byte)unitColor.green, (byte)unitColor.blue, 128);
                    }
                    else
                    {
                        int tissueIndex = creatureRaw.tissues.FindIndex(x => x.name == spriteLayerDef.token);
                        if (tissueIndex >= 0)
                        {
                            sprite.color = ContentLoader.GetColor(creatureRaw.tissues[tissueIndex].material);
                        }
                        else
                        {
                            sprite.gameObject.SetActive(false);
                        }
                        break;
                    }
                    break;

                case CreatureSpriteLayer.ColorSource.Job:
                    sprite.color = new Color(unit.profession_color.red / 255.0f, unit.profession_color.green / 255.0f, unit.profession_color.blue / 255.0f, 0.5f);
                    break;

                case CreatureSpriteLayer.ColorSource.BodyPart:
                    var part = casteRaw.body_parts.Find(x => x.token == spriteLayerDef.token);
                    if (part == null)
                    {
                        sprite.gameObject.SetActive(false);
                        break;
                    }
                    sprite.color = ContentLoader.GetColor(creatureRaw.tissues[part.layers[0].tissue_id].material);
                    break;

                default:
                    sprite.color = new Color32(128, 128, 128, 128);
                    break;
                }
                switch (spriteLayerDef.hairType)
                {
                case CreatureSpriteLayer.HairType.Hair:
                    if (unit.inventory.FindIndex(x => x.item.type.mat_type == (int)ItemType.Helm) >= 0)
                    {
                        sprite.gameObject.SetActive(false);
                        break;
                    }
                    if (unit.appearance == null || unit.appearance.hair == null)
                    {
                        sprite.gameObject.SetActive(spriteLayerDef.hairStyle == HairStyle.UNKEMPT);
                    }
                    else
                    {
                        sprite.gameObject.SetActive((spriteLayerDef.hairStyle == unit.appearance.hair.style) &&
                                                    (spriteLayerDef.hairMin <= unit.appearance.hair.length) &&
                                                    ((spriteLayerDef.hairMax < 0) || (spriteLayerDef.hairMax > unit.appearance.hair.length)));
                    }
                    break;

                case CreatureSpriteLayer.HairType.Beard:
                    if (unit.appearance == null || unit.appearance.beard == null)
                    {
                        sprite.gameObject.SetActive(spriteLayerDef.hairStyle == HairStyle.UNKEMPT);
                    }
                    else
                    {
                        sprite.gameObject.SetActive((spriteLayerDef.hairStyle == unit.appearance.beard.style) &&
                                                    (spriteLayerDef.hairMin <= unit.appearance.beard.length) &&
                                                    ((spriteLayerDef.hairMax < 0) || (spriteLayerDef.hairMax > unit.appearance.beard.length)));
                    }
                    break;

                case CreatureSpriteLayer.HairType.Moustache:
                    if (unit.appearance == null || unit.appearance.moustache == null)
                    {
                        sprite.gameObject.SetActive(spriteLayerDef.hairStyle == HairStyle.UNKEMPT);
                    }
                    else
                    {
                        sprite.gameObject.SetActive((spriteLayerDef.hairStyle == unit.appearance.moustache.style) &&
                                                    (spriteLayerDef.hairMin <= unit.appearance.moustache.length) &&
                                                    ((spriteLayerDef.hairMax < 0) || (spriteLayerDef.hairMax > unit.appearance.moustache.length)));
                    }
                    break;

                case CreatureSpriteLayer.HairType.Sideburns:
                    if (unit.appearance == null || unit.appearance.sideburns == null)
                    {
                        sprite.gameObject.SetActive(spriteLayerDef.hairStyle == HairStyle.UNKEMPT);
                    }
                    else
                    {
                        sprite.gameObject.SetActive((spriteLayerDef.hairStyle == unit.appearance.sideburns.style) &&
                                                    (spriteLayerDef.hairMin <= unit.appearance.sideburns.length) &&
                                                    ((spriteLayerDef.hairMax < 0) || (spriteLayerDef.hairMax > unit.appearance.sideburns.length)));
                    }
                    break;

                default:
                    sprite.gameObject.SetActive(true);
                    break;
                }
                break;

            case CreatureSpriteLayer.SpriteSource.Equipment:
                int inventoryIndex = unit.inventory.FindIndex(
                    x =>
                    (x.mode == InventoryMode.Weapon || x.mode == InventoryMode.Worn) &&
                    spriteLayerDef.token == ItemRaws.Instance[x.item.type].id
                    );
                if (inventoryIndex < 0)
                {
                    sprite.gameObject.SetActive(false);
                    break;
                }
                else
                {
                    sprite.enabled = true;
                }
                var item = unit.inventory[inventoryIndex].item;

                switch (spriteLayerDef.colorSource)
                {
                case CreatureSpriteLayer.ColorSource.Fixed:
                    sprite.color = spriteLayerDef.color;
                    break;

                case CreatureSpriteLayer.ColorSource.Material:
                    sprite.color = ContentLoader.GetColor(item);
                    break;

                case CreatureSpriteLayer.ColorSource.Job:
                    sprite.color = new Color(unit.profession_color.red / 255.0f, unit.profession_color.green / 255.0f, unit.profession_color.blue / 255.0f, 0.5f);
                    break;

                default:
                    sprite.color = new Color32(128, 128, 128, 128);
                    break;
                }
                break;

            default:
                sprite.gameObject.SetActive(false);
                break;
            }
            if (sprite.color.a < 0.5f)
            {
                sprite.sharedMaterial = SpriteMatTrans;
            }
            else
            {
                sprite.sharedMaterial = SpriteMat;
            }
        }
    }