Exemple #1
0
    public List <TerrainMod> GetTerrainMods()
    {
        List <TerrainMod> rtn = new List <TerrainMod>();
        //find out which is the highest terrain - this is used if we raise the terrain so that only the highest one is raised
        TerrainListItem HighestTerrain = TerrainController.Instance.TerrainList.OrderByDescending(item => item.TData.GetHeight(this.TerrainXBase, this.TerrainYBase)).First();

        foreach (TerrainListItem TLI in TerrainController.Instance.TerrainList)
        {
            TerrainMod Mod = new TerrainMod();
            Mod.TerrainId    = TLI.TerrainId;
            Mod.TerrainXBase = this.TerrainXBase;
            Mod.TerrainYBase = this.TerrainYBase;
            Mod.Heights      = new float[this.Heights.GetLength(1), this.Heights.GetLength(0)];
            bool ThisTerrainWasCut = false;
            float[,] PrevHeights = TLI.TData.GetHeights(this.TerrainXBase, this.TerrainYBase, this.Heights.GetLength(0), this.Heights.GetLength(1));
            for (int j = 0; j < this.Heights.GetLength(0); j++)
            {
                for (int k = 0; k < this.Heights.GetLength(1); k++)
                {
                    if (this.Heights[j, k] == 0)
                    {
                        Mod.Heights[k, j] = PrevHeights[k, j];
                    }
                    else
                    {
                        float NewHeight = (this.Heights[j, k] - TLI.T.transform.position.y) / TLI.yRes;
                        if (!this.RaiseAllowed)
                        {
                            if (NewHeight < PrevHeights[k, j])
                            {
                                Mod.Heights[k, j] = NewHeight;
                                ThisTerrainWasCut = true;
                            }
                            else
                            {
                                Mod.Heights[k, j] = PrevHeights[k, j];
                            }
                        }
                        else  //if RaiseAllowed
                        {
                            if (TLI == HighestTerrain)
                            {
                                Mod.Heights[k, j] = NewHeight;
                            }
                            else
                            {
                                Mod.Heights[k, j] = NewHeight * 0.95f;
                            }
                            ThisTerrainWasCut = true;
                        }
                    }
                }
            }
            if (ThisTerrainWasCut)
            {
                rtn.Add(Mod);
            }
        }
        return(rtn);
    }
    public void Encode(TerrainListItem tli)
    {
        TerrainId = tli.TerrainId;
        int xRes = tli.TData.heightmapResolution;
        int zRes = tli.TData.heightmapResolution;

        Heights = tli.TData.GetHeights(0, 0, xRes, zRes);
    }
Exemple #3
0
    //float[,,] SplatMapData;

    public void Encode(TerrainListItem tli)
    {
        int Width  = tli.TData.alphamapWidth;
        int Height = tli.TData.alphamapHeight;
        int Layers = tli.TData.alphamapLayers;

        TerrainId = tli.TerrainId;
        //SplatMapData = tli.TData.GetAlphamaps(0, 0, Width, Height);
    }
Exemple #4
0
    //public float ConvertToTerrainHeight(float y)
    //{
    //    return (y - T.transform.position.y) / yRes;
    //}

    /*public float[] OldHeight(int j, int k)
     * {
     *  float[] rtn = new float[TerrainCount];
     *  for (int i = 0; i < TerrainCount; i++)
     *  {
     *      rtn[i] = TerrainList[i].HeightsBkp[j, k];
     *  }
     *  return rtn;
     * }*/



    public void ApplyMods(List <TerrainMod> Mods)
    {
        foreach (TerrainMod Mod in Mods)
        {
            TerrainListItem TLI = TerrainList[Mod.TerrainId];
            TLI.TData.SetHeights(Mod.TerrainXBase, Mod.TerrainYBase, Mod.Heights);
        }
        //LoadedNewTerrainHeightmaps = false;   //Took this out cos I think its depreciated
    }
Exemple #5
0
    public void Init()
    {
        Debug.Log("TerrainCOntrollerInit");
        UnityEngine.Profiling.Profiler.BeginSample("TerrainInit");
        AllTerrainObjects = GameObject.FindGameObjectsWithTag("Terrain");
        System.Array.Sort(AllTerrainObjects, CompareObjNames);
        TerrainCount = AllTerrainObjects.Length;
        if (LoadedNewTerrainHeightmaps || RestoredTerrainBkp)
        {
            TerrainList.Clear();
            for (int i = 0; i < TerrainCount; i++)
            {
                TerrainListItem TLI = new TerrainListItem(AllTerrainObjects[i]);
                TLI.TerrainId = i;
                TerrainList.Add(TLI);
            }
        }
        else
        {
            for (int i = 0; i < AllTerrainObjects.Count(); i++)
            {
                TerrainList[i].T = AllTerrainObjects[i];
            }
        }

        if (LoadedNewTerrainHeightmaps)
        {
            ApplyTerrainHeightmaps(); if (GameData.current.Scene == "Canyon")
            {
                RepaintSplats();
            }
            LoadedNewTerrainHeightmaps = false;
        }

        if (RestoredTerrainBkp)
        {
            ApplyTerrainBkps(); RestoredTerrainBkp = false;
        }
        UnityEngine.Profiling.Profiler.EndSample();
    }