示例#1
0
 protected override void OnExpandedGUI(WorldStampCreator parent)
 {
     if (SplatData.Count == 0)
     {
         EditorGUILayout.HelpBox("No Splats Found", MessageType.Info);
         return;
     }
     foreach (var compressedDetailData in SplatData)
     {
         EditorGUILayout.BeginHorizontal();
         compressedDetailData.Wrapper = (SplatPrototypeWrapper)EditorGUILayout.ObjectField(compressedDetailData.Wrapper,
                                                                                           typeof(SplatPrototypeWrapper), false);
         GUI.color   = compressedDetailData.Wrapper != null && IgnoredSplats.Contains(compressedDetailData.Wrapper) ? Color.red : Color.white;
         GUI.enabled = compressedDetailData.Wrapper != null;
         if (GUILayout.Button("Ignore", EditorStyles.miniButton, GUILayout.Width(60)))
         {
             if (IgnoredSplats.Contains(compressedDetailData.Wrapper))
             {
                 IgnoredSplats.Remove(compressedDetailData.Wrapper);
             }
             else
             {
                 IgnoredSplats.Add(compressedDetailData.Wrapper);
             }
         }
         GUI.enabled = true;
         GUI.color   = Color.white;
         EditorGUILayout.EndHorizontal();
     }
 }
示例#2
0
        protected override void PreviewInSceneInternal(WorldStampCreator parent)
        {
            var bounds  = parent.Template.Bounds;
            int counter = 0;
            int res     = 32;

            foreach (var kvp in SplatData)
            {
                int     xStep    = kvp.Data.Width / res;
                int     zStep    = kvp.Data.Height / res;
                Vector2 cellSize = new Vector2((xStep / (float)kvp.Data.Width) * bounds.size.x, (zStep / (float)kvp.Data.Height) * bounds.size.z);
                for (var u = 0; u < kvp.Data.Width; u += xStep)
                {
                    var fU = u / (float)kvp.Data.Width;
                    var wU = bounds.min.x + fU * bounds.size.x;
                    for (var v = 0; v < kvp.Data.Height; v += zStep)
                    {
                        var fV = v / (float)kvp.Data.Height;
                        var wV = bounds.min.z + fV * bounds.size.z;

                        var val = kvp.Data[u, v] / 255f;
                        HandleExtensions.DrawXZCell(new Vector3(wU, counter, wV), cellSize,
                                                    Quaternion.identity, ColorUtils.GetIndexColor(counter).WithAlpha(val));
                    }
                }
                counter++;
            }
        }
示例#3
0
        protected override void OnExpandedGUI(WorldStampCreator parent)
        {
            if (EditorGUILayoutX.IndentedButton("Reset"))
            {
                ResetMask(parent.Template.Bounds, parent.Template.Terrain);
            }
            var hCreator = parent.GetCreator <HeightmapDataCreator>();
            var zLevel   = hCreator.ZeroLevel * parent.Template.Bounds.size.y;
            var width    = Mathf.Clamp(parent.Template.Bounds.size.y.ToString().Length * 16, 32, 64);

            if (_fillHeight.x == _fillHeight.y)
            {
                _fillHeight.y = _fillHeight.x + 0.001f;
            }
            _fillHeight = new Vector2(Mathf.Clamp(_fillHeight.x, -zLevel, parent.Template.Bounds.size.y - zLevel), Mathf.Clamp(_fillHeight.y, -zLevel, parent.Template.Bounds.size.y - zLevel));
            EditorGUILayout.BeginHorizontal();
            _fillHeight.x = EditorGUILayout.FloatField(_fillHeight.x, GUILayout.Width(width));
            EditorGUILayout.MinMaxSlider(ref _fillHeight.x, ref _fillHeight.y, -zLevel, parent.Template.Bounds.size.y - zLevel);
            _fillHeight.y = EditorGUILayout.FloatField(_fillHeight.y, GUILayout.Width(width));
            //_fillHeight = new Vector2(Mathf.RoundToInt(_fillHeight.x), Mathf.RoundToInt(_fillHeight.y));
            if (GUILayout.Button("Fill Below Height"))
            {
                FillMaskFromMinY(parent.Template.Bounds, parent.Template.Terrain, hCreator.Heights, _fillHeight - Vector2.one * (hCreator.ZeroLevel * parent.Template.Bounds.size.y));
            }
            EditorGUILayout.EndHorizontal();
            if (EditorGUILayoutX.IndentedButton("Load From Texture"))
            {
                LoadFromTexture(parent);
            }
        }
示例#4
0
        protected override void PreviewInSceneInternal(WorldStampCreator parent)
        {
            var bounds = parent.Template.Bounds;

            if (_maskPainter == null)
            {
                _maskPainter      = new Painter(Mask, GridManager);
                _maskPainter.Ramp = new Gradient()
                {
                    colorKeys = new[] { new GradientColorKey(Color.red, 0), new GradientColorKey(Color.black, 0.001f), new GradientColorKey(Color.black, 1), },
                    alphaKeys = new[] { new GradientAlphaKey(1, 0), new GradientAlphaKey(0, 1), }
                };
                _maskPainter.Rect = new Rect(bounds.min.xz(), bounds.size.xz());
            }
            else
            {
                GridSize = WorldStampCreator.GetMinGridSize(bounds, parent.Template.Terrain);
                _maskPainter.GridManager = GridManager;
                _maskPainter.Canvas      = Mask;
                _maskPainter.MaxValue    = 1;
                _maskPainter.MinValue    = 0;
                _maskPainter.Rect        = new Rect(Vector2.zero, bounds.size.xz());
                _maskPainter.TRS         = Matrix4x4.TRS(bounds.min, Quaternion.identity, Vector3.one);
                //_maskPainter.Repaint();
                _maskPainter.PaintingEnabled = true;
                _maskPainter.OnSceneGUI();
            }
        }
示例#5
0
 protected override void OnExpandedGUI(WorldStampCreator parent)
 {
     if (Prototypes.Count == 0)
     {
         EditorGUILayout.HelpBox("No Trees Found", MessageType.Info);
         return;
     }
     for (int i = 0; i < Prototypes.Count; i++)
     {
         EditorGUILayout.BeginHorizontal();
         Prototypes[i] = (GameObject)EditorGUILayout.ObjectField(Prototypes[i],
                                                                 typeof(GameObject), false);
         GUI.color = Prototypes[i] != null && IgnoredTrees.Contains(Prototypes[i])
             ? Color.red
             : Color.white;
         GUI.enabled = Prototypes[i] != null;
         if (GUILayout.Button("Ignore", EditorStyles.miniButton, GUILayout.Width(60)))
         {
             if (IgnoredTrees.Contains(Prototypes[i]))
             {
                 IgnoredTrees.Remove(Prototypes[i]);
             }
             else
             {
                 IgnoredTrees.Add(Prototypes[i]);
             }
         }
         GUI.enabled = true;
         GUI.color   = Color.white;
         EditorGUILayout.EndHorizontal();
     }
 }
示例#6
0
        public override void OnInspectorGUI()
        {
            var wsct = target as WorldStampTemplate;

            if (GUILayout.Button("Set as Capture Settings"))
            {
                var w = EditorWindow.GetWindow <WorldStampCreator>();

                w.Template = wsct.Template.JSONClone();
                if (w.Template.Terrain == null)
                {
                    w.Template.Terrain = Terrain.activeTerrain;
                }

                var newBounds = new Bounds(wsct.transform.position, wsct.Size);
                newBounds = WorldStampCreator.ClampBounds(w.Template.Terrain, newBounds);

                w.Template.Bounds = newBounds;
                var mask = w.GetCreator <MaskDataCreator>();
                mask.SetMaskFromArray(w, wsct.Mask);
                mask.LastBounds = newBounds;
            }
            GUI.color = _isPreviewing ? Color.green : Color.white;
            if (GUILayout.Button("Preview In Scene"))
            {
                _isPreviewing = !_isPreviewing;
                _hasSet       = false;
            }
            GUI.color = Color.white;
            DrawDefaultInspector();
        }
示例#7
0
        public Texture2D GetTextureFromMask(WorldStampCreator parent)
        {
            GridSize = WorldStampCreator.GetMinGridSize(parent.Template.Bounds, parent.Template.Terrain);
            var bounds = parent.Template.Bounds;
            var width  = Mathf.CeilToInt(bounds.size.x / GridSize);
            var height = Mathf.CeilToInt(bounds.size.z / GridSize);
            var tex    = new Texture2D(width, height);

            for (var u = 0; u < width; u++)
            {
                for (var v = 0; v < height; v++)
                {
                    var pos     = new Vector3((u / (float)width) * bounds.size.x, bounds.size.y / 2, (v / (float)height) * bounds.size.z);
                    var cell    = GridManager.GetCell(pos);
                    var cellMax = GridManager.GetCellMax(cell).x0z() + bounds.min;
                    var cellMin = GridManager.GetCellCenter(cell).x0z() + bounds.min;
                    if (!bounds.Contains(cellMax) || !bounds.Contains(cellMin))
                    {
                        continue;
                    }

                    var val = Mask.GetValue(cell);
                    tex.SetPixel(u, v, Color.Lerp(Color.black, Color.white, val));
                }
            }
            tex.Apply();
            return(tex);
        }
示例#8
0
        public Serializable2DFloatArray GetArrayFromMask(WorldStampCreator parent)
        {
            GridSize = WorldStampCreator.GetMinGridSize(parent.Template.Bounds, parent.Template.Terrain);
            var bounds = parent.Template.Bounds;
            var width  = Mathf.CeilToInt(bounds.size.x / GridSize);
            var height = Mathf.CeilToInt(bounds.size.z / GridSize);
            var array  = new Serializable2DFloatArray(width, height);

            for (var u = 0; u < width; u++)
            {
                for (var v = 0; v < height; v++)
                {
                    var pos     = new Vector3((u / (float)width) * bounds.size.x, bounds.size.y / 2, (v / (float)height) * bounds.size.z);
                    var cell    = GridManager.GetCell(pos);
                    var cellMax = GridManager.GetCellMax(cell).x0z() + bounds.min;
                    var cellMin = GridManager.GetCellCenter(cell).x0z() + bounds.min;
                    if (!bounds.Contains(cellMax) || !bounds.Contains(cellMin))
                    {
                        continue;
                    }

                    var val = Mask.GetValue(cell);
                    array[u, v] = val;
                }
            }
            return(array);
        }
示例#9
0
        private void FillMaskFromMinY(Bounds bounds, Terrain terrain, Serializable2DFloatArray heights, Vector2 minY)
        {
            Mask.Clear();
            GridSize = WorldStampCreator.GetMinGridSize(bounds, terrain);
            for (var u = GridSize / 2f; u < bounds.size.x; u += GridSize)
            {
                for (var v = GridSize / 2f; v < bounds.size.z; v += GridSize)
                {
                    var cell    = GridManager.GetCell(new Vector3(u, 0, v));
                    var cellMax = GridManager.GetCellMax(cell).x0z() + bounds.min;
                    var cellMin = GridManager.GetCellCenter(cell).x0z() + bounds.min;
                    if (!bounds.Contains(cellMax) || !bounds.Contains(cellMin))
                    {
                        continue;
                    }

                    var h = heights.BilinearSample(new Vector2(u / bounds.size.z, v / bounds.size.x)) * bounds.size.y;
                    if (h < minY.x)
                    {
                        Mask.SetValue(cell, 0);
                    }
                    else if (h <= minY.y)
                    {
                        Mask.SetValue(cell, (h - minY.x) / (minY.y - minY.x));
                    }
                    else
                    {
                        Mask.SetValue(cell, 1);
                    }
                }
            }
        }
示例#10
0
        protected override void OnExpandedGUI(WorldStampCreator parent)
        {
            if (Enabled && (Heights == null || Heights.IsEmpty()))
            {
                NeedsRecapture = true;
            }

            EditorGUI.BeginChangeCheck();
            var tHeight = parent.Template.Terrain.terrainData.size.y;

            AutoZeroLevel = EditorGUILayout.Toggle("Auto Zero Level" + (AutoZeroLevel ? (ZeroLevel * tHeight).ToString() : string.Empty), AutoZeroLevel);
            if (!AutoZeroLevel)
            {
                EditorGUI.indentLevel++;

                var newHeightMin = EditorGUILayout.Slider("Zero Level", ZeroLevel * tHeight, 0, tHeight) / tHeight;
                EditorGUI.indentLevel--;
                if (newHeightMin != ZeroLevel)
                {
                    ZeroLevel      = newHeightMin;
                    NeedsRecapture = true;
                    SceneView.RepaintAll();
                }
            }
            if (EditorGUI.EndChangeCheck())
            {
                NeedsRecapture = true;
            }
        }
示例#11
0
        /*protected override void OnExpandedGUI(WorldStampCreator parent)
         * {
         *  StripNetwork = EditorGUILayout.Toggle("Strip Network", StripNetwork);
         *  if (!StripNetwork)
         *  {
         *      DeleteDataContainers = EditorGUILayout.Toggle("Delete DataContainers", DeleteDataContainers);
         *  }
         * }*/

        protected override void PreviewInSceneInternal(WorldStampCreator parent)
        {
            Handles.color = Color.white;
            for (int i = RoadNetworks.Count - 1; i >= 0; i--)
            {
                var roadNetwork = RoadNetworks[i];
                if (!roadNetwork)
                {
                    RoadNetworks.RemoveAt(i);
                    continue;
                }

                roadNetwork.ForceThink();
                for (int j = 0; j < roadNetwork.Nodes.Count; j++)
                {
                    var node = roadNetwork.Nodes[j];
                    if (!node)
                    {
                        continue;
                    }
                    for (int k = 0; k < node.OutConnections.Count; k++)
                    {
                        var nodeConnection = node.OutConnections[k];
                        var thisPos        = nodeConnection.ThisNode.NodePosition;
                        var nextPos        = nodeConnection.NextNode.NodePosition;

                        /*if (!b.Contains(thisPos) && !b.Contains(nextPos))
                         * {
                         *  continue;
                         * }*/
                        Handles.DrawLine(thisPos, nextPos);
                    }
                }
            }
        }
示例#12
0
 public void PreviewInScene(WorldStampCreator parent)
 {
     if (parent.Template.Terrain == null || parent.Template.Bounds.size == Vector3.zero || (ManuallyRecapturable && NeedsRecapture))
     {
         return;
     }
     PreviewInSceneInternal(parent);
 }
示例#13
0
        public override void DrawGUI(WorldStampCreator parent)
        {
            if (parent.SceneGUIOwner != this && _maskPainter != null)
            {
                _maskPainter.Canvas = null;
            }
            if (_maskPainter != null && _maskPainter.Canvas != null && _maskPainter.Canvas != Mask)
            {
                _maskPainter.Canvas  = null;
                parent.SceneGUIOwner = null;
            }
            if (Mask.Count == 0 || LastBounds != parent.Template.Bounds)
            {
                ResetMask(parent.Template.Bounds, parent.Template.Terrain);
            }

            EditorExtensions.Seperator();
            EditorGUILayout.BeginHorizontal();

            GUIExpanded = EditorGUILayout.Foldout(GUIExpanded, Label);
            var previewContent = new GUIContent("Edit");

            previewContent.tooltip = "Edit the mask for this stamp.";
            GUI.color = parent.SceneGUIOwner == this ? Color.green : Color.white;
            if (GUILayout.Button(previewContent, EditorStyles.miniButton, GUILayout.Width(60), GUILayout.Height(16)))
            {
                if (parent.SceneGUIOwner == this && _maskPainter != null)
                {
                    _maskPainter.Destroy();
                    _maskPainter = null;
                }
                parent.SceneGUIOwner = parent.SceneGUIOwner == this ? null : this;
                if ((parent.Template.Bounds.size - LastBounds.size).magnitude > 1)
                {
                    ResetMask(parent.Template.Bounds, parent.Template.Terrain);
                }
                GUIUtility.ExitGUI();
                return;
            }
            GUI.color = Color.white;
            EditorGUILayout.EndHorizontal();

            if (GUIExpanded)
            {
                GUI.enabled = Enabled;
                EditorGUI.indentLevel++;
                EditorGUI.BeginChangeCheck();
                OnExpandedGUI(parent);
                if (EditorGUI.EndChangeCheck())
                {
                    NeedsRecapture = true;
                }
                EditorGUI.indentLevel--;
                GUI.enabled = true;
            }
        }
示例#14
0
 protected override void OnExpandedGUI(WorldStampCreator parent)
 {
     EditorGUI.BeginChangeCheck();
     Mask         = LayerMaskFieldUtility.LayerMaskField("Layer Mask", Mask, false);
     RelativeMode = (WorldStamp.EObjectRelativeMode)EditorGUILayout.EnumPopup("Relative Mode", RelativeMode);
     if (EditorGUI.EndChangeCheck())
     {
         NeedsRecapture = true;
     }
 }
示例#15
0
        private void LoadFromTexture(WorldStampCreator parent)
        {
            var path = EditorUtility.OpenFilePanel("Load Texture Into Mask", "Assets", "png");

            if (!string.IsNullOrEmpty(path))
            {
                var tex = new Texture2D(0, 0);
                tex.LoadImage(File.ReadAllBytes(path));
                SetMaskFromTexture(parent, tex);
                UnityEngine.Object.DestroyImmediate(tex);
            }
        }
示例#16
0
 protected override void PreviewInSceneInternal(WorldStampCreator parent)
 {
     Handles.color = Color.white.WithAlpha(.5f);
     for (int i = 0; i < Objects.Count; i++)
     {
         var    b = Objects[i];
         Bounds objBounds;
         if (BoundsMapping.TryGetValue(b, out objBounds))
         {
             Handles.DrawWireCube(objBounds.center, objBounds.size);
         }
     }
 }
示例#17
0
        protected override void PreviewInSceneInternal(WorldStampCreator parent)
        {
            var bounds  = parent.Template.Bounds;
            var terrain = parent.Template.Terrain;

            Handles.color = Color.green;
            foreach (var hurtTreeInstance in Trees)
            {
                var pos = new Vector3(hurtTreeInstance.Position.x * bounds.size.x, 0,
                                      hurtTreeInstance.Position.z * bounds.size.z) + bounds.min;
                pos.y += terrain.SampleHeight(pos);
                Handles.DrawDottedLine(pos, pos + Vector3.up * 10 * hurtTreeInstance.Scale.x, 1);
            }
        }
示例#18
0
        protected override void PreviewInSceneInternal(WorldStampCreator parent)
        {
            var bounds = parent.Template.Bounds;

            if (_preview == null || _preview.IsDisposed())
            {
                _preview = new WorldStampPreview();
                _dirty   = true;
            }
            if (_dirty)
            {
                _preview.Invalidate(
                    Heights, () => bounds.size, () => bounds.center.xz().x0z(bounds.min.y + ZeroLevel * bounds.size.y), () => Vector3.one,
                    () => Quaternion.identity, () => bounds.size, true, null, null,
                    () => parent.SceneGUIOwner == this, 128);
                _dirty = false;
            }
        }
示例#19
0
 private void ResetMask(Bounds bounds, Terrain terrain)
 {
     Mask.Clear();
     GridSize = WorldStampCreator.GetMinGridSize(bounds, terrain);
     for (var u = GridSize / 2f; u < bounds.size.x; u += GridSize)
     {
         for (var v = GridSize / 2f; v < bounds.size.z; v += GridSize)
         {
             var cell    = GridManager.GetCell(new Vector3(u, 0, v));
             var cellMax = GridManager.GetCellMax(cell).x0z() + bounds.min;
             var cellMin = GridManager.GetCellCenter(cell).x0z() + bounds.min;
             if (!bounds.Contains(cellMax) || !bounds.Contains(cellMin))
             {
                 continue;
             }
             Mask.SetValue(cell, 1);
         }
     }
     LastBounds = bounds;
 }
示例#20
0
 public void SetMaskFromTexture(WorldStampCreator parent, Texture2D tex)
 {
     GridSize = WorldStampCreator.GetMinGridSize(parent.Template.Bounds, parent.Template.Terrain);
     Mask.Clear();
     for (var u = 0f; u < parent.Template.Bounds.size.x; u += GridSize)
     {
         for (var v = 0f; v < parent.Template.Bounds.size.z; v += GridSize)
         {
             var cell    = GridManager.GetCell(new Vector3(u, 0, v));
             var cellMax = GridManager.GetCellMax(cell).x0z() + parent.Template.Bounds.min;
             var cellMin = GridManager.GetCellCenter(cell).x0z() + parent.Template.Bounds.min;
             if (!parent.Template.Bounds.Contains(cellMax) || !parent.Template.Bounds.Contains(cellMin))
             {
                 continue;
             }
             var val = tex.GetPixelBilinear(u / parent.Template.Bounds.size.x, v / parent.Template.Bounds.size.z).grayscale;
             Mask.SetValue(cell, val);
         }
     }
 }
示例#21
0
 public void SetMaskFromArray(WorldStampCreator parent, Serializable2DFloatArray mask)
 {
     GridSize = WorldStampCreator.GetMinGridSize(parent.Template.Bounds, parent.Template.Terrain);
     Mask.Clear();
     for (var u = GridSize / 2f; u < parent.Template.Bounds.size.x; u += GridSize)
     {
         for (var v = GridSize / 2f; v < parent.Template.Bounds.size.z; v += GridSize)
         {
             var cell    = GridManager.GetCell(new Vector3(u, 0, v));
             var cellMax = GridManager.GetCellMax(cell).x0z() + parent.Template.Bounds.min;
             var cellMin = GridManager.GetCellCenter(cell).x0z() + parent.Template.Bounds.min;
             if (!parent.Template.Bounds.Contains(cellMax) || !parent.Template.Bounds.Contains(cellMin))
             {
                 continue;
             }
             var val = mask.BilinearSample(new Vector2(u / parent.Template.Bounds.size.x, v / parent.Template.Bounds.size.z));
             Mask.SetValue(cell, val);
         }
     }
 }
示例#22
0
 protected virtual void OnExpandedGUI(WorldStampCreator parent)
 {
     GenericEditor.DrawGUI(this);
 }
示例#23
0
        public virtual void DrawGUI(WorldStampCreator parent)
        {
            EditorExtensions.Seperator();

            EditorGUILayout.BeginHorizontal();

            if (CanDisable)
            {
                Enabled = EditorGUILayout.Toggle(new GUIContent(string.Empty, Enabled ? "Enable Capture" : "Disable Capture"), Enabled, GUILayout.Width(18));
            }
            else
            {
                EditorGUILayout.LabelField("", GUILayout.Width(18));
            }
            if (!Enabled || NeedsRecapture)
            {
                if (parent.SceneGUIOwner == this)
                {
                    parent.SceneGUIOwner = null;
                }
            }

            GUIExpanded = EditorGUILayout.Foldout(GUIExpanded, Label);
            //EditorGUILayout.LabelField(NeedsRecapture && Enabled ? "(Needs Recapture)" : string.Empty);

            var previewContent = new GUIContent("Preview");

            previewContent.tooltip = "Preview this data.";
            GUI.color   = parent.SceneGUIOwner == this ? Color.green : Color.white;
            GUI.enabled = Enabled && !NeedsRecapture;
            if (GUILayout.Button(previewContent, EditorStyles.miniButton, GUILayout.Width(60), GUILayout.Height(16)))
            {
                if (parent.SceneGUIOwner == this)
                {
                    parent.SceneGUIOwner = null;
                }
                else
                {
                    if (!HasDataPreview)
                    {
                        parent.SceneGUIOwner = parent.SceneGUIOwner == this ? null : this;
                    }
                    else
                    {
                        var menu = new GenericMenu();
                        menu.AddItem(new GUIContent("Preview In Scene"), false, () => parent.SceneGUIOwner = parent.SceneGUIOwner == this ? null : this);
                        menu.AddItem(new GUIContent("Preview In Inspector"), false, PreviewInDataInspector);
                        menu.ShowAsContext();
                    }
                }
            }
            GUI.color = Color.white;

            GUI.enabled = true;
            EditorGUILayout.EndHorizontal();

            if (GUIExpanded)
            {
                GUI.enabled = Enabled;
                EditorGUI.indentLevel++;

                //EditorGUI.BeginChangeCheck();

                OnExpandedGUI(parent);

                /*if (EditorGUI.EndChangeCheck())
                 * {
                 *  NeedsRecapture = true;
                 * }*/

                EditorGUI.indentLevel--;
                GUI.enabled = true;
            }
        }
示例#24
0
 protected abstract void PreviewInSceneInternal(WorldStampCreator parent);