Porting Galaxy Editor
Ported the galaxy editor code from the old Aetheria
This commit is contained in:
parent
83c6246aa8
commit
ae98448942
17 changed files with 620 additions and 9 deletions
|
|
@ -16,6 +16,7 @@
|
|||
<e p="DatabaseItems.cs" t="Include" />
|
||||
<e p="Editor" t="Include">
|
||||
<e p="DatabaseEditor.cs" t="Include" />
|
||||
<e p="GalaxyEditor.cs" t="Include" />
|
||||
</e>
|
||||
<e p="Extensions.cs" t="Include" />
|
||||
<e p="Galaxy.cs" t="Include" />
|
||||
|
|
@ -26,6 +27,7 @@
|
|||
<e p="Icons.cs" t="Include" />
|
||||
<e p="InitialSettings.cs" t="Include" />
|
||||
<e p="ItemInstance.cs" t="Include" />
|
||||
<e p="MarkovNameGenerator.cs" t="Include" />
|
||||
<e p="NIH" t="Include">
|
||||
<e p="GPU Noise" t="Include">
|
||||
<e p="ClassicNoise2D.cginc" t="Include" />
|
||||
|
|
|
|||
|
|
@ -61,6 +61,7 @@
|
|||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Assets\Scripts\Editor\DatabaseEditor.cs" />
|
||||
<Compile Include="Assets\Scripts\Editor\GalaxyEditor.cs" />
|
||||
<Compile Include="Assets\Scripts\NIH\NaughtyAttributes\Scripts\Editor\Attributes\BaseAttribute.cs" />
|
||||
<Compile Include="Assets\Scripts\NIH\NaughtyAttributes\Scripts\Editor\Attributes\FieldDrawerAttribute.cs" />
|
||||
<Compile Include="Assets\Scripts\NIH\NaughtyAttributes\Scripts\Editor\Attributes\IAttribute.cs" />
|
||||
|
|
@ -407,6 +408,9 @@
|
|||
<Reference Include="JetBrains.Rider.Unity.Editor.Plugin.Repacked">
|
||||
<HintPath>C:/Users/rwvens/Documents/GitHub/Aetheria-Economy/Assets/Plugins/Editor/JetBrains/JetBrains.Rider.Unity.Editor.Plugin.Repacked.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.SqlServer.Types">
|
||||
<HintPath>C:/Users/rwvens/Documents/GitHub/Aetheria-Economy/Assets/Plugins/Microsoft.SqlServer.Types.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="mscorlib">
|
||||
<HintPath>C:/Program Files/Unity/Hub/Editor/2018.4.17f1/Editor/Data/MonoBleedingEdge/lib/mono/4.7.1-api/mscorlib.dll</HintPath>
|
||||
</Reference>
|
||||
|
|
|
|||
|
|
@ -72,6 +72,7 @@
|
|||
<Compile Include="Assets\Scripts\Icons.cs" />
|
||||
<Compile Include="Assets\Scripts\InitialSettings.cs" />
|
||||
<Compile Include="Assets\Scripts\ItemInstance.cs" />
|
||||
<Compile Include="Assets\Scripts\MarkovNameGenerator.cs" />
|
||||
<Compile Include="Assets\Scripts\NIH\LinqFaster\Aggregate.cs" />
|
||||
<Compile Include="Assets\Scripts\NIH\LinqFaster\AnyAll.cs" />
|
||||
<Compile Include="Assets\Scripts\NIH\LinqFaster\Average.cs" />
|
||||
|
|
@ -835,6 +836,9 @@
|
|||
<Reference Include="Google.Protobuf">
|
||||
<HintPath>C:/Users/rwvens/Documents/GitHub/Aetheria-Economy/Assets/Plugins/Google.Protobuf/lib/net45/Google.Protobuf.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.SqlServer.Types">
|
||||
<HintPath>C:/Users/rwvens/Documents/GitHub/Aetheria-Economy/Assets/Plugins/Microsoft.SqlServer.Types.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="mscorlib">
|
||||
<HintPath>C:/Program Files/Unity/Hub/Editor/2018.4.17f1/Editor/Data/MonoBleedingEdge/lib/mono/4.7.1-api/mscorlib.dll</HintPath>
|
||||
</Reference>
|
||||
|
|
|
|||
BIN
Assets/Plugins/Microsoft.SqlServer.Types.dll
(Stored with Git LFS)
Normal file
BIN
Assets/Plugins/Microsoft.SqlServer.Types.dll
(Stored with Git LFS)
Normal file
Binary file not shown.
33
Assets/Plugins/Microsoft.SqlServer.Types.dll.meta
Normal file
33
Assets/Plugins/Microsoft.SqlServer.Types.dll.meta
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 0c9892977144f954eaeb53285dbbb60e
|
||||
PluginImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
iconMap: {}
|
||||
executionOrder: {}
|
||||
defineConstraints: []
|
||||
isPreloaded: 0
|
||||
isOverridable: 0
|
||||
isExplicitlyReferenced: 0
|
||||
validateReferences: 1
|
||||
platformData:
|
||||
- first:
|
||||
Any:
|
||||
second:
|
||||
enabled: 1
|
||||
settings: {}
|
||||
- first:
|
||||
Editor: Editor
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
DefaultValueInitialized: true
|
||||
- first:
|
||||
Windows Store Apps: WindowsStoreApps
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
CPU: AnyCPU
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
BIN
Assets/Resources/Test Galaxy.asset
(Stored with Git LFS)
Normal file
BIN
Assets/Resources/Test Galaxy.asset
(Stored with Git LFS)
Normal file
Binary file not shown.
8
Assets/Resources/Test Galaxy.asset.meta
Normal file
8
Assets/Resources/Test Galaxy.asset.meta
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 931e677be56754f4f9d3d0817e2d38df
|
||||
NativeFormatImporter:
|
||||
externalObjects: {}
|
||||
mainObjectFileID: 11400000
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -122,7 +122,6 @@ GameObject:
|
|||
m_Component:
|
||||
- component: {fileID: 408552541}
|
||||
- component: {fileID: 408552540}
|
||||
- component: {fileID: 408552539}
|
||||
- component: {fileID: 408552538}
|
||||
m_Layer: 0
|
||||
m_Name: Gravity Camera
|
||||
|
|
@ -146,14 +145,6 @@ MonoBehaviour:
|
|||
BackgroundMaterial: {fileID: 2100000, guid: 90cead50364300d47bb35194fb52c117, type: 2}
|
||||
GravityTexture: {fileID: 0}
|
||||
GravityRenderer: {fileID: 1956833085}
|
||||
--- !u!81 &408552539
|
||||
AudioListener:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 408552537}
|
||||
m_Enabled: 1
|
||||
--- !u!20 &408552540
|
||||
Camera:
|
||||
m_ObjectHideFlags: 0
|
||||
|
|
|
|||
400
Assets/Scripts/Editor/GalaxyEditor.cs
Normal file
400
Assets/Scripts/Editor/GalaxyEditor.cs
Normal file
|
|
@ -0,0 +1,400 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.Remoting.Messaging;
|
||||
using MIConvexHull;
|
||||
using UniRx;
|
||||
using UnityEngine;
|
||||
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<string,bool> _expandRegion = new Dictionary<string, bool>();
|
||||
private Dictionary<string,bool> _expandSubregion = new Dictionary<string, bool>();
|
||||
private NameData _names = new NameData();
|
||||
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<Vector2> _stars = new Vector2[0];
|
||||
private bool _drawStars;
|
||||
private bool _drawCulture;
|
||||
private bool _drawLinks;
|
||||
private VoronoiMesh< Vertex2, Cell2, VoronoiEdge<Vertex2, Cell2>> _voronoiMesh;
|
||||
private List<VoronoiLink> _starLinks = new List<VoronoiLink>();
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
var galaxy = target as Galaxy;
|
||||
|
||||
if (_currentLayer == null)
|
||||
_currentLayer = galaxy.MapData.StarDensity;
|
||||
|
||||
if (Screen.width != _width)
|
||||
{
|
||||
_width = Screen.width;
|
||||
_preview = new Texture2D(_width,_width,TextureFormat.ARGB32,false);
|
||||
Render(galaxy.MapData, _currentLayer);
|
||||
}
|
||||
|
||||
GUILayout.Label("Preview", EditorStyles.boldLabel);
|
||||
EditorGUI.DrawPreviewTexture(EditorGUILayout.GetControlRect(false, _width), _preview);
|
||||
EditorGUI.BeginChangeCheck();
|
||||
_drawStars = EditorGUILayout.ToggleLeft($"Display {_stars.Count()} Stars", _drawStars);
|
||||
_drawCulture = EditorGUILayout.ToggleLeft("Display Cultures", _drawCulture);
|
||||
_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)
|
||||
{
|
||||
EditorGUI.indentLevel++;
|
||||
for (var i = 0; i < galaxy.MapData.CultureDensities.Count; i++)
|
||||
{
|
||||
var cultureMap = galaxy.MapData.CultureDensities[i];
|
||||
var data = galaxy.NameDatabase[i];
|
||||
if (GUILayout.Button("Inspect " + data.Name))
|
||||
{
|
||||
_currentLayerName = data.Name;
|
||||
_currentLayer = cultureMap;
|
||||
Render(galaxy.MapData, _currentLayer);
|
||||
}
|
||||
}
|
||||
EditorGUI.indentLevel--;
|
||||
}
|
||||
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<string, List<string>>();
|
||||
_names.Names["World"]["Miscellaneous"] = new List<string>();
|
||||
}
|
||||
foreach (var region in _names.Names.Keys.Where(s=>s!="World").ToArray())
|
||||
{
|
||||
if (!_names.Names[region].ContainsKey("Miscellaneous"))
|
||||
_names.Names[region]["Miscellaneous"] = new List<string>();
|
||||
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<ContinentData>();
|
||||
data.AddRange(_names.Names.Select(kvp => new ContinentData{Name = kvp.Key,Regions = new List<RegionData>()}));
|
||||
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();
|
||||
|
||||
EditorGUILayout.BeginVertical("Box");
|
||||
EditorGUI.indentLevel++;
|
||||
_showStarEditor = EditorGUILayout.Foldout(_showStarEditor, "Star Tools");
|
||||
if (_showStarEditor)
|
||||
{
|
||||
_hilbertOrder = EditorGUILayout.IntField("Hilbert Order", _hilbertOrder);
|
||||
_starCount = EditorGUILayout.IntField("Star Count", _starCount);
|
||||
//_hilbertIndex = (ulong) EditorGUILayout.IntField("Hilbert Index", (int) _hilbertIndex);
|
||||
if (GUILayout.Button("Evaluate Hilbert Curve"))
|
||||
{
|
||||
var points = EvaluateHilbert(_hilbertOrder,false);
|
||||
Debug.Log($"Hilbert curve has {points.Count()} points, resolution {Mathf.RoundToInt(points.Max(p=>p.x))+1}");
|
||||
}
|
||||
if (GUILayout.Button("Generate Stars"))
|
||||
{
|
||||
var points = EvaluateHilbert(_hilbertOrder).ToArray();
|
||||
var stars = new List<Vector2>();
|
||||
int bail = 0;
|
||||
while (stars.Count < _starCount && bail < 10)
|
||||
{
|
||||
var accum = 0f;
|
||||
foreach (var hp in points.Select(p=>p+UnityEngine.Random.insideUnitCircle * ((points[0]-points[1]).magnitude/2)))
|
||||
{
|
||||
var den = galaxy.MapData.StarDensity.Evaluate(hp, galaxy.MapData);
|
||||
if(!float.IsNaN(den))
|
||||
accum += den * UnityEngine.Random.value;
|
||||
// else
|
||||
// Debug.Log($"Density at ({hp.x},{hp.y}) is NaN");
|
||||
if (accum > 1)
|
||||
{
|
||||
stars.Add(hp);
|
||||
accum = 0;
|
||||
}
|
||||
//Debug.Log($"Accumulator: {accum}");
|
||||
}
|
||||
bail++;
|
||||
}
|
||||
Debug.Log($"Generated {stars.Count} stars.");
|
||||
_stars = stars;
|
||||
}
|
||||
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"))
|
||||
{
|
||||
_voronoiMesh = VoronoiMesh<Vertex2, Cell2, VoronoiEdge<Vertex2, Cell2>>.Create(_stars.Select(s=>new Vertex2(s.x,s.y)).ToList());
|
||||
_starLinks.Clear();
|
||||
// Each cell in this collection represents one of the triangle faces of the Delaunay Triangulation
|
||||
foreach (var cell in _voronoiMesh.Vertices)
|
||||
{
|
||||
var links = new[] {new VoronoiLink(cell.Vertices[0], cell.Vertices[1]),
|
||||
new VoronoiLink(cell.Vertices[0], cell.Vertices[2]),
|
||||
new VoronoiLink(cell.Vertices[2], cell.Vertices[1])};
|
||||
|
||||
_starLinks.AddRange(links.Where(l=>!_starLinks.ContainsLine(l) && l.Length < _maxLinkLength));
|
||||
}
|
||||
}
|
||||
if (_starLinks.Any())
|
||||
{
|
||||
_linkFilter = EditorGUILayout.FloatField("Link Filter Percentage", _linkFilter);
|
||||
if (GUILayout.Button("Filter Star Links"))
|
||||
{
|
||||
var bail = 0;
|
||||
var count = _starLinks.Count * Mathf.Clamp01(_linkFilter);
|
||||
var deadLinks = new List<VoronoiLink>();
|
||||
for (int i = 0; i < count && bail < count*10; bail++)
|
||||
{
|
||||
var link = _starLinks.ElementAt(UnityEngine.Random.Range(0, _starLinks.Count));
|
||||
|
||||
if (deadLinks.Contains(link)) continue;
|
||||
|
||||
var mapMinusLink = _starLinks.Where(l => !l.Equals(link)).ToArray();
|
||||
if (!mapMinusLink.ConnectedRegion(link.point1).Contains(link.point2))
|
||||
deadLinks.Add(link);
|
||||
else
|
||||
{
|
||||
_starLinks.Remove(link);
|
||||
i++;
|
||||
}
|
||||
//if (_starLinks.Count(sl => sl.ContainsPoint(link.point1)) > 1 && _starLinks.Count(sl => sl.ContainsPoint(link.point2)) > 1)
|
||||
}
|
||||
}
|
||||
if (GUILayout.Button("Apply Star Links"))
|
||||
{
|
||||
foreach (var star in galaxy.MapData.Stars)
|
||||
{
|
||||
star.Links.Clear();
|
||||
star.Links.AddRange(_starLinks.Where(sl => (sl.point1.ToVector2() - star.Position).sqrMagnitude < float.Epsilon)
|
||||
.Select(sl => galaxy.MapData.Stars.IndexOf(galaxy.MapData.Stars.First(s => (sl.point2.ToVector2() - s.Position).sqrMagnitude < float.Epsilon))));
|
||||
star.Links.AddRange(_starLinks.Where(sl => (sl.point2.ToVector2() - star.Position).sqrMagnitude < float.Epsilon)
|
||||
.Select(sl => galaxy.MapData.Stars.IndexOf(galaxy.MapData.Stars.First(s => (sl.point1.ToVector2() - s.Position).sqrMagnitude < float.Epsilon))));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
EditorGUI.indentLevel--;
|
||||
EditorGUILayout.EndVertical();
|
||||
|
||||
|
||||
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<Vector2> EvaluateHilbert(int order, bool normalized = true)
|
||||
{
|
||||
var points = new List<Vector2>();
|
||||
uint x = 0, y = 1;
|
||||
ulong i = 1;
|
||||
uint max = 0;
|
||||
while (x != 0 || y != 0)
|
||||
{
|
||||
Microsoft.SqlServer.Types.SpaceFillingCurve.ReverseHilbert(order, i, out x, out y);
|
||||
points.Add(new Vector2(x, y));
|
||||
if (x > max)
|
||||
max = x;
|
||||
i++;
|
||||
}
|
||||
return normalized ? points.Select(p => p / (max + 1)) : points;
|
||||
}
|
||||
|
||||
void Inspect(GalaxyMapLayerData layer)
|
||||
{
|
||||
layer.EdgeReduction = EditorGUILayout.FloatField("Edge Reduction", layer.EdgeReduction);
|
||||
layer.CoreBoost = EditorGUILayout.FloatField("Core Boost", layer.CoreBoost);
|
||||
layer.CoreBoostOffset = EditorGUILayout.FloatField("Core Boost Offset", layer.CoreBoostOffset);
|
||||
layer.CoreBoostPower = EditorGUILayout.FloatField("Core Boost Power", layer.CoreBoostPower);
|
||||
layer.NoiseOffset = EditorGUILayout.FloatField("Noise Offset", layer.NoiseOffset);
|
||||
layer.NoiseAmplitude = EditorGUILayout.FloatField("Noise Amplitude", layer.NoiseAmplitude);
|
||||
layer.NoiseGain = EditorGUILayout.FloatField("Noise Gain", layer.NoiseGain);
|
||||
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);
|
||||
}
|
||||
|
||||
void Render(GalaxyMapData galaxy, GalaxyMapLayerData layer)
|
||||
{
|
||||
Color[] pixels = new Color[_width*_width];
|
||||
Func<int, Vector2> indexToUV = i => new Vector2(i % _width / (float) _width, i / _width / (float) _width);
|
||||
Func<Vector2, int> 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);
|
||||
}
|
||||
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<pixelCount;i++)
|
||||
pixels[uvToIndex(Vector2.Lerp(l.point1.ToVector2(),l.point2.ToVector2(),(float)i/pixelCount))] += Color.white / 2;
|
||||
}
|
||||
_preview.SetPixels(pixels);
|
||||
_preview.Apply();
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Editor/GalaxyEditor.cs.meta
Normal file
11
Assets/Scripts/Editor/GalaxyEditor.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 3122b5a17f0ed2f4a90bb61f6766340a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
126
Assets/Scripts/MarkovNameGenerator.cs
Normal file
126
Assets/Scripts/MarkovNameGenerator.cs
Normal file
|
|
@ -0,0 +1,126 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
//Generates random names based on the statistical weight of letter sequences
|
||||
//in a collection of sample names
|
||||
public class MarkovNameGenerator
|
||||
{
|
||||
//constructor
|
||||
public MarkovNameGenerator(IEnumerable<string> sampleNames, int order, int minLength, int maxLength)
|
||||
{
|
||||
//fix parameter values
|
||||
if (order < 1)
|
||||
order = 1;
|
||||
if (minLength < 1)
|
||||
minLength = 1;
|
||||
|
||||
_order = order;
|
||||
_minLength = minLength;
|
||||
_maxLength = maxLength;
|
||||
|
||||
//split comma delimited lines
|
||||
foreach (string line in sampleNames)
|
||||
{
|
||||
string[] tokens = line.Split(' ','-','\'','(',')');
|
||||
foreach (string word in tokens)
|
||||
{
|
||||
string upper = word.Trim().ToUpper();
|
||||
if (upper.Length < order + 1)
|
||||
continue;
|
||||
_samples.Add(upper + '|'); // Add end character
|
||||
}
|
||||
}
|
||||
|
||||
//Build chains
|
||||
foreach (string word in _samples)
|
||||
{
|
||||
for (int letter = 0; letter < word.Length - order; letter++)
|
||||
{
|
||||
string token = word.Substring(letter, order);
|
||||
List<char> entry = null;
|
||||
if (_chains.ContainsKey(token))
|
||||
entry = _chains[token];
|
||||
else
|
||||
{
|
||||
entry = new List<char>();
|
||||
_chains[token] = entry;
|
||||
}
|
||||
entry.Add(word[letter + order]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Get the next random name
|
||||
public string NextName
|
||||
{
|
||||
get
|
||||
{
|
||||
|
||||
string s = "";
|
||||
do
|
||||
{
|
||||
int n = UnityEngine.Random.Range(0,_samples.Count);
|
||||
//int nameLength = _samples[n].Length;
|
||||
//s = _samples[n].Substring(UnityEngine.Random.Range(0, _samples[n].Length - _order), _order);//get a random token somewhere in middle of sample word
|
||||
s = _samples[n].Substring(0, _order);//get a random token at the start of a sample word
|
||||
while (true)//(s.Length < nameLength)
|
||||
{
|
||||
string token = s.Substring(s.Length - _order, _order);
|
||||
char c = GetLetter(token);
|
||||
if (c != '?' && c != '|')
|
||||
s += c;//GetLetter(token);
|
||||
else
|
||||
break;
|
||||
}
|
||||
|
||||
// if (s.Contains(" "))
|
||||
// {
|
||||
// string[] tokens = s.Split(' ');
|
||||
// s = "";
|
||||
// for (int t = 0; t < tokens.Length; t++)
|
||||
// {
|
||||
// if (tokens[t] == "")
|
||||
// continue;
|
||||
// if (tokens[t].Length == 1)
|
||||
// tokens[t] = tokens[t].ToUpper();
|
||||
// else
|
||||
// tokens[t] = tokens[t].Substring(0, 1) + tokens[t].Substring(1).ToLower();
|
||||
// if (s != "")
|
||||
// s += " ";
|
||||
// s += tokens[t];
|
||||
// }
|
||||
// }
|
||||
// else
|
||||
s = s.Substring(0, 1) + s.Substring(1).ToLower();
|
||||
}
|
||||
while (_used.Contains(s) || s.Length < _minLength || s.Length > _maxLength);
|
||||
_used.Add(s);
|
||||
return s;
|
||||
}
|
||||
}
|
||||
|
||||
//Reset the used names
|
||||
public void Reset()
|
||||
{
|
||||
_used.Clear();
|
||||
}
|
||||
|
||||
//private members
|
||||
private Dictionary<string, List<char>> _chains = new Dictionary<string, List<char>>();
|
||||
private List<string> _samples = new List<string>();
|
||||
private static List<string> _used = new List<string>();
|
||||
private int _order;
|
||||
private int _minLength;
|
||||
private int _maxLength;
|
||||
|
||||
//Get a random letter from the chain
|
||||
private char GetLetter(string token)
|
||||
{
|
||||
if (!_chains.ContainsKey(token))
|
||||
return '?';
|
||||
List<char> letters = _chains[token];
|
||||
int n = UnityEngine.Random.Range(0,letters.Count);
|
||||
return letters[n];
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/MarkovNameGenerator.cs.meta
Normal file
11
Assets/Scripts/MarkovNameGenerator.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 33c3b119ccc9de447b8c8318b6f0d1af
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -321,6 +321,9 @@
|
|||
<Reference Include="JetBrains.Rider.Unity.Editor.Plugin.Repacked">
|
||||
<HintPath>C:/Users/rwvens/Documents/GitHub/Aetheria-Economy/Assets/Plugins/Editor/JetBrains/JetBrains.Rider.Unity.Editor.Plugin.Repacked.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.SqlServer.Types">
|
||||
<HintPath>C:/Users/rwvens/Documents/GitHub/Aetheria-Economy/Assets/Plugins/Microsoft.SqlServer.Types.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="mscorlib">
|
||||
<HintPath>C:/Program Files/Unity/Hub/Editor/2018.4.17f1/Editor/Data/MonoBleedingEdge/lib/mono/4.7.1-api/mscorlib.dll</HintPath>
|
||||
</Reference>
|
||||
|
|
|
|||
|
|
@ -327,6 +327,9 @@
|
|||
<Reference Include="JetBrains.Rider.Unity.Editor.Plugin.Repacked">
|
||||
<HintPath>C:/Users/rwvens/Documents/GitHub/Aetheria-Economy/Assets/Plugins/Editor/JetBrains/JetBrains.Rider.Unity.Editor.Plugin.Repacked.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.SqlServer.Types">
|
||||
<HintPath>C:/Users/rwvens/Documents/GitHub/Aetheria-Economy/Assets/Plugins/Microsoft.SqlServer.Types.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="mscorlib">
|
||||
<HintPath>C:/Program Files/Unity/Hub/Editor/2018.4.17f1/Editor/Data/MonoBleedingEdge/lib/mono/4.7.1-api/mscorlib.dll</HintPath>
|
||||
</Reference>
|
||||
|
|
|
|||
|
|
@ -318,6 +318,9 @@
|
|||
<Reference Include="JetBrains.Rider.Unity.Editor.Plugin.Repacked">
|
||||
<HintPath>C:/Users/rwvens/Documents/GitHub/Aetheria-Economy/Assets/Plugins/Editor/JetBrains/JetBrains.Rider.Unity.Editor.Plugin.Repacked.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.SqlServer.Types">
|
||||
<HintPath>C:/Users/rwvens/Documents/GitHub/Aetheria-Economy/Assets/Plugins/Microsoft.SqlServer.Types.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="mscorlib">
|
||||
<HintPath>C:/Program Files/Unity/Hub/Editor/2018.4.17f1/Editor/Data/MonoBleedingEdge/lib/mono/4.7.1-api/mscorlib.dll</HintPath>
|
||||
</Reference>
|
||||
|
|
|
|||
|
|
@ -342,6 +342,9 @@
|
|||
<Reference Include="JetBrains.Rider.Unity.Editor.Plugin.Repacked">
|
||||
<HintPath>C:/Users/rwvens/Documents/GitHub/Aetheria-Economy/Assets/Plugins/Editor/JetBrains/JetBrains.Rider.Unity.Editor.Plugin.Repacked.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.SqlServer.Types">
|
||||
<HintPath>C:/Users/rwvens/Documents/GitHub/Aetheria-Economy/Assets/Plugins/Microsoft.SqlServer.Types.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="mscorlib">
|
||||
<HintPath>C:/Program Files/Unity/Hub/Editor/2018.4.17f1/Editor/Data/MonoBleedingEdge/lib/mono/4.7.1-api/mscorlib.dll</HintPath>
|
||||
</Reference>
|
||||
|
|
|
|||
|
|
@ -411,6 +411,9 @@
|
|||
<Reference Include="JetBrains.Rider.Unity.Editor.Plugin.Repacked">
|
||||
<HintPath>C:/Users/rwvens/Documents/GitHub/Aetheria-Economy/Assets/Plugins/Editor/JetBrains/JetBrains.Rider.Unity.Editor.Plugin.Repacked.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.SqlServer.Types">
|
||||
<HintPath>C:/Users/rwvens/Documents/GitHub/Aetheria-Economy/Assets/Plugins/Microsoft.SqlServer.Types.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="mscorlib">
|
||||
<HintPath>C:/Program Files/Unity/Hub/Editor/2018.4.17f1/Editor/Data/MonoBleedingEdge/lib/mono/4.7.1-api/mscorlib.dll</HintPath>
|
||||
</Reference>
|
||||
|
|
|
|||
Loading…
Reference in a new issue