First Flight

Added MPL license headers
SectorRenderer renders entities in sector, manages particle systems for ship thrusters
Thrusters apply torque based on orientation and position relative to ship center of mass
GameManager controls the player ship's thrusters
Player can dock with station if they are near
This commit is contained in:
Reinier Vens 2020-12-22 03:13:43 +00:00
commit c4be204cd0
172 changed files with 6753 additions and 779 deletions

View file

@ -1,4 +1,8 @@
using System;
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
@ -19,20 +23,27 @@ public class ActionGameManager : MonoBehaviour
public GameSettings Settings;
public SectorRenderer SectorRenderer;
// public MapView MapView;
public CinemachineVirtualCamera TopDownCamera;
public CinemachineVirtualCamera DockCamera;
public CinemachineVirtualCamera FollowCamera;
public GameObject GameplayUI;
public MenuPanel Menu;
public InventoryMenu Inventory;
public float2 Sensitivity;
//public PlayerInput Input;
// private CinemachineFramingTransposer _transposer;
// private CinemachineComposer _composer;
private DirectoryInfo _filePath;
private bool _editMode;
private float _time;
private AetheriaInput _input;
private int _zoomLevelIndex;
private Ship _currentShip;
private ShipInput _shipInput;
private float2 _shipYawPitch;
private float3 _viewDirection;
private Transform _lookAt;
public List<Ship> PlayerShips { get; } = new List<Ship>();
public DatabaseCache ItemData { get; private set; }
@ -42,6 +53,10 @@ public class ActionGameManager : MonoBehaviour
void Start()
{
// _transposer = DockCamera.GetCinemachineComponent<CinemachineFramingTransposer>();
// _composer = DockCamera.GetCinemachineComponent<CinemachineComposer>();
_lookAt = new GameObject().transform;
ConsoleController.MessageReceiver = this;
_filePath = new DirectoryInfo(Application.dataPath).Parent.CreateSubdirectory("GameData");
ItemData = new DatabaseCache();
@ -62,6 +77,7 @@ public class ActionGameManager : MonoBehaviour
);
Zone = new Zone(Settings.PlanetSettings, zonePack);
SectorRenderer.ItemManager = ItemManager;
SectorRenderer.LoadZone(Zone);
_input = new AetheriaInput();
@ -80,10 +96,14 @@ public class ActionGameManager : MonoBehaviour
{
if (Menu.gameObject.activeSelf && Menu.CurrentTab == MenuTab.Map)
{
Cursor.lockState = CursorLockMode.Locked;
_input.Player.Enable();
Menu.gameObject.SetActive(false);
return;
}
Cursor.lockState = CursorLockMode.None;
_input.Player.Disable();
Menu.ShowTab(MenuTab.Map);
};
@ -91,14 +111,24 @@ public class ActionGameManager : MonoBehaviour
{
if (Menu.gameObject.activeSelf && Menu.CurrentTab == MenuTab.Inventory)
{
Cursor.lockState = CursorLockMode.Locked;
_input.Player.Enable();
Menu.gameObject.SetActive(false);
return;
}
Cursor.lockState = CursorLockMode.None;
_input.Player.Disable();
Menu.ShowTab(MenuTab.Inventory);
};
ConsoleController.AddCommand("editmode", _ => ToggleEditMode());
_input.Global.Dock.performed += context =>
{
if (_currentShip.Parent == null) Dock();
else Undock();
};
// ConsoleController.AddCommand("editmode", _ => ToggleEditMode());
ConsoleController.AddCommand("savezone", args =>
{
if (args.Length > 0)
@ -118,23 +148,27 @@ public class ActionGameManager : MonoBehaviour
var dockingBayData = ItemData.GetAll<DockingBayData>().First();
var dockingBay = ItemManager.CreateInstance(dockingBayData, 1, 1) as EquippableItem;
station.TryEquip(dockingBay);
var dockingCargo = station.DockingBays.First();
var thrusterData = ItemData.GetAll<GearData>().First(x => x.HardpointType == HardpointType.Thruster && x.Shape.Height == 1);
for (int i = 0; i < 8; i++)
{
dockingCargo.TryStore(ItemManager.CreateInstance(thrusterData, .5f, 1));
}
var reactorData = ItemData.GetAll<GearData>().First(x => x.HardpointType == HardpointType.Reactor && x.Shape.Height == 2);
dockingCargo.TryStore(ItemManager.CreateInstance(reactorData, .5f, 1));
station.Active = true;
var hullType = ItemData.GetAll<HullData>().First(x=>x.HullType==HullType.Ship);
var shipHull = ItemManager.CreateInstance(hullType, 0, 1) as EquippableItem;
var ship = new Ship(ItemManager, Zone, shipHull);
PlayerShips.Add(ship);
_currentShip = ship;
var dockingCargo = station.DockingBays.First();
var thrusterData = ItemData.GetAll<GearData>().First(x => x.HardpointType == HardpointType.Thruster && x.Shape.Height == 1);
for (int i = 0; i < 8; i++)
{
ship.TryEquip(ItemManager.CreateInstance(thrusterData, .5f, 1) as EquippableItem);
//dockingCargo.TryStore(ItemManager.CreateInstance(thrusterData, .5f, 1));
}
var reactorData = ItemData.GetAll<GearData>().First(x => x.HardpointType == HardpointType.Reactor && x.Shape.Height == 2);
ship.TryEquip(ItemManager.CreateInstance(reactorData, .5f, 1) as EquippableItem);
//dockingCargo.TryStore(ItemManager.CreateInstance(reactorData, .5f, 1));
Dock();
// MapButton.onClick.AddListener(() =>
@ -150,7 +184,8 @@ public class ActionGameManager : MonoBehaviour
public void Dock()
{
foreach (var entity in Zone.Entities)
if (_currentShip.Parent != null) return;
foreach (var entity in Zone.Entities.ToArray())
{
if (lengthsq(entity.Position - _currentShip.Position) <
Settings.GameplaySettings.DockingDistance * Settings.GameplaySettings.DockingDistance)
@ -158,22 +193,51 @@ public class ActionGameManager : MonoBehaviour
var bay = entity.TryDock(_currentShip);
if (bay != null)
{
DockCamera.enabled = true;
FollowCamera.enabled = false;
_currentShip.Active = false;
var orbital = (OrbitalEntity) entity;
DockCamera.Follow = SectorRenderer.Orbitals[orbital];
var parentOrbit = Zone.Orbits[orbital.OrbitData].Data.Parent;
var parentPlanet = SectorRenderer.Planets[Zone.Planets.FirstOrDefault(p => p.Value.Orbit == parentOrbit).Key];
DockCamera.LookAt = parentPlanet.Body.transform;
Menu.ShowTab(MenuTab.Inventory);
Inventory.GetPanel.Display(bay);
Inventory.GetPanel.Display(_currentShip);
_shipInput = null;
Cursor.lockState = CursorLockMode.None;
_input.Player.Disable();
}
}
}
}
public void Undock()
{
if (_currentShip.Parent == null) return;
if (_currentShip.Parent.TryUndock(_currentShip))
{
Menu.gameObject.SetActive(false);
_currentShip.Active = true;
_shipInput = new ShipInput(_input.Player, _currentShip);
DockCamera.enabled = false;
FollowCamera.enabled = true;
FollowCamera.LookAt = _lookAt;
FollowCamera.Follow = SectorRenderer.Ships[_currentShip].Transform;
Cursor.lockState = CursorLockMode.Locked;
_input.Player.Enable();
}
}
public void SaveZone() => File.WriteAllBytes(
Path.Combine(_filePath.FullName, $"{Zone.Data.Name}.zone"), MessagePackSerializer.Serialize(Zone.Pack()));
public void ToggleEditMode()
{
_editMode = !_editMode;
FollowCamera.gameObject.SetActive(!_editMode);
TopDownCamera.gameObject.SetActive(_editMode);
}
// public void ToggleEditMode()
// {
// _editMode = !_editMode;
// FollowCamera.gameObject.SetActive(!_editMode);
// TopDownCamera.gameObject.SetActive(_editMode);
// }
public IEnumerable<EquippedCargoBay> AvailableCargoBays()
{
@ -205,8 +269,64 @@ public class ActionGameManager : MonoBehaviour
{
_time += Time.deltaTime;
ItemManager.Time = Time.time;
if(_shipInput!=null)
{
var look = _input.Player.Look.ReadValue<Vector2>();
_shipYawPitch = float2(_shipYawPitch.x + look.x * Sensitivity.x, clamp(_shipYawPitch.y + look.y * Sensitivity.y, -.45f * PI, .45f * PI));
_viewDirection = mul(float3(0, 0, 1), Unity.Mathematics.float3x3.Euler(float3(_shipYawPitch.yx, 0), RotationOrder.YXZ));
_lookAt.position = SectorRenderer.Ships[_currentShip].Transform.position + (Vector3) _viewDirection * 100;
_shipInput.DesiredOrientation = _viewDirection.xz;
_shipInput.Update();
}
}
Zone.Update(_time, Time.deltaTime);
SectorRenderer.Time = _time;
}
}
public class ShipInput
{
private AetheriaInput.PlayerActions _input;
private Ship _ship;
private Thruster[] _allThrusters;
private Thruster[] _forwardThrusters;
private Thruster[] _reverseThrusters;
private Thruster[] _rightThrusters;
private Thruster[] _leftThrusters;
private Thruster[] _clockwiseThrusters;
private Thruster[] _counterClockwiseThrusters;
public float2 DesiredOrientation { get; set; }
public float DesiredPitch { get; set; }
public ShipInput(AetheriaInput.PlayerActions input, Ship ship)
{
_input = input;
_ship = ship;
_allThrusters = ship.GetBehaviors<Thruster>().ToArray();
_forwardThrusters = _allThrusters.Where(x => x.Item.EquippableItem.Rotation == ItemRotation.Reversed).ToArray();
_reverseThrusters = _allThrusters.Where(x => x.Item.EquippableItem.Rotation == ItemRotation.None).ToArray();
_rightThrusters = _allThrusters.Where(x => x.Item.EquippableItem.Rotation == ItemRotation.CounterClockwise).ToArray();
_leftThrusters = _allThrusters.Where(x => x.Item.EquippableItem.Rotation == ItemRotation.Clockwise).ToArray();
_counterClockwiseThrusters = _allThrusters.Where(x => x.Torque < -.05f).ToArray();
_clockwiseThrusters = _allThrusters.Where(x => x.Torque > .05f).ToArray();
}
public void Update()
{
var move = _input.Move.ReadValue<Vector2>();
foreach (var thruster in _allThrusters) thruster.Axis = 0;
foreach (var thruster in _rightThrusters) thruster.Axis += move.x;
foreach (var thruster in _leftThrusters) thruster.Axis += -move.x;
foreach (var thruster in _forwardThrusters) thruster.Axis += move.y;
foreach (var thruster in _reverseThrusters) thruster.Axis += -move.y;
var deltaRot = dot(normalize(DesiredOrientation), normalize(_ship.Direction).Rotate(ItemRotation.Clockwise));
if (abs(deltaRot) < .01) deltaRot = 0;
deltaRot = pow(abs(deltaRot), .5f) * sign(deltaRot);
foreach (var thruster in _clockwiseThrusters) thruster.Axis += deltaRot;
foreach (var thruster in _counterClockwiseThrusters) thruster.Axis += -deltaRot;
}
}

View file

@ -190,7 +190,7 @@ public class @AetheriaInput : IInputActionCollection, IDisposable
""path"": ""<Pointer>/delta"",
""interactions"": """",
""processors"": """",
""groups"": "";Keyboard&Mouse;Touch"",
""groups"": "";Keyboard&Mouse"",
""action"": ""Look"",
""isComposite"": false,
""isPartOfComposite"": false
@ -234,7 +234,7 @@ public class @AetheriaInput : IInputActionCollection, IDisposable
""path"": ""<Touchscreen>/primaryTouch/tap"",
""interactions"": """",
""processors"": """",
""groups"": "";Touch"",
""groups"": """",
""action"": ""Fire"",
""isComposite"": false,
""isPartOfComposite"": false
@ -331,22 +331,6 @@ public class @AetheriaInput : IInputActionCollection, IDisposable
""processors"": """",
""interactions"": """"
},
{
""name"": ""TrackedDevicePosition"",
""type"": ""PassThrough"",
""id"": ""b297afa0-f417-4a48-aaa1-36a6efd36190"",
""expectedControlType"": ""Vector3"",
""processors"": """",
""interactions"": """"
},
{
""name"": ""TrackedDeviceOrientation"",
""type"": ""PassThrough"",
""id"": ""1a877e6d-221e-4815-a289-aa93412c8d87"",
""expectedControlType"": ""Quaternion"",
""processors"": """",
""interactions"": """"
},
{
""name"": ""Drag"",
""type"": ""Value"",
@ -665,17 +649,6 @@ public class @AetheriaInput : IInputActionCollection, IDisposable
""isComposite"": false,
""isPartOfComposite"": false
},
{
""name"": """",
""id"": ""5693e57a-238a-46ed-b5ae-e64e6e574302"",
""path"": ""<Touchscreen>/touch*/position"",
""interactions"": """",
""processors"": """",
""groups"": ""Touch"",
""action"": ""Point"",
""isComposite"": false,
""isPartOfComposite"": false
},
{
""name"": """",
""id"": ""4faf7dc9-b979-4210-aa8c-e808e1ef89f5"",
@ -698,28 +671,6 @@ public class @AetheriaInput : IInputActionCollection, IDisposable
""isComposite"": false,
""isPartOfComposite"": false
},
{
""name"": """",
""id"": ""47c2a644-3ebc-4dae-a106-589b7ca75b59"",
""path"": ""<Touchscreen>/touch*/press"",
""interactions"": """",
""processors"": """",
""groups"": ""Touch"",
""action"": ""Click"",
""isComposite"": false,
""isPartOfComposite"": false
},
{
""name"": """",
""id"": ""bb9e6b34-44bf-4381-ac63-5aa15d19f677"",
""path"": ""<XRController>/trigger"",
""interactions"": """",
""processors"": """",
""groups"": ""XR"",
""action"": ""Click"",
""isComposite"": false,
""isPartOfComposite"": false
},
{
""name"": """",
""id"": ""38c99815-14ea-4617-8627-164d27641299"",
@ -753,28 +704,6 @@ public class @AetheriaInput : IInputActionCollection, IDisposable
""isComposite"": false,
""isPartOfComposite"": false
},
{
""name"": """",
""id"": ""7236c0d9-6ca3-47cf-a6ee-a97f5b59ea77"",
""path"": ""<XRController>/devicePosition"",
""interactions"": """",
""processors"": """",
""groups"": ""XR"",
""action"": ""TrackedDevicePosition"",
""isComposite"": false,
""isPartOfComposite"": false
},
{
""name"": """",
""id"": ""23e01e3a-f935-4948-8d8b-9bcac77714fb"",
""path"": ""<XRController>/deviceRotation"",
""interactions"": """",
""processors"": """",
""groups"": ""XR"",
""action"": ""TrackedDeviceOrientation"",
""isComposite"": false,
""isPartOfComposite"": false
},
{
""name"": """",
""id"": ""618fb60f-5dc7-47ec-8dbf-fdc3d4c515a1"",
@ -807,6 +736,14 @@ public class @AetheriaInput : IInputActionCollection, IDisposable
""expectedControlType"": ""Button"",
""processors"": """",
""interactions"": """"
},
{
""name"": ""Dock"",
""type"": ""Button"",
""id"": ""d6e65ce8-149c-4009-ac38-66144cca311a"",
""expectedControlType"": ""Button"",
""processors"": """",
""interactions"": """"
}
],
""bindings"": [
@ -831,6 +768,17 @@ public class @AetheriaInput : IInputActionCollection, IDisposable
""action"": ""Inventory"",
""isComposite"": false,
""isPartOfComposite"": false
},
{
""name"": """",
""id"": ""3279cef8-8bd1-49f2-984a-637d1f8522f6"",
""path"": ""<Keyboard>/#(C)"",
""interactions"": """",
""processors"": """",
""groups"": ""Keyboard&Mouse"",
""action"": ""Dock"",
""isComposite"": false,
""isPartOfComposite"": false
}
]
}
@ -863,17 +811,6 @@ public class @AetheriaInput : IInputActionCollection, IDisposable
}
]
},
{
""name"": ""Touch"",
""bindingGroup"": ""Touch"",
""devices"": [
{
""devicePath"": ""<Touchscreen>"",
""isOptional"": false,
""isOR"": false
}
]
},
{
""name"": ""Joystick"",
""bindingGroup"": ""Joystick"",
@ -884,17 +821,6 @@ public class @AetheriaInput : IInputActionCollection, IDisposable
""isOR"": false
}
]
},
{
""name"": ""XR"",
""bindingGroup"": ""XR"",
""devices"": [
{
""devicePath"": ""<XRController>"",
""isOptional"": false,
""isOR"": false
}
]
}
]
}");
@ -914,13 +840,12 @@ public class @AetheriaInput : IInputActionCollection, IDisposable
m_UI_ScrollWheel = m_UI.FindAction("ScrollWheel", throwIfNotFound: true);
m_UI_MiddleClick = m_UI.FindAction("MiddleClick", throwIfNotFound: true);
m_UI_RightClick = m_UI.FindAction("RightClick", throwIfNotFound: true);
m_UI_TrackedDevicePosition = m_UI.FindAction("TrackedDevicePosition", throwIfNotFound: true);
m_UI_TrackedDeviceOrientation = m_UI.FindAction("TrackedDeviceOrientation", throwIfNotFound: true);
m_UI_Drag = m_UI.FindAction("Drag", throwIfNotFound: true);
// Global
m_Global = asset.FindActionMap("Global", throwIfNotFound: true);
m_Global_MapToggle = m_Global.FindAction("Map Toggle", throwIfNotFound: true);
m_Global_Inventory = m_Global.FindAction("Inventory", throwIfNotFound: true);
m_Global_Dock = m_Global.FindAction("Dock", throwIfNotFound: true);
}
public void Dispose()
@ -1035,8 +960,6 @@ public class @AetheriaInput : IInputActionCollection, IDisposable
private readonly InputAction m_UI_ScrollWheel;
private readonly InputAction m_UI_MiddleClick;
private readonly InputAction m_UI_RightClick;
private readonly InputAction m_UI_TrackedDevicePosition;
private readonly InputAction m_UI_TrackedDeviceOrientation;
private readonly InputAction m_UI_Drag;
public struct UIActions
{
@ -1050,8 +973,6 @@ public class @AetheriaInput : IInputActionCollection, IDisposable
public InputAction @ScrollWheel => m_Wrapper.m_UI_ScrollWheel;
public InputAction @MiddleClick => m_Wrapper.m_UI_MiddleClick;
public InputAction @RightClick => m_Wrapper.m_UI_RightClick;
public InputAction @TrackedDevicePosition => m_Wrapper.m_UI_TrackedDevicePosition;
public InputAction @TrackedDeviceOrientation => m_Wrapper.m_UI_TrackedDeviceOrientation;
public InputAction @Drag => m_Wrapper.m_UI_Drag;
public InputActionMap Get() { return m_Wrapper.m_UI; }
public void Enable() { Get().Enable(); }
@ -1086,12 +1007,6 @@ public class @AetheriaInput : IInputActionCollection, IDisposable
@RightClick.started -= m_Wrapper.m_UIActionsCallbackInterface.OnRightClick;
@RightClick.performed -= m_Wrapper.m_UIActionsCallbackInterface.OnRightClick;
@RightClick.canceled -= m_Wrapper.m_UIActionsCallbackInterface.OnRightClick;
@TrackedDevicePosition.started -= m_Wrapper.m_UIActionsCallbackInterface.OnTrackedDevicePosition;
@TrackedDevicePosition.performed -= m_Wrapper.m_UIActionsCallbackInterface.OnTrackedDevicePosition;
@TrackedDevicePosition.canceled -= m_Wrapper.m_UIActionsCallbackInterface.OnTrackedDevicePosition;
@TrackedDeviceOrientation.started -= m_Wrapper.m_UIActionsCallbackInterface.OnTrackedDeviceOrientation;
@TrackedDeviceOrientation.performed -= m_Wrapper.m_UIActionsCallbackInterface.OnTrackedDeviceOrientation;
@TrackedDeviceOrientation.canceled -= m_Wrapper.m_UIActionsCallbackInterface.OnTrackedDeviceOrientation;
@Drag.started -= m_Wrapper.m_UIActionsCallbackInterface.OnDrag;
@Drag.performed -= m_Wrapper.m_UIActionsCallbackInterface.OnDrag;
@Drag.canceled -= m_Wrapper.m_UIActionsCallbackInterface.OnDrag;
@ -1123,12 +1038,6 @@ public class @AetheriaInput : IInputActionCollection, IDisposable
@RightClick.started += instance.OnRightClick;
@RightClick.performed += instance.OnRightClick;
@RightClick.canceled += instance.OnRightClick;
@TrackedDevicePosition.started += instance.OnTrackedDevicePosition;
@TrackedDevicePosition.performed += instance.OnTrackedDevicePosition;
@TrackedDevicePosition.canceled += instance.OnTrackedDevicePosition;
@TrackedDeviceOrientation.started += instance.OnTrackedDeviceOrientation;
@TrackedDeviceOrientation.performed += instance.OnTrackedDeviceOrientation;
@TrackedDeviceOrientation.canceled += instance.OnTrackedDeviceOrientation;
@Drag.started += instance.OnDrag;
@Drag.performed += instance.OnDrag;
@Drag.canceled += instance.OnDrag;
@ -1142,12 +1051,14 @@ public class @AetheriaInput : IInputActionCollection, IDisposable
private IGlobalActions m_GlobalActionsCallbackInterface;
private readonly InputAction m_Global_MapToggle;
private readonly InputAction m_Global_Inventory;
private readonly InputAction m_Global_Dock;
public struct GlobalActions
{
private @AetheriaInput m_Wrapper;
public GlobalActions(@AetheriaInput wrapper) { m_Wrapper = wrapper; }
public InputAction @MapToggle => m_Wrapper.m_Global_MapToggle;
public InputAction @Inventory => m_Wrapper.m_Global_Inventory;
public InputAction @Dock => m_Wrapper.m_Global_Dock;
public InputActionMap Get() { return m_Wrapper.m_Global; }
public void Enable() { Get().Enable(); }
public void Disable() { Get().Disable(); }
@ -1163,6 +1074,9 @@ public class @AetheriaInput : IInputActionCollection, IDisposable
@Inventory.started -= m_Wrapper.m_GlobalActionsCallbackInterface.OnInventory;
@Inventory.performed -= m_Wrapper.m_GlobalActionsCallbackInterface.OnInventory;
@Inventory.canceled -= m_Wrapper.m_GlobalActionsCallbackInterface.OnInventory;
@Dock.started -= m_Wrapper.m_GlobalActionsCallbackInterface.OnDock;
@Dock.performed -= m_Wrapper.m_GlobalActionsCallbackInterface.OnDock;
@Dock.canceled -= m_Wrapper.m_GlobalActionsCallbackInterface.OnDock;
}
m_Wrapper.m_GlobalActionsCallbackInterface = instance;
if (instance != null)
@ -1173,6 +1087,9 @@ public class @AetheriaInput : IInputActionCollection, IDisposable
@Inventory.started += instance.OnInventory;
@Inventory.performed += instance.OnInventory;
@Inventory.canceled += instance.OnInventory;
@Dock.started += instance.OnDock;
@Dock.performed += instance.OnDock;
@Dock.canceled += instance.OnDock;
}
}
}
@ -1195,15 +1112,6 @@ public class @AetheriaInput : IInputActionCollection, IDisposable
return asset.controlSchemes[m_GamepadSchemeIndex];
}
}
private int m_TouchSchemeIndex = -1;
public InputControlScheme TouchScheme
{
get
{
if (m_TouchSchemeIndex == -1) m_TouchSchemeIndex = asset.FindControlSchemeIndex("Touch");
return asset.controlSchemes[m_TouchSchemeIndex];
}
}
private int m_JoystickSchemeIndex = -1;
public InputControlScheme JoystickScheme
{
@ -1213,15 +1121,6 @@ public class @AetheriaInput : IInputActionCollection, IDisposable
return asset.controlSchemes[m_JoystickSchemeIndex];
}
}
private int m_XRSchemeIndex = -1;
public InputControlScheme XRScheme
{
get
{
if (m_XRSchemeIndex == -1) m_XRSchemeIndex = asset.FindControlSchemeIndex("XR");
return asset.controlSchemes[m_XRSchemeIndex];
}
}
public interface IPlayerActions
{
void OnMove(InputAction.CallbackContext context);
@ -1239,13 +1138,12 @@ public class @AetheriaInput : IInputActionCollection, IDisposable
void OnScrollWheel(InputAction.CallbackContext context);
void OnMiddleClick(InputAction.CallbackContext context);
void OnRightClick(InputAction.CallbackContext context);
void OnTrackedDevicePosition(InputAction.CallbackContext context);
void OnTrackedDeviceOrientation(InputAction.CallbackContext context);
void OnDrag(InputAction.CallbackContext context);
}
public interface IGlobalActions
{
void OnMapToggle(InputAction.CallbackContext context);
void OnInventory(InputAction.CallbackContext context);
void OnDock(InputAction.CallbackContext context);
}
}

View file

@ -1,4 +1,8 @@
using System.Collections;
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Unity.Mathematics;

View file

@ -1,4 +1,8 @@
using System;
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;

View file

@ -1,4 +1,8 @@
using System;
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
@ -165,10 +169,16 @@ public class DatabaseInspector : EditorWindow
else if (type == typeof(bool)) field.SetValue(obj, Inspect(field.Name.SplitCamelCase(), (bool) value));
else if (type == typeof(string))
{
if (inspectable is InspectableUnityObjectAttribute unityObjectAttribute)
{
var inspectMethod = typeof(DatabaseInspector).GetMethod("InspectUnityObject");
var generic = inspectMethod.MakeGenericMethod(unityObjectAttribute.ObjectType);
field.SetValue(obj, generic.Invoke(this, new[] {value}));
}
if(inspectable is InspectablePrefabAttribute)
field.SetValue(obj, InspectGameObject(field.Name.SplitCamelCase(), (string) value));
field.SetValue(obj, InspectUnityObject<GameObject>(field.Name.SplitCamelCase(), (string) value));
else if(inspectable is InspectableTextureAttribute)
field.SetValue(obj, InspectTexture(field.Name.SplitCamelCase(), (string) value));
field.SetValue(obj, InspectUnityObject<Texture2D>(field.Name.SplitCamelCase(), (string) value));
else
field.SetValue(obj, Inspect(field.Name.SplitCamelCase(), (string) value, inspectable is InspectableTextAttribute));
}
@ -660,21 +670,12 @@ public class DatabaseInspector : EditorWindow
return index == 0 ? null : types[index - 1];
}
public string InspectGameObject(string label, string value)
public string InspectUnityObject<T>(string label, string value) where T : Object
{
using (var h = new HorizontalScope())
{
GUILayout.Label(label, GUILayout.Width(width));
return AssetDatabase.GetAssetPath(ObjectField(AssetDatabase.LoadAssetAtPath<GameObject>(value), typeof(GameObject), false));
}
}
public string InspectTexture(string label, string value)
{
using (var h = new HorizontalScope())
{
GUILayout.Label(label, GUILayout.Width(width));
return AssetDatabase.GetAssetPath(ObjectField(AssetDatabase.LoadAssetAtPath<Texture2D>(value), typeof(Texture2D), false));
return AssetDatabase.GetAssetPath(ObjectField(AssetDatabase.LoadAssetAtPath<T>(value), typeof(T), false));
}
}

View file

@ -1,4 +1,7 @@
// TODO: USE THIS EVERYWHERE
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
using System;
using System.Collections.Generic;
using System.IO;

View file

@ -1,4 +1,8 @@
using System;
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
using System;
using System.Collections.Generic;
using System.Linq;
using MIConvexHull;

View file

@ -1,4 +1,8 @@
using System;
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;

View file

@ -1,4 +1,8 @@
using System;
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;

View file

@ -1,4 +1,8 @@
using System;
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

View file

@ -1,4 +1,8 @@
using System.Collections;
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;

View file

@ -1,4 +1,8 @@
using System;
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
using System;
using System.Collections.Generic;
using UnityEngine;

View file

@ -47,6 +47,7 @@ public class Prototype : MonoBehaviour {
var instanceIdx = _instancePool.Count-1;
instance = _instancePool[instanceIdx];
_instancePool.RemoveAt(instanceIdx);
instance.transform.SetAsLastSibling();
}
// Instantiate fresh instance

View file

@ -1,4 +1,8 @@
using System;
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
using System;
using System.Collections;
using System.Collections.Generic;
using System.Reflection;

View file

@ -1,4 +1,8 @@
using System;
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

View file

@ -1,4 +1,8 @@
using System.Collections;
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

View file

@ -1,4 +1,8 @@
using System.Collections;
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

View file

@ -1,4 +1,8 @@
using System.Collections;
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.IO;

View file

@ -1,4 +1,8 @@
using System.Collections;
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

View file

@ -1,4 +1,8 @@
using System;
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

View file

@ -1,4 +1,8 @@
using System.Collections;
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

View file

@ -1,4 +1,8 @@
using System;
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
@ -8,6 +12,7 @@ using UnityEngine;
using static Unity.Mathematics.math;
using Unity.Mathematics;
using UnityEngine.Serialization;
using Object = UnityEngine.Object;
using Random = UnityEngine.Random;
public class SectorRenderer : MonoBehaviour
@ -27,6 +32,8 @@ public class SectorRenderer : MonoBehaviour
public int AsteroidSpritesheetWidth = 4;
public int AsteroidSpritesheetHeight = 4;
public LODHandler LODHandler;
[Header("Tour")]
public bool Tour;
public float TourSwitchTime = 5f;
public float TourFollowDistance = 30f;
@ -46,8 +53,14 @@ public class SectorRenderer : MonoBehaviour
public Texture2D PlanetoidIcon;
public Texture2D PlanetIcon;
[HideInInspector]
public Dictionary<OrbitalEntity, Transform> Orbitals = new Dictionary<OrbitalEntity, Transform>();
[HideInInspector]
public Dictionary<Ship, ShipInstance> Ships = new Dictionary<Ship, ShipInstance>();
[HideInInspector]
public Dictionary<Guid, PlanetObject> Planets = new Dictionary<Guid, PlanetObject>();
private Dictionary<Guid, AsteroidBeltUI> _beltObjects = new Dictionary<Guid, AsteroidBeltUI>();
private Dictionary<Guid, PlanetObject> _planets = new Dictionary<Guid, PlanetObject>();
private Dictionary<Guid, InstancedMesh[]> _beltMeshes = new Dictionary<Guid, InstancedMesh[]>();
private Dictionary<Guid, Matrix4x4[][]> _beltMatrices = new Dictionary<Guid, Matrix4x4[][]>();
private Dictionary<Guid, float3[]> _beltAsteroidPositions = new Dictionary<Guid, float3[]>();
@ -61,6 +74,8 @@ public class SectorRenderer : MonoBehaviour
private CinemachineTransposer _transposer;
private PlanetObject _root;
private bool _rootFound;
public ItemManager ItemManager { get; set; }
public float Time { get; set; }
@ -105,7 +120,7 @@ public class SectorRenderer : MonoBehaviour
foreach(var p in zone.Planets.Values)
LoadPlanet(p);
foreach (var x in _planets)
foreach (var x in Planets)
{
if (!(zone.Planets[x.Key] is GasGiantData))
{
@ -124,7 +139,7 @@ public class SectorRenderer : MonoBehaviour
if (parentPlanetData == null)
parent = _root;
else if (!_planets.TryGetValue(parentPlanetData.ID, out parent))
else if (!Planets.TryGetValue(parentPlanetData.ID, out parent))
{
Debug.Log("WTF!");
}
@ -132,23 +147,72 @@ public class SectorRenderer : MonoBehaviour
_tourPlanets.Add((x.Value.Body.transform, parent.Body.transform));
}
}
foreach(var entity in zone.Entities)
LoadEntity(entity);
zone.Entities.ObserveAdd().Subscribe(e => LoadEntity(e.Value));
zone.Entities.ObserveRemove().Subscribe(e => UnloadEntity(e.Value));
}
public void ClearZone()
{
if (_planets.Count > 0)
if (Planets.Count > 0)
{
foreach (var planet in _planets.Values)
foreach (var planet in Planets.Values)
{
DestroyImmediate(planet.gameObject);
}
_planets.Clear();
Planets.Clear();
_beltMeshes.Clear();
_beltMatrices.Clear();
_tourPlanets.Clear();
}
}
void LoadEntity(Entity entity)
{
var hullData = ItemManager.GetData(entity.Hull) as HullData;
if (entity is Ship ship)
{
var shipInstance = new ShipInstance();
shipInstance.Ship = ship;
shipInstance.Transform = Instantiate(UnityHelpers.LoadAsset<GameObject>(hullData.Prefab)).transform;
shipInstance.Thrusters = ship.GetBehaviors<Thruster>().ToArray();
shipInstance.ThrusterParticles = shipInstance.Thrusters
.Select(x =>
{
var particles = Instantiate(UnityHelpers.LoadAsset<ParticleSystem>(((ThrusterData) x.Data).ParticlesPrefab));
var particlesShape = particles.shape;
particlesShape.meshRenderer = shipInstance.Transform.Find(x.Entity.Hardpoints[x.Item.Position.x, x.Item.Position.y].Transform)
.GetComponent<MeshRenderer>();
return particles;
})
.ToArray();
shipInstance.ThrusterBaseEmission = shipInstance.ThrusterParticles.Select(x => x.emission.rateOverTimeMultiplier).ToArray();
Ships.Add(ship, shipInstance);
}
else if (entity is OrbitalEntity orbital)
{
Orbitals.Add(orbital,Instantiate(UnityHelpers.LoadAsset<GameObject>(hullData.Prefab)).transform);
}
}
void UnloadEntity(Entity entity)
{
if (entity is Ship ship)
{
Destroy(Ships[ship].Transform.gameObject);
foreach(var p in Ships[ship].ThrusterParticles)
Destroy(p.gameObject);
Ships.Remove(ship);
}
else if (entity is OrbitalEntity orbital)
{
Destroy(Orbitals[orbital].gameObject);
Orbitals.Remove(orbital);
}
}
void LoadPlanet(BodyData planetData)
{
if (planetData is AsteroidBeltData beltData)
@ -226,7 +290,7 @@ public class SectorRenderer : MonoBehaviour
planetInstance.BodyData.Mass.Subscribe(f => planet.Icon.transform.localScale = Settings.IconSize.Evaluate(f) * Vector3.one);
_planets[planetData.ID] = planet;
Planets[planetData.ID] = planet;
if (!_rootFound)
{
_rootFound = true;
@ -236,32 +300,32 @@ public class SectorRenderer : MonoBehaviour
LODHandler.FindPlanets();
}
private void Update()
{
if (Tour)
{
_tourTimer -= UnityEngine.Time.deltaTime;
if (_tourTimer < 0)
{
_tourTimer = TourSwitchTime;
_tourIndex = (_tourIndex + 1) % _tourPlanets.Count;
SceneCamera.Follow = _tourPlanets[_tourIndex].Item1;
SceneCamera.LookAt = _tourPlanets[_tourIndex].Item2;
if(_tourIndex==0) Debug.Log("Tour Complete!");
}
// if(_tourIndex>=0)
// {
// var offset = (SceneCamera.Follow.position - SceneCamera.LookAt.position);
// offset.y = 0;
// offset = offset.normalized * TourFollowDistance;
// offset.y = TourHeightOffset;
// offset = Quaternion.AngleAxis(TourFollowOffsetDegrees, Vector3.up) * offset;
// _transposer.m_FollowOffset = offset;
// }
}
}
// private void Update()
// {
// if (Tour)
// {
// _tourTimer -= UnityEngine.Time.deltaTime;
// if (_tourTimer < 0)
// {
// _tourTimer = TourSwitchTime;
// _tourIndex = (_tourIndex + 1) % _tourPlanets.Count;
// SceneCamera.Follow = _tourPlanets[_tourIndex].Item1;
// SceneCamera.LookAt = _tourPlanets[_tourIndex].Item2;
// if(_tourIndex==0) Debug.Log("Tour Complete!");
// }
// // if(_tourIndex>=0)
// // {
// // var offset = (SceneCamera.Follow.position - SceneCamera.LookAt.position);
// // offset.y = 0;
// // offset = offset.normalized * TourFollowDistance;
// // offset.y = TourHeightOffset;
// // offset = Quaternion.AngleAxis(TourFollowOffsetDegrees, Vector3.up) * offset;
// // _transposer.m_FollowOffset = offset;
// // }
// }
// }
void LateUpdate()
void Update()
{
foreach(var belt in _zone.AsteroidBelts)
{
@ -287,7 +351,7 @@ public class SectorRenderer : MonoBehaviour
_beltObjects[belt.Key].Update(_beltAsteroidPositions[belt.Key]);
}
foreach (var planet in _planets)
foreach (var planet in Planets)
{
var planetInstance = _zone.PlanetInstances[planet.Key];
var p = _zone.GetOrbitPosition(planetInstance.BodyData.Orbit);
@ -305,6 +369,30 @@ public class SectorRenderer : MonoBehaviour
else planet.Value.Body.transform.rotation *= Quaternion.AngleAxis(Settings.PlanetRotationSpeed, Vector3.up);
}
foreach (var ship in Ships)
{
var hullData = ItemManager.GetData(ship.Key.Hull) as HullData;
var h = _zone.GetHeight(ship.Key.Position);
ship.Value.Transform.position = new Vector3(ship.Key.Position.x,h + hullData.GridOffset,ship.Key.Position.y);
var normal = _zone.GetNormal(ship.Key.Position);
//Debug.Log($"Normal: {normal}");
var shipRight = ship.Key.Direction.Rotate(ItemRotation.Clockwise);
var forward = Vector3.Cross(new Vector3(shipRight.x,0,shipRight.y), normal);
ship.Value.Transform.rotation = Quaternion.LookRotation(forward, normal);
for (int i = 0; i < ship.Value.Thrusters.Length; i++)
{
var emissionModule = ship.Value.ThrusterParticles[i].emission;
emissionModule.rateOverTimeMultiplier = ship.Value.ThrusterBaseEmission[i] * ship.Value.Thrusters[i].Axis;
}
}
foreach (var orbital in Orbitals)
{
var hullData = ItemManager.GetData(orbital.Key.Hull) as HullData;
var h = _zone.GetHeight(orbital.Key.Position);
orbital.Value.position = new Vector3(orbital.Key.Position.x,h + hullData.GridOffset,orbital.Key.Position.y);
}
var fogPos = FogCameraParent.position;
SectorBoundaryBrush.material.SetFloat("_Power", Settings.PlanetSettings.ZoneDepthExponent);
SectorBoundaryBrush.material.SetFloat("_Depth", Settings.PlanetSettings.ZoneDepth + Settings.PlanetSettings.ZoneBoundaryFog);
@ -321,6 +409,15 @@ public class SectorRenderer : MonoBehaviour
}
}
public class ShipInstance
{
public ParticleSystem[] ThrusterParticles;
public Thruster[] Thrusters;
public float[] ThrusterBaseEmission;
public Ship Ship;
public Transform Transform;
}
[Serializable]
public class InstancedMesh
{

View file

@ -1,4 +1,8 @@
using System.Collections;
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

View file

@ -1,4 +1,8 @@
using System.Collections;
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using static Unity.Mathematics.math;

View file

@ -1,4 +1,8 @@
using System.Collections;
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

View file

@ -1,4 +1,8 @@
using System;
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
using System;
using UnityEngine;
/// <summary>

View file

@ -1,4 +1,8 @@
using System.Collections;
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

View file

@ -1,4 +1,8 @@
using System;
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
using System;
using System.Collections;
using System.Collections.Generic;

View file

@ -1,4 +1,8 @@
using System.Collections;
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
using System.Collections;
using System.Collections.Generic;
using Unity.Mathematics;
using static Unity.Mathematics.math;

View file

@ -1,4 +1,8 @@
using System;
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
using System;
using System.Collections;
using System.Collections.Generic;
using JsonKnownTypes;

View file

@ -1,4 +1,8 @@
using System.Collections;
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using Unity.Mathematics;

View file

@ -1,4 +1,8 @@
using System;
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
using System;
using System.Collections;
using System.Collections.Generic;
using MessagePack;

View file

@ -1,4 +1,8 @@
using System;
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;

View file

@ -1,4 +1,8 @@
using System;
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
using System;
using System.Collections;
using System.Collections.Generic;
using JsonKnownTypes;

View file

@ -1,4 +1,8 @@
using System;
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
using System;
using System.Collections;
using System.Collections.Generic;
using JsonKnownTypes;

View file

@ -1,4 +1,8 @@
using System;
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
using System;
using System.Collections;
using System.Collections.Generic;
using JsonKnownTypes;

View file

@ -1,4 +1,8 @@
using System;
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;

View file

@ -1,3 +1,6 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
public class WanderTask : AgentTask
{

View file

@ -1,4 +1,8 @@
using System;
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
using System;
public class NameAttribute : Attribute
{
@ -52,6 +56,17 @@ public class InspectableFieldAttribute : Attribute { }
[AttributeUsage(AttributeTargets.Field)]
public class InspectableTextAttribute : InspectableFieldAttribute { }
[AttributeUsage(AttributeTargets.Field)]
public class InspectableUnityObjectAttribute : InspectableFieldAttribute
{
public Type ObjectType;
public InspectableUnityObjectAttribute(Type type)
{
ObjectType = type;
}
}
[AttributeUsage(AttributeTargets.Field)]
public class InspectablePrefabAttribute : InspectableFieldAttribute { }

View file

@ -1,91 +0,0 @@
using System.Collections.Generic;
using System.Linq;
using MessagePack;
using Newtonsoft.Json;
// [InspectableField, MessagePackObject, JsonObject(MemberSerialization.OptIn)]
// public class AfterburnerData : BehaviorData
// {
// [InspectableField, JsonProperty("thrust"), Key(1)]
// public PerformanceStat ThrustModifier = new PerformanceStat();
//
// [InspectableField, JsonProperty("speed"), Key(2)]
// public PerformanceStat SpeedModifier = new PerformanceStat();
//
// [InspectableField, JsonProperty("torque"), Key(3)]
// public PerformanceStat TorqueModifier = new PerformanceStat();
//
// public override IBehavior CreateInstance(GameContext context, Entity entity, Gear item)
// {
// return new Afterburner(context, this, entity, item);
// }
// }
//
// public class Afterburner : IActivatedBehavior
// {
// private List<Dictionary<IBehavior,float>> _modifiers = new List<Dictionary<IBehavior, float>>();
// private AfterburnerData _data;
// private Thruster _thruster;
// private int _thrustAxis;
//
// public Entity Entity { get; }
// public Gear Item { get; }
// public GameContext Context { get; }
//
// public BehaviorData Data => _data;
//
// public Afterburner(GameContext context, AfterburnerData data, Entity entity, Gear item)
// {
// Context = context;
// _data = data;
// Entity = entity;
// Item = item;
// }
//
// public void Initialize()
// {
// _thruster = Entity.GetBehaviors<Thruster>().FirstOrDefault();
// _thrustAxis = Entity.GetAxis<Thruster>();
// }
//
// public bool Update(float delta)
// {
// return true;
// }
//
// public bool Activate()
// {
// if (_thruster == null) return false;
//
// var thrustMod = ((ThrusterData) _thruster.Data).Thrust.GetScaleModifiers(Entity);
// thrustMod.Add(this,Context.Evaluate(_data.ThrustModifier,Item, Entity));
// _modifiers.Add(thrustMod);
//
// Entity.AxisOverrides[_thrustAxis] = 1;
//
// return true;
//
// // var speedMod = (Ship.Hull.ItemData as HullData).TopSpeed.GetScaleModifiers(Ship);
// // _modifiers.Add(speedMod);
// // speedMod.Add(this,Context.Evaluate(_data.SpeedModifier,Item, Ship));
// //
// // var torqueMod = (Ship.GetEquipped(HardpointType.Thruster).ItemData as ThrusterData).Torque.GetScaleModifiers(Ship);
// // _modifiers.Add(torqueMod);
// // torqueMod.Add(this,Context.Evaluate(_data.TorqueModifier,Item, Ship));
// }
//
// public void Deactivate()
// {
// Entity.AxisOverrides.Remove(_thrustAxis);
// foreach (var mod in _modifiers)
// {
// mod.Remove(this);
// }
// _modifiers.Clear();
// }
//
// public void Remove()
// {
// }
// }

View file

@ -1,3 +0,0 @@
fileFormatVersion: 2
guid: 967ca96c9f90416887db9a6a0341f58c
timeCreated: 1584292755

View file

@ -1,4 +1,8 @@
using System;
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;

View file

@ -1,4 +1,8 @@
using System;
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
using System;
using System.Collections;
using System.Collections.Generic;
using MessagePack;

View file

@ -1,4 +1,8 @@
using System;
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
using System;
using System.Linq;
using MessagePack;
using Newtonsoft.Json;

View file

@ -1,4 +1,8 @@
using System;
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
using System;
using System.Linq;
using MessagePack;
using Newtonsoft.Json;

View file

@ -1,4 +1,8 @@
using System;
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
using System;
using System.Collections.Generic;
using System.Linq;
using MessagePack;

View file

@ -1,4 +1,8 @@
using System;
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;

View file

@ -1,4 +1,8 @@
using System;
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
using System;
using System.Linq;
using MessagePack;
using Newtonsoft.Json;

View file

@ -1,4 +1,8 @@
using MessagePack;
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
using MessagePack;
using Newtonsoft.Json;
[InspectableField, MessagePackObject, JsonObject(MemberSerialization.OptIn)]

View file

@ -1,4 +1,7 @@

/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
using System;
using System.Linq;
using MessagePack;

View file

@ -1,4 +1,6 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
using MessagePack;
using Newtonsoft.Json;

View file

@ -1,4 +1,8 @@
using System;
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;

View file

@ -1,4 +1,8 @@
using System;
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
using System;
using System.Linq;
using MessagePack;
using Newtonsoft.Json;

View file

@ -1,4 +1,8 @@
using System;
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;

View file

@ -1,3 +1,7 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
using MessagePack;
using Newtonsoft.Json;

View file

@ -1,4 +1,8 @@
using System;
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
using System;
using System.Linq;
using MessagePack;
using Newtonsoft.Json;

View file

@ -1,3 +1,7 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
using MessagePack;
using Newtonsoft.Json;
using Unity.Mathematics;

View file

@ -1,3 +1,7 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
using MessagePack;
using Newtonsoft.Json;

View file

@ -1,3 +1,7 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
using MessagePack;
using Newtonsoft.Json;
using Unity.Mathematics;

View file

@ -1,4 +1,8 @@
using System;
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
using System;
using System.Linq;
using MessagePack;
using Newtonsoft.Json;

View file

@ -1,3 +1,6 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
using MessagePack;
using Newtonsoft.Json;

View file

@ -1,3 +1,7 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
using MessagePack;
using Newtonsoft.Json;
using Unity.Mathematics;

View file

@ -1,4 +1,8 @@
using System;
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
using System;
using System.Linq;
using MessagePack;
using Newtonsoft.Json;

View file

@ -1,4 +1,8 @@
using System;
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;

View file

@ -1,4 +1,8 @@
using System;
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
using System;
using System.Linq;
using MessagePack;
using Newtonsoft.Json;

View file

@ -1,4 +1,8 @@
using System;
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
using System;
using System.Linq;
using MessagePack;
using Newtonsoft.Json;

View file

@ -1,3 +1,7 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
using MessagePack;
using Newtonsoft.Json;
using Unity.Mathematics;
@ -14,6 +18,9 @@ public class ThrusterData : BehaviorData
[InspectableField, JsonProperty("heat"), Key(3)]
public PerformanceStat Heat = new PerformanceStat();
[InspectablePrefab, JsonProperty("Particles"), Key(4)]
public string ParticlesPrefab;
public override IBehavior CreateInstance(ItemManager context, Entity entity, EquippedItem item)
{
@ -28,6 +35,7 @@ public class Thruster : IAnalogBehavior
public ItemManager Context { get; }
public float Thrust { get; private set; }
public float Torque { get; }
public float Axis
{
@ -47,12 +55,19 @@ public class Thruster : IAnalogBehavior
_data = data;
Entity = entity;
Item = item;
var hullData = context.GetData(entity.Hull) as HullData;
var hullCenter = hullData.Shape.CenterOfMass;
var itemData = context.GetData(item.EquippableItem);
var itemCenter = hullData.Shape.Inset(itemData.Shape, item.Position, item.EquippableItem.Rotation).CenterOfMass;
var toCenter = hullCenter - itemCenter;
Torque = -dot(toCenter, float2(1, 0).Rotate(item.EquippableItem.Rotation));
}
public bool Update(float delta)
{
Thrust = Context.Evaluate(_data.Thrust, Item.EquippableItem, Entity);
Entity.Velocity += Entity.Direction * _input * Thrust / Entity.Mass * delta;
Entity.Velocity -= Entity.Direction.Rotate(Item.EquippableItem.Rotation) * _input * Thrust / Entity.Mass * delta;
Entity.Direction = mul(Entity.Direction, Unity.Mathematics.float2x2.Rotate(_input * Torque * Thrust / Entity.Mass / 100 * delta));
Item.Temperature += (_input * Context.Evaluate(_data.Heat, Item.EquippableItem, Entity) * delta) / Context.GetThermalMass(Item.EquippableItem);
Entity.VisibilitySources[this] = _input * Context.Evaluate(_data.Visibility, Item.EquippableItem, Entity);
return true;

View file

@ -1,4 +1,8 @@
using System;
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;

View file

@ -1,4 +1,8 @@
using System;
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
using System;
using System.Linq;
using MessagePack;
using Newtonsoft.Json;

View file

@ -1,3 +1,7 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
using MessagePack;
using Newtonsoft.Json;
using Unity.Mathematics;

View file

@ -1,3 +1,7 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
using MessagePack;
using Newtonsoft.Json;
using Unity.Mathematics;

View file

@ -1,3 +1,7 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
using MessagePack;
using Newtonsoft.Json;
using Unity.Mathematics;

View file

@ -1,4 +1,8 @@
using System;
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
using System;
using System.Linq;
using MessagePack;
using Newtonsoft.Json;

View file

@ -1,4 +1,8 @@
using System;
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;

View file

@ -1,3 +1,7 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
using MessagePack;
using Newtonsoft.Json;

View file

@ -1,4 +1,8 @@
using System;
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
using System;
using System.Collections;
using System.Collections.Generic;
using MessagePack;

View file

@ -1,4 +1,8 @@
using System.Collections;
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
using System.Collections;
using System.Collections.Generic;
using Unity.Mathematics;
using static Unity.Mathematics.math;

View file

@ -1,4 +1,8 @@
using System;
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
using System;
using System.Collections;
using System.Collections.Generic;
using MessagePack;

View file

@ -1,4 +1,8 @@
using System;
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;

View file

@ -1,4 +1,8 @@
using System;
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
using System;
using System.Linq;
using JsonKnownTypes;
using MessagePack;

View file

@ -1,3 +1,7 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
using System;
using System.Collections.Generic;
using System.Linq;
@ -61,13 +65,12 @@ public abstract class Entity
_active = value;
if (_active)
{
foreach (var hardpoint in Equipment)
if(hardpoint.EquippableItem!=null)
foreach (var behavior in hardpoint.Behaviors)
{
if(behavior is IInitializableBehavior initializableBehavior)
initializableBehavior.Initialize();
}
foreach (var item in Equipment)
foreach (var behavior in item.Behaviors)
{
if(behavior is IInitializableBehavior initializableBehavior)
initializableBehavior.Initialize();
}
}
}
}
@ -84,6 +87,10 @@ public abstract class Entity
private void MapShip()
{
var hullData = ItemManager.GetData(Hull) as HullData;
var hull = new EquippedItem(ItemManager, Hull, int2.zero);
Equipment.Add(hull);
Hydrate(hull);
Mass = hullData.Mass;
GearOccupancy = new EquippedItem[hullData.Shape.Width, hullData.Shape.Height];
ThermalOccupancy = new EquippedItem[hullData.Shape.Width, hullData.Shape.Height];
Hardpoints = new HardpointData[hullData.Shape.Width, hullData.Shape.Height];
@ -197,6 +204,7 @@ public abstract class Entity
foreach (var i in hullData.Shape.Coordinates)
if (itemLayer[i.x, i.y] == item)
itemLayer[i.x, i.y] = null;
Mass -= itemData.Mass;
return item.EquippableItem;
}
@ -340,7 +348,8 @@ public abstract class Entity
var occupiedCoord = hullCoord + itemData.Shape.Rotate(i, item.Rotation);
(itemData.HardpointType == HardpointType.Thermal ? ThermalOccupancy : GearOccupancy)[occupiedCoord.x, occupiedCoord.y] = equippedItem;
}
Mass += itemData.Mass;
Hydrate(equippedItem);
return true;
}
@ -355,6 +364,7 @@ public abstract class Entity
(itemData.HardpointType == HardpointType.Thermal ? ThermalOccupancy : GearOccupancy)[occupiedCoord.x, occupiedCoord.y] = equippedItem;
}
Mass += itemData.Mass;
Hydrate(equippedItem);
return true;
}
@ -480,6 +490,8 @@ public abstract class Entity
Messages.Remove(message);
}
}
foreach(var child in Children)
child.Update(delta);
if (Parent != null)
{
@ -551,11 +563,11 @@ public class EquippedItem
public void Update(float delta)
{
if(Temperature < _data.MinimumTemperature || Temperature > _data.MaximumTemperature)
{
EquippableItem.Durability -= delta;
return;
}
// if(Temperature < _data.MinimumTemperature || Temperature > _data.MaximumTemperature)
// {
// EquippableItem.Durability -= delta;
// return;
// }
foreach (var group in BehaviorGroups)
{

View file

@ -1,11 +1,15 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
using System;
public enum ItemRotation
{
None = 0,
Clockwise = 1,
CounterClockwise = 1,
Reversed = 2,
CounterClockwise = 3
Clockwise = 3
}
public enum LauncherCaliber

View file

@ -1,4 +1,8 @@
using System;
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
using System;
using System.Collections;
using System.Collections.Generic;
using MessagePack;

View file

@ -5,12 +5,14 @@ using System.Linq;
using System.Numerics;
using System.Reflection;
using System.Text.RegularExpressions;
using Grpc.Core;
using LiteNetLib;
using MessagePack;
using Unity.Mathematics;
using static Unity.Mathematics.math;
using Random = Unity.Mathematics.Random;
using Unity.Tiny;
using float2 = Unity.Mathematics.float2;
public static class Extensions
{
@ -60,6 +62,40 @@ public static class Extensions
throw new ArgumentOutOfRangeException(nameof(rot), rot, null);
}
}
public static float2 Direction(this ItemRotation rotation)
{
switch (rotation)
{
case ItemRotation.None:
return float2(0, 1);
case ItemRotation.CounterClockwise:
return float2(-1, 0);
case ItemRotation.Reversed:
return float2(0, -1);
case ItemRotation.Clockwise:
return float2(1, 0);
default:
throw new ArgumentOutOfRangeException(nameof(rotation), rotation, null);
}
}
public static float2 Rotate(this float2 v, ItemRotation rotation)
{
switch (rotation)
{
case ItemRotation.None:
return v;
case ItemRotation.CounterClockwise:
return float2(-v.y, v.x);
case ItemRotation.Reversed:
return float2(-v.x, -v.y);
case ItemRotation.Clockwise:
return float2(v.y, -v.x);
default:
throw new ArgumentOutOfRangeException(nameof(rotation), rotation, null);
}
}
public static string SplitCamelCase( this string str )
{

View file

@ -1,4 +1,8 @@
using System;
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
using System;
using System.Collections;
using System.Collections.Generic;
using MessagePack;

View file

@ -1,3 +1,7 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
using System;
using System.Collections;
using System.Collections.Generic;
@ -7,6 +11,7 @@ using MessagePack;
using Newtonsoft.Json;
using Unity.Mathematics;
using static Unity.Mathematics.math;
using float2 = Unity.Mathematics.float2;
using int2 = Unity.Mathematics.int2;
[InspectableField, MessagePackObject, JsonObject(MemberSerialization.OptIn)]
@ -83,7 +88,11 @@ public class Shape
{
get
{
if (_dirty) _cachedShapeCoordinates = EnumerateShapeCoordinates().ToArray();
if (_dirty)
{
_cachedShapeCoordinates = EnumerateShapeCoordinates().ToArray();
_dirty = false;
}
return _cachedShapeCoordinates;
}
}
@ -115,6 +124,12 @@ public class Shape
}
}
private float2? _centerOfMass;
[IgnoreMember]
public float2 CenterOfMass => _centerOfMass ?? (_centerOfMass = Coordinates
.Aggregate(float2.zero, (total, coord) => total + coord) / Coordinates.Length).Value;
public bool this[int2 pos] {
get { return pos.x >= 0 && pos.y >= 0 && pos.x < Width && pos.y < Height && Cells[pos.x, pos.y]; }
set

View file

@ -1,4 +1,8 @@
using System;
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;

View file

@ -1,4 +1,8 @@
using System;
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;

View file

@ -1,3 +1,7 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
using System;
using System.Collections.Generic;
using MessagePack;

View file

@ -1,4 +1,8 @@
using System;
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
using System;
using System.Collections;
using System.Collections.Generic;
using LiteNetLib;

View file

@ -1,4 +1,8 @@
using System;
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
using System;
using System.Collections;
using System.Collections.Generic;
using Unity.Mathematics;

View file

@ -1,3 +1,7 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
using System;
using MessagePack;
using Newtonsoft.Json;

View file

@ -1,4 +1,8 @@
using System;
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
using System;
using System.Collections;
using System.Collections.Generic;
using MessagePack;

View file

@ -1,4 +1,8 @@
using System;
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;

View file

@ -1,4 +1,8 @@
using System;
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
@ -11,7 +15,7 @@ using Random = Unity.Mathematics.Random;
public class Zone
{
//public HashSet<Guid> Planets = new HashSet<Guid>();
public List<Entity> Entities = new List<Entity>();
public ReactiveCollection<Entity> Entities = new ReactiveCollection<Entity>();
//public Dictionary<Guid, OrbitData> Orbits = new Dictionary<Guid, OrbitData>();
public Dictionary<Guid, BodyData> Planets = new Dictionary<Guid, BodyData>();
public Dictionary<Guid, Planet> PlanetInstances = new Dictionary<Guid, Planet>();
@ -65,7 +69,7 @@ public class Zone
return new ZonePack
{
Data = Data,
Entities = Entities,
Entities = Entities.ToList(),
Orbits = Orbits.Values.Select(o=>o.Data).ToList(),
Planets = Planets.Values.ToList()
};
@ -312,7 +316,7 @@ public class Zone
return PowerPulse(x, maskExponent) * cos(pow(x, sineExponent) * frequency + phase);
}
public float3 GetNormal(float2 pos, float step, float mul)
public float3 GetNormal(float2 pos, float step = .1f, float mul = 1)
{
float hL = GetHeight(new float2(pos.x - step, pos.y)) * mul;
float hR = GetHeight(new float2(pos.x + step, pos.y)) * mul;
@ -320,14 +324,8 @@ public class Zone
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);
float3 normal = new float3((hL - hR), (hD - hU), step*2);
return normalize(normal).xzy;
}
public override int GetHashCode()

View file

@ -1,4 +1,8 @@
using System;
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
using System;
using System.Collections;
using System.Collections.Generic;
using MessagePack;

View file

@ -1,4 +1,8 @@
using System;
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;

View file

@ -1,4 +1,8 @@
using System;
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;

View file

@ -1,4 +1,8 @@
using System.Collections;
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;

View file

@ -1,4 +1,8 @@
using System;
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

Some files were not shown because too many files have changed in this diff Show more