Esempio n. 1
0
        private void PaintHeight(float hardness)
        {
            GameObject terrain = m_Editor.terrain.gameObject;
            Vector2    size    = UEditorTools.GetSizeOfMesh(m_Editor.terrain.mesh, terrain.transform);
            float      multiple;

            if (size.x > size.y)
            {
                multiple = size.y;
            }
            else
            {
                multiple = size.x;
            }
            Event e   = Event.current;
            Ray   ray = HandleUtility.GUIPointToWorldRay(e.mousePosition);

            RaycastHit[] hits    = Physics.RaycastAll(ray);
            float        bs      = m_BrushSize;
            int          fallOff = m_FallOff;

            foreach (RaycastHit hit in hits)
            {
                if (hit.collider.gameObject == terrain)
                {
                    Vector3 relativePoint = terrain.transform.InverseTransformPoint(hit.point);
                    DeformMesh(m_Editor.terrain.mesh, relativePoint, (float)(hardness * 30 * Time.deltaTime * multiple), bs, fallOff);
                }
            }
        }
Esempio n. 2
0
        void Paint(RaycastHit hit)
        {
            int      texIndex  = m_SelectedTex;
            float    hardness  = m_Hardness;
            int      passIndex = m_SelectedPass;
            float    brushSize = m_BrushSize;
            USubMesh sm        = subMesh;
            UPass    pass      = sm[passIndex];
            int      texW      = pass.mixTex.width;
            int      texH      = pass.mixTex.height;

            int centerX = Mathf.FloorToInt(hit.textureCoord.x * texW);
            int centerY = Mathf.FloorToInt(hit.textureCoord.y * texH);

            Vector2 bounds    = UEditorTools.GetSizeOfMesh(sm.mesh, m_Editor.terrain.transform);
            int     pixelSize = 0;

            if (texW > texH)
            {
                pixelSize = (int)((brushSize / bounds.x) * texW);
            }
            else
            {
                pixelSize = (int)((brushSize / bounds.y) * texH);
            }

            int            x         = Mathf.Clamp(centerX - pixelSize, 0, texW - 1);
            int            y         = Mathf.Clamp(centerY - pixelSize, 0, texH - 1);
            int            width     = Mathf.Clamp(2 * pixelSize, 0, texW - x);
            int            height    = Mathf.Clamp(2 * pixelSize, 0, texH - y);
            List <Color[]> srcPixels = new List <Color[]>();

            sm.passes.ToList().ForEach(p => srcPixels.Add(p.mixTex.GetPixels(x, y, width, height, 0)));
            for (int i = 0, max = srcPixels.Count; i < max; i++)
            {
                Color[] pixels = srcPixels[i];
                for (int h = 0; h < height; h++)
                {
                    for (int w = 0; w < width; w++)
                    {
                        Color targetColor;
                        if (i == passIndex)
                        {
                            targetColor = GetColor(texIndex);
                        }
                        else
                        {
                            targetColor = Color.clear;
                        }
                        int   ix          = (int)(w * 64 / width);
                        int   iy          = (int)(h * 64 / height);
                        int   index       = (h * width) + w;
                        float blendFactor = m_Brush.GetStrengthInt(ix, iy) * hardness * 0.1f;
                        pixels[index] = Color.Lerp(pixels[index], targetColor, blendFactor);
                    }
                }
                sm[i].Paint(x, y, width, height, pixels);
            }
        }
Esempio n. 3
0
 void TreeField()
 {
     m_Selected = UEditorTools.SelectionGridImageAndText(m_Selected, m_Editor.terrain.data.treeData.trees.Select(tree => {
         Texture2D tex = null;
         while (!CheckPreviewReady(tree.prefab, ref tex))
         {
         }
         tex      = AssetPreview.GetAssetPreview(tree.prefab);
         tex.name = tree.prefab.name;
         return(tex);
     }).ToArray(), 0x40, "No Tree Added.");
     GUILayout.Space(2);
     EditorGUILayout.BeginHorizontal();
     EditorGUILayout.Space();
     if (GUILayout.Button("Edit Trees...", EditorStyles.popup, GUILayout.Width(80)))
     {
         GenericMenu menu = new GenericMenu();
         menu.AddItem(new GUIContent("Add Tree"), false, () => {
             UTreeWizard.GetWizard("Add Tree", "Add").InitializeDefaults(m_Editor);
         });
         if (m_Selected == -1)
         {
             menu.AddDisabledItem(new GUIContent("Edit Tree"));
             m_Editor.Repaint();
         }
         else
         {
             menu.AddItem(new GUIContent("Edit Tree"), false, () => {
                 UTreeWizard wizard = UTreeWizard.GetWizard("Edit Tree", "Apply");
                 wizard.InitializeDefaults(m_Editor);
                 UTree ut                = m_Editor.terrain.data.treeData.trees[m_Selected];
                 wizard.tree             = ut.prefab;
                 wizard.billBoardTexture = ut.texture;
                 wizard.treeIndex        = m_Selected;
                 wizard.OnWizardUpdate();
                 m_Editor.Repaint();
             });
         }
         if (m_Selected == -1)
         {
             menu.AddDisabledItem(new GUIContent("Remove Tree"));
         }
         else
         {
             menu.AddItem(new GUIContent("Remove Tree"), false, () => {
                 m_Editor.terrain.data.treeData.RemoveAt(m_Selected);
                 m_Selected = -1;
                 m_Editor.Repaint();
             });
         }
         menu.ShowAsContext();
         Event.current.Use();
     }
     EditorGUILayout.EndHorizontal();
 }
Esempio n. 4
0
        void AddArea(Vector3 position, Vector3 normal)
        {
            int     num    = 0;
            Vector3 extent = Vector3.one;

            extent.y = 0f;
            float num2 = m_BrushSize / ((extent.magnitude * m_Density) * 0.5f);
            int   num3 = (int)((num2 * num2) * 0.5f);

            num3 = Mathf.Clamp(num3, 0, 100);

            List <UBillBoardInstance> list = new List <UBillBoardInstance>();

            for (int i = 1; (i < num3) && (num < num3); i++)
            {
                Vector2 insideUnitCircle = UnityEngine.Random.insideUnitCircle;
                float   blendFactor      = CheckBrush(insideUnitCircle);
                float   newDensity;
                if (blendFactor == 0)
                {
                    continue;
                }
                else
                {
                    newDensity = m_Density / blendFactor;
                }
                insideUnitCircle.x *= m_BrushSize;
                insideUnitCircle.y *= m_BrushSize;

                Vector3 off       = new Vector3(insideUnitCircle.x, 0f, insideUnitCircle.y);
                Vector3 pos       = Vector3.Cross(normal, off);
                Vector3 position2 = position + pos;
                Vector3 nom       = position2 - (position2 + normal * 10);
                Vector3 formPos   = position2 + normal * 50;

                Ray          ray  = new Ray(formPos, nom);
                RaycastHit[] hits = Physics.RaycastAll(ray);
                list.Clear();
                foreach (RaycastHit hit in hits)
                {
                    if (hit.collider.gameObject == m_Editor.terrain.gameObject)
                    {
                        float newW = UEditorTools.RandomOfVaration(m_Width, m_WidthVar);
                        float newH = UEditorTools.RandomOfVaration(m_Height, m_HeightVar);
                        float newL = UEditorTools.RandomOfVaration(m_Length, m_LengthVar);
                        tree.AddArea(hit.point - m_Editor.terrain.transform.position, new Vector3(newW, newH, newL), newDensity);
                    }
                }
            }
            tree.Apply();
        }
Esempio n. 5
0
        void GetTexSize(ref int width, ref int height)
        {
            Vector2 size = UEditorTools.GetSizeOfMesh(subMesh.mesh, m_Editor.terrain.transform);

            if (size.x < size.y)
            {
                width  = (int)(maxSize * size.x / size.y);
                height = maxSize;
            }
            else if (size.x >= size.y)
            {
                height = (int)(maxSize * size.y / size.x);
                width  = maxSize;
            }
        }
Esempio n. 6
0
 void GrassField()
 {
     m_Selected = UEditorTools.SelectionGrid(m_Selected, m_Editor.terrain.data.grassData.grasses.Select(grass => grass.texture).ToArray(), 0x40, "No Grass Added.");
     GUILayout.Space(2);
     EditorGUILayout.BeginHorizontal();
     EditorGUILayout.Space();
     if (GUILayout.Button("Edit Grasses...", EditorStyles.popup, GUILayout.Width(93)))
     {
         GenericMenu menu = new GenericMenu();
         menu.AddItem(new GUIContent("Add Grass"), false, () => {
             UGrassWizard.GetWizard("Add Grass", "Add").InitializeDefaults(m_Editor);
             m_Editor.Repaint();
         });
         if (m_Selected == -1)
         {
             menu.AddDisabledItem(new GUIContent("Edit Grass"));
         }
         else
         {
             menu.AddItem(new GUIContent("Edit Grass"), false, () => {
                 UGrassWizard wizard = UGrassWizard.GetWizard("Edit Grass", "Apply");
                 wizard.InitializeDefaults(m_Editor);
                 wizard.texture    = grass.texture;
                 wizard.grassIndex = m_Selected;
                 wizard.OnWizardUpdate();
                 m_Editor.Repaint();
             });
         }
         if (m_Selected == -1)
         {
             menu.AddDisabledItem(new GUIContent("Remove Grass"));
         }
         else
         {
             menu.AddItem(new GUIContent("Remove Grass"), false, () => {
                 m_Editor.terrain.data.grassData.RemoveAt(m_Selected);
                 m_Selected = -1;
                 m_Editor.Repaint();
             });
         }
         menu.ShowAsContext();
         Event.current.Use();
     }
     EditorGUILayout.EndHorizontal();
 }
Esempio n. 7
0
        void SubMeshField()
        {
            int selected = m_SelectedSM;

            GUILayout.Label("SubMeshes", EditorStyles.boldLabel);
            Mesh[] subMeshes = m_Editor.terrain.GetAllSubMesh();
            m_SelectedSM = UEditorTools.SelectionGrid(m_SelectedSM, subMeshes.Select(sm => {
                Texture2D tex = null;
                while (!CheckPreviewReady(sm, ref tex))
                {
                }
                tex = AssetPreview.GetAssetPreview(sm);
                return(tex);
            }).ToArray(), 0x40, "No SubMesh.");
            if (selected != m_SelectedSM)
            {
                m_SelectedPass = 0;
                m_SelectedTex  = -1;
            }
        }
Esempio n. 8
0
        protected override void CtrlAndClick()
        {
            if (m_Selected == -1 || m_Model == 1 || !grass.active)
            {
                return;
            }
            Ray        ray = HandleUtility.GUIPointToWorldRay(Event.current.mousePosition);
            RaycastHit hit;

            if (Physics.Raycast(ray, out hit))
            {
                if (hit.collider.gameObject == m_Editor.terrain.gameObject)
                {
                    float newW = UEditorTools.RandomOfVaration(m_Width, m_WidthVar);
                    float newH = UEditorTools.RandomOfVaration(m_Height, m_HeightVar);
                    grass.Add(hit.point - m_Editor.terrain.transform.position, newW, newH);
                }
            }
            grass.Apply();
        }
Esempio n. 9
0
        public static Texture2D Field(Texture2D brush)
        {
            GUILayout.Label("Brushes", EditorStyles.boldLabel);
            int selectedBrush = -1;

            if (brush != null)
            {
                for (int i = 0, max = UIcon.brushes.Length; i < max; i++)
                {
                    if (brush == UIcon.brushes[i])
                    {
                        selectedBrush = i;
                        break;
                    }
                }
            }
            selectedBrush = UEditorTools.SelectionGrid(selectedBrush, UIcon.brushes, 0x20, "No brushes defined.");
            if (selectedBrush == -1)
            {
                return(null);
            }
            return(UIcon.brushes[selectedBrush]);
        }
Esempio n. 10
0
 public static int IntFiled(int index)
 {
     GUILayout.Label("Brushes", EditorStyles.boldLabel);
     index = UEditorTools.SelectionGrid(index, UIcon.brushes, 0x20, "No brushes defined.");
     return(index);
 }