public static Vector3 GetPrototypeExtent(TerrainData terrainData, int prototypeIndex)
        {
            Vector3 result;

            TerrainInspectorUtil.INTERNAL_CALL_GetPrototypeExtent(terrainData, prototypeIndex, out result);
            return(result);
        }
Beispiel #2
0
        public static void PlaceTrees(Terrain terrain, float xBase, float yBase)
        {
            int prototypeCount = TerrainInspectorUtil.GetPrototypeCount(terrain.terrainData);

            if (TreePainter.selectedTree == -1 || TreePainter.selectedTree >= prototypeCount)
            {
                return;
            }
            if (!TerrainInspectorUtil.PrototypeIsRenderable(terrain.terrainData, TreePainter.selectedTree))
            {
                return;
            }
            int          num      = 0;
            TreeInstance instance = default(TreeInstance);

            instance.position       = new Vector3(xBase, 0f, yBase);
            instance.color          = TreePainter.GetTreeColor();
            instance.lightmapColor  = Color.white;
            instance.prototypeIndex = TreePainter.selectedTree;
            instance.heightScale    = TreePainter.GetTreeHeight();
            instance.widthScale     = ((!TreePainter.lockWidthToHeight) ? TreePainter.GetTreeWidth() : instance.heightScale);
            instance.rotation       = TreePainter.GetTreeRotation();
            bool flag = Event.current.type == EventType.MouseDrag || TreePainter.brushSize > 1f;

            if (!flag || TerrainInspectorUtil.CheckTreeDistance(terrain.terrainData, instance.position, instance.prototypeIndex, TreePainter.spacing))
            {
                terrain.AddTreeInstance(instance);
                num++;
            }
            Vector3 prototypeExtent = TerrainInspectorUtil.GetPrototypeExtent(terrain.terrainData, TreePainter.selectedTree);

            prototypeExtent.y = 0f;
            float num2 = TreePainter.brushSize / (prototypeExtent.magnitude * TreePainter.spacing * 0.5f);
            int   num3 = (int)(num2 * num2 * 0.5f);

            num3 = Mathf.Clamp(num3, 0, 100);
            int num4 = 1;

            while (num4 < num3 && num < num3)
            {
                Vector2 insideUnitCircle = UnityEngine.Random.insideUnitCircle;
                insideUnitCircle.x *= TreePainter.brushSize / terrain.terrainData.size.x;
                insideUnitCircle.y *= TreePainter.brushSize / terrain.terrainData.size.z;
                Vector3 position = new Vector3(xBase + insideUnitCircle.x, 0f, yBase + insideUnitCircle.y);
                if (position.x >= 0f && position.x <= 1f && position.z >= 0f && position.z <= 1f && TerrainInspectorUtil.CheckTreeDistance(terrain.terrainData, position, TreePainter.selectedTree, TreePainter.spacing * 0.5f))
                {
                    instance                = default(TreeInstance);
                    instance.position       = position;
                    instance.color          = TreePainter.GetTreeColor();
                    instance.lightmapColor  = Color.white;
                    instance.prototypeIndex = TreePainter.selectedTree;
                    instance.heightScale    = TreePainter.GetTreeHeight();
                    instance.widthScale     = ((!TreePainter.lockWidthToHeight) ? TreePainter.GetTreeWidth() : instance.heightScale);
                    instance.rotation       = TreePainter.GetTreeRotation();
                    terrain.AddTreeInstance(instance);
                    num++;
                }
                num4++;
            }
        }
        public static void PlaceTrees(Terrain terrain, float xBase, float yBase)
        {
            int prototypeCount = TerrainInspectorUtil.GetPrototypeCount(terrain.terrainData);

            if (((selectedTree != -1) && (selectedTree < prototypeCount)) && TerrainInspectorUtil.PrototypeIsRenderable(terrain.terrainData, selectedTree))
            {
                int          num2     = 0;
                TreeInstance instance = new TreeInstance {
                    position       = new Vector3(xBase, 0f, yBase),
                    color          = GetTreeColor(),
                    lightmapColor  = Color.white,
                    prototypeIndex = selectedTree,
                    heightScale    = GetTreeHeight()
                };
                instance.widthScale = !lockWidthToHeight?GetTreeWidth() : instance.heightScale;

                instance.rotation = GetTreeRotation();
                if (((Event.current.type != EventType.MouseDrag) && (brushSize <= 1f)) || TerrainInspectorUtil.CheckTreeDistance(terrain.terrainData, instance.position, instance.prototypeIndex, spacing))
                {
                    terrain.AddTreeInstance(instance);
                    num2++;
                }
                Vector3 prototypeExtent = TerrainInspectorUtil.GetPrototypeExtent(terrain.terrainData, selectedTree);
                prototypeExtent.y = 0f;
                float num3 = brushSize / ((prototypeExtent.magnitude * spacing) * 0.5f);
                int   num4 = (int)((num3 * num3) * 0.5f);
                num4 = Mathf.Clamp(num4, 0, 100);
                for (int i = 1; (i < num4) && (num2 < num4); i++)
                {
                    Vector2 insideUnitCircle = UnityEngine.Random.insideUnitCircle;
                    insideUnitCircle.x *= brushSize / terrain.terrainData.size.x;
                    insideUnitCircle.y *= brushSize / terrain.terrainData.size.z;
                    Vector3 position = new Vector3(xBase + insideUnitCircle.x, 0f, yBase + insideUnitCircle.y);
                    if ((((position.x >= 0f) && (position.x <= 1f)) && ((position.z >= 0f) && (position.z <= 1f))) && TerrainInspectorUtil.CheckTreeDistance(terrain.terrainData, position, selectedTree, spacing * 0.5f))
                    {
                        instance = new TreeInstance {
                            position       = position,
                            color          = GetTreeColor(),
                            lightmapColor  = Color.white,
                            prototypeIndex = selectedTree,
                            heightScale    = GetTreeHeight()
                        };
                        instance.widthScale = !lockWidthToHeight?GetTreeWidth() : instance.heightScale;

                        instance.rotation = GetTreeRotation();
                        terrain.AddTreeInstance(instance);
                        num2++;
                    }
                }
            }
        }
        public static void PlaceTrees(Terrain terrain, float xBase, float yBase)
        {
            int prototypeCount = TerrainInspectorUtil.GetPrototypeCount(terrain.terrainData);

            if (TreePainter.selectedTree == -1 || TreePainter.selectedTree >= prototypeCount || !TerrainInspectorUtil.PrototypeIsRenderable(terrain.terrainData, TreePainter.selectedTree))
            {
                return;
            }
            int          num1     = 0;
            TreeInstance instance = new TreeInstance();

            instance.position       = new Vector3(xBase, 0.0f, yBase);
            instance.color          = (Color32)TreePainter.GetTreeColor();
            instance.lightmapColor  = (Color32)Color.white;
            instance.prototypeIndex = TreePainter.selectedTree;
            instance.heightScale    = TreePainter.GetTreeHeight();
            instance.widthScale     = !TreePainter.lockWidthToHeight ? TreePainter.GetTreeWidth() : instance.heightScale;
            instance.rotation       = TreePainter.GetTreeRotation();
            if (Event.current.type != EventType.MouseDrag && (double)TreePainter.brushSize <= 1.0 || TerrainInspectorUtil.CheckTreeDistance(terrain.terrainData, instance.position, instance.prototypeIndex, TreePainter.spacing))
            {
                terrain.AddTreeInstance(instance);
                ++num1;
            }
            Vector3 prototypeExtent = TerrainInspectorUtil.GetPrototypeExtent(terrain.terrainData, TreePainter.selectedTree);

            prototypeExtent.y = 0.0f;
            float num2 = TreePainter.brushSize / (float)((double)prototypeExtent.magnitude * (double)TreePainter.spacing * 0.5);
            int   num3 = Mathf.Clamp((int)((double)num2 * (double)num2 * 0.5), 0, 100);

            for (int index = 1; index < num3 && num1 < num3; ++index)
            {
                Vector2 insideUnitCircle = UnityEngine.Random.insideUnitCircle;
                insideUnitCircle.x *= TreePainter.brushSize / terrain.terrainData.size.x;
                insideUnitCircle.y *= TreePainter.brushSize / terrain.terrainData.size.z;
                Vector3 position = new Vector3(xBase + insideUnitCircle.x, 0.0f, yBase + insideUnitCircle.y);
                if ((double)position.x >= 0.0 && (double)position.x <= 1.0 && ((double)position.z >= 0.0 && (double)position.z <= 1.0) && TerrainInspectorUtil.CheckTreeDistance(terrain.terrainData, position, TreePainter.selectedTree, TreePainter.spacing * 0.5f))
                {
                    instance                = new TreeInstance();
                    instance.position       = position;
                    instance.color          = (Color32)TreePainter.GetTreeColor();
                    instance.lightmapColor  = (Color32)Color.white;
                    instance.prototypeIndex = TreePainter.selectedTree;
                    instance.heightScale    = TreePainter.GetTreeHeight();
                    instance.widthScale     = !TreePainter.lockWidthToHeight ? TreePainter.GetTreeWidth() : instance.heightScale;
                    instance.rotation       = TreePainter.GetTreeRotation();
                    terrain.AddTreeInstance(instance);
                    ++num1;
                }
            }
        }
 public static bool CheckTreeDistance(TerrainData terrainData, Vector3 position, int prototypeIndex, float distanceBias)
 {
     return(TerrainInspectorUtil.INTERNAL_CALL_CheckTreeDistance(terrainData, ref position, prototypeIndex, distanceBias));
 }
Beispiel #6
0
 private float GetTreePlacementSize(TerrainData terrainData, float treeCount)
 {
     return(TerrainInspectorUtil.GetTreePlacementSize(terrainData, TreePainter.selectedTree, TreePainter.spacing, treeCount));
 }