Esempio n. 1
0
 public static bool ApplyTerrainChecks(
     this Transform transform,
     TerrainCheck[] anchors,
     Vector3 pos,
     Quaternion rot,
     Vector3 scale,
     SpawnFilter filter = null)
 {
     if (anchors.Length == 0)
     {
         return(true);
     }
     for (int index = 0; index < anchors.Length; ++index)
     {
         TerrainCheck anchor    = anchors[index];
         Vector3      vector3_1 = Vector3.Scale(anchor.worldPosition, scale);
         if (anchor.Rotate)
         {
             vector3_1 = Quaternion.op_Multiply(rot, vector3_1);
         }
         Vector3 vector3_2 = Vector3.op_Addition(pos, vector3_1);
         if (TerrainMeta.OutOfBounds(vector3_2) || filter != null && (double)filter.GetFactor(vector3_2) == 0.0 || !anchor.Check(vector3_2))
         {
             return(false);
         }
     }
     return(true);
 }
 public static bool ApplyTerrainChecks(this Transform transform, TerrainCheck[] anchors, Vector3 pos, Quaternion rot, Vector3 scale, SpawnFilter filter = null)
 {
     if (anchors.Length == 0)
     {
         return(true);
     }
     for (int i = 0; i < (int)anchors.Length; i++)
     {
         TerrainCheck terrainCheck = anchors[i];
         Vector3      vector3      = Vector3.Scale(terrainCheck.worldPosition, scale);
         if (terrainCheck.Rotate)
         {
             vector3 = rot * vector3;
         }
         Vector3 vector31 = pos + vector3;
         if (TerrainMeta.OutOfBounds(vector31))
         {
             return(false);
         }
         if (filter != null && filter.GetFactor(vector31) == 0f)
         {
             return(false);
         }
         if (!terrainCheck.Check(vector31))
         {
             return(false);
         }
     }
     return(true);
 }
Esempio n. 3
0
 public static bool ApplyTerrainFilters(this Transform transform, TerrainFilter[] filters, Vector3 pos, Quaternion rot, Vector3 scale, SpawnFilter globalFilter = null)
 {
     if (filters.Length == 0)
     {
         return(true);
     }
     for (int i = 0; i < (int)filters.Length; i++)
     {
         TerrainFilter terrainFilter = filters[i];
         Vector3       vector3       = Vector3.Scale(terrainFilter.worldPosition, scale);
         vector3 = rot * vector3;
         Vector3 vector31 = pos + vector3;
         if (TerrainMeta.OutOfBounds(vector31))
         {
             return(false);
         }
         if (globalFilter != null && globalFilter.GetFactor(vector31) == 0f)
         {
             return(false);
         }
         if (!terrainFilter.Check(vector31))
         {
             return(false);
         }
     }
     return(true);
 }
    public void UpdateDistributions()
    {
        if (World.Size == 0)
        {
            return;
        }
        this.SpawnDistributions      = new SpawnDistribution[(int)this.AllSpawnPopulations.Length];
        this.population2distribution = new Dictionary <SpawnPopulation, SpawnDistribution>();
        Vector3 size     = TerrainMeta.Size;
        Vector3 position = TerrainMeta.Position;
        int     num      = Mathf.NextPowerOfTwo((int)((float)((float)World.Size) * 0.25f));

        for (int i1 = 0; i1 < (int)this.AllSpawnPopulations.Length; i1++)
        {
            SpawnPopulation allSpawnPopulations = this.AllSpawnPopulations[i1];
            if (allSpawnPopulations != null)
            {
                byte[]      factor = new byte[num * num];
                SpawnFilter filter = allSpawnPopulations.Filter;
                Parallel.For(0, num, (int z) => {
                    for (int i = 0; i < num; i++)
                    {
                        float popRes        = ((float)i + 0.5f) / (float)num;
                        float single        = ((float)z + 0.5f) / (float)num;
                        factor[z * num + i] = (byte)(255f * filter.GetFactor(popRes, single));
                    }
                });
                SpawnDistribution[] spawnDistributions = this.SpawnDistributions;
                SpawnDistribution   spawnDistribution  = new SpawnDistribution(this, factor, position, size);
                SpawnDistribution   spawnDistribution1 = spawnDistribution;
                spawnDistributions[i1] = spawnDistribution;
                this.population2distribution.Add(allSpawnPopulations, spawnDistribution1);
            }
            else
            {
                UnityEngine.Debug.LogError("Spawn handler contains null spawn population.");
            }
        }
        int num1 = Mathf.NextPowerOfTwo((int)((float)((float)World.Size) * 0.5f));

        byte[]      numArray       = new byte[num1 * num1];
        SpawnFilter characterSpawn = this.CharacterSpawn;

        Parallel.For(0, num1, (int z) => {
            for (int i = 0; i < num1; i++)
            {
                float charRes          = ((float)i + 0.5f) / (float)num1;
                float single           = ((float)z + 0.5f) / (float)num1;
                numArray[z * num1 + i] = (byte)(255f * characterSpawn.GetFactor(charRes, single));
            }
        });
        this.CharDistribution = new SpawnDistribution(this, numArray, position, size);
    }
Esempio n. 5
0
    public void UpdateDistributions()
    {
        if (World.Size == 0U)
        {
            return;
        }
        this.SpawnDistributions      = new SpawnDistribution[this.AllSpawnPopulations.Length];
        this.population2distribution = new Dictionary <SpawnPopulation, SpawnDistribution>();
        Vector3 size     = TerrainMeta.Size;
        Vector3 position = TerrainMeta.Position;
        int     pop_res  = Mathf.NextPowerOfTwo((int)((double)World.Size * 0.25));

        for (int index1 = 0; index1 < this.AllSpawnPopulations.Length; ++index1)
        {
            SpawnPopulation allSpawnPopulation = this.AllSpawnPopulations[index1];
            if ((BaseScriptableObject)allSpawnPopulation == (BaseScriptableObject)null)
            {
                Debug.LogError((object)"Spawn handler contains null spawn population.");
            }
            else
            {
                byte[]      map    = new byte[pop_res * pop_res];
                SpawnFilter filter = allSpawnPopulation.Filter;
                Parallel.For(0, pop_res, (Action <int>)(z =>
                {
                    for (int index = 0; index < pop_res; ++index)
                    {
                        float normX = ((float)index + 0.5f) / (float)pop_res;
                        float normZ = ((float)z + 0.5f) / (float)pop_res;
                        map[z * pop_res + index] = (byte)((double)byte.MaxValue * (double)filter.GetFactor(normX, normZ));
                    }
                }));
                SpawnDistribution spawnDistribution = this.SpawnDistributions[index1] = new SpawnDistribution(this, map, position, size);
                this.population2distribution.Add(allSpawnPopulation, spawnDistribution);
            }
        }
        int char_res = Mathf.NextPowerOfTwo((int)((double)World.Size * 0.5));

        byte[]      map1    = new byte[char_res * char_res];
        SpawnFilter filter1 = this.CharacterSpawn;

        Parallel.For(0, char_res, (Action <int>)(z =>
        {
            for (int index = 0; index < char_res; ++index)
            {
                float normX = ((float)index + 0.5f) / (float)char_res;
                float normZ = ((float)z + 0.5f) / (float)char_res;
                map1[z * char_res + index] = (byte)((double)byte.MaxValue * (double)filter1.GetFactor(normX, normZ));
            }
        }));
        this.CharDistribution = new SpawnDistribution(this, map1, position, size);
    }
Esempio n. 6
0
    public Vector3 RandomDropPosition()
    {
        Vector3 vector = Vector3.zero;
        float   num    = 100f;
        float   x      = TerrainMeta.Size.x;

        do
        {
            vector = Vector3Ex.Range(0f - x / 3f, x / 3f);
        }while (filter.GetFactor(vector) == 0f && (num -= 1f) > 0f);
        vector.y = 0f;
        return(vector);
    }
Esempio n. 7
0
        public Vector3 RandomDropPosition() // CargoPlane.RandomDropPosition()
        {
            var         vector = Vector3.zero;
            SpawnFilter filter = new SpawnFilter();

            float num = 100f, x = TerrainMeta.Size.x / 3f;

            do
            {
                vector = Vector3Ex.Range(-x, x);
            }while (filter.GetFactor(vector) == 0f && (num -= 1f) > 0f);
            vector.y = 0f;
            return(vector);
        }
Esempio n. 8
0
    public static bool ApplyTerrainAnchors(this Transform transform, TerrainAnchor[] anchors, ref Vector3 pos, Quaternion rot, Vector3 scale, TerrainAnchorMode mode, SpawnFilter filter = null)
    {
        float single;
        float single1;
        float single2;

        if (anchors.Length == 0)
        {
            return(true);
        }
        float single3 = 0f;
        float single4 = Single.MinValue;
        float single5 = Single.MaxValue;

        for (int i = 0; i < (int)anchors.Length; i++)
        {
            TerrainAnchor terrainAnchor = anchors[i];
            Vector3       vector3       = Vector3.Scale(terrainAnchor.worldPosition, scale);
            vector3 = rot * vector3;
            Vector3 vector31 = pos + vector3;
            if (TerrainMeta.OutOfBounds(vector31))
            {
                return(false);
            }
            if (filter != null && filter.GetFactor(vector31) == 0f)
            {
                return(false);
            }
            terrainAnchor.Apply(out single, out single1, out single2, vector31);
            single3 = single3 + (single - vector3.y);
            single4 = Mathf.Max(single4, single1 - vector3.y);
            single5 = Mathf.Min(single5, single2 - vector3.y);
            if (single5 < single4)
            {
                return(false);
            }
        }
        if (mode != TerrainAnchorMode.MinimizeError)
        {
            pos.y = Mathf.Clamp(pos.y, single4, single5);
        }
        else
        {
            pos.y = Mathf.Clamp(single3 / (float)((int)anchors.Length), single4, single5);
        }
        return(true);
    }
    public static bool ApplyTerrainAnchors(
        this Transform transform,
        TerrainAnchor[] anchors,
        ref Vector3 pos,
        Quaternion rot,
        Vector3 scale,
        TerrainAnchorMode mode,
        SpawnFilter filter = null)
    {
        if (anchors.Length == 0)
        {
            return(true);
        }
        float num1 = 0.0f;
        float num2 = float.MinValue;
        float num3 = float.MaxValue;

        for (int index = 0; index < anchors.Length; ++index)
        {
            TerrainAnchor anchor    = anchors[index];
            Vector3       vector3_1 = Vector3.Scale(anchor.worldPosition, scale);
            Vector3       vector3_2 = Quaternion.op_Multiply(rot, vector3_1);
            Vector3       vector3_3 = Vector3.op_Addition(pos, vector3_2);
            if (TerrainMeta.OutOfBounds(vector3_3) || filter != null && (double)filter.GetFactor(vector3_3) == 0.0)
            {
                return(false);
            }
            float height;
            float min;
            float max;
            anchor.Apply(out height, out min, out max, vector3_3);
            num1 += height - (float)vector3_2.y;
            num2  = Mathf.Max(num2, min - (float)vector3_2.y);
            num3  = Mathf.Min(num3, max - (float)vector3_2.y);
            if ((double)num3 < (double)num2)
            {
                return(false);
            }
        }
        pos.y = mode != TerrainAnchorMode.MinimizeError ? (__Null)(double)Mathf.Clamp((float)pos.y, num2, num3) : (__Null)(double)Mathf.Clamp(num1 / (float)anchors.Length, num2, num3);
        return(true);
    }
Esempio n. 10
0
 public static bool ApplyTerrainFilters(
     this Transform transform,
     TerrainFilter[] filters,
     Vector3 pos,
     Quaternion rot,
     Vector3 scale,
     SpawnFilter globalFilter = null)
 {
     if (filters.Length == 0)
     {
         return(true);
     }
     for (int index = 0; index < filters.Length; ++index)
     {
         TerrainFilter filter    = filters[index];
         Vector3       vector3_1 = Vector3.Scale(filter.worldPosition, scale);
         Vector3       vector3_2 = Quaternion.op_Multiply(rot, vector3_1);
         Vector3       vector3_3 = Vector3.op_Addition(pos, vector3_2);
         if (TerrainMeta.OutOfBounds(vector3_3) || globalFilter != null && (double)globalFilter.GetFactor(vector3_3) == 0.0 || !filter.Check(vector3_3))
         {
             return(false);
         }
     }
     return(true);
 }
Esempio n. 11
0
    public void SpawnSide(ref uint seed, PathList.SideObject obj)
    {
        if (string.IsNullOrEmpty(obj.Folder))
        {
            return;
        }
        Prefab[] prefabArray = Prefab.Load(string.Concat("assets/bundled/prefabs/autospawn/", obj.Folder), null, null, true);
        if (prefabArray == null || prefabArray.Length == 0)
        {
            Debug.LogError(string.Concat("Empty decor folder: ", obj.Folder));
            return;
        }
        PathList.Side    side      = obj.Side;
        SpawnFilter      filter    = obj.Filter;
        float            density   = obj.Density;
        float            distance  = obj.Distance;
        float            width     = this.Width * 0.5f + obj.Offset;
        TerrainHeightMap heightMap = TerrainMeta.HeightMap;

        float[]        singleArray = new float[] { -width, width };
        int            num         = 0;
        Vector3        startPoint  = this.Path.GetStartPoint();
        List <Vector3> vector3s    = new List <Vector3>();
        float          single      = distance * 0.25f;
        float          single1     = distance * 0.5f;
        float          length      = this.Path.Length - this.Path.EndOffset - single1;

        for (float i = this.Path.StartOffset + single1; i <= length; i += single)
        {
            Vector3 vector3 = (this.Spline ? this.Path.GetPointCubicHermite(i) : this.Path.GetPoint(i));
            if ((vector3 - startPoint).magnitude >= distance)
            {
                Vector3 tangent  = this.Path.GetTangent(i);
                Vector3 vector31 = PathList.rot90 * tangent;
                for (int j = 0; j < (int)singleArray.Length; j++)
                {
                    int length1 = (num + j) % (int)singleArray.Length;
                    if ((side != PathList.Side.Left || length1 == 0) && (side != PathList.Side.Right || length1 == 1))
                    {
                        float     single2       = singleArray[length1];
                        Vector3   height        = vector3;
                        ref float singlePointer = ref height.x;
                        singlePointer = singlePointer + vector31.x * single2;
                        ref float singlePointer1 = ref height.z;
                        singlePointer1 = singlePointer1 + vector31.z * single2;
                        float single3 = TerrainMeta.NormalizeX(height.x);
                        float single4 = TerrainMeta.NormalizeZ(height.z);
                        if (filter.GetFactor(single3, single4) >= SeedRandom.Value(ref seed))
                        {
                            if (density >= SeedRandom.Value(ref seed))
                            {
                                height.y = heightMap.GetHeight(single3, single4);
                                if (obj.Alignment == PathList.Alignment.None)
                                {
                                    if (this.SpawnObject(ref seed, prefabArray, height, Quaternion.identity, filter))
                                    {
                                        goto Label1;
                                    }
                                    goto Label0;
                                }
                                else if (obj.Alignment == PathList.Alignment.Forward)
                                {
                                    if (this.SpawnObject(ref seed, prefabArray, height, Quaternion.LookRotation(tangent * single2), filter))
                                    {
                                        goto Label1;
                                    }
                                    goto Label0;
                                }
                                else if (obj.Alignment != PathList.Alignment.Inward)
                                {
                                    vector3s.Add(height);
                                }
                                else
                                {
                                    if (this.SpawnObject(ref seed, prefabArray, height, Quaternion.LookRotation(-vector31 * single2), filter))
                                    {
                                        goto Label1;
                                    }
                                    goto Label0;
                                }
                            }
Label1:
                            num        = length1;
                            startPoint = vector3;
                            if (side == PathList.Side.Any)
                            {
                                break;
                            }
                        }
                    }
Label0:
                }
            }
Esempio n. 12
0
    public void SpawnAlong(ref uint seed, PathList.PathObject obj)
    {
        if (string.IsNullOrEmpty(obj.Folder))
        {
            return;
        }
        Prefab[] prefabArray = Prefab.Load(string.Concat("assets/bundled/prefabs/autospawn/", obj.Folder), null, null, true);
        if (prefabArray == null || prefabArray.Length == 0)
        {
            Debug.LogError(string.Concat("Empty decor folder: ", obj.Folder));
            return;
        }
        SpawnFilter      filter     = obj.Filter;
        float            density    = obj.Density;
        float            distance   = obj.Distance;
        float            dithering  = obj.Dithering;
        TerrainHeightMap heightMap  = TerrainMeta.HeightMap;
        Vector3          startPoint = this.Path.GetStartPoint();
        List <Vector3>   vector3s   = new List <Vector3>();
        float            single     = distance * 0.25f;
        float            single1    = distance * 0.5f;
        float            length     = this.Path.Length - this.Path.EndOffset - single1;

        for (float i = this.Path.StartOffset + single1; i <= length; i += single)
        {
            Vector3 vector3 = (this.Spline ? this.Path.GetPointCubicHermite(i) : this.Path.GetPoint(i));
            if ((vector3 - startPoint).magnitude >= distance)
            {
                Vector3 tangent  = this.Path.GetTangent(i);
                Vector3 vector31 = PathList.rot90 * tangent;
                Vector3 height   = vector3;
                height.x += SeedRandom.Range(ref seed, -dithering, dithering);
                height.z += SeedRandom.Range(ref seed, -dithering, dithering);
                float single2 = TerrainMeta.NormalizeX(height.x);
                float single3 = TerrainMeta.NormalizeZ(height.z);
                if (filter.GetFactor(single2, single3) >= SeedRandom.Value(ref seed))
                {
                    if (density >= SeedRandom.Value(ref seed))
                    {
                        height.y = heightMap.GetHeight(single2, single3);
                        if (obj.Alignment == PathList.Alignment.None)
                        {
                            if (this.SpawnObject(ref seed, prefabArray, height, Quaternion.identity, filter))
                            {
                                goto Label1;
                            }
                            goto Label0;
                        }
                        else if (obj.Alignment == PathList.Alignment.Forward)
                        {
                            if (this.SpawnObject(ref seed, prefabArray, height, Quaternion.LookRotation(tangent), filter))
                            {
                                goto Label1;
                            }
                            goto Label0;
                        }
                        else if (obj.Alignment != PathList.Alignment.Inward)
                        {
                            vector3s.Add(height);
                        }
                        else
                        {
                            if (this.SpawnObject(ref seed, prefabArray, height, Quaternion.LookRotation(vector31), filter))
                            {
                                goto Label1;
                            }
                            goto Label0;
                        }
                    }
Label1:
                    startPoint = vector3;
                }
            }
Label0:
        }
        if (vector3s.Count > 0)
        {
            this.SpawnObjectsNeighborAligned(ref seed, prefabArray, vector3s, filter);
        }
    }