Esempio n. 1
0
    private void SetCaseTerrainHeight(Vector2 pos, TerrainData terrainData)
    {
        int x        = (int)pos.x;
        int y        = (int)pos.y;
        int cellSize = CoordinatesConverter.cellSize;

        float[,] heights = new float[cellSize, cellSize];

        CaseInfos infos = _mapInfosManager.GetInfosAtPos(new Vector2(x, y));

        if (infos != null)
        {
            for (int i = 0; i < cellSize; i++)
            {
                for (int j = 0; j < cellSize; j++)
                {
                    float newHeight = 0.005f;

                    if (infos.mapType == MapInfosManager.MapType.Water)
                    {
                        newHeight = 0.0f;
                    }
                    else if (infos.mapType == MapInfosManager.MapType.Sand)
                    {
                        newHeight /= 2;
                    }

                    heights[j, i] = newHeight;
                }
            }
            terrainData.SetHeights(y * cellSize, x * cellSize, heights);
        }
    }
Esempio n. 2
0
 private int GetTextureId(CaseInfos caseInfos)
 {
     if (caseInfos == null)
     {
         return(-1);
     }
     return(GetTextureId(caseInfos.mapType));
 }
    public MapType GetMapTypeAtPos(Vector2 pos)
    {
        CaseInfos info = GetInfosAtPos(pos);

        if (info == null)
        {
            Debug.LogWarning("Fetching MapType from wrong position (" + pos.x + ", " + pos.y + ")");
            return(MapType.Unknown);
        }
        return(info.mapType);
    }
 private void InitMapWithGrass()
 {
     for (int i = 0; i < mapSize.x; i++)
     {
         for (int j = 0; j < mapSize.y; j++)
         {
             Vector2   pos       = new Vector2(i, j);
             CaseInfos caseInfos = new CaseInfos(MapType.Grass, 0.0f);
             infos.Add(pos, caseInfos);
         }
     }
 }
    private void InitGridMap()
    {
        int x = (int)mapSize.x;
        int y = (int)mapSize.y;

        infos = new Dictionary <Vector2, CaseInfos>();
        for (int i = 0; i < x; i++)
        {
            for (int j = 0; j < y; j++)
            {
                Vector2   pos       = new Vector2(i, j);
                MapType   mapType   = (i % 2 == 0) ^ (j % 2 == 0) ? MapType.Grass : MapType.Mountain;
                CaseInfos caseInfos = new CaseInfos(mapType, 0.0f);
                infos.Add(pos, caseInfos);
            }
        }
    }
        //选中一个案子
        private void OnItemSelected(object[] selectedItems)
        {
            if (selectedItems != null && selectedItems.Count() > 0)
            {
                TaskViewModel task = (TaskViewModel)selectedItems.FirstOrDefault();
                SelectedAttorneySeries = task.AttorneySeries;
                SelectedCaseInfo       = CaseInfos.Find(s => s.AttorneySeries == SelectedAttorneySeries);
                List <FileViewModel> fileinfos;

                Paths    = new List <string>();
                CasePath = Userinfo.WorkPath + "NewApplication\\" + SelectedAttorneySeries;
                HttpDataService hds = new HttpDataService(Cookie);
                fileinfos = hds.GetFileInfos(SelectedCaseInfo.taskInfos[0].TaskID);

                FileList = new ObservableCollection <FileViewModel>();
                foreach (var item in fileinfos)
                {
                    FileViewModel fileinfo = new FileViewModel();
                    fileinfo.FileName     = item.FileName;
                    fileinfo.FileID       = item.FileID;
                    fileinfo.FileDescribe = item.FileDescribe;
                    fileinfo.UploadUser   = item.UploadUser;
                    fileinfo.UploadTime   = item.UploadTime;

                    FileList.Add(fileinfo);
                }
                Index = 0;
            }

            //获取文件信息
            if (!Directory.Exists(CasePath))
            {
                HasFolder = true;
            }
            else
            {
                HasFolder = false;
            }
        }
Esempio n. 7
0
    private void OldAssignTextures()
    {
        // Get a reference to the terrain data
        TerrainData terrainData = _terrain.terrainData;

        // Splatmap data is stored internally as a 3d array of floats, so declare a new empty array ready for your custom splatmap data:
        float[,,] splatmapData = new float[terrainData.alphamapWidth,
                                           terrainData.alphamapHeight,
                                           terrainData.alphamapLayers];

        for (int y = 0; y < terrainData.alphamapHeight; y++)
        {
            for (int x = 0; x < terrainData.alphamapWidth; x++)
            {
                // Normalise x/y coordinates to range 0-1
                float y_01 = (float)y / (float)terrainData.alphamapHeight;
                float x_01 = (float)x / (float)terrainData.alphamapWidth;

                // Sample the height at this location (note GetHeight expects int coordinates corresponding to locations in the heightmap array)
                //float height = terrainData.GetHeight(Mathf.RoundToInt(y_01 * terrainData.heightmapHeight), Mathf.RoundToInt(x_01 * terrainData.heightmapWidth));

                // Calculate the normal of the terrain (note this is in normalised coordinates relative to the overall terrain dimensions)
                //Vector3 normal = terrainData.GetInterpolatedNormal(y_01, x_01);

                // Calculate the steepness of the terrain
                // float steepness = terrainData.GetSteepness(y_01, x_01);

                // Setup an array to record the mix of texture weights at this point
                float[] splatWeights = new float[terrainData.alphamapLayers];

                // CHANGE THE RULES BELOW TO SET THE WEIGHTS OF EACH TEXTURE ON WHATEVER RULES YOU WANT
                CaseInfos caseInfo   = _mapInfosManager.GetInfosAtPos(new Vector2(x, y));
                CaseInfos infoXPlus  = _mapInfosManager.GetInfosAtPos(new Vector2(x + 10, y));
                CaseInfos infoXMoins = _mapInfosManager.GetInfosAtPos(new Vector2(x - 10, y));
                CaseInfos infoYPlus  = _mapInfosManager.GetInfosAtPos(new Vector2(x, y + 10));
                CaseInfos infoYMoins = _mapInfosManager.GetInfosAtPos(new Vector2(x, y - 10));

                int idCase   = GetTextureId(caseInfo);
                int idXPlus  = GetTextureId(infoXPlus);
                int idXMoins = GetTextureId(infoXMoins);
                int idYPlus  = GetTextureId(infoYPlus);
                int idYMoins = GetTextureId(infoYMoins);

                if (caseInfo == null)
                {
                    //Debug.LogWarning("Case infos not found at pos (" + x + "," + y + ")");
                    splatWeights[0] = 0.5f;
                    splatWeights[1] = 0.5f;
                }
                else
                {
                    int yunit = y - (y / 10) * 10;
                    int xunit = x - (x / 10) * 10;

                    float currentRatio;

                    if (xunit < 4 && xunit != 0 && idXMoins != -1 && idXMoins != idCase)
                    {
                        currentRatio           = (-2 * xunit + 7) / 10.0f;
                        splatWeights[idXMoins] = currentRatio + splatWeights[idXMoins] - splatWeights[idXMoins] * currentRatio;
                    }
                    else if (xunit > 7 && idXPlus != -1 && idXPlus != idCase)
                    {
                        currentRatio          = (2 * xunit - 15) / 10.0f;
                        splatWeights[idXPlus] = currentRatio + splatWeights[idXPlus] - splatWeights[idXPlus] * currentRatio;
                    }
                    else if (xunit == 0 && idXPlus != -1 && idXPlus != idCase)
                    {
                        currentRatio          = 0.49f;
                        splatWeights[idXPlus] = currentRatio + splatWeights[idXPlus] - splatWeights[idXPlus] * currentRatio;
                    }

                    if (yunit < 4 && yunit != 0 && idYMoins != -1 && idYMoins != idCase)
                    {
                        currentRatio           = (-2 * yunit + 7) / 10.0f;
                        splatWeights[idYMoins] = currentRatio + splatWeights[idYMoins] - splatWeights[idYMoins] * currentRatio;
                    }
                    else if (yunit > 7 && idYPlus != -1 && idYPlus != idCase)
                    {
                        currentRatio          = (2 * yunit - 15) / 10.0f;
                        splatWeights[idYPlus] = currentRatio + splatWeights[idYPlus] - splatWeights[idYPlus] * currentRatio;
                    }
                    else if (yunit == 0 && idYPlus != -1 && idYPlus != idCase)
                    {
                        currentRatio          = 0.50f;
                        splatWeights[idYPlus] = currentRatio + splatWeights[idYPlus] - splatWeights[idYPlus] * currentRatio;
                    }
                    splatWeights[idCase] = splatWeights[idCase] == 0 ? 1 - splatWeights.Sum() : splatWeights[idCase] * (1 - splatWeights.Sum());
                }


                // Texture[2] stronger on flatter terrain
                // Note "steepness" is unbounded, so we "normalise" it by dividing by the extent of heightmap height and scale factor
                // Subtract result from 1.0 to give greater weighting to flat surfaces
                //splatWeights[2] = 1.0f - Mathf.Clamp01(steepness * steepness / (terrainData.heightmapHeight / 5.0f));

                // Texture[3] increases with height but only on surfaces facing positive Z axis
                //splatWeights[3] = height * Mathf.Clamp01(normal.z);

                // Sum of all textures weights must add to 1, so calculate normalization factor from sum of weights
                float z = splatWeights.Sum();

                // Loop through each terrain texture
                for (int i = 0; i < terrainData.alphamapLayers; i++)
                {
                    // Normalize so that sum of all texture weights = 1
                    splatWeights[i] /= z;

                    // Assign this point to the splatmap array
                    splatmapData[x, y, i] = splatWeights[i];
                }
            }
        }

        // Finally assign the new splatmap to the terrainData:
        terrainData.SetAlphamaps(0, 0, splatmapData);
    }