示例#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);
 }
示例#2
0
    private bool CheckObjects(Prefab[] prefabs, Vector3 pos, Vector3 dir, PathList.BasicObject obj)
    {
        if (!obj.AlignToNormal)
        {
            Vector3 vector3 = Vector3Ex.XZ3D(dir);
            dir = ((Vector3) ref vector3).get_normalized();
        }
        SpawnFilter filter    = obj.Filter;
        Vector3     vector3_1 = Vector3.op_Multiply(this.Width * 0.5f + obj.Offset, Quaternion.op_Multiply(PathList.rot90, dir));

        for (int index = 0; index < PathList.placements.Length; ++index)
        {
            if ((obj.Placement != PathList.Placement.Center || index == 0) && (obj.Placement != PathList.Placement.Side || index != 0))
            {
                Vector3 vector3_2 = Vector3.op_Addition(pos, Vector3.op_Multiply(PathList.placements[index], vector3_1));
                if (obj.HeightToTerrain)
                {
                    vector3_2.y = (__Null)(double)TerrainMeta.HeightMap.GetHeight(vector3_2);
                }
                if (filter.Test(vector3_2))
                {
                    Quaternion rotation = index == 2 ? Quaternion.LookRotation(Quaternion.op_Multiply(PathList.rot180, dir)) : Quaternion.LookRotation(dir);
                    if (this.CheckObjects(prefabs, vector3_2, rotation, filter))
                    {
                        return(true);
                    }
                }
            }
        }
        return(false);
    }
示例#3
0
    private void SpawnObject(ref uint seed, Prefab[] prefabs, Vector3 pos, Vector3 dir, PathList.BasicObject obj)
    {
        if (!obj.AlignToNormal)
        {
            dir = dir.XZ3D().normalized;
        }
        SpawnFilter filter = obj.Filter;
        Vector3     width  = (this.Width * 0.5f + obj.Offset) * PathList.rot90 * dir;

        for (int i = 0; i < (int)PathList.placements.Length; i++)
        {
            if ((obj.Placement != PathList.Placement.Center || i == 0) && (obj.Placement != PathList.Placement.Side || i != 0))
            {
                Vector3 height = pos + (PathList.placements[i] * width);
                if (obj.HeightToTerrain)
                {
                    height.y = TerrainMeta.HeightMap.GetHeight(height);
                }
                if (filter.Test(height))
                {
                    if (this.SpawnObject(ref seed, prefabs, height, (i == 2 ? Quaternion.LookRotation(PathList.rot180 * dir) : Quaternion.LookRotation(dir)), filter))
                    {
                        break;
                    }
                }
            }
        }
    }
示例#4
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);
 }
示例#5
0
 public bool ApplyTerrainAnchors(
     ref Vector3 pos,
     Quaternion rot,
     Vector3 scale,
     SpawnFilter filter = null)
 {
     return(this.Object.get_transform().ApplyTerrainAnchors(this.Attribute.FindAll <TerrainAnchor>(this.ID), ref pos, rot, scale, filter));
 }
 public static bool ApplyTerrainAnchors(
     this Transform transform,
     TerrainAnchor[] anchors,
     ref Vector3 pos,
     Quaternion rot,
     Vector3 scale,
     SpawnFilter filter = null)
 {
     return(transform.ApplyTerrainAnchors(anchors, ref pos, rot, scale, TerrainAnchorMode.MinimizeError, filter));
 }
示例#7
0
 public static SpawnFilterData FromSpawnFilter(SpawnFilter filter)
 {
     return(new SpawnFilterData
     {
         BiomeType = (TerrainBiomeEnum)filter.BiomeType,
         SplatType = (TerrainSplatEnum)filter.SplatType,
         TopologyAll = (TerrainTopologyEnum)filter.TopologyAll,
         TopologyAny = (TerrainTopologyEnum)filter.TopologyAny,
         TopologyNot = (TerrainTopologyEnum)filter.TopologyNot
     });
 }
    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);
    }
示例#9
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);
    }
示例#10
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);
        }
示例#11
0
 public void SpawnSide(ref uint seed, PathList.SideObject obj)
 {
     if (string.IsNullOrEmpty(obj.Folder))
     {
         return;
     }
     Prefab[] prefabs = Prefab.Load("assets/bundled/prefabs/autospawn/" + obj.Folder, (GameManager)null, (PrefabAttribute.Library)null, true);
     if (prefabs == null || prefabs.Length == 0)
     {
         Debug.LogError((object)("Empty decor folder: " + obj.Folder));
     }
     else
     {
         PathList.Side    side      = obj.Side;
         SpawnFilter      filter    = obj.Filter;
         float            density   = obj.Density;
         float            distance1 = obj.Distance;
         float            num1      = this.Width * 0.5f + obj.Offset;
         TerrainHeightMap heightMap = TerrainMeta.HeightMap;
         float[]          numArray  = new float[2] {
             -num1, num1
         };
         int            num2      = 0;
         Vector3        vector3_1 = this.Path.GetStartPoint();
         List <Vector3> positions = new List <Vector3>();
         float          num3      = distance1 * 0.25f;
         float          num4      = distance1 * 0.5f;
         double         num5      = (double)this.Path.StartOffset + (double)num4;
         float          num6      = this.Path.Length - this.Path.EndOffset - num4;
         for (float distance2 = (float)num5; (double)distance2 <= (double)num6; distance2 += num3)
         {
             Vector3 vector3_2 = this.Spline ? this.Path.GetPointCubicHermite(distance2) : this.Path.GetPoint(distance2);
             Vector3 vector3_3 = Vector3.op_Subtraction(vector3_2, vector3_1);
             if ((double)((Vector3) ref vector3_3).get_magnitude() >= (double)distance1)
             {
                 Vector3 tangent   = this.Path.GetTangent(distance2);
                 Vector3 vector3_4 = Quaternion.op_Multiply(PathList.rot90, tangent);
                 for (int index1 = 0; index1 < numArray.Length; ++index1)
                 {
                     int index2 = (num2 + index1) % numArray.Length;
                     if ((side != PathList.Side.Left || index2 == 0) && (side != PathList.Side.Right || index2 == 1))
                     {
                         float      num7     = numArray[index2];
                         Vector3    position = vector3_2;
                         ref __Null local1   = ref position.x;
示例#12
0
 private bool CheckObjects(
     Prefab[] prefabs,
     Vector3 position,
     Quaternion rotation,
     SpawnFilter filter = null)
 {
     for (int index = 0; index < prefabs.Length; ++index)
     {
         Prefab     prefab     = prefabs[index];
         Vector3    pos        = position;
         Quaternion rot        = rotation;
         Vector3    localScale = prefab.Object.get_transform().get_localScale();
         if (!prefab.ApplyTerrainAnchors(ref pos, rot, localScale, filter))
         {
             return(false);
         }
     }
     return(true);
 }
示例#13
0
 private void SpawnObjectsNeighborAligned(
     ref uint seed,
     Prefab[] prefabs,
     List <Vector3> positions,
     SpawnFilter filter = null)
 {
     if (positions.Count < 2)
     {
         return;
     }
     for (int index1 = 0; index1 < positions.Count; ++index1)
     {
         int        index2   = Mathf.Max(index1 - 1, 0);
         int        index3   = Mathf.Min(index1 + 1, positions.Count - 1);
         Vector3    position = positions[index1];
         Quaternion rotation = Quaternion.LookRotation(Vector3Ex.XZ3D(Vector3.op_Subtraction(positions[index3], positions[index2])));
         this.SpawnObject(ref seed, prefabs, position, rotation, filter);
     }
 }
    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);
    }
示例#15
0
    private bool SpawnObject(
        ref uint seed,
        Prefab[] prefabs,
        Vector3 position,
        Quaternion rotation,
        SpawnFilter filter = null)
    {
        Prefab     random     = prefabs.GetRandom <Prefab>(ref seed);
        Vector3    pos        = position;
        Quaternion rot        = rotation;
        Vector3    localScale = random.Object.get_transform().get_localScale();

        random.ApplyDecorComponents(ref pos, ref rot, ref localScale);
        if (!random.ApplyTerrainAnchors(ref pos, rot, localScale, filter))
        {
            return(false);
        }
        random.ApplyTerrainPlacements(pos, rot, localScale);
        random.ApplyTerrainModifiers(pos, rot, localScale);
        World.AddPrefab(this.Name, random.ID, pos, rot, localScale);
        return(true);
    }
示例#16
0
 private void SpawnObjectsNeighborAligned(ref uint seed, Prefab[] prefabs, List <Vector3> positions, SpawnFilter filter = null)
 {
     if (positions.Count < 2)
     {
         return;
     }
     for (int i = 0; i < positions.Count; i++)
     {
         int        num        = Mathf.Max(i - 1, 0);
         int        num1       = Mathf.Min(i + 1, positions.Count - 1);
         Vector3    item       = positions[i];
         Quaternion quaternion = Quaternion.LookRotation((positions[num1] - positions[num]).XZ3D());
         this.SpawnObject(ref seed, prefabs, item, quaternion, filter);
     }
 }
示例#17
0
 private bool CheckObjects(Prefab[] prefabs, Vector3 position, Quaternion rotation, SpawnFilter filter = null)
 {
     for (int i = 0; i < (int)prefabs.Length; i++)
     {
         Prefab  prefab  = prefabs[i];
         Vector3 vector3 = position;
         if (!prefab.ApplyTerrainAnchors(ref vector3, rotation, prefab.Object.transform.localScale, filter))
         {
             return(false);
         }
     }
     return(true);
 }
示例#18
0
 public bool ApplyTerrainAnchors(ref Vector3 pos, Quaternion rot, Vector3 scale, TerrainAnchorMode mode, SpawnFilter filter = null)
 {
     TerrainAnchor[] terrainAnchorArray = this.Attribute.FindAll <TerrainAnchor>(this.ID);
     return(this.Object.transform.ApplyTerrainAnchors(terrainAnchorArray, ref pos, rot, scale, mode, filter));
 }
示例#19
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);
    }
示例#20
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);
        }
    }
示例#21
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:
                }
            }
 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);
 }
示例#23
0
    private bool SpawnObject(ref uint seed, Prefab[] prefabs, Vector3 position, Quaternion rotation, SpawnFilter filter = null)
    {
        Prefab     random     = prefabs.GetRandom <Prefab>(ref seed);
        Vector3    vector3    = position;
        Quaternion quaternion = rotation;
        Vector3    obj        = random.Object.transform.localScale;

        random.ApplyDecorComponents(ref vector3, ref quaternion, ref obj);
        if (!random.ApplyTerrainAnchors(ref vector3, quaternion, obj, filter))
        {
            return(false);
        }
        random.ApplyTerrainPlacements(vector3, quaternion, obj);
        random.ApplyTerrainModifiers(vector3, quaternion, obj);
        World.AddPrefab(this.Name, random.ID, vector3, quaternion, obj);
        return(true);
    }
示例#24
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);
 }
示例#25
0
 public bool ApplyTerrainFilters(Vector3 pos, Quaternion rot, Vector3 scale, SpawnFilter filter = null)
 {
     TerrainFilter[] terrainFilterArray = this.Attribute.FindAll <TerrainFilter>(this.ID);
     return(this.Object.transform.ApplyTerrainFilters(terrainFilterArray, pos, rot, scale, filter));
 }