From 5e5a7487208cd9657c236dfa6aa945c47d33c6d4 Mon Sep 17 00:00:00 2001 From: hyperion51 Date: Mon, 23 Mar 2020 01:43:37 +0000 Subject: [PATCH] Galaxy Editor Changes --- Assets/Resources/Test Galaxy.asset | 3 - Assets/Resources/Test.asset | 3 + ...Test Galaxy.asset.meta => Test.asset.meta} | 2 +- Assets/Scripts/Editor/GalaxyEditor.cs | 290 +++++++----------- Assets/Scripts/Galaxy.cs | 10 +- Assets/Shaders/GalaxyMap.shader | 12 +- README.md | 4 +- 7 files changed, 120 insertions(+), 204 deletions(-) delete mode 100644 Assets/Resources/Test Galaxy.asset create mode 100644 Assets/Resources/Test.asset rename Assets/Resources/{Test Galaxy.asset.meta => Test.asset.meta} (79%) diff --git a/Assets/Resources/Test Galaxy.asset b/Assets/Resources/Test Galaxy.asset deleted file mode 100644 index c8598fdde..000000000 --- a/Assets/Resources/Test Galaxy.asset +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:04fce9f206f067f70b4248f38c0ef6eebdbc784f7d33dc5baeb4fb60ba291237 -size 836 diff --git a/Assets/Resources/Test.asset b/Assets/Resources/Test.asset new file mode 100644 index 000000000..c6625d600 --- /dev/null +++ b/Assets/Resources/Test.asset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c57c71d8366538de1f9abaca57bda7d253e7d9b63711276244ed4cf1d0aa8314 +size 792 diff --git a/Assets/Resources/Test Galaxy.asset.meta b/Assets/Resources/Test.asset.meta similarity index 79% rename from Assets/Resources/Test Galaxy.asset.meta rename to Assets/Resources/Test.asset.meta index 1ed5e52ab..c135d349b 100644 --- a/Assets/Resources/Test Galaxy.asset.meta +++ b/Assets/Resources/Test.asset.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 931e677be56754f4f9d3d0817e2d38df +guid: 8525ebaeff3478247bbeb4d8eb71ef35 NativeFormatImporter: externalObjects: {} mainObjectFileID: 11400000 diff --git a/Assets/Scripts/Editor/GalaxyEditor.cs b/Assets/Scripts/Editor/GalaxyEditor.cs index 1cf894fb3..5ec402b76 100644 --- a/Assets/Scripts/Editor/GalaxyEditor.cs +++ b/Assets/Scripts/Editor/GalaxyEditor.cs @@ -10,30 +10,37 @@ using UnityEditor; [CustomEditor(typeof(Galaxy))] public class GalaxyEditor : Editor { - private Texture2D _preview; private int _width = 0; - private TextAsset _nameData; - private bool _showNameData; - private bool _showCultureMaps; - private Dictionary _expandRegion = new Dictionary(); - private Dictionary _expandSubregion = new Dictionary(); - private NameData _names = new NameData(); + private bool _showResourceMaps; private GalaxyMapLayerData _currentLayer; private string _currentLayerName = "Star Density"; private bool _showStarEditor; private int _hilbertOrder = 6; private ulong _hilbertIndex; private int _starCount = 1; - private int _nameMinLength = 5; - private int _nameMaxLength = 8; private float _maxLinkLength = .1f; private float _linkFilter = .5f; private IEnumerable _stars = new Vector2[0]; private bool _drawStars; - private bool _drawCulture; + private bool _drawResource; private bool _drawLinks; private VoronoiMesh< Vertex2, Cell2, VoronoiEdge> _voronoiMesh; private List _starLinks = new List(); + private Texture2D _white; + private Texture2D _starTex; + private Texture2D _linkTex; + private Material _galaxyMat; + private Material _transparent; + + private void OnEnable() + { + _white = Color.white.ToTexture(); + _galaxyMat = new Material(Shader.Find("Unlit/GalaxyMap")); + _transparent = new Material(Shader.Find("Unlit/Transparent")); + _width = Screen.width; + _starTex = new Texture2D(_width,_width, TextureFormat.ARGB32, false); + _linkTex = new Texture2D(_width,_width, TextureFormat.ARGB32, false); + } public override void OnInspectorGUI() { @@ -45,134 +52,84 @@ public class GalaxyEditor : Editor if (Screen.width != _width) { _width = Screen.width; - _preview = new Texture2D(_width,_width,TextureFormat.ARGB32,false); - Render(galaxy.MapData, _currentLayer); + _starTex = new Texture2D(_width,_width, TextureFormat.ARGB32, false); + _linkTex = new Texture2D(_width,_width, TextureFormat.ARGB32, false); + RenderStars(); + RenderLinks(); } GUILayout.Label("Preview", EditorStyles.boldLabel); - EditorGUI.DrawPreviewTexture(EditorGUILayout.GetControlRect(false, _width), _preview); - EditorGUI.BeginChangeCheck(); + _galaxyMat.SetFloat("Arms", galaxy.MapData.Arms); + _galaxyMat.SetFloat("Twist", galaxy.MapData.Twist); + _galaxyMat.SetFloat("TwistPower", galaxy.MapData.TwistPower); + _galaxyMat.SetFloat("Arms", galaxy.MapData.Arms); + _galaxyMat.SetFloat("SpokeOffset", _currentLayer.SpokeOffset); + _galaxyMat.SetFloat("SpokeScale", _currentLayer.SpokeScale); + _galaxyMat.SetFloat("CoreBoost", _currentLayer.CoreBoost); + _galaxyMat.SetFloat("CoreBoostOffset", _currentLayer.CoreBoostOffset); + _galaxyMat.SetFloat("CoreBoostPower", _currentLayer.CoreBoostPower); + _galaxyMat.SetFloat("EdgeReduction", _currentLayer.EdgeReduction); + _galaxyMat.SetFloat("NoisePosition", _currentLayer.NoisePosition); + _galaxyMat.SetFloat("NoiseAmplitude", _currentLayer.NoiseAmplitude); + _galaxyMat.SetFloat("NoiseOffset", _currentLayer.NoiseOffset); + _galaxyMat.SetFloat("NoiseGain", _currentLayer.NoiseGain); + _galaxyMat.SetFloat("NoiseLacunarity", _currentLayer.NoiseLacunarity); + _galaxyMat.SetFloat("NoiseFrequency", _currentLayer.NoiseFrequency); + var rect = EditorGUILayout.GetControlRect(false, _width); + EditorGUI.DrawPreviewTexture(rect, _white, _galaxyMat); + if(_drawLinks) + EditorGUI.DrawPreviewTexture(rect, _linkTex, _transparent); + if(_drawStars) + EditorGUI.DrawPreviewTexture(rect, _starTex, _transparent); + _drawStars = EditorGUILayout.ToggleLeft($"Display {_stars.Count()} Stars", _drawStars); - _drawCulture = EditorGUILayout.ToggleLeft("Display Cultures", _drawCulture); + _drawResource = EditorGUILayout.ToggleLeft("Display Resources", _drawResource); _drawLinks = EditorGUILayout.ToggleLeft($"Display {_starLinks.Count} Links", _drawLinks); + GUILayout.Space(10); // Show default inspector property editor DrawDefaultInspector (); - if (galaxy.MapData.CultureDensities.Count != galaxy.NameDatabase.Count) - galaxy.MapData.CultureDensities = galaxy.NameDatabase.Select(continent=>new GalaxyMapLayerData()).ToList(); EditorGUILayout.BeginVertical("Box"); EditorGUI.indentLevel++; GUILayout.Label(_currentLayerName); Inspect(_currentLayer); EditorGUI.indentLevel--; EditorGUILayout.EndVertical(); - if(EditorGUI.EndChangeCheck()) - Render(galaxy.MapData, _currentLayer); EditorGUILayout.BeginVertical("Box"); EditorGUI.indentLevel++; - _showCultureMaps = EditorGUILayout.Foldout(_showCultureMaps, "Culture Density Maps"); - if (_showCultureMaps) + _showResourceMaps = EditorGUILayout.Foldout(_showResourceMaps, "Resource Density Maps"); + if (_showResourceMaps) { EditorGUI.indentLevel++; - for (var i = 0; i < galaxy.MapData.CultureDensities.Count; i++) + foreach (var resourceDensity in galaxy.MapData.ResourceDensities.ToArray()) { - var cultureMap = galaxy.MapData.CultureDensities[i]; - var data = galaxy.NameDatabase[i]; - if (GUILayout.Button("Inspect " + data.Name)) + EditorGUILayout.BeginHorizontal(); + var newName = EditorGUILayout.DelayedTextField(resourceDensity.Key); + if (newName != resourceDensity.Key) { - _currentLayerName = data.Name; - _currentLayer = cultureMap; - Render(galaxy.MapData, _currentLayer); + galaxy.MapData.ResourceDensities.Remove(resourceDensity.Key); + galaxy.MapData.ResourceDensities[newName] = resourceDensity.Value; } + if (GUILayout.Button("Inspect")) + { + _currentLayerName = resourceDensity.Key; + _currentLayer = resourceDensity.Value; + } + EditorGUILayout.EndHorizontal(); } EditorGUI.indentLevel--; + if (GUILayout.Button("Add New Resource")) + { + galaxy.MapData.ResourceDensities["New Resource"] = new GalaxyMapLayerData(); + } } else if(_currentLayer != galaxy.MapData.StarDensity) { _currentLayerName = "Star Density"; _currentLayer = galaxy.MapData.StarDensity; - Render(galaxy.MapData, _currentLayer); - } - EditorGUI.indentLevel--; - EditorGUILayout.EndVertical(); - - EditorGUILayout.BeginVertical("Box"); - EditorGUI.indentLevel++; - _showNameData = EditorGUILayout.Foldout(_showNameData, "Name Database Tools"); - if (_showNameData) - { - EditorGUI.indentLevel++; - foreach (var region in _names.Names.Keys) - { - if (!_expandRegion.ContainsKey(region)) - _expandRegion[region] = false; - _expandRegion[region] = EditorGUILayout.Foldout(_expandRegion[region], region + ": " + _names.Names[region].Count + " Subregions"); - if (_expandRegion[region]) - { - EditorGUI.indentLevel++; - foreach (var subregion in _names.Names[region].Keys) - { - if (!_expandSubregion.ContainsKey(subregion)) - _expandSubregion[subregion] = false; - _expandSubregion[subregion] = EditorGUILayout.Foldout(_expandSubregion[subregion], subregion + ": " + _names.Names[region][subregion].Count + " Towns"); - if (_expandSubregion[subregion]) - { - EditorGUI.indentLevel++; - foreach (var town in _names.Names[region][subregion]) - { - GUILayout.Label(town); - } - EditorGUI.indentLevel--; - } - } - EditorGUI.indentLevel--; - } - } - EditorGUI.indentLevel--; - GUILayout.Space(10); - _nameData = EditorGUILayout.ObjectField(_nameData, typeof(TextAsset), false) as TextAsset; - if (GUILayout.Button("Parse Data")) - { - _names.Names.Clear(); - foreach (var s in _nameData.text.Split('\n')) - _names.Add(s); - } - if (GUILayout.Button("Filter Data")) - { - if (!_names.Names.ContainsKey("World")) - { - _names.Names["World"] = new Dictionary>(); - _names.Names["World"]["Miscellaneous"] = new List(); - } - foreach (var region in _names.Names.Keys.Where(s=>s!="World").ToArray()) - { - if (!_names.Names[region].ContainsKey("Miscellaneous")) - _names.Names[region]["Miscellaneous"] = new List(); - foreach (var subregion in _names.Names[region].Keys.Where(s=>s!="Miscellaneous").ToArray()) - { - if (_names.Names[region][subregion].Count < 500) - { - _names.Names[region]["Miscellaneous"].AddRange(_names.Names[region][subregion]); - _names.Names[region].Remove(subregion); - } - } - if (_names.Names[region].Count == 1) - { - _names.Names["World"]["Miscellaneous"].AddRange(_names.Names[region]["Miscellaneous"]); - _names.Names.Remove(region); - } - } - } - if (GUILayout.Button("Set Data")) - { - var data = new List(); - data.AddRange(_names.Names.Select(kvp => new ContinentData{Name = kvp.Key,Regions = new List()})); - data.ForEach(c=>c.Regions.AddRange(_names.Names[c.Name].Select(kvp=> new RegionData{Name = kvp.Key,Towns = kvp.Value}))); - galaxy.NameDatabase = data; - } } EditorGUI.indentLevel--; EditorGUILayout.EndVertical(); @@ -216,29 +173,10 @@ public class GalaxyEditor : Editor } Debug.Log($"Generated {stars.Count} stars."); _stars = stars; + RenderStars(); } if (_stars.Any()) { - _nameMinLength = EditorGUILayout.IntField("Minimum Length", _nameMinLength); - _nameMaxLength = EditorGUILayout.IntField("Maximum Length", _nameMaxLength); - if (GUILayout.Button("Generate Star Names")) - { - galaxy.MapData.Stars = _stars.Select(s => - { - var culture = galaxy.MapData.CultureDensities.IndexOf(galaxy.MapData.CultureDensities.OrderByDescending(c => c.Evaluate(s, galaxy.MapData)) - .First()); - var subculture = UnityEngine.Random.Range(0, galaxy.NameDatabase[culture].Regions.Count); - var markov = new MarkovNameGenerator(galaxy.NameDatabase[culture].Regions[subculture].Towns, 2, _nameMinLength, _nameMaxLength); - return new StarData - { - Position = s, - NameSource = (galaxy.NameDatabase[culture].Regions[subculture].Name == "Miscellaneous") - ? galaxy.NameDatabase[culture].Name - : galaxy.NameDatabase[culture].Regions[subculture].Name, - Names = Enumerable.Range(0,20).Select(_ => markov.NextName).ToList() - }; - }).ToList(); - } _maxLinkLength = EditorGUILayout.FloatField("Max Link Length", _maxLinkLength); if (GUILayout.Button("Generate Star Links")) { @@ -252,6 +190,7 @@ public class GalaxyEditor : Editor new VoronoiLink(cell.Vertices[2], cell.Vertices[1])}; _starLinks.AddRange(links.Where(l=>!_starLinks.ContainsLine(l) && l.Length < _maxLinkLength)); + RenderLinks(); } } if (_starLinks.Any()) @@ -278,8 +217,9 @@ public class GalaxyEditor : Editor } //if (_starLinks.Count(sl => sl.ContainsPoint(link.point1)) > 1 && _starLinks.Count(sl => sl.ContainsPoint(link.point2)) > 1) } + RenderLinks(); } - if (GUILayout.Button("Apply Star Links")) + if (GUILayout.Button("Save Star Links")) { foreach (var star in galaxy.MapData.Stars) { @@ -298,33 +238,6 @@ public class GalaxyEditor : Editor EditorUtility.SetDirty(target); - -/* - EditorGUI.BeginChangeCheck(); - _arms = EditorGUILayout.IntField("Arms", _arms); - _twist = EditorGUILayout.FloatField("Twist", _twist); - _twistPower = EditorGUILayout.FloatField("Twist Power", _twistPower); - EditorGUILayout.field - - _edgeReduction = EditorGUILayout.FloatField("Edge Reduction", _edgeReduction); - _coreBoost = EditorGUILayout.FloatField("Core Boost", _coreBoost); - _coreBoostOffset = EditorGUILayout.FloatField("Core Boost Offset", _coreBoostOffset); - _coreBoostPower = EditorGUILayout.FloatField("Core Boost Power", _coreBoostPower); - _noiseAmplitude = EditorGUILayout.FloatField("Noise Amplitude", _noiseAmplitude); - _noise.SetFractalGain(_noiseGain = EditorGUILayout.FloatField("Noise Gain", _noiseGain)); - _noise.SetFractalLacunarity(_noiseLacunarity = EditorGUILayout.FloatField("Noise Lacunarity", _noiseLacunarity)); - _noise.SetFractalOctaves(_noiseOctaves = EditorGUILayout.IntField("Noise Octaves", _noiseOctaves)); - _noise.SetFrequency(_noiseFrequency = EditorGUILayout.FloatField("Noise Frequency", _noiseFrequency)); - if(EditorGUI.EndChangeCheck()) - Render(); - if (GUILayout.Button("Randomize Seed")) - { - _noise.SetSeed((int) (UnityEngine.Random.value*int.MaxValue)); - Render(); - } - if(GUILayout.Button("Regenerate")) - Render(); - */ } private IEnumerable EvaluateHilbert(int order, bool normalized = true) @@ -356,45 +269,50 @@ public class GalaxyEditor : Editor layer.NoiseLacunarity = EditorGUILayout.FloatField("Noise Lacunarity", layer.NoiseLacunarity); layer.NoiseOctaves = EditorGUILayout.IntField("Noise Octaves", layer.NoiseOctaves); layer.NoiseFrequency = EditorGUILayout.FloatField("Noise Frequency", layer.NoiseFrequency); - layer.NoiseOffset = EditorGUILayout.FloatField("Noise Seed", layer.NoiseOffset); layer.SpokeOffset = EditorGUILayout.FloatField("Spoke Offset", layer.SpokeOffset); layer.SpokeScale = EditorGUILayout.FloatField("Spoke Scale", layer.SpokeScale); } + + int UvToIndex(Vector2 v) => (int) (v.y * _width) * _width + (int) (v.x * _width); - void Render(GalaxyMapData galaxy, GalaxyMapLayerData layer) + void RenderLinks() { Color[] pixels = new Color[_width*_width]; - Func indexToUV = i => new Vector2(i % _width / (float) _width, i / _width / (float) _width); - Func uvToIndex = v => (int) (v.y * _width) * _width + (int) (v.x * _width); for (var i = 0; i < pixels.Length; i++) { - Vector2 uv = indexToUV(i); - pixels[i] = layer.Evaluate(uv, galaxy) * Color.white; - if (_drawCulture) - pixels[i] += Color.HSVToRGB( - (float) galaxy.CultureDensities.IndexOf(galaxy.CultureDensities.OrderByDescending(m => m.Evaluate(uv, galaxy)).First()) / - galaxy.CultureDensities.Count, - 1, - .5f); + pixels[i] = Color.clear; } - if(_drawStars) - foreach (var s in _stars) - { - pixels[uvToIndex(s)] = Color.white; - pixels[uvToIndex(s + Vector2.up / _width)] += Color.white / 2; - pixels[uvToIndex(s - Vector2.up / _width)] += Color.white / 2; - pixels[uvToIndex(s + Vector2.right / _width)] += Color.white / 2; - pixels[uvToIndex(s - Vector2.right / _width)] += Color.white / 2; - } - if(_drawLinks) - foreach (var l in _starLinks) - { - var pixelCount = Mathf.Max((int) (Mathf.Abs((float) (l.point1.x - l.point2.x)) * _width), (int) (Mathf.Abs((float) (l.point1.y - l.point2.y)) * _width)); - //Debug.Log($"Marching across {pixelCount} pixels!"); - for(int i=0;i NameDatabase; } [Serializable] @@ -28,7 +27,7 @@ public class GalaxyMapData [HideInInspector] public GalaxyMapLayerData StarDensity; [HideInInspector] - public List CultureDensities = new List(); + public Dictionary ResourceDensities = new Dictionary(); //[HideInInspector] public List Stars = new List(); } @@ -77,8 +76,6 @@ public class StarData { public Vector2 Position; public List Links = new List(); - public string NameSource; - public List Names = new List(); } public static class NoiseFbm @@ -121,7 +118,7 @@ public class GalaxyMapLayerData float angle = pow(length(offset)*2,galaxy.TwistPower) * galaxy.Twist; float2 twist = float2(offset.x*cos(angle) - offset.y*sin(angle), offset.x*sin(angle) + offset.y*cos(angle)); float atan = atan2(twist.y,twist.x); - float spokes = sin(atan*galaxy.Arms) * SpokeScale + SpokeOffset; + float spokes = (sin(atan*galaxy.Arms) + SpokeOffset) * SpokeScale; float noise = fBm(uv + float2(NoisePosition), NoiseOctaves, NoiseFrequency, NoiseOffset, NoiseAmplitude, NoiseLacunarity, NoiseGain); float shape = lerp(spokes - EdgeReduction * length(offset), 1, pow(circle + CoreBoostOffset, CoreBoostPower) * CoreBoost); float gal = max(shape - noise * saturate(circle), 0); @@ -254,7 +251,8 @@ public static class VoronoiLinkExtensions int lastCount = members.Count; // For each member, add all vertices that are connected to it via a line but are not already a member foreach (Vertex2 m in members.ToArray()) - members.AddRange(data.Where(l => l.point1 == m).Select(l => l.point2).Concat(data.Where(l => l.point2 == m).Select(l => l.point1)) + members.AddRange(data.Where(l => l.point1 == m).Select(l => l.point2) + .Concat(data.Where(l => l.point2 == m).Select(l => l.point1)) .Where(n => !members.Contains(n))); // If we have stopped finding neighbors, stop traversing if (members.Count == lastCount) diff --git a/Assets/Shaders/GalaxyMap.shader b/Assets/Shaders/GalaxyMap.shader index 4324eb577..69e2ad27f 100644 --- a/Assets/Shaders/GalaxyMap.shader +++ b/Assets/Shaders/GalaxyMap.shader @@ -20,10 +20,10 @@ NoiseGain("NoiseGain", Float) = 1 NoiseLacunarity("NoiseLacunarity", Float) = 2 NoiseFrequency("NoiseFrequency", Float) = 1 - GlowOffset("GlowOffset", Float) = 1 - GlowAmount("GlowAmount", Float) = 1 - GlowPower("GlowPower", Float) = 1 - StarBoost("StarBoost", Float) = 1 + GlowOffset("GlowOffset", Float) = 0 + GlowAmount("GlowAmount", Float) = 0 + GlowPower("GlowPower", Float) = 0 + StarBoost("StarBoost", Float) = 0 // required for UI.Mask _StencilComp ("Stencil Comparison", Float) = 8 @@ -127,13 +127,13 @@ float angle = pow(length(offset)*2,TwistPower) * Twist; float2 twist = float2(offset.x*cos(angle) - offset.y*sin(angle), offset.x*sin(angle) + offset.y*cos(angle)); float atan = atan2(twist.y,twist.x); - float spokes = sin(atan*Arms) * SpokeScale + SpokeOffset; + float spokes = (sin(atan*Arms) + SpokeOffset) * SpokeScale; float noise = fBm(i.uv + NoisePosition.xx, 7); float shape = lerp(spokes - EdgeReduction * length(offset), 1, pow(circle + CoreBoostOffset, CoreBoostPower) * CoreBoost); float gal = max(shape - noise * clamp(circle,0,1), 0); float glow = (pow(circle,GlowPower) + GlowOffset) * GlowAmount; float stars = tex2D(_MainTex, i.uv2) * clamp(shape*StarBoost, 0, 1); - fixed4 col = fixed4(gal*_CloudColor.rgb + glow*_GlowColor.rgb + stars.xxx,1); + fixed4 col = fixed4(gal*_CloudColor.rgb + glow*_GlowColor.rgb + stars.xxx, 1); return col; } ENDCG diff --git a/README.md b/README.md index 59e8b196b..f75de904f 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # Aetheria-Economy -Economy Simulation for Aetheria - +This repository is the home of Aetheria, which could be described as a sci-fi hybrid ARPG/RTS MMO about a group of corporations colonizing a hostile alien galaxy, with a satirical narrative critiquing late-stage capitalism. +The ARPG game design document is available [here](https://docs.google.com/document/d/1iULu1WsbuQoUM3c87XkGseb1P-8R5xlruoiyg03TsSE/edit?usp=sharing), while the RTS gameplay is documented [here](https://docs.google.com/document/d/1U3uGFqQboAiFJ_Y-nUOGpyixbXUHRbc5DiCuB59GM4w/edit?usp=sharing). The goal is to essentially create two games which both take place in the same persistent universe, allowing players with vastly different preferences to struggle together for the survival of mankind. ## Architecture