GUNS GUNS GUNS

GUESS WHAT
This commit is contained in:
Reinier Vens 2021-01-05 02:56:17 +00:00
commit 8aaccac2b5
83 changed files with 15291 additions and 1291 deletions

View file

@ -28,6 +28,7 @@ public class ActionGameManager : MonoBehaviour
public GameObject GameplayUI;
public MenuPanel Menu;
public MapRenderer MenuMap;
public SchematicDisplay SchematicDisplay;
public InventoryMenu Inventory;
public InventoryPanel ShipPanel;
public ConfirmationDialog ConfirmationDialog;
@ -43,10 +44,9 @@ public class ActionGameManager : MonoBehaviour
private AetheriaInput _input;
private int _zoomLevelIndex;
private Ship _currentShip;
private ShipInput _shipInput;
// 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; }
@ -58,7 +58,7 @@ public class ActionGameManager : MonoBehaviour
{
// _transposer = DockCamera.GetCinemachineComponent<CinemachineFramingTransposer>();
// _composer = DockCamera.GetCinemachineComponent<CinemachineComposer>();
_lookAt = new GameObject().transform;
//_lookAt = new GameObject().transform;
ConsoleController.MessageReceiver = this;
_filePath = new DirectoryInfo(Application.dataPath).Parent.CreateSubdirectory("GameData");
@ -143,6 +143,206 @@ public class ActionGameManager : MonoBehaviour
else Undock();
};
#region Trigger Groups
_input.Player.PreviousWeaponGroup.performed += context =>
{
if (_currentShip.Parent != null) return;
SchematicDisplay.SelectedGroupIndex--;
};
_input.Player.NextWeaponGroup.performed += context =>
{
if (_currentShip.Parent != null) return;
SchematicDisplay.SelectedGroupIndex++;
};
_input.Player.PreviousWeapon.performed += context =>
{
if (_currentShip.Parent != null) return;
SchematicDisplay.SelectedItemIndex--;
};
_input.Player.NextWeapon.performed += context =>
{
if (_currentShip.Parent != null) return;
SchematicDisplay.SelectedItemIndex++;
};
_input.Player.ToggleWeaponGroup.performed += context =>
{
if (_currentShip.Parent != null) return;
var item = SchematicDisplay.SchematicItems[SchematicDisplay.SelectedItemIndex];
if (_currentShip.TriggerGroups[SchematicDisplay.SelectedGroupIndex].Contains(item.Item))
_currentShip.TriggerGroups[SchematicDisplay.SelectedGroupIndex].Remove(item.Item);
else _currentShip.TriggerGroups[SchematicDisplay.SelectedGroupIndex].Add(item.Item);
SchematicDisplay.UpdateTriggerGroups();
};
_input.Player.FireGroup1.started += context =>
{
if (_currentShip.Parent != null) return;
foreach (var item in _currentShip.TriggerGroups[0])
{
foreach (var behaviors in item.BehaviorGroups)
{
if (behaviors.Switch != null)
behaviors.Switch.Activated = true;
behaviors.Trigger?.Pull();
}
}
};
_input.Player.FireGroup1.canceled += context =>
{
if (_currentShip.Parent != null) return;
foreach (var item in _currentShip.TriggerGroups[0])
{
foreach (var behaviors in item.BehaviorGroups)
{
if (behaviors.Switch != null)
behaviors.Switch.Activated = false;
}
}
};
_input.Player.FireGroup2.started += context =>
{
if (_currentShip.Parent != null) return;
foreach (var item in _currentShip.TriggerGroups[1])
{
foreach (var behaviors in item.BehaviorGroups)
{
if (behaviors.Switch != null)
behaviors.Switch.Activated = true;
behaviors.Trigger?.Pull();
}
}
};
_input.Player.FireGroup2.canceled += context =>
{
if (_currentShip.Parent != null) return;
foreach (var item in _currentShip.TriggerGroups[1])
{
foreach (var behaviors in item.BehaviorGroups)
{
if (behaviors.Switch != null)
behaviors.Switch.Activated = false;
}
}
};
_input.Player.FireGroup3.started += context =>
{
if (_currentShip.Parent != null) return;
foreach (var item in _currentShip.TriggerGroups[2])
{
foreach (var behaviors in item.BehaviorGroups)
{
if (behaviors.Switch != null)
behaviors.Switch.Activated = true;
behaviors.Trigger?.Pull();
}
}
};
_input.Player.FireGroup3.canceled += context =>
{
if (_currentShip.Parent != null) return;
foreach (var item in _currentShip.TriggerGroups[2])
{
foreach (var behaviors in item.BehaviorGroups)
{
if (behaviors.Switch != null)
behaviors.Switch.Activated = false;
}
}
};
_input.Player.FireGroup4.started += context =>
{
if (_currentShip.Parent != null) return;
foreach (var item in _currentShip.TriggerGroups[3])
{
foreach (var behaviors in item.BehaviorGroups)
{
if (behaviors.Switch != null)
behaviors.Switch.Activated = true;
behaviors.Trigger?.Pull();
}
}
};
_input.Player.FireGroup4.canceled += context =>
{
if (_currentShip.Parent != null) return;
foreach (var item in _currentShip.TriggerGroups[3])
{
foreach (var behaviors in item.BehaviorGroups)
{
if (behaviors.Switch != null)
behaviors.Switch.Activated = false;
}
}
};
_input.Player.FireGroup5.started += context =>
{
if (_currentShip.Parent != null) return;
foreach (var item in _currentShip.TriggerGroups[4])
{
foreach (var behaviors in item.BehaviorGroups)
{
if (behaviors.Switch != null)
behaviors.Switch.Activated = true;
behaviors.Trigger?.Pull();
}
}
};
_input.Player.FireGroup5.canceled += context =>
{
if (_currentShip.Parent != null) return;
foreach (var item in _currentShip.TriggerGroups[4])
{
foreach (var behaviors in item.BehaviorGroups)
{
if (behaviors.Switch != null)
behaviors.Switch.Activated = false;
}
}
};
_input.Player.FireGroup6.started += context =>
{
if (_currentShip.Parent != null) return;
foreach (var item in _currentShip.TriggerGroups[5])
{
foreach (var behaviors in item.BehaviorGroups)
{
if (behaviors.Switch != null)
behaviors.Switch.Activated = true;
behaviors.Trigger?.Pull();
}
}
};
_input.Player.FireGroup6.canceled += context =>
{
if (_currentShip.Parent != null) return;
foreach (var item in _currentShip.TriggerGroups[5])
{
foreach (var behaviors in item.BehaviorGroups)
{
if (behaviors.Switch != null)
behaviors.Switch.Activated = false;
}
}
};
#endregion
// ConsoleController.AddCommand("editmode", _ => ToggleEditMode());
ConsoleController.AddCommand("savezone", args =>
{
@ -183,6 +383,16 @@ public class ActionGameManager : MonoBehaviour
var cockpitData = ItemData.GetAll<GearData>().First(x => x.Behaviors.Any(b=>b is CockpitData));
ship.TryEquip(ItemManager.CreateInstance(cockpitData, .5f, 1) as EquippableItem);
var autocannonData = ItemData.GetAll<GearData>().First(x => x.Name == "Autocannon");
ship.TryEquip(ItemManager.CreateInstance(autocannonData, .5f, 1) as EquippableItem);
ship.TryEquip(ItemManager.CreateInstance(autocannonData, .5f, 1) as EquippableItem);
var cargoData = ItemData.GetAll<CargoBayData>().First(x => x.Name == "Cargo Bay 4x4");
ship.TryEquip(ItemManager.CreateInstance(cargoData, .5f, 1) as EquippableItem);
var ammoData = ItemData.GetAll<SimpleCommodityData>().First(x => x.Name == "AC2 Ammo");
ship.CargoBays.First().TryStore(ItemManager.CreateInstance(ammoData, 100));
//dockingCargo.TryStore(ItemManager.CreateInstance(reactorData, .5f, 1));
Dock();
@ -213,14 +423,13 @@ public class ActionGameManager : MonoBehaviour
FollowCamera.enabled = false;
_currentShip.Active = false;
var orbital = (OrbitalEntity) entity;
DockCamera.Follow = SectorRenderer.Orbitals[orbital];
DockCamera.Follow = SectorRenderer.EntityInstances[orbital].Transform;
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();
GameplayUI.SetActive(false);
@ -251,15 +460,16 @@ public class ActionGameManager : MonoBehaviour
{
Menu.gameObject.SetActive(false);
_currentShip.Active = true;
_shipInput = new ShipInput(_input.Player, _currentShip);
//_shipInput = new ShipInput(_input.Player, _currentShip);
DockCamera.enabled = false;
FollowCamera.enabled = true;
FollowCamera.LookAt = _lookAt;
FollowCamera.Follow = SectorRenderer.Ships[_currentShip].Transform;
FollowCamera.LookAt = SectorRenderer.EntityInstances[_currentShip].LookAtPoint;
FollowCamera.Follow = SectorRenderer.EntityInstances[_currentShip].Transform;
Cursor.lockState = CursorLockMode.Locked;
GameplayUI.SetActive(true);
_input.Player.Enable();
ShipPanel.Display(_currentShip);
SchematicDisplay.ShowShip(_currentShip);
}
else
{
@ -308,64 +518,16 @@ public class ActionGameManager : MonoBehaviour
{
_time += Time.deltaTime;
ItemManager.Time = Time.time;
if(_shipInput!=null)
if(_currentShip.Parent==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();
_currentShip.LookDirection = _viewDirection;
_currentShip.MovementDirection = _input.Player.Move.ReadValue<Vector2>();
}
}
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

@ -35,13 +35,53 @@ public class @AetheriaInput : IInputActionCollection, IDisposable
""interactions"": """"
},
{
""name"": ""Fire"",
""name"": ""Fire Group 1"",
""type"": ""Button"",
""id"": ""575943b0-4866-4be0-a289-3253973523b1"",
""expectedControlType"": ""Button"",
""processors"": """",
""interactions"": """"
},
{
""name"": ""Fire Group 2"",
""type"": ""Button"",
""id"": ""b9bdfa1f-db61-4ec3-883a-fc3f9e88c5f5"",
""expectedControlType"": ""Button"",
""processors"": """",
""interactions"": """"
},
{
""name"": ""Fire Group 3"",
""type"": ""Button"",
""id"": ""d79871a2-8565-4cf3-809f-9c979adfcd81"",
""expectedControlType"": ""Button"",
""processors"": """",
""interactions"": """"
},
{
""name"": ""Fire Group 4"",
""type"": ""Button"",
""id"": ""59902e9e-1dfb-4624-9599-72ff763ef327"",
""expectedControlType"": ""Button"",
""processors"": """",
""interactions"": """"
},
{
""name"": ""Fire Group 5"",
""type"": ""Button"",
""id"": ""80b549c1-7378-48c5-8da2-ce95b9c92913"",
""expectedControlType"": ""Button"",
""processors"": """",
""interactions"": """"
},
{
""name"": ""Fire Group 6"",
""type"": ""Button"",
""id"": ""4ba5091e-051a-41df-9985-6c0e082b20a5"",
""expectedControlType"": ""Button"",
""processors"": """",
""interactions"": """"
},
{
""name"": ""Minimap Zoom"",
""type"": ""Button"",
@ -49,6 +89,46 @@ public class @AetheriaInput : IInputActionCollection, IDisposable
""expectedControlType"": ""Button"",
""processors"": """",
""interactions"": """"
},
{
""name"": ""Next Weapon Group"",
""type"": ""Button"",
""id"": ""8ed69fe0-d934-44ea-94c0-d5d69cc33b32"",
""expectedControlType"": ""Button"",
""processors"": """",
""interactions"": """"
},
{
""name"": ""Previous Weapon Group"",
""type"": ""Button"",
""id"": ""93f19768-6c19-4bab-8b53-4e3e5ba764fc"",
""expectedControlType"": ""Button"",
""processors"": """",
""interactions"": """"
},
{
""name"": ""Next Weapon"",
""type"": ""Button"",
""id"": ""09a5e315-6290-4ab5-9e7c-55b7523562b7"",
""expectedControlType"": ""Button"",
""processors"": """",
""interactions"": """"
},
{
""name"": ""Previous Weapon"",
""type"": ""Button"",
""id"": ""ed923265-545f-4475-ba7c-885371612325"",
""expectedControlType"": ""Button"",
""processors"": """",
""interactions"": """"
},
{
""name"": ""Toggle Weapon Group"",
""type"": ""Button"",
""id"": ""c61da4ef-e0bc-4d17-aab0-8e2979c3de3c"",
""expectedControlType"": ""Button"",
""processors"": """",
""interactions"": """"
}
],
""bindings"": [
@ -213,7 +293,7 @@ public class @AetheriaInput : IInputActionCollection, IDisposable
""interactions"": """",
""processors"": """",
""groups"": "";Gamepad"",
""action"": ""Fire"",
""action"": ""Fire Group 1"",
""isComposite"": false,
""isPartOfComposite"": false
},
@ -224,18 +304,7 @@ public class @AetheriaInput : IInputActionCollection, IDisposable
""interactions"": """",
""processors"": """",
""groups"": "";Keyboard&Mouse"",
""action"": ""Fire"",
""isComposite"": false,
""isPartOfComposite"": false
},
{
""name"": """",
""id"": ""886e731e-7071-4ae4-95c0-e61739dad6fd"",
""path"": ""<Touchscreen>/primaryTouch/tap"",
""interactions"": """",
""processors"": """",
""groups"": """",
""action"": ""Fire"",
""action"": ""Fire Group 1"",
""isComposite"": false,
""isPartOfComposite"": false
},
@ -246,7 +315,18 @@ public class @AetheriaInput : IInputActionCollection, IDisposable
""interactions"": """",
""processors"": """",
""groups"": ""Joystick"",
""action"": ""Fire"",
""action"": ""Fire Group 1"",
""isComposite"": false,
""isPartOfComposite"": false
},
{
""name"": """",
""id"": ""8c676533-8c53-4b6a-9368-d194b8a997f8"",
""path"": ""<Keyboard>/1"",
""interactions"": """",
""processors"": """",
""groups"": ""Keyboard&Mouse"",
""action"": ""Fire Group 1"",
""isComposite"": false,
""isPartOfComposite"": false
},
@ -260,6 +340,138 @@ public class @AetheriaInput : IInputActionCollection, IDisposable
""action"": ""Minimap Zoom"",
""isComposite"": false,
""isPartOfComposite"": false
},
{
""name"": """",
""id"": ""444b4049-a11e-4bef-8a57-345c3d1a7545"",
""path"": ""<Keyboard>/rightArrow"",
""interactions"": """",
""processors"": """",
""groups"": ""Keyboard&Mouse"",
""action"": ""Next Weapon Group"",
""isComposite"": false,
""isPartOfComposite"": false
},
{
""name"": """",
""id"": ""fb6c0d4c-dae6-406b-b35a-c35b5d25022c"",
""path"": ""<Keyboard>/leftArrow"",
""interactions"": """",
""processors"": """",
""groups"": ""Keyboard&Mouse"",
""action"": ""Previous Weapon Group"",
""isComposite"": false,
""isPartOfComposite"": false
},
{
""name"": """",
""id"": ""bac8c902-3cad-4a7f-8773-35800a2ee3b9"",
""path"": ""<Keyboard>/downArrow"",
""interactions"": """",
""processors"": """",
""groups"": ""Keyboard&Mouse"",
""action"": ""Next Weapon"",
""isComposite"": false,
""isPartOfComposite"": false
},
{
""name"": """",
""id"": ""969aff21-097a-4c35-9c46-2239e5f321f5"",
""path"": ""<Keyboard>/upArrow"",
""interactions"": """",
""processors"": """",
""groups"": ""Keyboard&Mouse"",
""action"": ""Previous Weapon"",
""isComposite"": false,
""isPartOfComposite"": false
},
{
""name"": """",
""id"": ""a2bcbfda-f091-433f-8ac9-112396507408"",
""path"": ""<Keyboard>/rightCtrl"",
""interactions"": """",
""processors"": """",
""groups"": ""Keyboard&Mouse"",
""action"": ""Toggle Weapon Group"",
""isComposite"": false,
""isPartOfComposite"": false
},
{
""name"": """",
""id"": ""48b8b6ee-8435-439a-96a1-c968254ff605"",
""path"": ""<Mouse>/rightButton"",
""interactions"": """",
""processors"": """",
""groups"": "";Keyboard&Mouse"",
""action"": ""Fire Group 2"",
""isComposite"": false,
""isPartOfComposite"": false
},
{
""name"": """",
""id"": ""8ae75721-10ab-4d83-8322-82cbb3fdcc44"",
""path"": ""<Keyboard>/2"",
""interactions"": """",
""processors"": """",
""groups"": ""Keyboard&Mouse"",
""action"": ""Fire Group 2"",
""isComposite"": false,
""isPartOfComposite"": false
},
{
""name"": """",
""id"": ""7f89c9af-795b-4b1e-ad43-dac3350cfbe3"",
""path"": ""<Mouse>/middleButton"",
""interactions"": """",
""processors"": """",
""groups"": "";Keyboard&Mouse"",
""action"": ""Fire Group 3"",
""isComposite"": false,
""isPartOfComposite"": false
},
{
""name"": """",
""id"": ""c249f018-c10a-4c2c-a4ba-9fba54ed33e9"",
""path"": ""<Keyboard>/3"",
""interactions"": """",
""processors"": """",
""groups"": ""Keyboard&Mouse"",
""action"": ""Fire Group 3"",
""isComposite"": false,
""isPartOfComposite"": false
},
{
""name"": """",
""id"": ""421e49a0-897e-4ea3-af8d-af96989d2957"",
""path"": ""<Keyboard>/4"",
""interactions"": """",
""processors"": """",
""groups"": "";Keyboard&Mouse"",
""action"": ""Fire Group 4"",
""isComposite"": false,
""isPartOfComposite"": false
},
{
""name"": """",
""id"": ""1c8a43b7-4200-43b9-925c-c1634554083c"",
""path"": ""<Keyboard>/5"",
""interactions"": """",
""processors"": """",
""groups"": "";Keyboard&Mouse"",
""action"": ""Fire Group 5"",
""isComposite"": false,
""isPartOfComposite"": false
},
{
""name"": """",
""id"": ""0680216e-b462-45a3-8050-2b89dcb615aa"",
""path"": ""<Keyboard>/6"",
""interactions"": """",
""processors"": """",
""groups"": "";Keyboard&Mouse"",
""action"": ""Fire Group 6"",
""isComposite"": false,
""isPartOfComposite"": false
}
]
},
@ -828,8 +1040,18 @@ public class @AetheriaInput : IInputActionCollection, IDisposable
m_Player = asset.FindActionMap("Player", throwIfNotFound: true);
m_Player_Move = m_Player.FindAction("Move", throwIfNotFound: true);
m_Player_Look = m_Player.FindAction("Look", throwIfNotFound: true);
m_Player_Fire = m_Player.FindAction("Fire", throwIfNotFound: true);
m_Player_FireGroup1 = m_Player.FindAction("Fire Group 1", throwIfNotFound: true);
m_Player_FireGroup2 = m_Player.FindAction("Fire Group 2", throwIfNotFound: true);
m_Player_FireGroup3 = m_Player.FindAction("Fire Group 3", throwIfNotFound: true);
m_Player_FireGroup4 = m_Player.FindAction("Fire Group 4", throwIfNotFound: true);
m_Player_FireGroup5 = m_Player.FindAction("Fire Group 5", throwIfNotFound: true);
m_Player_FireGroup6 = m_Player.FindAction("Fire Group 6", throwIfNotFound: true);
m_Player_MinimapZoom = m_Player.FindAction("Minimap Zoom", throwIfNotFound: true);
m_Player_NextWeaponGroup = m_Player.FindAction("Next Weapon Group", throwIfNotFound: true);
m_Player_PreviousWeaponGroup = m_Player.FindAction("Previous Weapon Group", throwIfNotFound: true);
m_Player_NextWeapon = m_Player.FindAction("Next Weapon", throwIfNotFound: true);
m_Player_PreviousWeapon = m_Player.FindAction("Previous Weapon", throwIfNotFound: true);
m_Player_ToggleWeaponGroup = m_Player.FindAction("Toggle Weapon Group", throwIfNotFound: true);
// UI
m_UI = asset.FindActionMap("UI", throwIfNotFound: true);
m_UI_Navigate = m_UI.FindAction("Navigate", throwIfNotFound: true);
@ -897,16 +1119,36 @@ public class @AetheriaInput : IInputActionCollection, IDisposable
private IPlayerActions m_PlayerActionsCallbackInterface;
private readonly InputAction m_Player_Move;
private readonly InputAction m_Player_Look;
private readonly InputAction m_Player_Fire;
private readonly InputAction m_Player_FireGroup1;
private readonly InputAction m_Player_FireGroup2;
private readonly InputAction m_Player_FireGroup3;
private readonly InputAction m_Player_FireGroup4;
private readonly InputAction m_Player_FireGroup5;
private readonly InputAction m_Player_FireGroup6;
private readonly InputAction m_Player_MinimapZoom;
private readonly InputAction m_Player_NextWeaponGroup;
private readonly InputAction m_Player_PreviousWeaponGroup;
private readonly InputAction m_Player_NextWeapon;
private readonly InputAction m_Player_PreviousWeapon;
private readonly InputAction m_Player_ToggleWeaponGroup;
public struct PlayerActions
{
private @AetheriaInput m_Wrapper;
public PlayerActions(@AetheriaInput wrapper) { m_Wrapper = wrapper; }
public InputAction @Move => m_Wrapper.m_Player_Move;
public InputAction @Look => m_Wrapper.m_Player_Look;
public InputAction @Fire => m_Wrapper.m_Player_Fire;
public InputAction @FireGroup1 => m_Wrapper.m_Player_FireGroup1;
public InputAction @FireGroup2 => m_Wrapper.m_Player_FireGroup2;
public InputAction @FireGroup3 => m_Wrapper.m_Player_FireGroup3;
public InputAction @FireGroup4 => m_Wrapper.m_Player_FireGroup4;
public InputAction @FireGroup5 => m_Wrapper.m_Player_FireGroup5;
public InputAction @FireGroup6 => m_Wrapper.m_Player_FireGroup6;
public InputAction @MinimapZoom => m_Wrapper.m_Player_MinimapZoom;
public InputAction @NextWeaponGroup => m_Wrapper.m_Player_NextWeaponGroup;
public InputAction @PreviousWeaponGroup => m_Wrapper.m_Player_PreviousWeaponGroup;
public InputAction @NextWeapon => m_Wrapper.m_Player_NextWeapon;
public InputAction @PreviousWeapon => m_Wrapper.m_Player_PreviousWeapon;
public InputAction @ToggleWeaponGroup => m_Wrapper.m_Player_ToggleWeaponGroup;
public InputActionMap Get() { return m_Wrapper.m_Player; }
public void Enable() { Get().Enable(); }
public void Disable() { Get().Disable(); }
@ -922,12 +1164,42 @@ public class @AetheriaInput : IInputActionCollection, IDisposable
@Look.started -= m_Wrapper.m_PlayerActionsCallbackInterface.OnLook;
@Look.performed -= m_Wrapper.m_PlayerActionsCallbackInterface.OnLook;
@Look.canceled -= m_Wrapper.m_PlayerActionsCallbackInterface.OnLook;
@Fire.started -= m_Wrapper.m_PlayerActionsCallbackInterface.OnFire;
@Fire.performed -= m_Wrapper.m_PlayerActionsCallbackInterface.OnFire;
@Fire.canceled -= m_Wrapper.m_PlayerActionsCallbackInterface.OnFire;
@FireGroup1.started -= m_Wrapper.m_PlayerActionsCallbackInterface.OnFireGroup1;
@FireGroup1.performed -= m_Wrapper.m_PlayerActionsCallbackInterface.OnFireGroup1;
@FireGroup1.canceled -= m_Wrapper.m_PlayerActionsCallbackInterface.OnFireGroup1;
@FireGroup2.started -= m_Wrapper.m_PlayerActionsCallbackInterface.OnFireGroup2;
@FireGroup2.performed -= m_Wrapper.m_PlayerActionsCallbackInterface.OnFireGroup2;
@FireGroup2.canceled -= m_Wrapper.m_PlayerActionsCallbackInterface.OnFireGroup2;
@FireGroup3.started -= m_Wrapper.m_PlayerActionsCallbackInterface.OnFireGroup3;
@FireGroup3.performed -= m_Wrapper.m_PlayerActionsCallbackInterface.OnFireGroup3;
@FireGroup3.canceled -= m_Wrapper.m_PlayerActionsCallbackInterface.OnFireGroup3;
@FireGroup4.started -= m_Wrapper.m_PlayerActionsCallbackInterface.OnFireGroup4;
@FireGroup4.performed -= m_Wrapper.m_PlayerActionsCallbackInterface.OnFireGroup4;
@FireGroup4.canceled -= m_Wrapper.m_PlayerActionsCallbackInterface.OnFireGroup4;
@FireGroup5.started -= m_Wrapper.m_PlayerActionsCallbackInterface.OnFireGroup5;
@FireGroup5.performed -= m_Wrapper.m_PlayerActionsCallbackInterface.OnFireGroup5;
@FireGroup5.canceled -= m_Wrapper.m_PlayerActionsCallbackInterface.OnFireGroup5;
@FireGroup6.started -= m_Wrapper.m_PlayerActionsCallbackInterface.OnFireGroup6;
@FireGroup6.performed -= m_Wrapper.m_PlayerActionsCallbackInterface.OnFireGroup6;
@FireGroup6.canceled -= m_Wrapper.m_PlayerActionsCallbackInterface.OnFireGroup6;
@MinimapZoom.started -= m_Wrapper.m_PlayerActionsCallbackInterface.OnMinimapZoom;
@MinimapZoom.performed -= m_Wrapper.m_PlayerActionsCallbackInterface.OnMinimapZoom;
@MinimapZoom.canceled -= m_Wrapper.m_PlayerActionsCallbackInterface.OnMinimapZoom;
@NextWeaponGroup.started -= m_Wrapper.m_PlayerActionsCallbackInterface.OnNextWeaponGroup;
@NextWeaponGroup.performed -= m_Wrapper.m_PlayerActionsCallbackInterface.OnNextWeaponGroup;
@NextWeaponGroup.canceled -= m_Wrapper.m_PlayerActionsCallbackInterface.OnNextWeaponGroup;
@PreviousWeaponGroup.started -= m_Wrapper.m_PlayerActionsCallbackInterface.OnPreviousWeaponGroup;
@PreviousWeaponGroup.performed -= m_Wrapper.m_PlayerActionsCallbackInterface.OnPreviousWeaponGroup;
@PreviousWeaponGroup.canceled -= m_Wrapper.m_PlayerActionsCallbackInterface.OnPreviousWeaponGroup;
@NextWeapon.started -= m_Wrapper.m_PlayerActionsCallbackInterface.OnNextWeapon;
@NextWeapon.performed -= m_Wrapper.m_PlayerActionsCallbackInterface.OnNextWeapon;
@NextWeapon.canceled -= m_Wrapper.m_PlayerActionsCallbackInterface.OnNextWeapon;
@PreviousWeapon.started -= m_Wrapper.m_PlayerActionsCallbackInterface.OnPreviousWeapon;
@PreviousWeapon.performed -= m_Wrapper.m_PlayerActionsCallbackInterface.OnPreviousWeapon;
@PreviousWeapon.canceled -= m_Wrapper.m_PlayerActionsCallbackInterface.OnPreviousWeapon;
@ToggleWeaponGroup.started -= m_Wrapper.m_PlayerActionsCallbackInterface.OnToggleWeaponGroup;
@ToggleWeaponGroup.performed -= m_Wrapper.m_PlayerActionsCallbackInterface.OnToggleWeaponGroup;
@ToggleWeaponGroup.canceled -= m_Wrapper.m_PlayerActionsCallbackInterface.OnToggleWeaponGroup;
}
m_Wrapper.m_PlayerActionsCallbackInterface = instance;
if (instance != null)
@ -938,12 +1210,42 @@ public class @AetheriaInput : IInputActionCollection, IDisposable
@Look.started += instance.OnLook;
@Look.performed += instance.OnLook;
@Look.canceled += instance.OnLook;
@Fire.started += instance.OnFire;
@Fire.performed += instance.OnFire;
@Fire.canceled += instance.OnFire;
@FireGroup1.started += instance.OnFireGroup1;
@FireGroup1.performed += instance.OnFireGroup1;
@FireGroup1.canceled += instance.OnFireGroup1;
@FireGroup2.started += instance.OnFireGroup2;
@FireGroup2.performed += instance.OnFireGroup2;
@FireGroup2.canceled += instance.OnFireGroup2;
@FireGroup3.started += instance.OnFireGroup3;
@FireGroup3.performed += instance.OnFireGroup3;
@FireGroup3.canceled += instance.OnFireGroup3;
@FireGroup4.started += instance.OnFireGroup4;
@FireGroup4.performed += instance.OnFireGroup4;
@FireGroup4.canceled += instance.OnFireGroup4;
@FireGroup5.started += instance.OnFireGroup5;
@FireGroup5.performed += instance.OnFireGroup5;
@FireGroup5.canceled += instance.OnFireGroup5;
@FireGroup6.started += instance.OnFireGroup6;
@FireGroup6.performed += instance.OnFireGroup6;
@FireGroup6.canceled += instance.OnFireGroup6;
@MinimapZoom.started += instance.OnMinimapZoom;
@MinimapZoom.performed += instance.OnMinimapZoom;
@MinimapZoom.canceled += instance.OnMinimapZoom;
@NextWeaponGroup.started += instance.OnNextWeaponGroup;
@NextWeaponGroup.performed += instance.OnNextWeaponGroup;
@NextWeaponGroup.canceled += instance.OnNextWeaponGroup;
@PreviousWeaponGroup.started += instance.OnPreviousWeaponGroup;
@PreviousWeaponGroup.performed += instance.OnPreviousWeaponGroup;
@PreviousWeaponGroup.canceled += instance.OnPreviousWeaponGroup;
@NextWeapon.started += instance.OnNextWeapon;
@NextWeapon.performed += instance.OnNextWeapon;
@NextWeapon.canceled += instance.OnNextWeapon;
@PreviousWeapon.started += instance.OnPreviousWeapon;
@PreviousWeapon.performed += instance.OnPreviousWeapon;
@PreviousWeapon.canceled += instance.OnPreviousWeapon;
@ToggleWeaponGroup.started += instance.OnToggleWeaponGroup;
@ToggleWeaponGroup.performed += instance.OnToggleWeaponGroup;
@ToggleWeaponGroup.canceled += instance.OnToggleWeaponGroup;
}
}
}
@ -1125,8 +1427,18 @@ public class @AetheriaInput : IInputActionCollection, IDisposable
{
void OnMove(InputAction.CallbackContext context);
void OnLook(InputAction.CallbackContext context);
void OnFire(InputAction.CallbackContext context);
void OnFireGroup1(InputAction.CallbackContext context);
void OnFireGroup2(InputAction.CallbackContext context);
void OnFireGroup3(InputAction.CallbackContext context);
void OnFireGroup4(InputAction.CallbackContext context);
void OnFireGroup5(InputAction.CallbackContext context);
void OnFireGroup6(InputAction.CallbackContext context);
void OnMinimapZoom(InputAction.CallbackContext context);
void OnNextWeaponGroup(InputAction.CallbackContext context);
void OnPreviousWeaponGroup(InputAction.CallbackContext context);
void OnNextWeapon(InputAction.CallbackContext context);
void OnPreviousWeapon(InputAction.CallbackContext context);
void OnToggleWeaponGroup(InputAction.CallbackContext context);
}
public interface IUIActions
{

View file

@ -691,7 +691,7 @@ public class DatabaseInspector : EditorWindow
public float4[] InspectAnimationCurve(string label, float4[] value)
{
var val = value != null && value.Length > 0
? new AnimationCurve(value.Select(v => new Keyframe(v.x, v.y, v.z, v.w)).ToArray())
? value.ToCurve()
: new AnimationCurve();
using (var h = new HorizontalScope())
{

View file

@ -17,6 +17,7 @@ using Random = UnityEngine.Random;
public class SectorRenderer : MonoBehaviour
{
public Transform EffectManagerParent;
public Transform FogCameraParent;
public GameSettings Settings;
public Transform ZoneRoot;
@ -54,9 +55,7 @@ public class SectorRenderer : MonoBehaviour
public Texture2D PlanetIcon;
[HideInInspector]
public Dictionary<OrbitalEntity, Transform> Orbitals = new Dictionary<OrbitalEntity, Transform>();
[HideInInspector]
public Dictionary<Ship, ShipInstance> Ships = new Dictionary<Ship, ShipInstance>();
public Dictionary<Entity, EntityInstance> EntityInstances = new Dictionary<Entity, EntityInstance>();
[HideInInspector]
public Dictionary<Guid, PlanetObject> Planets = new Dictionary<Guid, PlanetObject>();
@ -64,6 +63,8 @@ public class SectorRenderer : MonoBehaviour
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[]>();
private Dictionary<ProjectileWeaponData, ProjectileManager> _projectileManagers = new Dictionary<ProjectileWeaponData, ProjectileManager>();
private Dictionary<LauncherData, GuidedProjectileManager> _guidedProjectileManagers = new Dictionary<LauncherData, GuidedProjectileManager>();
private Zone _zone;
private float _viewDistance;
private float _maxDepth;
@ -172,45 +173,99 @@ public class SectorRenderer : MonoBehaviour
void LoadEntity(Entity entity)
{
var hullData = ItemManager.GetData(entity.Hull) as HullData;
EntityInstance instance;
if (entity is Ship ship)
{
var shipInstance = new ShipInstance();
shipInstance.Ship = ship;
shipInstance.Transform = Instantiate(UnityHelpers.LoadAsset<GameObject>(hullData.Prefab), ZoneRoot).transform;
instance = new ShipInstance();
instance.Transform = Instantiate(UnityHelpers.LoadAsset<GameObject>(hullData.Prefab), ZoneRoot).transform;
instance.Prefab = instance.Transform.GetComponent<EntityPrefab>();
var shipInstance = (ShipInstance) instance;
shipInstance.Thrusters = ship.GetBehaviors<Thruster>().ToArray();
shipInstance.ThrusterParticles = shipInstance.Thrusters
.Select(x =>
{
var particles = Instantiate(UnityHelpers.LoadAsset<ParticleSystem>(((ThrusterData) x.Data).ParticlesPrefab), shipInstance.Transform, false);
var particlesShape = particles.shape;
particlesShape.meshRenderer = shipInstance.Transform.Find(x.Entity.Hardpoints[x.Item.Position.x, x.Item.Position.y].Transform)
.GetComponent<MeshRenderer>();
particlesShape.meshRenderer = shipInstance.Prefab.ThrusterHardpoints
.FirstOrDefault(t => t.name == x.Entity.Hardpoints[x.Item.Position.x, x.Item.Position.y].Transform)
?.Emitter;
return particles;
})
.ToArray();
shipInstance.ThrusterBaseEmission = shipInstance.ThrusterParticles.Select(x => x.emission.rateOverTimeMultiplier).ToArray();
Ships.Add(ship, shipInstance);
}
else if (entity is OrbitalEntity orbital)
else
{
Orbitals.Add(orbital,Instantiate(UnityHelpers.LoadAsset<GameObject>(hullData.Prefab)).transform);
instance = new EntityInstance();
instance.Transform = Instantiate(UnityHelpers.LoadAsset<GameObject>(hullData.Prefab), ZoneRoot).transform;
instance.Prefab = instance.Transform.GetComponent<EntityPrefab>();
}
instance.Entity = entity;
foreach (var item in entity.Equipment)
{
foreach (var behavior in item.Behaviors)
{
if (behavior is InstantWeapon instantWeapon)
{
if (behavior.Data is ProjectileWeaponData projectileWeaponData)
{
if (!_projectileManagers.ContainsKey(projectileWeaponData))
{
var managerPrefab = UnityHelpers.LoadAsset<ProjectileManager>(projectileWeaponData.EffectPrefab);
if(managerPrefab)
{
_projectileManagers.Add(projectileWeaponData, Instantiate(managerPrefab, EffectManagerParent));
}
else Debug.LogError($"No ProjectileManager prefab found at path {projectileWeaponData.EffectPrefab}");
}
instantWeapon.OnFire += () => _projectileManagers[projectileWeaponData].Launch(projectileWeaponData, item, instance);
}
else if (behavior.Data is LauncherData launcherData)
{
if (!_guidedProjectileManagers.ContainsKey(launcherData))
{
var managerPrefab = UnityHelpers.LoadAsset<GuidedProjectileManager>(launcherData.EffectPrefab);
if(managerPrefab)
{
_guidedProjectileManagers.Add(launcherData, Instantiate(managerPrefab, EffectManagerParent));
}
else Debug.LogError($"No ProjectileManager prefab found at path {launcherData.EffectPrefab}");
}
instantWeapon.OnFire += () =>
_guidedProjectileManagers[launcherData].Launch(launcherData, item, instance, EntityInstances[entity.Target]);
}
}
}
}
instance.Barrels = new Dictionary<HardpointData, Transform[]>();
instance.BarrelIndices = new Dictionary<HardpointData, int>();
foreach (var hp in hullData.Hardpoints)
{
var whp = instance.Prefab.WeaponHardpoints.FirstOrDefault(x => x.name == hp.Transform);
if(whp)
{
instance.Barrels.Add(hp, whp.FiringPoint);
instance.BarrelIndices.Add(hp, 0);
}
}
instance.LookAtPoint = new GameObject().transform;
foreach (var articulationPoint in instance.Prefab.ArticulationPoints)
{
articulationPoint.Target = instance.LookAtPoint;
}
EntityInstances.Add(entity, instance);
}
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);
}
Destroy(EntityInstances[entity].Transform.gameObject);
EntityInstances.Remove(entity);
}
void LoadPlanet(BodyData planetData)
@ -369,35 +424,36 @@ public class SectorRenderer : MonoBehaviour
else planet.Value.Body.transform.rotation *= Quaternion.AngleAxis(Settings.PlanetRotationSpeed, Vector3.up);
}
foreach (var ship in Ships)
foreach (var entity in EntityInstances)
{
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);
var f = new float2(normal.x, normal.z);
var fl = lengthsq(f);
if(fl > .001)
var hullData = ItemManager.GetData(entity.Key.Hull) as HullData;
if(entity.Key is Ship ship)
{
var fa = 1 / (1 - fl) - 1;
ship.Key.Velocity += normalize(f) * Settings.PlanetSettings.GravityStrength * fa;
}
//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;
}
}
var shipInstance = entity.Value as ShipInstance;
var normal = _zone.GetNormal(ship.Position);
var f = new float2(normal.x, normal.z);
var fl = lengthsq(f);
if (fl > .001)
{
var fa = 1 / (1 - fl) - 1;
entity.Key.Velocity += normalize(f) * Settings.PlanetSettings.GravityStrength * fa;
}
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);
//Debug.Log($"Normal: {normal}");
var shipRight = ship.Direction.Rotate(ItemRotation.Clockwise);
var forward = Vector3.Cross(new Vector3(shipRight.x, 0, shipRight.y), normal);
entity.Value.Transform.rotation = Quaternion.LookRotation(forward, normal);
for (int i = 0; i < shipInstance.Thrusters.Length; i++)
{
var emissionModule = shipInstance.ThrusterParticles[i].emission;
emissionModule.rateOverTimeMultiplier = shipInstance.ThrusterBaseEmission[i] * shipInstance.Thrusters[i].Axis;
}
}
entity.Value.LookAtPoint.position = entity.Value.Transform.position + (Vector3) entity.Key.LookDirection * (entity.Key.Target != null
? (EntityInstances[entity.Key.Target].Transform.position - entity.Value.Transform.position).magnitude : 100);
var h = _zone.GetHeight(entity.Key.Position);
entity.Value.Transform.position = new Vector3(entity.Key.Position.x, h + hullData.GridOffset, entity.Key.Position.y);
}
var fogPos = FogCameraParent.position;
@ -416,13 +472,32 @@ public class SectorRenderer : MonoBehaviour
}
}
public class ShipInstance
public class EntityInstance
{
public Entity Entity;
public Transform Transform;
public EntityPrefab Prefab;
public Dictionary<HardpointData, Transform[]> Barrels;
public Dictionary<HardpointData, int> BarrelIndices;
public Transform LookAtPoint;
public Transform GetBarrel(HardpointData hardpoint)
{
if (Barrels.ContainsKey(hardpoint))
{
var barrel = Barrels[hardpoint][BarrelIndices[hardpoint]];
BarrelIndices[hardpoint] = (BarrelIndices[hardpoint] + 1) % Barrels[hardpoint].Length;
return barrel;
}
return Transform;
}
}
public class ShipInstance : EntityInstance
{
public ParticleSystem[] ThrusterParticles;
public Thruster[] Thrusters;
public float[] ThrusterBaseEmission;
public Ship Ship;
public Transform Transform;
}
[Serializable]

View file

@ -0,0 +1,74 @@
/* 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;
[InspectableField, MessagePackObject, JsonObject(MemberSerialization.OptIn)]
public class ConstantWeaponData : WeaponData
{
public override IBehavior CreateInstance(ItemManager context, Entity entity, EquippedItem item)
{
return new ConstantWeapon(context, this, entity, item);
}
}
public class ConstantWeapon : IBehavior, IAlwaysUpdatedBehavior
{
private ConstantWeaponData _data;
public int _burstCount;
public float _burstTimer;
private Entity Entity { get; }
private EquippedItem Item { get; }
private ItemManager Context { get; }
public BehaviorData Data => _data;
public event Action OnStartFiring;
public event Action OnStopFiring;
private bool _firing;
private bool _stoppedFiring;
public ConstantWeapon(ItemManager context, ConstantWeaponData c, Entity entity, EquippedItem item)
{
Context = context;
_data = c;
Entity = entity;
Item = item;
}
public bool Update(float delta)
{
if (!_firing)
{
_firing = true;
OnStartFiring?.Invoke();
}
_stoppedFiring = false;
return true;
}
public void AlwaysUpdate(float delta)
{
// Update executes after AlwaysUpdate,
// so if the stop flag didn't get disabled previous frame,
// we know the weapon has stopped firing
if (_firing)
{
if (_stoppedFiring)
{
_firing = false;
_stoppedFiring = false;
OnStopFiring?.Invoke();
}
else
_stoppedFiring = true;
}
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: f437aa69c4d96524cbe4caedd16678b6
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -7,11 +7,8 @@ using Newtonsoft.Json;
using Unity.Mathematics;
[InspectableField, MessagePackObject, JsonObject(MemberSerialization.OptIn)]
public class LauncherData : WeaponData
public class LauncherData : InstantWeaponData
{
[InspectablePrefab, JsonProperty("missile"), Key(6)]
public string MissilePrefab;
[InspectableAnimationCurve, JsonProperty("guidance"), Key(7)]
public float4[] GuidanceCurve;
@ -41,7 +38,7 @@ public class LauncherData : WeaponData
public override IBehavior CreateInstance(ItemManager context, Entity entity, EquippedItem item)
{
return new Launcher(context, this, entity, item);
return new InstantWeapon(context, this, entity, item);
}
}

View file

@ -2,15 +2,13 @@
* 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;
[InspectableField, MessagePackObject, JsonObject(MemberSerialization.OptIn)]
public class ProjectileWeaponData : WeaponData
public class ProjectileWeaponData : InstantWeaponData
{
[InspectablePrefab, JsonProperty("bullet"), Key(6)]
public string BulletPrefab;
[InspectableField, JsonProperty("spread"), Key(7)]
public PerformanceStat Spread = new PerformanceStat();
@ -22,46 +20,6 @@ public class ProjectileWeaponData : WeaponData
public override IBehavior CreateInstance(ItemManager context, Entity entity, EquippedItem item)
{
return new ProjectileWeapon(context, this, entity, item);
}
}
public class ProjectileWeapon : IBehavior
{
private ProjectileWeaponData _data;
private Entity Entity { get; }
private EquippedItem Item { get; }
private ItemManager Context { get; }
public BehaviorData Data => _data;
public ProjectileWeapon(ItemManager context, ProjectileWeaponData c, Entity entity, EquippedItem item)
{
Context = context;
_data = c;
Entity = entity;
Item = item;
}
// private void Fire()
// {
// Hardpoint.Temperature += _projectileWeapon.Heat.Evaluate(Hardpoint) / Hardpoint.HeatCapacity;
// var inst = GameObject.Instantiate(_projectileWeapon.BulletPrefab).transform;
// Physics.IgnoreCollision(Hardpoint.Ship.Ship.GetComponent<Collider>(), inst.GetComponent<Collider>());
// var bullet = inst.GetComponent<Bullet>();
// bullet.Target = Hardpoint.Ship.Ship.Target;
// bullet.Source = Hardpoint.Ship.Ship.Hitpoints;
// bullet.Lifetime = _projectileWeapon.Range.Evaluate(Hardpoint) / _projectileWeapon.Velocity.Evaluate(Hardpoint);
// bullet.Damage = _projectileWeapon.Damage.Evaluate(Hardpoint);
// inst.position = Hardpoint.Proxy.position;
// inst.rotation = Hardpoint.Proxy.rotation;
// inst.GetComponent<Rigidbody>().velocity = _projectileWeapon.Velocity.Evaluate(Hardpoint) * Vector3.RotateTowards(-inst.forward, Hardpoint.Ship.Ship.Direction, _projectileWeapon.Deflection * Mathf.Deg2Rad, 1);
// Hardpoint.Ship.Ship.AudioSource.PlayOneShot(_projectileWeapon.Sounds.RandomElement());
// Debug.Log($"Firing bullet {b}");
// }
public bool Update(float delta)
{
return true;
return new InstantWeapon(context, this, entity, item);
}
}

View file

@ -51,8 +51,11 @@ public class Visibility : IBehavior, IAlwaysUpdatedBehavior
public void AlwaysUpdate(float delta)
{
// TODO: Time independent decay?
Entity.VisibilitySources[this] *= Context.Evaluate(_data.VisibilityDecay, Item.EquippableItem, Entity);
if (Entity.VisibilitySources[this] < 0.01f) Entity.VisibilitySources.Remove(this);
if(Entity.VisibilitySources.ContainsKey(this))
{
Entity.VisibilitySources[this] *= Context.Evaluate(_data.VisibilityDecay, Item.EquippableItem, Entity);
if (Entity.VisibilitySources[this] < 0.01f) Entity.VisibilitySources.Remove(this);
}
}
}

View file

@ -2,11 +2,13 @@
* 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;
[Union(0, typeof(ProjectileWeaponData)),
Union(1, typeof(LauncherData))]
Union(1, typeof(LauncherData)),
Union(2, typeof(ConstantWeaponData))]
public abstract class WeaponData : BehaviorData
{
[InspectableField, JsonProperty("damageType"), Key(1)]
@ -17,10 +19,93 @@ public abstract class WeaponData : BehaviorData
[InspectableField, JsonProperty("range"), Key(3)]
public PerformanceStat Range = new PerformanceStat();
[InspectablePrefab, JsonProperty("effect"), Key(4)]
public string EffectPrefab;
}
[InspectableField, JsonProperty("burstCount"), Key(4)]
[InspectableField, MessagePackObject, JsonObject(MemberSerialization.OptIn)]
public abstract class InstantWeaponData : WeaponData
{
[InspectableField, JsonProperty("burstCount"), Key(5)]
public int BurstCount;
[InspectableField, JsonProperty("burstTime"), Key(5)]
[InspectableField, JsonProperty("burstTime"), Key(6)]
public PerformanceStat BurstTime = new PerformanceStat();
}
public class InstantWeapon : IBehavior, IAlwaysUpdatedBehavior
{
private InstantWeaponData _data;
public int _burstCount;
public float _burstTimer;
private Entity Entity { get; }
private EquippedItem Item { get; }
private ItemManager Context { get; }
public BehaviorData Data => _data;
public event Action OnFire;
private float _burstTime;
public InstantWeapon(ItemManager context, InstantWeaponData c, Entity entity, EquippedItem item)
{
Context = context;
_data = c;
Entity = entity;
Item = item;
}
// private void Fire()
// {
// Hardpoint.Temperature += _projectileWeapon.Heat.Evaluate(Hardpoint) / Hardpoint.HeatCapacity;
// var inst = GameObject.Instantiate(_projectileWeapon.BulletPrefab).transform;
// Physics.IgnoreCollision(Hardpoint.Ship.Ship.GetComponent<Collider>(), inst.GetComponent<Collider>());
// var bullet = inst.GetComponent<Bullet>();
// bullet.Target = Hardpoint.Ship.Ship.Target;
// bullet.Source = Hardpoint.Ship.Ship.Hitpoints;
// bullet.Lifetime = _projectileWeapon.Range.Evaluate(Hardpoint) / _projectileWeapon.Velocity.Evaluate(Hardpoint);
// bullet.Damage = _projectileWeapon.Damage.Evaluate(Hardpoint);
// inst.position = Hardpoint.Proxy.position;
// inst.rotation = Hardpoint.Proxy.rotation;
// inst.GetComponent<Rigidbody>().velocity = _projectileWeapon.Velocity.Evaluate(Hardpoint) * Vector3.RotateTowards(-inst.forward, Hardpoint.Ship.Ship.Direction, _projectileWeapon.Deflection * Mathf.Deg2Rad, 1);
// Hardpoint.Ship.Ship.AudioSource.PlayOneShot(_projectileWeapon.Sounds.RandomElement());
// Debug.Log($"Firing bullet {b}");
// }
public bool Update(float delta)
{
_burstTime = Context.Evaluate(_data.BurstTime, Item.EquippableItem, Entity) / _burstCount;
if (_burstTime < .01f)
{
for(int i=0; i<_data.BurstCount; i++)
OnFire?.Invoke();
}
else
{
_burstCount = _data.BurstCount;
Fire();
}
return true;
}
private void Fire()
{
_burstCount--;
_burstTimer = _burstTime;
OnFire?.Invoke();
}
public void AlwaysUpdate(float delta)
{
if(_burstCount > 0)
{
_burstTimer -= delta;
if(_burstTimer < 0)
Fire();
}
}
}

View file

@ -38,6 +38,9 @@ public abstract class Entity
public Entity Parent;
public List<Entity> Children = new List<Entity>();
public Entity Target;
public float3 LookDirection;
public string Name;
@ -56,7 +59,7 @@ public abstract class Entity
public HardpointData[,] Hardpoints;
private EquippedItem[] _orderedEquipment;
private bool _active;
protected bool _active;
public ItemManager ItemManager { get; }
public int AssignedPopulation => PopulationAssignments.Sum(pa => pa.AssignedPopulation);
@ -77,10 +80,13 @@ public abstract class Entity
if(behavior is IInitializableBehavior initializableBehavior)
initializableBehavior.Initialize();
}
OnActivate();
}
}
}
protected virtual void OnActivate(){}
public Entity(ItemManager itemManager, Zone zone, EquippableItem hull)
{
ItemManager = itemManager;
@ -231,9 +237,10 @@ public abstract class Entity
foreach (var i in itemData.Shape.Coordinates)
{
// If there is any gear already occupying that space, it won't fit
// If there's a hardpoint there, it won't fit
// Thermal items have their own layer and do not collide with gear
var itemCoord = hullCoord + itemData.Shape.Rotate(i, item.Rotation);
if (!hullData.InteriorCells[itemCoord] || (itemData.HardpointType == HardpointType.Thermal ? ThermalOccupancy : GearOccupancy)[itemCoord.x, itemCoord.y] != null) return false;
if (!hullData.InteriorCells[itemCoord] || (itemData.HardpointType == HardpointType.Tool && Hardpoints[itemCoord.x, itemCoord.y] != null) || (itemData.HardpointType == HardpointType.Thermal ? ThermalOccupancy : GearOccupancy)[itemCoord.x, itemCoord.y] != null) return false;
}
}
else
@ -661,6 +668,9 @@ public class EquippedItem
// EquippableItem.Durability -= delta;
// return;
// }
foreach (var behavior in Behaviors.Where(b => b is IAlwaysUpdatedBehavior).Cast<IAlwaysUpdatedBehavior>())
behavior.AlwaysUpdate(delta);
foreach (var group in BehaviorGroups)
{
@ -670,9 +680,6 @@ public class EquippedItem
break;
}
}
foreach (var behavior in Behaviors.Where(b => b is IAlwaysUpdatedBehavior).Cast<IAlwaysUpdatedBehavior>())
behavior.AlwaysUpdate(delta);
}
}

View file

@ -22,7 +22,27 @@ public class Ship : Entity
// [IgnoreMember] public Dictionary<Targetable, float> Contacts = new Dictionary<Targetable, float>();
// [IgnoreMember] public Targetable Target;
public Entity HomeEntity;
public float2 MovementDirection;
private Thruster[] _allThrusters;
private Thruster[] _forwardThrusters;
private Thruster[] _reverseThrusters;
private Thruster[] _rightThrusters;
private Thruster[] _leftThrusters;
private Thruster[] _clockwiseThrusters;
private Thruster[] _counterClockwiseThrusters;
protected override void OnActivate()
{
_allThrusters = 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 Ship(ItemManager itemManager, Zone zone, EquippableItem hull) : base(itemManager, zone, hull)
{
}
@ -30,6 +50,21 @@ public class Ship : Entity
public override void Update(float delta)
{
Position += Velocity * delta;
if (_active)
{
foreach (var thruster in _allThrusters) thruster.Axis = 0;
foreach (var thruster in _rightThrusters) thruster.Axis += MovementDirection.x;
foreach (var thruster in _leftThrusters) thruster.Axis += -MovementDirection.x;
foreach (var thruster in _forwardThrusters) thruster.Axis += MovementDirection.y;
foreach (var thruster in _reverseThrusters) thruster.Axis += -MovementDirection.y;
var deltaRot = dot(normalize(LookDirection.xz), normalize(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;
}
base.Update(delta);
}
}

View file

@ -6,6 +6,7 @@ using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.UI;
public class ConfirmationDialog : PropertiesPanel
@ -55,7 +56,7 @@ public class ConfirmationDialog : PropertiesPanel
Confirm.gameObject.SetActive(onConfirm!=null);
_onCancel = onCancel;
Cancel.gameObject.SetActive(onCancel!=null);
transform.position = Input.mousePosition;
transform.position = Mouse.current.position.ReadValue();
CancelClickCatcher.gameObject.SetActive(true);
}
}

View file

@ -104,6 +104,11 @@ public static class UnityExtensions
grad.colorKeys = keys.Select(k => new GradientColorKey(k.xyz.ToColor(), k.w)).ToArray();
return grad;
}
public static AnimationCurve ToCurve(this float4[] keys)
{
return new AnimationCurve(keys.Select(v => new Keyframe(v.x, v.y, v.z, v.w)).ToArray());
}
public static Color ToColor(this float3 v) => new Color(v.x,v.y,v.z);