GetTreeRotation() private static method

private static GetTreeRotation ( ) : float
return float
示例#1
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++;
            }
        }
示例#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 || !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;
                }
            }
        }
示例#3
0
        public static void MassPlaceTrees(TerrainData terrainData, int numberOfTrees, bool randomTreeColor, bool keepExistingTrees)
        {
            int length = terrainData.treePrototypes.Length;

            if (length == 0)
            {
                Debug.Log((object)"Can't place trees because no prototypes are defined");
            }
            else
            {
                Undo.RegisterCompleteObjectUndo((UnityEngine.Object)terrainData, "Mass Place Trees");
                TreeInstance[] treeInstanceArray1 = new TreeInstance[numberOfTrees];
                int            num = 0;
                while (num < treeInstanceArray1.Length)
                {
                    TreeInstance treeInstance = new TreeInstance();
                    treeInstance.position = new Vector3(UnityEngine.Random.value, 0.0f, UnityEngine.Random.value);
                    if ((double)terrainData.GetSteepness(treeInstance.position.x, treeInstance.position.z) < 30.0)
                    {
                        treeInstance.color          = (Color32)(!randomTreeColor ? Color.white : TreePainter.GetTreeColor());
                        treeInstance.lightmapColor  = (Color32)Color.white;
                        treeInstance.prototypeIndex = UnityEngine.Random.Range(0, length);
                        treeInstance.heightScale    = TreePainter.GetTreeHeight();
                        treeInstance.widthScale     = !TreePainter.lockWidthToHeight ? TreePainter.GetTreeWidth() : treeInstance.heightScale;
                        treeInstance.rotation       = TreePainter.GetTreeRotation();
                        treeInstanceArray1[num++]   = treeInstance;
                    }
                }
                if (keepExistingTrees)
                {
                    TreeInstance[] treeInstances      = terrainData.treeInstances;
                    TreeInstance[] treeInstanceArray2 = new TreeInstance[treeInstances.Length + treeInstanceArray1.Length];
                    Array.Copy((Array)treeInstances, 0, (Array)treeInstanceArray2, 0, treeInstances.Length);
                    Array.Copy((Array)treeInstanceArray1, 0, (Array)treeInstanceArray2, treeInstances.Length, treeInstanceArray1.Length);
                    treeInstanceArray1 = treeInstanceArray2;
                }
                terrainData.treeInstances = treeInstanceArray1;
                terrainData.RecalculateTreePositions();
            }
        }
示例#4
0
        public static void MassPlaceTrees(TerrainData terrainData, int numberOfTrees, bool randomTreeColor, bool keepExistingTrees)
        {
            int num = terrainData.treePrototypes.Length;

            if (num == 0)
            {
                Debug.Log("Can't place trees because no prototypes are defined");
            }
            else
            {
                Undo.RegisterCompleteObjectUndo(terrainData, "Mass Place Trees");
                TreeInstance[] array = new TreeInstance[numberOfTrees];
                int            i     = 0;
                while (i < array.Length)
                {
                    TreeInstance treeInstance = default(TreeInstance);
                    treeInstance.position = new Vector3(UnityEngine.Random.value, 0f, UnityEngine.Random.value);
                    if (terrainData.GetSteepness(treeInstance.position.x, treeInstance.position.z) < 30f)
                    {
                        treeInstance.color          = ((!randomTreeColor) ? Color.white : TreePainter.GetTreeColor());
                        treeInstance.lightmapColor  = Color.white;
                        treeInstance.prototypeIndex = UnityEngine.Random.Range(0, num);
                        treeInstance.heightScale    = TreePainter.GetTreeHeight();
                        treeInstance.widthScale     = ((!TreePainter.lockWidthToHeight) ? TreePainter.GetTreeWidth() : treeInstance.heightScale);
                        treeInstance.rotation       = TreePainter.GetTreeRotation();
                        array[i++] = treeInstance;
                    }
                }
                if (keepExistingTrees)
                {
                    TreeInstance[] treeInstances = terrainData.treeInstances;
                    TreeInstance[] array2        = new TreeInstance[treeInstances.Length + array.Length];
                    Array.Copy(treeInstances, 0, array2, 0, treeInstances.Length);
                    Array.Copy(array, 0, array2, treeInstances.Length, array.Length);
                    array = array2;
                }
                terrainData.treeInstances = array;
                terrainData.RecalculateTreePositions();
            }
        }