Asteroid Belts
Sector renderer is now also rendering asteroid belts. All gravity calculations have been moved out of monobehaviors.
This commit is contained in:
parent
d12d7c5c45
commit
a981a46170
76 changed files with 25027 additions and 2016 deletions
|
|
@ -2,7 +2,9 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using Cinemachine;
|
||||
using MessagePack;
|
||||
using UniRx;
|
||||
using UnityEngine;
|
||||
using Unity.Mathematics;
|
||||
using static Unity.Mathematics.math;
|
||||
|
|
@ -10,27 +12,34 @@ using float2 = Unity.Mathematics.float2;
|
|||
|
||||
public class ActionGameManager : MonoBehaviour
|
||||
{
|
||||
public SectorRenderer SectorRenderer;
|
||||
public CinemachineVirtualCamera TopDownCamera;
|
||||
public CinemachineVirtualCamera FollowCamera;
|
||||
|
||||
private DirectoryInfo _filePath;
|
||||
private bool _editMode;
|
||||
private float _time;
|
||||
|
||||
public DatabaseCache Cache { get; private set; }
|
||||
public GameContext Context { get; private set; }
|
||||
public Zone CurrentZone { get; private set; }
|
||||
|
||||
public event EventHandler<ZoneChangeEventArgs> ZoneChanged;
|
||||
public Zone Zone { get; private set; }
|
||||
|
||||
void Start()
|
||||
{
|
||||
var filePath = new DirectoryInfo(Application.dataPath).Parent;
|
||||
ConsoleController.MessageReceiver = this;
|
||||
_filePath = new DirectoryInfo(Application.dataPath).Parent.CreateSubdirectory("GameData");
|
||||
Cache = new DatabaseCache();
|
||||
Cache.Load(filePath.FullName);
|
||||
Cache.Load(_filePath.FullName);
|
||||
Context = new GameContext(Cache, Debug.Log);
|
||||
|
||||
var zoneFile = Path.Combine(filePath.FullName, "Home.msgpack");
|
||||
var zoneFile = Path.Combine(_filePath.FullName, "Home.zone");
|
||||
|
||||
// If the game has already been run, there will be a Home file containing a ZonePack; if not, generate one
|
||||
var zonePack = File.Exists(zoneFile) ?
|
||||
MessagePackSerializer.Deserialize<ZonePack>(File.ReadAllBytes(zoneFile)) :
|
||||
ZoneGenerator.GenerateZone(
|
||||
context: Context,
|
||||
name: "Home",
|
||||
name: Guid.NewGuid().ToString().Substring(0,8),
|
||||
position: float2.zero,
|
||||
mapLayers: Context.MapLayers.Values,
|
||||
resources: Context.Resources,
|
||||
|
|
@ -38,26 +47,33 @@ public class ActionGameManager : MonoBehaviour
|
|||
radius: 1500
|
||||
);
|
||||
|
||||
//var oldZone = CurrentZone;
|
||||
CurrentZone = Context.GetZone(zonePack);
|
||||
//ZoneChanged?.Invoke(this, new ZoneChangeEventArgs(oldZone, CurrentZone));
|
||||
Zone = Context.GetZone(zonePack);
|
||||
SectorRenderer.Context = Context;
|
||||
SectorRenderer.LoadZone(Zone);
|
||||
|
||||
ConsoleController.AddCommand("editmode", _ => ToggleEditMode());
|
||||
// ConsoleController.AddCommand("savezone", args =>
|
||||
// {
|
||||
// if (args.Length > 0)
|
||||
// Zone.Value.Data.Name = args[0];
|
||||
// SaveZone();
|
||||
// });
|
||||
}
|
||||
|
||||
public void ToggleEditMode()
|
||||
{
|
||||
_editMode = !_editMode;
|
||||
FollowCamera.gameObject.SetActive(!_editMode);
|
||||
TopDownCamera.gameObject.SetActive(_editMode);
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
Context.Time = Time.time;
|
||||
if(!_editMode)
|
||||
{
|
||||
_time += Time.deltaTime;
|
||||
Context.Time = Time.time;
|
||||
}
|
||||
Context.Update();
|
||||
}
|
||||
}
|
||||
|
||||
public class ZoneChangeEventArgs : EventArgs
|
||||
{
|
||||
public Zone OldZone { get; set; }
|
||||
public Zone NewZone { get; set; }
|
||||
|
||||
public ZoneChangeEventArgs(Zone oldZone, Zone newZone)
|
||||
{
|
||||
OldZone = oldZone;
|
||||
NewZone = newZone;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,138 +0,0 @@
|
|||
/// <summary>
|
||||
/// Marshals events and data between ConsoleController and uGUI.
|
||||
/// </summary>
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using System.Text;
|
||||
using System.Collections;
|
||||
using System.Linq;
|
||||
using TMPro;
|
||||
using UniRx;
|
||||
|
||||
public class ConsoleView : MonoBehaviour {
|
||||
bool _didShow = false;
|
||||
|
||||
public GameObject ViewContainer; //Container for console view, should be a child of this GameObject
|
||||
public TextMeshProUGUI LogTextArea;
|
||||
public ScrollRect Scroll;
|
||||
|
||||
private string _inputString = "";
|
||||
private string[] _log;
|
||||
public bool AcceptingInput { get; private set; }
|
||||
|
||||
public ConsoleView()
|
||||
{
|
||||
AcceptingInput = false;
|
||||
}
|
||||
|
||||
public bool Visible { get; private set; }
|
||||
|
||||
void Start()
|
||||
{
|
||||
//_console = new ConsoleController();
|
||||
Application.logMessageReceived += (condition, trace, type) => ConsoleController.Instance.AppendLogLine("<color=" + (type == LogType.Error ? "red" : type == LogType.Warning ? "yellow" : "white") + ">" + condition + "</color>");
|
||||
|
||||
SetVisibility(false);
|
||||
|
||||
ConsoleController.Instance.VisibilityChanged += OnVisibilityChanged;
|
||||
ConsoleController.Instance.LogChanged += OnLogChanged;
|
||||
|
||||
UpdateLogStr(ConsoleController.Instance.Log);
|
||||
|
||||
// var sizeFitter = GetComponentInChildren<ContentSizeFitter>().on
|
||||
}
|
||||
|
||||
~ConsoleView() {
|
||||
ConsoleController.Instance.VisibilityChanged -= OnVisibilityChanged;
|
||||
ConsoleController.Instance.LogChanged -= OnLogChanged;
|
||||
}
|
||||
|
||||
void Update() {
|
||||
//Toggle visibility when tilde key pressed
|
||||
if (Input.GetKeyUp("`")) {
|
||||
ToggleVisibility();
|
||||
}
|
||||
|
||||
if (Visible)
|
||||
{
|
||||
string s = Input.inputString;
|
||||
|
||||
if (s.Length > 0)
|
||||
{
|
||||
if (s.Contains("\b"))
|
||||
{
|
||||
if(_inputString.Length>0)
|
||||
_inputString = _inputString.Substring(0, _inputString.Length - 1);
|
||||
}
|
||||
else
|
||||
_inputString += s;
|
||||
DisplayLog();
|
||||
}
|
||||
|
||||
if (Input.GetKeyDown(KeyCode.Return))
|
||||
{
|
||||
if (AcceptingInput && _inputString.Length > 0)
|
||||
{
|
||||
if(_inputString.StartsWith("!") || _inputString.StartsWith("/"))
|
||||
ConsoleController.Instance.RunCommandString(_inputString.Substring(1));
|
||||
else ConsoleController.Instance.RunCommandString($"say \"{_inputString}\"");
|
||||
}
|
||||
AcceptingInput = !AcceptingInput;
|
||||
_inputString = "";
|
||||
DisplayLog();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Example of a console command. Can be on any behavior but always has lowercase name and string array parameter
|
||||
/// </summary>
|
||||
/// <param name="args"></param>
|
||||
void echo(string[] args)
|
||||
{
|
||||
if(args.Length>0)
|
||||
Debug.Log(args.Aggregate((a,b) => a + " " + b));
|
||||
}
|
||||
|
||||
void ToggleVisibility() {
|
||||
SetVisibility(!ViewContainer.activeSelf);
|
||||
}
|
||||
|
||||
void SetVisibility(bool visible) {
|
||||
ViewContainer.SetActive(visible);
|
||||
Visible = visible;
|
||||
if(visible)
|
||||
Cursor.lockState = CursorLockMode.None;
|
||||
}
|
||||
|
||||
void OnVisibilityChanged(bool visible) {
|
||||
SetVisibility(visible);
|
||||
}
|
||||
|
||||
void OnLogChanged(string[] newLog) {
|
||||
UpdateLogStr(newLog);
|
||||
}
|
||||
|
||||
void UpdateLogStr(string[] newLog)
|
||||
{
|
||||
_log = newLog;
|
||||
DisplayLog();
|
||||
}
|
||||
|
||||
void DisplayLog()
|
||||
{
|
||||
if (_log == null)
|
||||
{
|
||||
LogTextArea.text = "";
|
||||
}
|
||||
else
|
||||
{
|
||||
LogTextArea.text = string.Join("\n", _log);
|
||||
if (AcceptingInput)
|
||||
LogTextArea.text += "\n\n> " + _inputString;
|
||||
}
|
||||
|
||||
Observable.NextFrame().Subscribe(_ => Scroll.verticalNormalizedPosition = 0);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -17,8 +17,9 @@ public class DatabaseInspector : EditorWindow
|
|||
public static DatabaseCache DatabaseCache;
|
||||
public DatabaseEntry entry;
|
||||
|
||||
// Singleton to avoid multiple instances of window.
|
||||
// Singleton to avoid multiple instances of window.
|
||||
private static DatabaseInspector _instance;
|
||||
public static DatabaseInspector Instance => _instance ?? GetWindow<DatabaseInspector>();
|
||||
|
||||
private DatabaseListView _list;
|
||||
private GUIStyle _labelStyle;
|
||||
|
|
@ -36,32 +37,12 @@ public class DatabaseInspector : EditorWindow
|
|||
|
||||
public Color LabelColor => EditorGUIUtility.isProSkin ? Color.white : Color.black;
|
||||
|
||||
// Set instance on reloading the window, else it gets lost after script reload (due to PlayMode changes, ...).
|
||||
public DatabaseInspector()
|
||||
{
|
||||
_instance = this;
|
||||
}
|
||||
|
||||
public static DatabaseInspector ShowWindow()
|
||||
{
|
||||
if (_instance == null)
|
||||
{
|
||||
// "Get existing open window or if none, make a new one:" says documentation.
|
||||
// But if called after script reloads a second instance will be opened! => Custom singleton required.
|
||||
DatabaseInspector window = GetWindow<DatabaseInspector>();
|
||||
window.titleContent = new GUIContent("DB Inspector");
|
||||
_instance = window;
|
||||
window.Show();
|
||||
}
|
||||
else
|
||||
_instance.Focus();
|
||||
|
||||
return _instance;
|
||||
}
|
||||
|
||||
void OnEnable()
|
||||
{
|
||||
_list = DatabaseListView.ShowWindow();
|
||||
_instance = this;
|
||||
_list = DatabaseListView.Instance;
|
||||
_list.Show();
|
||||
DatabaseCache.OnDataUpdateLocal += _ => Repaint();
|
||||
DatabaseCache.OnDataUpdateRemote += _ => EditorDispatcher.Dispatch(Repaint);
|
||||
wantsMouseMove = true;
|
||||
|
|
|
|||
|
|
@ -14,6 +14,14 @@ public class DatabaseListView : EditorWindow
|
|||
{
|
||||
// Singleton to avoid multiple instances of window.
|
||||
private static DatabaseListView _instance;
|
||||
public static DatabaseListView Instance => _instance ?? (DatabaseListView)GetWindow<DatabaseListView>();
|
||||
[MenuItem("Window/Aetheria Database Tools")]
|
||||
static void Init() => Instance.Show();
|
||||
private void Awake()
|
||||
{
|
||||
_instance = this;
|
||||
}
|
||||
|
||||
public Guid SelectedItem;
|
||||
public GUIStyle SelectedStyle;
|
||||
|
||||
|
|
@ -43,39 +51,9 @@ public class DatabaseListView : EditorWindow
|
|||
|
||||
public Color LabelColor => EditorGUIUtility.isProSkin ? Color.white : Color.black;
|
||||
|
||||
// Set instance on reloading the window, else it gets lost after script reload (due to PlayMode changes, ...).
|
||||
public DatabaseListView()
|
||||
{
|
||||
_instance = this;
|
||||
}
|
||||
|
||||
public static DatabaseListView ShowWindow()
|
||||
{
|
||||
if (_instance == null)
|
||||
{
|
||||
// "Get existing open window or if none, make a new one:" says documentation.
|
||||
// But if called after script reloads a second instance will be opened! => Custom singleton required.
|
||||
DatabaseListView window = GetWindow<DatabaseListView>();
|
||||
window.titleContent = new GUIContent("DB List");
|
||||
_instance = window;
|
||||
_instance.InitStyles();
|
||||
window.Show();
|
||||
}
|
||||
else
|
||||
_instance.Focus();
|
||||
|
||||
return _instance;
|
||||
}
|
||||
|
||||
public GUIStyle ListItemStyle =>
|
||||
(_listItemStyle = !_listItemStyle) ? _listStyleEven : _listStyleOdd;
|
||||
|
||||
[MenuItem("Window/Aetheria Database Tools")]
|
||||
static void Init()
|
||||
{
|
||||
ShowWindow();
|
||||
}
|
||||
|
||||
|
||||
void OnEnable()
|
||||
{
|
||||
// Create database cache
|
||||
|
|
@ -114,7 +92,8 @@ public class DatabaseListView : EditorWindow
|
|||
_databaseCache.OnDataDeleteRemote += _ => EditorDispatcher.Dispatch(Repaint);
|
||||
|
||||
DatabaseInspector.DatabaseCache = _databaseCache;
|
||||
_inspector = DatabaseInspector.ShowWindow();
|
||||
_inspector = DatabaseInspector.Instance;
|
||||
_inspector.Show();
|
||||
|
||||
_itemTypes = typeof(ItemData).GetAllChildClasses()
|
||||
.Where(t => t.GetCustomAttribute<InspectableAttribute>() != null).ToArray();
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using MessagePack;
|
||||
using MessagePack.Formatters;
|
||||
using MessagePack.Resolvers;
|
||||
|
|
@ -32,7 +33,11 @@ public class SerializerTestWindow : EditorWindow
|
|||
public void OnGUI()
|
||||
{
|
||||
//var obj = new ShieldData() {ID = Guid.NewGuid(), Name = "Bar" , HeatPerformanceCurve = new []{float4(0,0,0,0), float4(1,1,1,1)}} as DatabaseEntry;
|
||||
var obj = new GalaxyRequestMessage() as Message;
|
||||
//var obj = new GalaxyRequestMessage() as Message;
|
||||
var obj = new Gradient();
|
||||
var times = Enumerable.Range(0, 5).Select(i => (float) i / 4).ToArray();
|
||||
obj.alphaKeys = times.Select(f => new GradientAlphaKey(1, f)).ToArray();
|
||||
obj.colorKeys = times.Select(f => new GradientColorKey(UnityEngine.Random.ColorHSV(), f)).ToArray();
|
||||
// JsonSerializer serializer = new JsonSerializer();
|
||||
// serializer.Converters.Add(new MathJsonConverter());
|
||||
// serializer.Converters.Add(Converter.DateTimeConverter);
|
||||
|
|
|
|||
84
Assets/Scripts/Editor/ZoneEditor.cs
Normal file
84
Assets/Scripts/Editor/ZoneEditor.cs
Normal file
|
|
@ -0,0 +1,84 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using MessagePack;
|
||||
using UnityEditor;
|
||||
using UnityEditor.SceneManagement;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
public class ZoneEditor : EditorWindow
|
||||
{
|
||||
// Singleton to avoid multiple instances of window.
|
||||
private static ZoneEditor _instance;
|
||||
public static ZoneEditor Instance => _instance ?? GetWindow<ZoneEditor>();
|
||||
[MenuItem("Window/Aetheria/Zone Editor")]
|
||||
static void Init() => Instance.Show();
|
||||
|
||||
private SectorRenderer _sectorRenderer;
|
||||
private DirectoryInfo _filePath;
|
||||
private GameContext _context;
|
||||
private DatabaseCache _cache;
|
||||
private Zone _zone;
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
_instance = this;
|
||||
_filePath = new DirectoryInfo(Application.dataPath).Parent.CreateSubdirectory("GameData");
|
||||
|
||||
// Create Game Context
|
||||
_cache = new DatabaseCache();
|
||||
_cache.Load(_filePath.FullName);
|
||||
_context = new GameContext(_cache, Debug.Log);
|
||||
|
||||
// Find Sector Renderer and apply context
|
||||
_sectorRenderer = FindObjectOfType<SectorRenderer>();
|
||||
_sectorRenderer.Context = _context;
|
||||
}
|
||||
|
||||
private void OnGUI()
|
||||
{
|
||||
if (GUILayout.Button("Load Zone"))
|
||||
{
|
||||
GenericMenu menu = new GenericMenu();
|
||||
foreach(var file in _filePath.EnumerateFiles("*.zone"))
|
||||
menu.AddItem(new GUIContent(file.Name), false, () => LoadZone(file));
|
||||
menu.ShowAsContext();
|
||||
}
|
||||
|
||||
if (GUILayout.Button("Clear Zone"))
|
||||
_sectorRenderer.ClearZone();
|
||||
|
||||
if (GUILayout.Button("Save Zone"))
|
||||
SaveZone();
|
||||
|
||||
if (GUILayout.Button("Update Orbits"))
|
||||
{
|
||||
_zone.Update(.01f);
|
||||
//_sectorRenderer.LateUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
// Does the rendering of the map editor in the scene view.
|
||||
private void OnSceneGUI(SceneView sceneView) { }
|
||||
|
||||
void OnFocus()
|
||||
{
|
||||
SceneView.onSceneGUIDelegate -= this.OnSceneGUI; // Just in case
|
||||
SceneView.onSceneGUIDelegate += this.OnSceneGUI;
|
||||
}
|
||||
|
||||
private void LoadZone(FileInfo zoneFile)
|
||||
{
|
||||
var zonePack = MessagePackSerializer.Deserialize<ZonePack>(File.ReadAllBytes(zoneFile.FullName));
|
||||
_zone = new Zone(_context, zonePack);
|
||||
_sectorRenderer.LoadZone(_zone);
|
||||
}
|
||||
|
||||
public void SaveZone()
|
||||
{
|
||||
var dir = Path.Combine(_filePath.FullName, $"{_zone.Data.Name}.zone");
|
||||
File.WriteAllBytes(dir,MessagePackSerializer.Serialize(_zone.Pack()));
|
||||
}
|
||||
}
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 1c1faf0a46b9cf24498cd5ec93c34c71
|
||||
guid: d675657ad7e1e7246b133b7abadaee2f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: b6674829093b8084dae06c4c1a73cbcd
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -0,0 +1,106 @@
|
|||
// Copyright (c) All contributors. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using MessagePack.Formatters;
|
||||
using UniRx;
|
||||
|
||||
#pragma warning disable SA1649 // File name should match first type name
|
||||
|
||||
namespace MessagePack.ReactivePropertyExtension
|
||||
{
|
||||
public class ReactivePropertyFormatter<T> : IMessagePackFormatter<ReactiveProperty<T>>
|
||||
{
|
||||
public void Serialize(ref MessagePackWriter writer, ReactiveProperty<T> value, MessagePackSerializerOptions options)
|
||||
{
|
||||
if (value == null)
|
||||
{
|
||||
writer.WriteNil();
|
||||
}
|
||||
else
|
||||
{
|
||||
options.Resolver.GetFormatterWithVerify<T>().Serialize(ref writer, value.Value, options);
|
||||
}
|
||||
}
|
||||
|
||||
public ReactiveProperty<T> Deserialize(ref MessagePackReader reader, MessagePackSerializerOptions options)
|
||||
{
|
||||
if (reader.TryReadNil())
|
||||
{
|
||||
return null;
|
||||
}
|
||||
else
|
||||
{
|
||||
T v = options.Resolver.GetFormatterWithVerify<T>().Deserialize(ref reader, options);
|
||||
|
||||
return new ReactiveProperty<T>(v);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class ReactiveCollectionFormatter<T> : CollectionFormatterBase<T, ReactiveCollection<T>>
|
||||
{
|
||||
protected override void Add(ReactiveCollection<T> collection, int index, T value, MessagePackSerializerOptions options)
|
||||
{
|
||||
collection.Add(value);
|
||||
}
|
||||
|
||||
protected override ReactiveCollection<T> Create(int count, MessagePackSerializerOptions options)
|
||||
{
|
||||
return new ReactiveCollection<T>();
|
||||
}
|
||||
}
|
||||
|
||||
public class UnitFormatter : IMessagePackFormatter<Unit>
|
||||
{
|
||||
public static readonly UnitFormatter Instance = new UnitFormatter();
|
||||
|
||||
private UnitFormatter()
|
||||
{
|
||||
}
|
||||
|
||||
public void Serialize(ref MessagePackWriter writer, Unit value, MessagePackSerializerOptions options)
|
||||
{
|
||||
writer.WriteNil();
|
||||
}
|
||||
|
||||
public Unit Deserialize(ref MessagePackReader reader, MessagePackSerializerOptions options)
|
||||
{
|
||||
if (reader.TryReadNil())
|
||||
{
|
||||
return Unit.Default;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new InvalidOperationException("Invalid Data type. Code: " + MessagePackCode.ToFormatName(reader.NextCode));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class NullableUnitFormatter : IMessagePackFormatter<Unit?>
|
||||
{
|
||||
public static readonly NullableUnitFormatter Instance = new NullableUnitFormatter();
|
||||
|
||||
private NullableUnitFormatter()
|
||||
{
|
||||
}
|
||||
|
||||
public void Serialize(ref MessagePackWriter writer, Unit? value, MessagePackSerializerOptions options)
|
||||
{
|
||||
writer.WriteNil();
|
||||
}
|
||||
|
||||
public Unit? Deserialize(ref MessagePackReader reader, MessagePackSerializerOptions options)
|
||||
{
|
||||
if (reader.TryReadNil())
|
||||
{
|
||||
return Unit.Default;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new InvalidOperationException("Invalid Data type. Code: " + MessagePackCode.ToFormatName(reader.NextCode));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 2ba66c25dd4bca148a26245df562577b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -0,0 +1,75 @@
|
|||
// Copyright (c) All contributors. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
using MessagePack.Formatters;
|
||||
using UniRx;
|
||||
|
||||
namespace MessagePack.ReactivePropertyExtension
|
||||
{
|
||||
public class ReactivePropertyResolver : IFormatterResolver
|
||||
{
|
||||
public static readonly ReactivePropertyResolver Instance = new ReactivePropertyResolver();
|
||||
|
||||
private ReactivePropertyResolver()
|
||||
{
|
||||
}
|
||||
|
||||
public IMessagePackFormatter<T> GetFormatter<T>()
|
||||
{
|
||||
return FormatterCache<T>.Formatter;
|
||||
}
|
||||
|
||||
private static class FormatterCache<T>
|
||||
{
|
||||
internal static readonly IMessagePackFormatter<T> Formatter;
|
||||
|
||||
static FormatterCache()
|
||||
{
|
||||
Formatter = (IMessagePackFormatter<T>)ReactivePropertyResolverGetFormatterHelper.GetFormatter(typeof(T));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal static class ReactivePropertyResolverGetFormatterHelper
|
||||
{
|
||||
private static readonly Dictionary<Type, Type> FormatterMap = new Dictionary<Type, Type>()
|
||||
{
|
||||
{ typeof(ReactiveProperty<>), typeof(ReactivePropertyFormatter<>) },
|
||||
{ typeof(ReactiveCollection<>), typeof(ReactiveCollectionFormatter<>) },
|
||||
};
|
||||
|
||||
internal static object GetFormatter(Type t)
|
||||
{
|
||||
if (t == typeof(Unit))
|
||||
{
|
||||
return UnitFormatter.Instance;
|
||||
}
|
||||
else if (t == typeof(Unit?))
|
||||
{
|
||||
return NullableUnitFormatter.Instance;
|
||||
}
|
||||
|
||||
TypeInfo ti = t.GetTypeInfo();
|
||||
|
||||
if (ti.IsGenericType)
|
||||
{
|
||||
Type genericType = ti.GetGenericTypeDefinition();
|
||||
Type formatterType;
|
||||
if (FormatterMap.TryGetValue(genericType, out formatterType))
|
||||
{
|
||||
return CreateInstance(formatterType, ti.GenericTypeArguments);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private static object CreateInstance(Type genericType, Type[] genericTypeArguments, params object[] arguments)
|
||||
{
|
||||
return Activator.CreateInstance(genericType.MakeGenericType(genericTypeArguments), arguments);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 9605defad6e10ba4e910ed209eb12b08
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -1,7 +1,8 @@
|
|||
{
|
||||
"name": "MessagePack",
|
||||
"references": [],
|
||||
"optionalUnityReferences": [],
|
||||
"references": [
|
||||
"GUID:215598cda61754a45bc1f34e1d38d3af"
|
||||
],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": true,
|
||||
|
|
@ -9,5 +10,6 @@
|
|||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [],
|
||||
"versionDefines": []
|
||||
"versionDefines": [],
|
||||
"noEngineReferences": false
|
||||
}
|
||||
3
Assets/Scripts/NIH/UniRx/UniRx.asmdef
Normal file
3
Assets/Scripts/NIH/UniRx/UniRx.asmdef
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
"name": "UniRx"
|
||||
}
|
||||
7
Assets/Scripts/NIH/UniRx/UniRx.asmdef.meta
Normal file
7
Assets/Scripts/NIH/UniRx/UniRx.asmdef.meta
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 215598cda61754a45bc1f34e1d38d3af
|
||||
AssemblyDefinitionImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -11,7 +11,7 @@ public class BlueNoiseProvider : MonoBehaviour
|
|||
|
||||
private Camera _camera;
|
||||
|
||||
void Start()
|
||||
private void Start()
|
||||
{
|
||||
_camera = Camera.main;
|
||||
|
||||
|
|
@ -7,5 +7,4 @@ public class GasGiantObject : PlanetObject
|
|||
public SunMaterial SunMaterial;
|
||||
public GradientMapper GradientMapper;
|
||||
public MeshRenderer GravityWaves;
|
||||
public WaveScroll WaveScroll;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@ using UnityEngine;
|
|||
public class PlanetObject : MonoBehaviour
|
||||
{
|
||||
public MeshRenderer Body;
|
||||
public SnapToGrid GridSnap;
|
||||
public MeshRenderer GravityWell;
|
||||
public MeshRenderer Icon;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,13 +9,8 @@ public class SectorDisplayProperties : ScriptableObject
|
|||
public float DefaultViewDistance;
|
||||
public float DefaultMinimapDistance;
|
||||
public ExponentialCurve BodyDiameter;
|
||||
public ExponentialCurve GravityDepth;
|
||||
public ExponentialCurve GravityRadius;
|
||||
public ExponentialCurve WaveDepth;
|
||||
public ExponentialCurve WaveRadius;
|
||||
public ExponentialCurve WaveFrequency;
|
||||
public ExponentialCurve WaveSpeed;
|
||||
public GravitySettings GravitySettings;
|
||||
public ExponentialCurve FogTintRadius;
|
||||
public ExponentialCurve LightRadius;
|
||||
public Gradient DefaultGradient;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,8 +1,12 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Cinemachine;
|
||||
using UniRx;
|
||||
using UnityEngine;
|
||||
using static Unity.Mathematics.math;
|
||||
using Unity.Mathematics;
|
||||
|
||||
public class SectorRenderer : MonoBehaviour
|
||||
{
|
||||
|
|
@ -14,9 +18,10 @@ public class SectorRenderer : MonoBehaviour
|
|||
public Camera[] FogCameras;
|
||||
public Camera[] MinimapCameras;
|
||||
public Material FogMaterial;
|
||||
public ActionGameManager Manager;
|
||||
public float FogFarFadeFraction = .125f;
|
||||
public float FarPlaneDistanceMultiplier = 2;
|
||||
public Mesh[] AsteroidMeshes;
|
||||
public Material AsteroidMaterial;
|
||||
|
||||
[Header("Prefabs")]
|
||||
public GameObject Belt;
|
||||
|
|
@ -31,6 +36,8 @@ public class SectorRenderer : MonoBehaviour
|
|||
private Dictionary<Guid, Transform> _planets = new Dictionary<Guid, Transform>();
|
||||
private Zone _zone;
|
||||
private float _viewDistance;
|
||||
|
||||
public GameContext Context { get; set; }
|
||||
|
||||
public float ViewDistance
|
||||
{
|
||||
|
|
@ -56,29 +63,36 @@ public class SectorRenderer : MonoBehaviour
|
|||
|
||||
void Start()
|
||||
{
|
||||
LoadZone(Manager.CurrentZone);
|
||||
ViewDistance = Properties.DefaultViewDistance;
|
||||
MinimapDistance = Properties.DefaultMinimapDistance;
|
||||
Manager.ZoneChanged += (_, args) => LoadZone(args.NewZone);
|
||||
}
|
||||
|
||||
void LoadZone(Zone zone)
|
||||
public void LoadZone(Zone zone)
|
||||
{
|
||||
_zone = zone;
|
||||
_zone.GravitySettings = Properties.GravitySettings;
|
||||
SectorBrushes.localScale = zone.Data.Radius * 2 * Vector3.one;
|
||||
if (_planets.Count > 0)
|
||||
{
|
||||
foreach (var planet in _planets.Values)
|
||||
{
|
||||
Destroy(planet.gameObject);
|
||||
}
|
||||
_planets.Clear();
|
||||
}
|
||||
_zone.ZoneDepth = 50;
|
||||
_zone.ZoneDepthExponent = .25f;
|
||||
_zone.ZoneDepthRadius = zone.Data.Radius * 2;
|
||||
ClearZone();
|
||||
foreach(var p in zone.Planets.Values)
|
||||
LoadPlanet(p);
|
||||
}
|
||||
|
||||
void LoadPlanet(PlanetData planetData)
|
||||
public void ClearZone()
|
||||
{
|
||||
if (_planets.Count > 0)
|
||||
{
|
||||
foreach (var planet in _planets.Values)
|
||||
{
|
||||
DestroyImmediate(planet.gameObject);
|
||||
}
|
||||
_planets.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
void LoadPlanet(BodyData planetData)
|
||||
{
|
||||
if (planetData is AsteroidBeltData beltData)
|
||||
{
|
||||
|
|
@ -93,49 +107,85 @@ public class SectorRenderer : MonoBehaviour
|
|||
{
|
||||
planet = Instantiate(Sun, SectorRoot);
|
||||
var sun = (SunObject) planet;
|
||||
sun.Light.color = sunData.LightColor;
|
||||
sun.Light.range = Properties.LightRadius.Evaluate(sunData.Mass);
|
||||
sun.FogTint.material.SetColor("_Color", sunData.FogTintColor);
|
||||
sun.FogTint.transform.localScale = Properties.FogTintRadius.Evaluate(sunData.Mass) * Vector3.one;
|
||||
sunData.LightColor.Subscribe(c => sun.Light.color = c);
|
||||
sunData.Mass.Subscribe(m => sun.Light.range = Properties.LightRadius.Evaluate(m));
|
||||
sunData.FogTintColor.Subscribe(c => sun.FogTint.material.SetColor("_Color", c));
|
||||
sunData.Mass.Subscribe(m => sun.FogTint.transform.localScale = Properties.FogTintRadius.Evaluate(m) * Vector3.one);
|
||||
}
|
||||
else planet = Instantiate(GasGiant, SectorRoot);
|
||||
|
||||
var gas = (GasGiantObject) planet;
|
||||
gas.GradientMapper.ApplyGradient(gasGiantData.Colors);
|
||||
gas.SunMaterial.AlbedoRotationSpeed = gasGiantData.AlbedoRotationSpeed;
|
||||
gas.SunMaterial.FirstOffsetRotationSpeed = gasGiantData.AlbedoRotationSpeed;
|
||||
gas.SunMaterial.SecondOffsetRotationSpeed = gasGiantData.AlbedoRotationSpeed;
|
||||
gas.SunMaterial.FirstOffsetDomainRotationSpeed = gasGiantData.AlbedoRotationSpeed;
|
||||
gas.SunMaterial.SecondOffsetDomainRotationSpeed = gasGiantData.AlbedoRotationSpeed;
|
||||
gas.GravityWaves.material.SetFloat("_Depth", Properties.WaveDepth.Evaluate(planetData.Mass));
|
||||
gas.GravityWaves.material.SetFloat("_Frequency", Properties.WaveFrequency.Evaluate(planetData.Mass));
|
||||
gas.WaveScroll.Speed = Properties.WaveSpeed.Evaluate(planetData.Mass);
|
||||
gas.GravityWaves.transform.localScale = Properties.WaveRadius.Evaluate(planetData.Mass) * Vector3.one;
|
||||
gasGiantData.Colors.Subscribe(c => gas.GradientMapper.ApplyGradient(c.ToGradient()));
|
||||
gasGiantData.AlbedoRotationSpeed.Subscribe(f => gas.SunMaterial.AlbedoRotationSpeed = f);
|
||||
gasGiantData.FirstOffsetRotationSpeed.Subscribe(f => gas.SunMaterial.FirstOffsetRotationSpeed = f);
|
||||
gasGiantData.SecondOffsetRotationSpeed.Subscribe(f => gas.SunMaterial.SecondOffsetRotationSpeed = f);
|
||||
gasGiantData.FirstOffsetDomainRotationSpeed.Subscribe(f => gas.SunMaterial.FirstOffsetDomainRotationSpeed = f);
|
||||
gasGiantData.SecondOffsetDomainRotationSpeed.Subscribe(f => gas.SunMaterial.SecondOffsetDomainRotationSpeed = f);
|
||||
planetData.Mass.CombineLatest(planetData.GravityRadiusMultiplier,
|
||||
(mass, radius) => Properties.GravitySettings.WaveRadius.Evaluate(mass) * radius)
|
||||
.Subscribe(f => gas.GravityWaves.transform.localScale = f * Vector3.one);
|
||||
planetData.Mass.CombineLatest(planetData.GravityDepthMultiplier,
|
||||
(mass, depth) => Properties.GravitySettings.WaveDepth.Evaluate(mass) * depth)
|
||||
.Subscribe(f => gas.GravityWaves.material.SetFloat("_Depth", f));
|
||||
planetData.Mass.Subscribe(f =>
|
||||
{
|
||||
gas.GravityWaves.material.SetFloat("_Frequency", Properties.GravitySettings.WaveFrequency.Evaluate(f));
|
||||
//gas.WaveScroll.Speed = Properties.GravitySettings.WaveSpeed.Evaluate(f);
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
planet = Instantiate(Planet, SectorRoot);
|
||||
planet.Icon.material.mainTexture = planetData.Mass > Manager.Context.GlobalData.PlanetMass ? PlanetIcon : PlanetoidIcon;
|
||||
//planet.Icon.material.mainTexture = planetData.Mass > Context.GlobalData.PlanetMass ? PlanetIcon : PlanetoidIcon;
|
||||
}
|
||||
|
||||
planetData.Mass.Subscribe(mass =>
|
||||
{
|
||||
var diameter = Properties.BodyDiameter.Evaluate(mass);
|
||||
planet.Body.transform.localScale = diameter * Vector3.one;
|
||||
//planet.GridSnap.Offset = diameter * 2;
|
||||
});
|
||||
|
||||
var diameter = Properties.BodyDiameter.Evaluate(planetData.Mass);
|
||||
planet.Body.transform.localScale = diameter * Vector3.one;
|
||||
planet.GravityWell.transform.localScale = Properties.GravityRadius.Evaluate(planetData.Mass) * Vector3.one;
|
||||
planet.GravityWell.material.SetFloat("_Depth", Properties.GravityDepth.Evaluate(planetData.Mass));
|
||||
planet.GridSnap.Offset = diameter * 2;
|
||||
planetData.Mass.CombineLatest(planetData.GravityRadiusMultiplier,
|
||||
(mass, radius) => Properties.GravitySettings.GravityRadius.Evaluate(mass) * radius)
|
||||
.Subscribe(f => planet.GravityWell.transform.localScale = f * Vector3.one);
|
||||
planetData.Mass.CombineLatest(planetData.GravityDepthMultiplier,
|
||||
(mass, depth) => Properties.GravitySettings.GravityDepth.Evaluate(mass) * depth)
|
||||
.Subscribe(f => planet.GravityWell.material.SetFloat("_Depth", f));
|
||||
|
||||
_planets.Add(planetData.ID, planet.transform);
|
||||
}
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
foreach(var belt in _zone.AsteroidBelts.Values)
|
||||
{
|
||||
for (int i = 0; i < AsteroidMeshes.Length; i++)
|
||||
{
|
||||
var matrices = belt.Transforms
|
||||
.Skip((int) (((float)i / AsteroidMeshes.Length) * belt.Transforms.Length))
|
||||
.Take((int) (1f / AsteroidMeshes.Length * belt.Transforms.Length))
|
||||
.Select(v => Matrix4x4.TRS(
|
||||
new Vector3(v.x, _zone.GetHeight(v.xy) + 5, v.y),
|
||||
Quaternion.Euler(cos(v.z + (float) i / AsteroidMeshes.Length) * 100, sin(v.z + (float) i / AsteroidMeshes.Length) * 100, 0),
|
||||
Vector3.one * (v.w)))
|
||||
.ToArray();
|
||||
Graphics.DrawMeshInstanced(AsteroidMeshes[i], 0, AsteroidMaterial, matrices);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void LateUpdate()
|
||||
{
|
||||
foreach (var planet in _planets)
|
||||
{
|
||||
planet.Value.position = ((Vector2) _zone.GetOrbitPosition(_zone.Planets[planet.Key].Orbit)).Flatland();
|
||||
var p = _zone.GetOrbitPosition(_zone.Planets[planet.Key].Orbit);
|
||||
planet.Value.position = new Vector3(p.x, _zone.GetHeight(p) + 10, p.y);
|
||||
}
|
||||
|
||||
var pos = FogCameraParent.position;
|
||||
FogMaterial.SetVector("_GridTransform", new Vector4(pos.x,pos.z,_viewDistance*2));
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using static Unity.Mathematics.math;
|
||||
|
||||
//[ExecuteInEditMode]
|
||||
public class SunMaterial : MonoBehaviour
|
||||
|
|
@ -39,14 +40,23 @@ public class SunMaterial : MonoBehaviour
|
|||
_secondOffsetRotation = Random.value * Mathf.PI;
|
||||
_albedoRotation = Random.value * Mathf.PI;
|
||||
}
|
||||
|
||||
public void ApplyGradient(Gradient gradient)
|
||||
{
|
||||
var tex = gradient.ToTexture();
|
||||
if (_material.HasProperty("_ColorRamp"))
|
||||
{
|
||||
_material.SetTexture("_ColorRamp", tex);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnWillRenderObject()
|
||||
{
|
||||
_firstOffsetDomainRotation = FirstOffsetDomainRotationSpeed * SpeedMultiplier * Time.time;
|
||||
_firstOffsetRotation = FirstOffsetRotationSpeed * SpeedMultiplier * Time.time;
|
||||
_secondOffsetDomainRotation = SecondOffsetDomainRotationSpeed * SpeedMultiplier * Time.time;
|
||||
_secondOffsetRotation = SecondOffsetRotationSpeed * SpeedMultiplier * Time.time;
|
||||
_albedoRotation = AlbedoRotationSpeed * SpeedMultiplier * Time.time;
|
||||
_firstOffsetDomainRotation += FirstOffsetDomainRotationSpeed * SpeedMultiplier * Time.deltaTime;
|
||||
_firstOffsetRotation += FirstOffsetRotationSpeed * SpeedMultiplier * Time.deltaTime;
|
||||
_secondOffsetDomainRotation += SecondOffsetDomainRotationSpeed * SpeedMultiplier * Time.deltaTime;
|
||||
_secondOffsetRotation += SecondOffsetRotationSpeed * SpeedMultiplier * Time.deltaTime;
|
||||
_albedoRotation += AlbedoRotationSpeed * SpeedMultiplier * Time.deltaTime;
|
||||
|
||||
_material.SetVector("_LightingDirection", LightingDirection);
|
||||
_material.SetMatrix("_FirstOffsetDomainRotation", Matrix4x4.TRS(Vector3.zero, Quaternion.Euler(0, Mathf.Rad2Deg * _firstOffsetDomainRotation, 0), Vector3.one));
|
||||
|
|
|
|||
|
|
@ -15,6 +15,6 @@ public class WaveScroll : MonoBehaviour
|
|||
}
|
||||
|
||||
void Update () {
|
||||
_material.SetFloat("_Phase", _phase+=Time.deltaTime*Speed);
|
||||
_material.SetFloat("_Phase", _phase=Time.time*Speed);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@ using System.Collections.Generic;
|
|||
using JsonKnownTypes;
|
||||
using MessagePack;
|
||||
using Newtonsoft.Json;
|
||||
using UnityEngine;
|
||||
|
||||
[MessagePackObject,
|
||||
Union(0, typeof(StationTowing)),
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@ using System.Collections;
|
|||
using System.Collections.Generic;
|
||||
using MessagePack;
|
||||
using Newtonsoft.Json;
|
||||
using UnityEngine;
|
||||
|
||||
public class HaulingTask : AgentTask
|
||||
{
|
||||
|
|
|
|||
|
|
@ -63,7 +63,7 @@ public class ResourceScanner : IBehavior, IAlwaysUpdatedBehavior
|
|||
|
||||
public bool Update(float delta)
|
||||
{
|
||||
var planetData = Context.Cache.Get<PlanetData>(ScanTarget);
|
||||
var planetData = Context.Cache.Get<BodyData>(ScanTarget);
|
||||
if (planetData != null)
|
||||
{
|
||||
if (planetData is AsteroidBeltData beltData)
|
||||
|
|
|
|||
|
|
@ -64,7 +64,7 @@ public class SurveyController : ControllerBase, IBehavior, IPersistentBehavior,
|
|||
if (!corporation.PlanetSurveyFloor.ContainsKey(_targetPlanet) ||
|
||||
corporation.PlanetSurveyFloor[_targetPlanet] + .5f < _scanningTool.MinimumDensity)
|
||||
{
|
||||
var planetData = _context.Cache.Get<PlanetData>(_targetPlanet);
|
||||
var planetData = _context.Cache.Get<BodyData>(_targetPlanet);
|
||||
MoveTo(() =>
|
||||
{
|
||||
var target = GetPosition(planetData, _asteroid);
|
||||
|
|
@ -88,7 +88,7 @@ public class SurveyController : ControllerBase, IBehavior, IPersistentBehavior,
|
|||
{
|
||||
if (!Moving)
|
||||
{
|
||||
var planetData = _context.Cache.Get<PlanetData>(_targetPlanet);
|
||||
var planetData = _context.Cache.Get<BodyData>(_targetPlanet);
|
||||
if ((!corporation.PlanetSurveyFloor.ContainsKey(_targetPlanet) ||
|
||||
corporation.PlanetSurveyFloor[_targetPlanet] + .5f < _scanningTool.MinimumDensity) &&
|
||||
length(_entity.Position - GetPosition(planetData, _asteroid)) < _scanningTool.Range)
|
||||
|
|
@ -117,7 +117,7 @@ public class SurveyController : ControllerBase, IBehavior, IPersistentBehavior,
|
|||
_targetPlanet = nearestPlanet.ID;
|
||||
}
|
||||
|
||||
private float2 GetPosition(PlanetData planet, int asteroid = -1)
|
||||
private float2 GetPosition(BodyData planet, int asteroid = -1)
|
||||
{
|
||||
if (planet is AsteroidBeltData)
|
||||
{
|
||||
|
|
@ -127,7 +127,7 @@ public class SurveyController : ControllerBase, IBehavior, IPersistentBehavior,
|
|||
return Zone.GetOrbitPosition(planet.Orbit);
|
||||
}
|
||||
|
||||
private float2 GetVelocity(PlanetData planet, int asteroid = -1)
|
||||
private float2 GetVelocity(BodyData planet, int asteroid = -1)
|
||||
{
|
||||
if (planet is AsteroidBeltData)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@ using System.Collections;
|
|||
using System.Collections.Generic;
|
||||
using MessagePack;
|
||||
using Newtonsoft.Json;
|
||||
using UnityEngine;
|
||||
|
||||
|
||||
[RethinkTable("Galaxy"), MessagePackObject, JsonObject(MemberSerialization.OptIn)]
|
||||
|
|
|
|||
|
|
@ -6,9 +6,6 @@ using Newtonsoft.Json;
|
|||
// TODO: USE THIS EVERYWHERE
|
||||
using Unity.Mathematics;
|
||||
using static Unity.Mathematics.math;
|
||||
#if UNITY_EDITOR
|
||||
using UnityEditor;
|
||||
#endif
|
||||
|
||||
public interface INamedEntry
|
||||
{
|
||||
|
|
@ -33,7 +30,7 @@ public interface INamedEntry
|
|||
Union(13, typeof(MegaCorporation)),
|
||||
Union(14, typeof(OrbitalEntity)),
|
||||
Union(15, typeof(OrbitData)),
|
||||
Union(16, typeof(PlanetData)),
|
||||
Union(16, typeof(BodyData)),
|
||||
Union(17, typeof(PersonalityAttribute)),
|
||||
Union(18, typeof(AgentTask)),
|
||||
Union(19, typeof(LoadoutData)),
|
||||
|
|
@ -45,6 +42,7 @@ public interface INamedEntry
|
|||
Union(25, typeof(AsteroidBeltData)),
|
||||
Union(26, typeof(GasGiantData)),
|
||||
Union(27, typeof(SunData)),
|
||||
Union(28, typeof(PlanetData)),
|
||||
JsonObject(MemberSerialization.OptIn), JsonConverter(typeof(JsonKnownTypesConverter<DatabaseEntry>))]
|
||||
//[Union(21, typeof(ContractData))]
|
||||
//[Union(22, typeof(Station))]
|
||||
|
|
|
|||
|
|
@ -3,14 +3,16 @@
|
|||
"references": [
|
||||
"MessagePack",
|
||||
"MagicOnion.Abstractions",
|
||||
"Unity.Mathematics"
|
||||
"Unity.Mathematics",
|
||||
"UniRx"
|
||||
],
|
||||
"optionalUnityReferences": [],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": []
|
||||
"defineConstraints": [],
|
||||
"versionDefines": [],
|
||||
"noEngineReferences": true
|
||||
}
|
||||
|
|
@ -20,3 +20,28 @@ public class ExponentialCurve
|
|||
|
||||
public float Evaluate(float value) => Multiplier * pow(value, Exponent) + Constant;
|
||||
}
|
||||
|
||||
[Serializable, MessagePackObject, JsonObject]
|
||||
public class GravitySettings
|
||||
{
|
||||
[JsonProperty("gravityDepth"), Key(0)]
|
||||
public ExponentialCurve GravityDepth;
|
||||
|
||||
[JsonProperty("gravityRadius"), Key(1)]
|
||||
public ExponentialCurve GravityRadius;
|
||||
|
||||
[JsonProperty("waveDepth"), Key(2)]
|
||||
public ExponentialCurve WaveDepth;
|
||||
|
||||
[JsonProperty("waveRadius"), Key(3)]
|
||||
public ExponentialCurve WaveRadius;
|
||||
|
||||
[JsonProperty("waveFrequency"), Key(4)]
|
||||
public ExponentialCurve WaveFrequency;
|
||||
|
||||
[JsonProperty("waveSpeed"), Key(5)]
|
||||
public ExponentialCurve WaveSpeed;
|
||||
|
||||
[JsonProperty("gravityStrength"), Key(6)]
|
||||
public float GravityStrength;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
|
||||
public interface IChangeSource
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ namespace LiteNetLib
|
|||
if (Logger == null)
|
||||
{
|
||||
#if UNITY_4 || UNITY_5 || UNITY_5_3_OR_NEWER
|
||||
UnityEngine.Debug.Log(string.Format(str, args));
|
||||
//UnityEngine.Debug.Log(string.Format(str, args));
|
||||
#else
|
||||
Console.WriteLine(str, args);
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -8,10 +8,14 @@ using float2 = Unity.Mathematics.float2;
|
|||
|
||||
public class Zone
|
||||
{
|
||||
public float ZoneDepth;
|
||||
public float ZoneDepthExponent;
|
||||
public float ZoneDepthRadius;
|
||||
public GravitySettings GravitySettings;
|
||||
//public HashSet<Guid> Planets = new HashSet<Guid>();
|
||||
public Dictionary<Guid, Entity> Entities = new Dictionary<Guid, Entity>();
|
||||
//public Dictionary<Guid, OrbitData> Orbits = new Dictionary<Guid, OrbitData>();
|
||||
public Dictionary<Guid, PlanetData> Planets = new Dictionary<Guid, PlanetData>();
|
||||
public Dictionary<Guid, BodyData> Planets = new Dictionary<Guid, BodyData>();
|
||||
|
||||
public Dictionary<Guid, Orbit> Orbits = new Dictionary<Guid, Orbit>();
|
||||
public Dictionary<Guid, AsteroidBelt> AsteroidBelts = new Dictionary<Guid, AsteroidBelt>();
|
||||
|
|
@ -178,7 +182,7 @@ public class Zone
|
|||
belt.Transforms[i] = float4(
|
||||
OrbitData.Evaluate((float) frac(_context.Time / _context.GlobalData.OrbitalPeriod(beltData.Asteroids[i].Distance) * _context.GlobalData.OrbitSpeedMultiplier +
|
||||
beltData.Asteroids[i].Phase)) * beltData.Asteroids[i].Distance + orbitPosition,
|
||||
(float) (_context.Time * beltData.Asteroids[i].RotationSpeed % 360.0), size);
|
||||
(float) (_context.Time * beltData.Asteroids[i].RotationSpeed % (PI * 2)), size);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -244,6 +248,73 @@ public class Zone
|
|||
miner.AddCargo(newSimpleCommodity);
|
||||
}
|
||||
}
|
||||
public float GetHeight(float2 position)
|
||||
{
|
||||
float result = -PowerPulse(length(position)/ZoneDepthRadius, ZoneDepthExponent) * ZoneDepth;
|
||||
foreach (var body in Planets.Values)
|
||||
{
|
||||
if (body is AsteroidBeltData) continue;
|
||||
|
||||
var p = (position - GetOrbitPosition(body.Orbit));
|
||||
var dist = length(p);
|
||||
var gravityRadius = GravitySettings.GravityRadius.Evaluate(body.Mass.Value) * body.GravityRadiusMultiplier.Value;
|
||||
if (dist < gravityRadius)
|
||||
{
|
||||
var depth = GravitySettings.GravityDepth.Evaluate(body.Mass.Value) * body.GravityDepthMultiplier.Value;
|
||||
result -= PowerPulse(dist / gravityRadius, body.GravityDepthExponent.Value) * depth;
|
||||
}
|
||||
|
||||
if (body is GasGiantData)
|
||||
{
|
||||
var waveRadius = GravitySettings.WaveRadius.Evaluate(body.Mass.Value) * body.GravityRadiusMultiplier.Value;
|
||||
if(dist < waveRadius)
|
||||
{
|
||||
var depth = GravitySettings.WaveDepth.Evaluate(body.Mass.Value) * body.GravityDepthMultiplier.Value;
|
||||
var frequency = GravitySettings.WaveFrequency.Evaluate(body.Mass.Value);
|
||||
var speed = GravitySettings.WaveSpeed.Evaluate(body.Mass.Value);
|
||||
result -= RadialWaves(dist / gravityRadius, 8, 1.5f, frequency, (float) (_context.Time * speed)) * depth;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public float2 GetForce(float2 position)
|
||||
{
|
||||
var normal = GetNormal(position);
|
||||
var f = new float2(normal.x, normal.z);
|
||||
return f * GravitySettings.GravityStrength * lengthsq(f);// * Mathf.Abs(GetHeight(position));
|
||||
}
|
||||
|
||||
public static float PowerPulse(float x, float exponent)
|
||||
{
|
||||
x = clamp(x, -1, 1);
|
||||
return pow((x + 1) * (1 - x), exponent);
|
||||
}
|
||||
|
||||
public static float RadialWaves(float x, float maskExponent, float sineExponent, float frequency, float phase)
|
||||
{
|
||||
return PowerPulse(x, maskExponent) * cos(pow(x, sineExponent) * frequency + phase);
|
||||
}
|
||||
|
||||
public float3 GetNormal(float2 pos, float step, float mul)
|
||||
{
|
||||
float hL = GetHeight(new float2(pos.x - step, pos.y)) * mul;
|
||||
float hR = GetHeight(new float2(pos.x + step, pos.y)) * mul;
|
||||
float hD = GetHeight(new float2(pos.x, pos.y - step)) * mul;
|
||||
float hU = GetHeight(new float2(pos.x, pos.y + step)) * mul;
|
||||
|
||||
// Deduce terrain normal
|
||||
float3 normal = new float3((hL - hR), (hD - hU), 2);
|
||||
normalize(normal);
|
||||
return new float3(normal.x, normal.z, normal.y);
|
||||
}
|
||||
|
||||
public float3 GetNormal(float2 pos)
|
||||
{
|
||||
return GetNormal(pos, .1f, 1);
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -3,9 +3,10 @@ using System.Collections;
|
|||
using System.Collections.Generic;
|
||||
using MessagePack;
|
||||
using Newtonsoft.Json;
|
||||
using UniRx;
|
||||
using Unity.Mathematics;
|
||||
using UnityEngine;
|
||||
using static Unity.Mathematics.math;
|
||||
using float3 = Unity.Mathematics.float3;
|
||||
|
||||
[RethinkTable("Galaxy"), MessagePackObject, JsonObject(MemberSerialization.OptIn)]
|
||||
public class ZoneData : DatabaseEntry, INamedEntry
|
||||
|
|
@ -48,7 +49,7 @@ public class ZonePack : INamedEntry
|
|||
public ZoneData Data;
|
||||
|
||||
[JsonProperty("planets"), Key(1)]
|
||||
public List<PlanetData> Planets = new List<PlanetData>();
|
||||
public List<BodyData> Planets = new List<BodyData>();
|
||||
|
||||
[JsonProperty("orbits"), Key(2)]
|
||||
public List<OrbitData> Orbits = new List<OrbitData>();
|
||||
|
|
@ -97,73 +98,85 @@ public class ZonePack : INamedEntry
|
|||
|
||||
[MessagePackObject,
|
||||
JsonObject(MemberSerialization.OptIn),
|
||||
Union(0, typeof(PlanetData)),
|
||||
Union(1, typeof(AsteroidBeltData)),
|
||||
Union(2, typeof(GasGiantData)),
|
||||
Union(3, typeof(SunData))]
|
||||
public class PlanetData : DatabaseEntry, INamedEntry
|
||||
public abstract class BodyData : DatabaseEntry, INamedEntry
|
||||
{
|
||||
[JsonProperty("name"), Key(1)]
|
||||
public string Name;
|
||||
public ReactiveProperty<string> Name = new ReactiveProperty<string>("");
|
||||
|
||||
[JsonProperty("orbit"), Key(2)]
|
||||
public Guid Orbit;
|
||||
|
||||
[JsonProperty("mass"), Key(3)]
|
||||
public float Mass;
|
||||
public ReactiveProperty<float> Mass = new ReactiveProperty<float>(0);
|
||||
|
||||
[JsonProperty("resources"), Key(4)]
|
||||
public Dictionary<Guid, float> Resources = new Dictionary<Guid, float>();
|
||||
|
||||
[JsonProperty("radiusMul")] [Key(5)]
|
||||
public float GravityRadiusMultiplier = 1;
|
||||
public ReactiveProperty<float> GravityRadiusMultiplier = new ReactiveProperty<float>(1);
|
||||
|
||||
[JsonProperty("depthMul")] [Key(6)]
|
||||
public float GravityDepthMultiplier = 1;
|
||||
public ReactiveProperty<float> GravityDepthMultiplier = new ReactiveProperty<float>(1);
|
||||
|
||||
[JsonProperty("depthExp")] [Key(7)]
|
||||
public ReactiveProperty<float> GravityDepthExponent = new ReactiveProperty<float>(8);
|
||||
|
||||
[IgnoreMember] public string EntryName
|
||||
{
|
||||
get => Name;
|
||||
set => Name = value;
|
||||
get => Name.Value;
|
||||
set => Name.Value = value;
|
||||
}
|
||||
}
|
||||
|
||||
public class AsteroidBeltData : PlanetData
|
||||
[MessagePackObject, JsonObject(MemberSerialization.OptIn)]
|
||||
public class PlanetData : BodyData
|
||||
{
|
||||
[JsonProperty("asteroids"), Key(7)]
|
||||
|
||||
}
|
||||
|
||||
[MessagePackObject, JsonObject(MemberSerialization.OptIn)]
|
||||
public class AsteroidBeltData : BodyData
|
||||
{
|
||||
[JsonProperty("asteroids"), Key(8)]
|
||||
public Asteroid[] Asteroids;
|
||||
}
|
||||
|
||||
public class GasGiantData : PlanetData
|
||||
[MessagePackObject, JsonObject(MemberSerialization.OptIn)]
|
||||
public class GasGiantData : BodyData
|
||||
{
|
||||
[JsonProperty("firstOffsetDomainRotationSpeed"), Key(7)]
|
||||
public float FirstOffsetDomainRotationSpeed;
|
||||
[JsonProperty("firstOffsetDomainRotationSpeed"), Key(8)]
|
||||
public ReactiveProperty<float> FirstOffsetDomainRotationSpeed = new ReactiveProperty<float>(1);
|
||||
|
||||
[JsonProperty("firstOffsetRotationSpeed"), Key(8)]
|
||||
public float FirstOffsetRotationSpeed;
|
||||
[JsonProperty("firstOffsetRotationSpeed"), Key(9)]
|
||||
public ReactiveProperty<float> FirstOffsetRotationSpeed = new ReactiveProperty<float>(1);
|
||||
|
||||
[JsonProperty("secondOffsetDomainRotationSpeed"), Key(9)]
|
||||
public float SecondOffsetDomainRotationSpeed;
|
||||
[JsonProperty("secondOffsetDomainRotationSpeed"), Key(10)]
|
||||
public ReactiveProperty<float> SecondOffsetDomainRotationSpeed = new ReactiveProperty<float>(1);
|
||||
|
||||
[JsonProperty("secondOffsetRotationSpeed"), Key(10)]
|
||||
public float SecondOffsetRotationSpeed;
|
||||
[JsonProperty("secondOffsetRotationSpeed"), Key(11)]
|
||||
public ReactiveProperty<float> SecondOffsetRotationSpeed = new ReactiveProperty<float>(1);
|
||||
|
||||
[JsonProperty("albedoRotationSpeed"), Key(11)]
|
||||
public float AlbedoRotationSpeed;
|
||||
[JsonProperty("albedoRotationSpeed"), Key(12)]
|
||||
public ReactiveProperty<float> AlbedoRotationSpeed = new ReactiveProperty<float>(1);
|
||||
|
||||
[JsonProperty("materialOverrides"), Key(12)]
|
||||
[JsonProperty("materialOverrides"), Key(13)]
|
||||
public List<string> MaterialOverrides = new List<string>();
|
||||
|
||||
[JsonProperty("colors"), Key(13)]
|
||||
public Gradient Colors;
|
||||
[JsonProperty("colors"), Key(14)]
|
||||
public ReactiveProperty<float4[]> Colors = new ReactiveProperty<float4[]>();
|
||||
}
|
||||
|
||||
public class SunData : GasGiantData
|
||||
{
|
||||
[JsonProperty("lightColor"), Key(17)]
|
||||
public Color LightColor;
|
||||
[JsonProperty("lightColor"), Key(15)]
|
||||
public ReactiveProperty<float3> LightColor = new ReactiveProperty<float3>(float3.zero);
|
||||
|
||||
[JsonProperty("fogTintColor"), Key(18)]
|
||||
public Color FogTintColor;
|
||||
[JsonProperty("fogTintColor"), Key(16)]
|
||||
public ReactiveProperty<float3> FogTintColor = new ReactiveProperty<float3>(float3.zero);
|
||||
}
|
||||
|
||||
[MessagePackObject, JsonObject(MemberSerialization.OptIn)]
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@ using System.Globalization;
|
|||
using System.Linq;
|
||||
using MessagePack;
|
||||
using Unity.Mathematics;
|
||||
using UnityEngine;
|
||||
using static Unity.Mathematics.math;
|
||||
using Random = Unity.Mathematics.Random;
|
||||
|
||||
|
|
@ -103,7 +102,7 @@ public class ZoneGenerator
|
|||
}
|
||||
}
|
||||
|
||||
PlanetData planetData;
|
||||
BodyData planetData;
|
||||
switch (bodyType)
|
||||
{
|
||||
case BodyType.Asteroid:
|
||||
|
|
@ -123,14 +122,14 @@ public class ZoneGenerator
|
|||
throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
|
||||
planetData.Mass = planet.Mass;
|
||||
planetData.Mass.Value = planet.Mass;
|
||||
planetData.Orbit = orbitMap[planet].ID;
|
||||
planetData.Resources = planetResources;
|
||||
planetData.Name = planetData.ID.ToString().Substring(0, 8);
|
||||
planetData.Name.Value = planetData.ID.ToString().Substring(0, 8);
|
||||
if (planetData is AsteroidBeltData beltData)
|
||||
{
|
||||
beltData.Asteroids =
|
||||
Enumerable.Range(0, (int) (pow(planetData.Mass, context.GlobalData.BeltMassExponent) / context.GlobalData.BeltMassRatio * orbitMap[planet].Distance))
|
||||
Enumerable.Range(0, (int) (pow(planetData.Mass.Value, context.GlobalData.BeltMassExponent) / context.GlobalData.BeltMassRatio * orbitMap[planet].Distance))
|
||||
.Select(_ => new Asteroid
|
||||
{
|
||||
Distance = context.Random.NextFloat(orbitMap[planet].Distance * .5f, orbitMap[planet].Distance * 1.5f),
|
||||
|
|
@ -143,19 +142,17 @@ public class ZoneGenerator
|
|||
}
|
||||
else if (planetData is GasGiantData gas)
|
||||
{
|
||||
var grad = new Gradient();
|
||||
var times = Enumerable.Range(0, 5).Select(i => (float) i / 4).ToArray();
|
||||
grad.alphaKeys = times.Select(f => new GradientAlphaKey(1, f)).ToArray();
|
||||
grad.colorKeys = times.Select(f => new GradientColorKey(UnityEngine.Random.ColorHSV(), f)).ToArray();
|
||||
gas.Colors = grad;
|
||||
gas.AlbedoRotationSpeed = 1;
|
||||
gas.FirstOffsetRotationSpeed = 1;
|
||||
gas.FirstOffsetDomainRotationSpeed = 1;
|
||||
gas.SecondOffsetRotationSpeed = 1;
|
||||
gas.SecondOffsetDomainRotationSpeed = 1;
|
||||
gas.Colors.Value = times.Select(time => float4(context.Random.NextFloat3(),time)).ToArray();
|
||||
gas.AlbedoRotationSpeed.Value = -3;
|
||||
gas.FirstOffsetRotationSpeed.Value = 5;
|
||||
gas.FirstOffsetDomainRotationSpeed.Value = 0;
|
||||
gas.SecondOffsetRotationSpeed.Value = 10;
|
||||
gas.SecondOffsetDomainRotationSpeed.Value = -25;
|
||||
if (planetData is SunData sun)
|
||||
{
|
||||
sun.FogTintColor = sun.LightColor = UnityEngine.Random.ColorHSV();
|
||||
sun.FogTintColor.Value = sun.LightColor.Value = context.Random.NextFloat3();
|
||||
gas.FirstOffsetDomainRotationSpeed.Value = 5;
|
||||
}
|
||||
}
|
||||
return planetData;
|
||||
|
|
|
|||
|
|
@ -573,7 +573,7 @@ public class StrategyGameManager : MonoBehaviour
|
|||
var targetObject = _context.Cache.Get(clickTarget);
|
||||
ContextMenu.gameObject.SetActive(true);
|
||||
ContextMenu.Clear();
|
||||
if (targetObject is PlanetData planet)
|
||||
if (targetObject is BodyData planet)
|
||||
{
|
||||
if (planet is AsteroidBeltData)
|
||||
{
|
||||
|
|
@ -680,7 +680,7 @@ public class StrategyGameManager : MonoBehaviour
|
|||
_selectedObject = clickTarget;
|
||||
var targetObject = _context.Cache.Get(_selectedObject);
|
||||
|
||||
if (targetObject is PlanetData planet)
|
||||
if (targetObject is BodyData planet)
|
||||
{
|
||||
if (_orbitSelectMode)
|
||||
{
|
||||
7
Assets/Scripts/StrategyGameManager.csbak.meta
Normal file
7
Assets/Scripts/StrategyGameManager.csbak.meta
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 8a3350bbbac7a7e4f9354196f7985fcb
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -16,8 +16,9 @@ using Object = UnityEngine.Object;
|
|||
public class ConsoleController
|
||||
{
|
||||
public static Component MessageReceiver;
|
||||
private static ConsoleController instance;
|
||||
private static Regex permittedCharacters = new Regex("[^a-zA-Z0-9 -]");
|
||||
private static ConsoleController _instance;
|
||||
private static Regex _permittedCharacters = new Regex("[^a-zA-Z0-9 -]");
|
||||
private static Dictionary<string, Action<string[]>> _commands = new Dictionary<string, Action<string[]>>();
|
||||
|
||||
private ConsoleController()
|
||||
{
|
||||
|
|
@ -25,14 +26,14 @@ public class ConsoleController
|
|||
|
||||
public static ConsoleController Instance
|
||||
{
|
||||
get
|
||||
{
|
||||
if (instance == null)
|
||||
{
|
||||
instance = new ConsoleController();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
get => _instance ?? (_instance = new ConsoleController());
|
||||
}
|
||||
|
||||
public static void AddCommand(string command, Action<string[]> action)
|
||||
{
|
||||
var lower = command.ToLowerInvariant();
|
||||
if(!_commands.ContainsKey(lower))
|
||||
_commands.Add(lower, action);
|
||||
}
|
||||
|
||||
#region Event declarations
|
||||
|
|
@ -48,34 +49,30 @@ public class ConsoleController
|
|||
/// How many log lines should be retained?
|
||||
/// Note that strings submitted to appendLogLine with embedded newlines will be counted as a single line.
|
||||
/// </summary>
|
||||
const int ScrollbackSize = 100;
|
||||
private const int ScrollbackSize = 100;
|
||||
|
||||
Queue<string> _scrollback = new Queue<string>(ScrollbackSize);
|
||||
List<string> _commandHistory = new List<string>();
|
||||
private readonly Queue<string> _scrollback = new Queue<string>(ScrollbackSize);
|
||||
private readonly List<string> _commandHistory = new List<string>();
|
||||
|
||||
public string[] Log { get; private set; } //Copy of scrollback as an array for easier use by ConsoleView
|
||||
|
||||
public void AppendLogLine(string line) {
|
||||
//Debug.Log(line);
|
||||
|
||||
if (_scrollback.Count >= ConsoleController.ScrollbackSize) {
|
||||
if (_scrollback.Count >= ScrollbackSize) {
|
||||
_scrollback.Dequeue();
|
||||
}
|
||||
_scrollback.Enqueue(line);
|
||||
|
||||
Log = _scrollback.ToArray();
|
||||
if (LogChanged != null) {
|
||||
LogChanged(Log);
|
||||
}
|
||||
LogChanged?.Invoke(Log);
|
||||
}
|
||||
|
||||
public void RunCommandString(string commandString) {
|
||||
AppendLogLine("$ " + commandString);
|
||||
AppendLogLine($"$ {commandString}");
|
||||
|
||||
string[] commandSplit = ParseArguments(commandString);
|
||||
string[] args = {"",""};
|
||||
if (commandSplit.Length < 1) {
|
||||
AppendLogLine(string.Format("Unable to process command '{0}'", commandString));
|
||||
AppendLogLine($"Unable to process command '{commandString}'");
|
||||
return;
|
||||
|
||||
}
|
||||
|
|
@ -84,14 +81,19 @@ public class ConsoleController
|
|||
args = new string[numArgs];
|
||||
Array.Copy(commandSplit, 1, args, 0, numArgs);
|
||||
}
|
||||
MessageReceiver.SendMessage(commandSplit[0].ToLower(), args, SendMessageOptions.DontRequireReceiver);
|
||||
|
||||
var cmd = commandSplit[0].ToLower();
|
||||
if(_commands.ContainsKey(cmd))
|
||||
_commands[cmd].Invoke(args);
|
||||
else AppendLogLine("Invalid command!");
|
||||
//MessageReceiver.SendMessage(commandSplit[0].ToLower(), args, SendMessageOptions.DontRequireReceiver);
|
||||
_commandHistory.Add(commandString);
|
||||
}
|
||||
|
||||
static string[] ParseArguments(string commandString)
|
||||
{
|
||||
LinkedList<char> parmChars = new LinkedList<char>(commandString.ToCharArray());
|
||||
bool inQuote = false;
|
||||
var parmChars = new LinkedList<char>(commandString.ToCharArray());
|
||||
var inQuote = false;
|
||||
var node = parmChars.First;
|
||||
while (node != null)
|
||||
{
|
||||
|
|
@ -105,12 +107,12 @@ public class ConsoleController
|
|||
}
|
||||
node = next;
|
||||
}
|
||||
char[] parmCharsArr = new char[parmChars.Count];
|
||||
var parmCharsArr = new char[parmChars.Count];
|
||||
parmChars.CopyTo(parmCharsArr, 0);
|
||||
var args = new string(parmCharsArr).Split(new[] {'\n'}, StringSplitOptions.RemoveEmptyEntries);
|
||||
for (var i = 0; i < args.Length; i++)
|
||||
{
|
||||
args[i] = permittedCharacters.Replace(args[i], "");
|
||||
args[i] = _permittedCharacters.Replace(args[i], "");
|
||||
}
|
||||
return args;
|
||||
}
|
||||
121
Assets/Scripts/UI/ConsoleView.cs
Normal file
121
Assets/Scripts/UI/ConsoleView.cs
Normal file
|
|
@ -0,0 +1,121 @@
|
|||
/// <summary>
|
||||
/// Marshals events and data between ConsoleController and uGUI.
|
||||
/// </summary>
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using System.Text;
|
||||
using System.Collections;
|
||||
using System.Linq;
|
||||
using TMPro;
|
||||
using UniRx;
|
||||
using UnityEngine.InputSystem;
|
||||
|
||||
public class ConsoleView : MonoBehaviour {
|
||||
bool _didShow = false;
|
||||
|
||||
public GameObject ViewContainer; //Container for console view, should be a child of this GameObject
|
||||
public TextMeshProUGUI LogTextArea;
|
||||
public TextMeshProUGUI InputArea;
|
||||
public ScrollRect Scroll;
|
||||
|
||||
private string _inputString = "";
|
||||
|
||||
public string InputString
|
||||
{
|
||||
get => _inputString;
|
||||
set
|
||||
{
|
||||
_inputString = value;
|
||||
InputArea.text = $"> {_inputString}";
|
||||
}
|
||||
}
|
||||
|
||||
//public bool AcceptingInput { get; private set; }
|
||||
|
||||
public bool Visible { get; private set; }
|
||||
|
||||
void Start()
|
||||
{
|
||||
//AcceptingInput = false;
|
||||
//_console = new ConsoleController();
|
||||
Application.logMessageReceived += (condition, trace, type) => ConsoleController.Instance.AppendLogLine("<color=" + (type == LogType.Error ? "red" : type == LogType.Warning ? "yellow" : "white") + ">" + condition + "</color>");
|
||||
|
||||
SetVisibility(false);
|
||||
|
||||
ConsoleController.Instance.VisibilityChanged += OnVisibilityChanged;
|
||||
ConsoleController.Instance.LogChanged += OnLogChanged;
|
||||
|
||||
Keyboard.current.onTextInput += c =>
|
||||
{
|
||||
if (!Visible || c == '`') return;
|
||||
InputString += c;
|
||||
};
|
||||
InputString = "";
|
||||
|
||||
ConsoleController.AddCommand("echo", Echo);
|
||||
|
||||
// var sizeFitter = GetComponentInChildren<ContentSizeFitter>().on
|
||||
}
|
||||
|
||||
~ConsoleView() {
|
||||
ConsoleController.Instance.VisibilityChanged -= OnVisibilityChanged;
|
||||
ConsoleController.Instance.LogChanged -= OnLogChanged;
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
var keyboard = Keyboard.current;
|
||||
//Toggle visibility when tilde key pressed
|
||||
if (keyboard.backquoteKey.wasPressedThisFrame) {
|
||||
ToggleVisibility();
|
||||
}
|
||||
|
||||
if (!Visible) return;
|
||||
|
||||
if(keyboard.deleteKey.wasPressedThisFrame && InputString.Length>0)
|
||||
{
|
||||
InputString = InputString.Substring(0, InputString.Length - 1);
|
||||
}
|
||||
|
||||
if (keyboard.enterKey.wasPressedThisFrame)
|
||||
{
|
||||
if (/*AcceptingInput && */InputString.Length > 0)
|
||||
{
|
||||
//if(_inputString.StartsWith("!") || _inputString.StartsWith("/"))
|
||||
ConsoleController.Instance.RunCommandString(InputString);//.Substring(1));
|
||||
//else ConsoleController.Instance.RunCommandString($"say \"{_inputString}\"");
|
||||
InputString = "";
|
||||
}
|
||||
//AcceptingInput = !AcceptingInput;
|
||||
}
|
||||
}
|
||||
|
||||
void Echo(string[] args)
|
||||
{
|
||||
if(args.Length>0)
|
||||
Debug.Log(args.Aggregate((a,b) => a + " " + b));
|
||||
}
|
||||
|
||||
void ToggleVisibility() {
|
||||
SetVisibility(!ViewContainer.activeSelf);
|
||||
}
|
||||
|
||||
void SetVisibility(bool visible) {
|
||||
ViewContainer.SetActive(visible);
|
||||
Visible = visible;
|
||||
if(visible)
|
||||
Cursor.lockState = CursorLockMode.None;
|
||||
}
|
||||
|
||||
void OnVisibilityChanged(bool visible) {
|
||||
SetVisibility(visible);
|
||||
}
|
||||
|
||||
void OnLogChanged(string[] newLog) {
|
||||
LogTextArea.text = string.Join("\n", newLog);
|
||||
// if (AcceptingInput)
|
||||
// LogTextArea.text += "\n\n> " + _inputString;
|
||||
Observable.NextFrame().Subscribe(_ => Scroll.verticalNormalizedPosition = 0);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -83,6 +83,26 @@ public static class UnityExtensions
|
|||
|
||||
return result;
|
||||
}
|
||||
|
||||
private const int GradSteps = 32;
|
||||
public static Texture2D ToTexture(this Gradient g)
|
||||
{
|
||||
var tex = new Texture2D(GradSteps, 1) {wrapMode = TextureWrapMode.Clamp};
|
||||
for (int x = 0; x < GradSteps; x++)
|
||||
{
|
||||
tex.SetPixel(x, 0, g.Evaluate( (float)x / GradSteps));
|
||||
}
|
||||
tex.Apply();
|
||||
return tex;
|
||||
}
|
||||
|
||||
public static Gradient ToGradient(this float4[] keys)
|
||||
{
|
||||
var grad = new Gradient();
|
||||
grad.alphaKeys = new[] {new GradientAlphaKey(1, 0), new GradientAlphaKey(1, 1)};
|
||||
grad.colorKeys = keys.Select(k => new GradientColorKey(k.xyz, k.w)).ToArray();
|
||||
return grad;
|
||||
}
|
||||
|
||||
public static Vector3 Flatland(this Vector2 v) => new Vector3(v.x,0,v.y);
|
||||
public static Vector2 Flatland(this Vector3 v) => new Vector2(v.x,v.z);
|
||||
|
|
|
|||
Loading…
Reference in a new issue