Drag & Drop Inventory

Implemented the ability to drag items within and between inventories, including equipping them onto entity hardpoints
This commit is contained in:
Reinier Vens 2020-12-20 03:04:52 +00:00
commit e3f3bd5de5
21 changed files with 2029 additions and 1389 deletions

View file

@ -27,6 +27,7 @@
<e p="FilterTest.cs" t="Include" />
<e p="FitToCamera.cs" t="Include" />
<e p="GaussianBlurFilter.shader" t="Include" />
<e p="InventoryCell.cs" t="Include" />
<e p="InventoryMenu.cs" t="Include" />
<e p="MapMenuInput.cs" t="Include" />
<e p="MapRenderer.cs" t="Include" />

View file

@ -684,6 +684,7 @@
<Compile Include="Assets\Scripts\NIH\MSAGL\Routing\Rectilinear\BasicReflectionEvent.cs" />
<Compile Include="Assets\Scripts\NIH\MSAGL\Layout\Layered\IntEdge.cs" />
<Compile Include="Assets\Scripts\NIH\MSAGL\Routing\Spline\Bundling\PointPairOrder.cs" />
<Compile Include="Assets\InventoryCell.cs" />
<None Include="Assets\TextMesh Pro\Resources\Shaders\TMPro.cginc" />
<None Include="Assets\TextMesh Pro\Resources\Shaders\TMP_SDF-Mobile Overlay.shader" />
<None Include="Assets\Shaders\Clouds.shader" />

17
Assets/InventoryCell.cs Normal file
View file

@ -0,0 +1,17 @@
using System.Collections;
using System.Collections.Generic;
using UniRx.Triggers;
using UnityEngine;
using UnityEngine.UI;
public class InventoryCell : MonoBehaviour
{
public Image Icon;
public ObservablePointerClickTrigger PointerClickTrigger;
public ObservableBeginDragTrigger BeginDragTrigger;
public ObservableDragTrigger DragTrigger;
public ObservableEndDragTrigger EndDragTrigger;
public ObservablePointerEnterTrigger PointerEnterTrigger;
public ObservablePointerExitTrigger PointerExitTrigger;
}

View file

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

View file

@ -1,15 +1,270 @@
using System.Collections;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UniRx;
using UniRx.Triggers;
using Unity.Mathematics;
using UnityEngine.UI;
public class InventoryMenu : MonoBehaviour
{
public InventoryPanel LeftInventoryPanel;
public InventoryPanel RightInventoryPanel;
public InventoryPanel[] InventoryPanels;
public PropertiesPanel PropertiesPanel;
public ActionGameManager GameManager;
public RectTransform DragParent;
private int _currentPanel;
private int2 _selectedPosition;
private InventoryPanel _selectedPanel;
private ItemData _selectedItemData;
private ItemInstance _dragItem;
private Transform[] _dragCells;
private Vector2[] _dragOffsets;
private int2 _dragCellOffset;
private ItemRotation _originalRotation;
//private Shape _previousFakeOccupancy;
private Shape _originalOccupancy;
private EquippedItem _originalEquippedItem;
private InventoryPanel _originalPanel;
private InventoryPanel _dragTargetPanel;
private int2 _dragTargetPosition;
private int2 _lastDragPosition;
private bool _dragTargetValid;
public InventoryPanel GetPanel => InventoryPanels[_currentPanel = (_currentPanel + 1) % InventoryPanels.Length];
void Start()
{
PropertiesPanel.Context = GameManager.ItemManager;
foreach (var panel in InventoryPanels)
{
panel.OnBeginDragAsObservable().Subscribe(data =>
{
//Debug.Log($"Begin drag on panel {panel.name}");
if (data is InventoryCargoEventData cargoEvent)
{
var item = cargoEvent.CargoBay.Occupancy[cargoEvent.Position.x, cargoEvent.Position.y];
if (item != null)
{
var itemData = GameManager.ItemManager.GetData(item);
var itemPosition = cargoEvent.CargoBay.Cargo[item];
_originalOccupancy = cargoEvent.CargoBay.Data.InteriorShape.Inset(itemData.Shape, itemPosition, item.Rotation);
_originalRotation = item.Rotation;
_originalPanel = panel;
_dragItem = item;
_dragCellOffset = itemPosition - cargoEvent.Position;
_dragCells = _originalOccupancy.Coordinates
.Select(v => Instantiate(panel.CellInstances[v], DragParent, true).transform).ToArray();
foreach(var cell in _dragCells)
{
foreach (var component in cell.GetComponentsInChildren<ObservableTriggerBase>())
component.enabled = false;
cell.GetComponentInChildren<Image>().raycastTarget = false;
}
_dragOffsets = _dragCells.Select(x => (Vector2) x.position - data.PointerEventData.position).ToArray();
panel.IgnoreOccupancy = _originalOccupancy;
panel.RefreshCells(_originalOccupancy.Expand().Coordinates);
}
}
else if (data is InventoryEntityEventData entityEvent)
{
var item = entityEvent.Entity.GearOccupancy[entityEvent.Position.x, entityEvent.Position.y];
if (item != null)
{
var itemData = GameManager.ItemManager.GetData(item.EquippableItem);
var hullData = GameManager.ItemManager.GetData(entityEvent.Entity.Hull);
_originalRotation = item.EquippableItem.Rotation;
_originalEquippedItem = entityEvent.Entity.GearOccupancy[data.Position.x, data.Position.y];
_originalOccupancy = hullData.Shape.Inset(itemData.Shape, item.Position, item.EquippableItem.Rotation);
_originalPanel = panel;
_dragItem = item.EquippableItem;
_dragCellOffset = item.Position - entityEvent.Position;
_dragCells = _originalOccupancy.Coordinates
.Select(v => Instantiate(panel.CellInstances[v], DragParent, true).transform).ToArray();
foreach(var cell in _dragCells)
{
foreach (var component in cell.GetComponentsInChildren<ObservableTriggerBase>())
component.enabled = false;
cell.GetComponentInChildren<Image>().raycastTarget = false;
}
_dragOffsets = _dragCells.Select(x => (Vector2) x.position - data.PointerEventData.position).ToArray();
panel.IgnoreOccupancy = _originalOccupancy;
panel.RefreshCells(_originalOccupancy.Expand().Coordinates);
}
}
});
panel.OnDragAsObservable().Subscribe(data =>
{
if (_dragItem == null) return;
var scroll = data.PointerEventData.scrollDelta.y;
if(scroll != 0)
Debug.Log($"Scrolling {scroll}!");
for (var i = 0; i < _dragCells.Length; i++)
_dragCells[i].position = new Vector3(
data.PointerEventData.position.x + _dragOffsets[i].x,
data.PointerEventData.position.y + _dragOffsets[i].y,
_dragCells[i].position.z);
});
panel.OnEndDragAsObservable().Subscribe(data =>
{
if (_dragItem == null) return;
if (_dragTargetValid)
{
if (data is InventoryCargoEventData cargoEvent)
{
cargoEvent.CargoBay.Remove(_dragItem);
}
else if (data is InventoryEntityEventData entityEvent)
{
entityEvent.Entity.Unequip(_originalEquippedItem);
}
_dragTargetPanel.DropItem(_dragItem, _dragTargetPosition);
_dragTargetPanel.FakeOccupancy = null;
}
else
{
_dragItem.Rotation = _originalRotation;
}
panel.IgnoreOccupancy = null;
panel.RefreshCells();
if(_dragTargetPanel!=panel)
_dragTargetPanel.RefreshCells();
_dragItem = null;
foreach (var cell in _dragCells) Destroy(cell.gameObject);
});
Action floatCells = () =>
{
foreach (var cell in _dragCells) cell.gameObject.SetActive(true);
_dragTargetValid = false;
};
panel.OnPointerEnterAsObservable().Subscribe(data =>
{
if (_dragItem == null) return;
Debug.Log($"Pointer entered {data.Position}");
// if(panel != _originalPanel)
// _originalPanel.RefreshCells();
_dragTargetPanel = panel;
_lastDragPosition = data.Position;
_dragTargetPosition = data.Position + _dragCellOffset;
if (data is InventoryCargoEventData cargoEvent)
{
if (cargoEvent.CargoBay.ItemFits(_dragItem, _dragTargetPosition))
{
foreach (var cell in _dragCells) cell.gameObject.SetActive(false);
var itemData = GameManager.ItemManager.GetData(_dragItem);
panel.FakeItem = _dragItem;
panel.FakeOccupancy = cargoEvent.CargoBay.Data.InteriorShape.Inset(itemData.Shape, _dragTargetPosition, _dragItem.Rotation);
_dragTargetValid = true;
panel.RefreshCells();
}
}
else if (data is InventoryEntityEventData entityEvent)
{
var eqItem = _dragItem as EquippableItem;
var hullData = GameManager.ItemManager.GetData(entityEvent.Entity.Hull);
if (eqItem != null && entityEvent.Entity.ItemFits(eqItem, _dragTargetPosition))
{
foreach (var cell in _dragCells) cell.gameObject.SetActive(false);
var itemData = GameManager.ItemManager.GetData(_dragItem);
panel.FakeEquipment = _originalEquippedItem;
panel.FakeOccupancy = hullData.Shape.Inset(itemData.Shape, _dragTargetPosition, _dragItem.Rotation);
_dragTargetValid = true;
panel.RefreshCells();
}
}
});
panel.OnPointerExitAsObservable().Subscribe(data =>
{
if (_dragItem == null) return;
if (data.Position.Equals(_lastDragPosition) || !_dragTargetValid)
{
panel.FakeItem = null;
panel.FakeOccupancy = null;
panel.RefreshCells();
// if (_originalPanel != panel)
// {
// _originalPanel.FakeItem = null;
// _originalPanel.FakeOccupancy = null;
// _originalPanel.RefreshCells();
// }
floatCells();
}
});
panel.OnClickAsObservable().Subscribe(data =>
{
if (data is InventoryCargoEventData cargoEvent)
{
var item = cargoEvent.CargoBay.Occupancy[cargoEvent.Position.x, cargoEvent.Position.y];
if(item!=null)
{
if (_selectedPanel != null)
{
foreach (var v in _selectedItemData.Shape.Coordinates)
{
var v2 = v + _selectedPosition;
_selectedPanel.CellInstances[v2].Icon.color = _selectedPanel.GetColor(v2);
}
}
_selectedPanel = panel;
_selectedPosition = cargoEvent.Position;
PropertiesPanel.Clear();
PropertiesPanel.AddItemProperties(item);
_selectedPanel = panel;
_selectedPosition = cargoEvent.CargoBay.Cargo[item];
_selectedItemData = GameManager.ItemManager.GetData(item);
foreach (var v in _selectedItemData.Shape.Coordinates)
{
var v2 = _selectedItemData.Shape.Rotate(v, item.Rotation) + _selectedPosition;
_selectedPanel.CellInstances[v2].Icon.color = _selectedPanel.GetColor(v2, true);
}
}
}
else if (data is InventoryEntityEventData entityEvent)
{
var item = entityEvent.Entity.GearOccupancy[entityEvent.Position.x, entityEvent.Position.y];
if (item != null)
{
if (_selectedPanel != null)
{
foreach (var v in _selectedItemData.Shape.Coordinates)
{
var v2 = v + _selectedItemData.Shape.Rotate(_selectedPosition, item.EquippableItem.Rotation);
_selectedPanel.CellInstances[v2].Icon.color = _selectedPanel.GetColor(v2);
}
}
PropertiesPanel.Inspect(entityEvent.Entity, item);
_selectedPanel = panel;
_selectedPosition = item.Position;
_selectedItemData = GameManager.ItemManager.GetData(item.EquippableItem);
foreach (var v in _selectedItemData.Shape.Coordinates)
{
var v2 = v + _selectedPosition;
_selectedPanel.CellInstances[v2].Icon.color = _selectedPanel.GetColor(v2, true);
}
}
}
});
}
}
void Update()

View file

@ -82,7 +82,7 @@ Material:
- _Mode: 0
- _OcclusionStrength: 1
- _Parallax: 0.02
- _Scale: 1.7903528
- _Scale: 1
- _SmoothnessTextureChannel: 0
- _SpecularHighlights: 1
- _SrcBlend: 1

View file

@ -74,8 +74,8 @@ Material:
- _UVSec: 0
- _ZWrite: 1
m_Colors:
- _AdditiveColor: {r: 0.022499999, g: 0.025, b: 0.03, a: 0}
- _AdditiveColor: {r: 0.035, g: 0.035, b: 0.05, a: 0}
- _Color: {r: 1, g: 1, b: 1, a: 1}
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}
- _MultiplyColor: {r: 0.45000002, g: 0.50000006, b: 0.6, a: 1}
- _MultiplyColor: {r: 0.21071698, g: 0.24110693, b: 0.3018868, a: 1}
m_BuildTextureStacks: []

View file

@ -596,7 +596,7 @@ MonoBehaviour:
m_TargetGraphic: {fileID: 2279630452912159028}
m_HandleRect: {fileID: 2279630452912159027}
m_Direction: 0
m_Value: 1
m_Value: 0
m_Size: 1
m_NumberOfSteps: 0
m_OnValueChanged:
@ -613,6 +613,12 @@ GameObject:
- component: {fileID: 2279630453345861720}
- component: {fileID: 2279630453345861722}
- component: {fileID: 2279630453345861721}
- component: {fileID: 5461050610218844277}
- component: {fileID: 5747035144148683486}
- component: {fileID: 3584371112157775779}
- component: {fileID: 3507449623040604819}
- component: {fileID: 1876119682947177707}
- component: {fileID: 3026868749259999386}
m_Layer: 5
m_Name: Image
m_TagString: Untagged
@ -677,6 +683,78 @@ MonoBehaviour:
m_FillOrigin: 0
m_UseSpriteMesh: 0
m_PixelsPerUnitMultiplier: 1
--- !u!114 &5461050610218844277
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2279630453345861799}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: aa69c313aba23f945b760e79c45083ad, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!114 &5747035144148683486
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2279630453345861799}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: b8ce8424f238d6842bd8b09c0cca1ac4, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!114 &3584371112157775779
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2279630453345861799}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 3a81a9b6bec6b4f4fba7e0047cd989f6, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!114 &3507449623040604819
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2279630453345861799}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 79db090dc9e4db245821e8b89b0e208e, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!114 &1876119682947177707
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2279630453345861799}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 3468b3db8d419c745b12124f6432696b, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!114 &3026868749259999386
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2279630453345861799}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 9643e74593988274bbed9adf40384e48, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!1 &2279630453679143106
GameObject:
m_ObjectHideFlags: 0
@ -847,9 +925,9 @@ RectTransform:
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 1, y: 1}
m_AnchoredPosition: {x: -0.000030517578, y: 0}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 0, y: 0}
m_Pivot: {x: 0, y: 1}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &2279630453710142156
MonoBehaviour:
m_ObjectHideFlags: 0
@ -1459,6 +1537,7 @@ MonoBehaviour:
- {fileID: -3137123266071239926, guid: ef4a863cd35ba454cb1d7e37e6388abe, type: 3}
- {fileID: 6575361018301538774, guid: ef4a863cd35ba454cb1d7e37e6388abe, type: 3}
NodePrototype: {fileID: 2279630454000268455}
EmptyCells: []
--- !u!222 &6932930312706461541
CanvasRenderer:
m_ObjectHideFlags: 0
@ -1507,6 +1586,7 @@ GameObject:
m_Component:
- component: {fileID: 2279630454000268454}
- component: {fileID: 2279630454000268455}
- component: {fileID: 7879594224560844191}
m_Layer: 5
m_Name: Inventory Cell
m_TagString: Untagged
@ -1546,6 +1626,25 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 1281fe44325f9b548aa42dc331b17266, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!114 &7879594224560844191
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2279630454000268453}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: e28c3f1c546ff7544a127c24a6ee3091, type: 3}
m_Name:
m_EditorClassIdentifier:
Icon: {fileID: 2279630453345861721}
PointerClickTrigger: {fileID: 5461050610218844277}
BeginDragTrigger: {fileID: 3584371112157775779}
DragTrigger: {fileID: 3507449623040604819}
EndDragTrigger: {fileID: 5747035144148683486}
PointerEnterTrigger: {fileID: 1876119682947177707}
PointerExitTrigger: {fileID: 3026868749259999386}
--- !u!1 &2279630454002795610
GameObject:
m_ObjectHideFlags: 0
@ -1770,7 +1869,7 @@ RectTransform:
m_Children: []
m_Father: {fileID: 6584545650613466935}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: -90}
m_AnchorMin: {x: 0, y: 1}
m_AnchorMax: {x: 0, y: 1}
m_AnchoredPosition: {x: 208.995, y: -20}

Binary file not shown.

File diff suppressed because it is too large Load diff

Binary file not shown.

View file

@ -1006,6 +1006,41 @@ RectTransform:
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 0, y: 0}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!1 &245842384
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 245842385}
m_Layer: 5
m_Name: Drag Parent
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!224 &245842385
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 245842384}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 1997243493}
m_RootOrder: 3
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 1, y: 1}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 0, y: 0}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!1 &250585912
GameObject:
m_ObjectHideFlags: 0
@ -1273,6 +1308,11 @@ PrefabInstance:
propertyPath: m_Name
value: Enum Field
objectReference: {fileID: 0}
- target: {fileID: 1444953514731475977, guid: f19a14cd178d48f49ace9ad217bea2ed,
type: 3}
propertyPath: m_IsActive
value: 0
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: f19a14cd178d48f49ace9ad217bea2ed, type: 3}
--- !u!224 &298915890 stripped
@ -1398,6 +1438,11 @@ PrefabInstance:
propertyPath: m_Name
value: Property Button
objectReference: {fileID: 0}
- target: {fileID: 1613450655389604798, guid: 99bde06e2f0ca504bb95f2a4e3429462,
type: 3}
propertyPath: m_IsActive
value: 0
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 99bde06e2f0ca504bb95f2a4e3429462, type: 3}
--- !u!224 &314907096 stripped
@ -1528,6 +1573,11 @@ PrefabInstance:
propertyPath: m_Name
value: Input Field
objectReference: {fileID: 0}
- target: {fileID: 23155009655760171, guid: fb49ef180533e3e488fa39d80cc2423a,
type: 3}
propertyPath: m_IsActive
value: 0
objectReference: {fileID: 0}
- target: {fileID: 23155009655760172, guid: fb49ef180533e3e488fa39d80cc2423a,
type: 3}
propertyPath: m_LocalPosition.x
@ -1990,6 +2040,11 @@ PrefabInstance:
propertyPath: m_Name
value: Property Label
objectReference: {fileID: 0}
- target: {fileID: 2677123916507168712, guid: 5b8c5126640066e4fabe6e65b7225b3b,
type: 3}
propertyPath: m_IsActive
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2677123916507168719, guid: 5b8c5126640066e4fabe6e65b7225b3b,
type: 3}
propertyPath: m_LocalPosition.x
@ -2423,6 +2478,7 @@ MonoBehaviour:
type: 3}
IncrementField: {fileID: 5486709585343280439, guid: 9c14c92a1a08b0a4fb4f6aa6f8504082,
type: 3}
Content: {fileID: 0}
SelectedChild: {fileID: 0}
CancelClickCatcher: {fileID: 1420548305}
Cancel: {fileID: 0}
@ -2545,116 +2601,6 @@ PrefabInstance:
m_Modification:
m_TransformParent: {fileID: 1997243493}
m_Modifications:
- target: {fileID: 2279630452592903581, guid: aac073da6df367d499834c926930dd84,
type: 3}
propertyPath: m_AnchorMax.x
value: 1
objectReference: {fileID: 0}
- target: {fileID: 2279630452592903581, guid: aac073da6df367d499834c926930dd84,
type: 3}
propertyPath: m_AnchorMax.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2279630452592903581, guid: aac073da6df367d499834c926930dd84,
type: 3}
propertyPath: m_AnchorMin.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2279630452912159027, guid: aac073da6df367d499834c926930dd84,
type: 3}
propertyPath: m_AnchorMax.x
value: 1
objectReference: {fileID: 0}
- target: {fileID: 2279630452912159027, guid: aac073da6df367d499834c926930dd84,
type: 3}
propertyPath: m_AnchorMax.y
value: 1
objectReference: {fileID: 0}
- target: {fileID: 2279630452912159027, guid: aac073da6df367d499834c926930dd84,
type: 3}
propertyPath: m_AnchorMin.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2279630452951644481, guid: aac073da6df367d499834c926930dd84,
type: 3}
propertyPath: m_AnchorMax.x
value: 1
objectReference: {fileID: 0}
- target: {fileID: 2279630452951644481, guid: aac073da6df367d499834c926930dd84,
type: 3}
propertyPath: m_AnchorMax.y
value: 1
objectReference: {fileID: 0}
- target: {fileID: 2279630452951644481, guid: aac073da6df367d499834c926930dd84,
type: 3}
propertyPath: m_SizeDelta.x
value: -10
objectReference: {fileID: 0}
- target: {fileID: 2279630452951644481, guid: aac073da6df367d499834c926930dd84,
type: 3}
propertyPath: m_SizeDelta.y
value: -10
objectReference: {fileID: 0}
- target: {fileID: 2279630453233804081, guid: aac073da6df367d499834c926930dd84,
type: 3}
propertyPath: m_AnchorMax.x
value: 1
objectReference: {fileID: 0}
- target: {fileID: 2279630453233804081, guid: aac073da6df367d499834c926930dd84,
type: 3}
propertyPath: m_SizeDelta.x
value: -10
objectReference: {fileID: 0}
- target: {fileID: 2279630453679143107, guid: aac073da6df367d499834c926930dd84,
type: 3}
propertyPath: m_AnchorMin.y
value: 1
objectReference: {fileID: 0}
- target: {fileID: 2279630453679143107, guid: aac073da6df367d499834c926930dd84,
type: 3}
propertyPath: m_AnchorMax.y
value: 1
objectReference: {fileID: 0}
- target: {fileID: 2279630453679143107, guid: aac073da6df367d499834c926930dd84,
type: 3}
propertyPath: m_AnchoredPosition.x
value: 224.995
objectReference: {fileID: 0}
- target: {fileID: 2279630453679143107, guid: aac073da6df367d499834c926930dd84,
type: 3}
propertyPath: m_AnchoredPosition.y
value: -8
objectReference: {fileID: 0}
- target: {fileID: 2279630453679143107, guid: aac073da6df367d499834c926930dd84,
type: 3}
propertyPath: m_SizeDelta.y
value: 24
objectReference: {fileID: 0}
- target: {fileID: 2279630453679143107, guid: aac073da6df367d499834c926930dd84,
type: 3}
propertyPath: m_SizeDelta.x
value: 108.01
objectReference: {fileID: 0}
- target: {fileID: 2279630453710142155, guid: aac073da6df367d499834c926930dd84,
type: 3}
propertyPath: m_SizeDelta.x
value: -396
objectReference: {fileID: 0}
- target: {fileID: 2279630453710142155, guid: aac073da6df367d499834c926930dd84,
type: 3}
propertyPath: m_SizeDelta.y
value: -544.6676
objectReference: {fileID: 0}
- target: {fileID: 2279630453710142155, guid: aac073da6df367d499834c926930dd84,
type: 3}
propertyPath: m_AnchoredPosition.x
value: 0.00063671323
objectReference: {fileID: 0}
- target: {fileID: 2279630453710142155, guid: aac073da6df367d499834c926930dd84,
type: 3}
propertyPath: m_AnchoredPosition.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2279630453886260052, guid: aac073da6df367d499834c926930dd84,
type: 3}
propertyPath: m_Name
@ -2775,91 +2721,6 @@ PrefabInstance:
propertyPath: ContextMenu
value:
objectReference: {fileID: 1157981993}
- target: {fileID: 2279630454000268454, guid: aac073da6df367d499834c926930dd84,
type: 3}
propertyPath: m_AnchorMin.y
value: 1
objectReference: {fileID: 0}
- target: {fileID: 2279630454000268454, guid: aac073da6df367d499834c926930dd84,
type: 3}
propertyPath: m_AnchorMax.y
value: 1
objectReference: {fileID: 0}
- target: {fileID: 2279630454000268454, guid: aac073da6df367d499834c926930dd84,
type: 3}
propertyPath: m_AnchoredPosition.x
value: 72
objectReference: {fileID: 0}
- target: {fileID: 2279630454000268454, guid: aac073da6df367d499834c926930dd84,
type: 3}
propertyPath: m_AnchoredPosition.y
value: -24
objectReference: {fileID: 0}
- target: {fileID: 2279630454000268454, guid: aac073da6df367d499834c926930dd84,
type: 3}
propertyPath: m_SizeDelta.x
value: 32
objectReference: {fileID: 0}
- target: {fileID: 2279630454000268454, guid: aac073da6df367d499834c926930dd84,
type: 3}
propertyPath: m_SizeDelta.y
value: 32
objectReference: {fileID: 0}
- target: {fileID: 2279630454002795611, guid: aac073da6df367d499834c926930dd84,
type: 3}
propertyPath: m_AnchorMax.y
value: 1
objectReference: {fileID: 0}
- target: {fileID: 2279630454002795611, guid: aac073da6df367d499834c926930dd84,
type: 3}
propertyPath: m_SizeDelta.y
value: -10
objectReference: {fileID: 0}
- target: {fileID: 4397116930423727094, guid: aac073da6df367d499834c926930dd84,
type: 3}
propertyPath: m_SizeDelta.y
value: 16
objectReference: {fileID: 0}
- target: {fileID: 4397116930423727094, guid: aac073da6df367d499834c926930dd84,
type: 3}
propertyPath: m_AnchorMin.y
value: 1
objectReference: {fileID: 0}
- target: {fileID: 4397116930423727094, guid: aac073da6df367d499834c926930dd84,
type: 3}
propertyPath: m_AnchorMax.y
value: 1
objectReference: {fileID: 0}
- target: {fileID: 4397116930423727094, guid: aac073da6df367d499834c926930dd84,
type: 3}
propertyPath: m_AnchoredPosition.x
value: 208.995
objectReference: {fileID: 0}
- target: {fileID: 4397116930423727094, guid: aac073da6df367d499834c926930dd84,
type: 3}
propertyPath: m_SizeDelta.x
value: 16
objectReference: {fileID: 0}
- target: {fileID: 4397116930423727094, guid: aac073da6df367d499834c926930dd84,
type: 3}
propertyPath: m_AnchoredPosition.y
value: -20
objectReference: {fileID: 0}
- target: {fileID: 4397116930423727094, guid: aac073da6df367d499834c926930dd84,
type: 3}
propertyPath: m_LocalEulerAnglesHint.z
value: -90
objectReference: {fileID: 0}
- target: {fileID: 5451249918807071883, guid: aac073da6df367d499834c926930dd84,
type: 3}
propertyPath: m_IsActive
value: 1
objectReference: {fileID: 0}
- target: {fileID: 6584545650613466935, guid: aac073da6df367d499834c926930dd84,
type: 3}
propertyPath: m_LocalPosition.y
value: 0
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: aac073da6df367d499834c926930dd84, type: 3}
--- !u!224 &642590527 stripped
@ -3497,6 +3358,11 @@ PrefabInstance:
propertyPath: m_Name
value: Increment Field
objectReference: {fileID: 0}
- target: {fileID: 6770904480725292324, guid: 9c14c92a1a08b0a4fb4f6aa6f8504082,
type: 3}
propertyPath: m_IsActive
value: 0
objectReference: {fileID: 0}
- target: {fileID: 7863247503782211248, guid: 9c14c92a1a08b0a4fb4f6aa6f8504082,
type: 3}
propertyPath: m_SizeDelta.y
@ -3905,6 +3771,11 @@ PrefabInstance:
propertyPath: m_Name
value: Button Field
objectReference: {fileID: 0}
- target: {fileID: 6566784227922820056, guid: 6db1feb4cda7b8c419384cd42c85a5c4,
type: 3}
propertyPath: m_IsActive
value: 0
objectReference: {fileID: 0}
- target: {fileID: 6566784227922820063, guid: 6db1feb4cda7b8c419384cd42c85a5c4,
type: 3}
propertyPath: m_LocalPosition.x
@ -4656,8 +4527,8 @@ MonoBehaviour:
TopDownCamera: {fileID: 887677622}
FollowCamera: {fileID: 887677622}
GameplayUI: {fileID: 346000246}
Menu: {fileID: 0}
Inventory: {fileID: 0}
Menu: {fileID: 1726632268}
Inventory: {fileID: 1997243495}
--- !u!4 &1009503730
Transform:
m_ObjectHideFlags: 0
@ -4936,6 +4807,18 @@ MonoBehaviour:
m_EditorClassIdentifier:
lod1Threshold: 0.5
lod2Threshold: 0.2
--- !u!114 &1010491577 stripped
MonoBehaviour:
m_CorrespondingSourceObject: {fileID: 2279630453886260054, guid: aac073da6df367d499834c926930dd84,
type: 3}
m_PrefabInstance: {fileID: 2279630454421103832}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 78aa0b8ec7594a7438f13757228e3500, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!1 &1037490738
GameObject:
m_ObjectHideFlags: 0
@ -7209,6 +7092,11 @@ PrefabInstance:
propertyPath: m_Name
value: Ranged Float Field
objectReference: {fileID: 0}
- target: {fileID: 4127690186169542500, guid: c214f62d8f2188140b96ed12798034c8,
type: 3}
propertyPath: m_IsActive
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4127690186274268520, guid: c214f62d8f2188140b96ed12798034c8,
type: 3}
propertyPath: m_AnchorMin.y
@ -8057,6 +7945,18 @@ CanvasRenderer:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1868140980}
m_CullTransparentMesh: 0
--- !u!114 &1897237531 stripped
MonoBehaviour:
m_CorrespondingSourceObject: {fileID: 2279630453886260054, guid: aac073da6df367d499834c926930dd84,
type: 3}
m_PrefabInstance: {fileID: 642590526}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 78aa0b8ec7594a7438f13757228e3500, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!1 &1938407917
GameObject:
m_ObjectHideFlags: 0
@ -8368,6 +8268,7 @@ RectTransform:
- {fileID: 642590527}
- {fileID: 568539021}
- {fileID: 7399108074413661591}
- {fileID: 245842385}
m_Father: {fileID: 1726632265}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
@ -8396,8 +8297,12 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 238f19b944b59394481b32a38d68dc0f, type: 3}
m_Name:
m_EditorClassIdentifier:
LeftInventoryPanel: {fileID: 0}
RightInventoryPanel: {fileID: 0}
InventoryPanels:
- {fileID: 1897237531}
- {fileID: 1010491577}
PropertiesPanel: {fileID: 7399108074413661592}
GameManager: {fileID: 1009503729}
DragParent: {fileID: 245842385}
--- !u!1001 &2078780388
PrefabInstance:
m_ObjectHideFlags: 0
@ -8440,6 +8345,11 @@ PrefabInstance:
propertyPath: m_Name
value: Property
objectReference: {fileID: 0}
- target: {fileID: 9159917045172241899, guid: be88722a74d512d45a454fe91327a389,
type: 3}
propertyPath: m_IsActive
value: 0
objectReference: {fileID: 0}
- target: {fileID: 9159917045172241900, guid: be88722a74d512d45a454fe91327a389,
type: 3}
propertyPath: m_LocalPosition.x
@ -8595,6 +8505,11 @@ PrefabInstance:
propertyPath: m_Name
value: Bool Field
objectReference: {fileID: 0}
- target: {fileID: 7661950293931311386, guid: 001ad6a15f0d582458d359c0ae4405ed,
type: 3}
propertyPath: m_IsActive
value: 0
objectReference: {fileID: 0}
- target: {fileID: 7661950293931311387, guid: 001ad6a15f0d582458d359c0ae4405ed,
type: 3}
propertyPath: m_LocalPosition.x
@ -8895,6 +8810,11 @@ PrefabInstance:
propertyPath: m_Name
value: Progress Field
objectReference: {fileID: 0}
- target: {fileID: 3301729265155698788, guid: e6524d59d9bc67545b0eb1304bfb9d4b,
type: 3}
propertyPath: m_IsActive
value: 0
objectReference: {fileID: 0}
- target: {fileID: 3301729265189646952, guid: e6524d59d9bc67545b0eb1304bfb9d4b,
type: 3}
propertyPath: m_AnchorMin.y
@ -9297,6 +9217,7 @@ MonoBehaviour:
type: 3}
IncrementField: {fileID: 5486709585343280439, guid: 9c14c92a1a08b0a4fb4f6aa6f8504082,
type: 3}
Content: {fileID: 0}
SelectedChild: {fileID: 0}
--- !u!1 &560317484550429498
GameObject:
@ -9787,6 +9708,11 @@ PrefabInstance:
propertyPath: m_Name
value: Property Section
objectReference: {fileID: 0}
- target: {fileID: 1026668114703092141, guid: 3a149ea40b43fbf47b51ec165cb04e5f,
type: 3}
propertyPath: m_IsActive
value: 0
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 3a149ea40b43fbf47b51ec165cb04e5f, type: 3}
--- !u!224 &1719766129265659975 stripped
@ -9912,6 +9838,11 @@ PrefabInstance:
propertyPath: m_Name
value: Property List
objectReference: {fileID: 0}
- target: {fileID: 2088721703295321221, guid: 93e63e3a8b352a04897123288d70f04b,
type: 3}
propertyPath: m_IsActive
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2118837324186690404, guid: 93e63e3a8b352a04897123288d70f04b,
type: 3}
propertyPath: m_AnchoredPosition.y
@ -13185,6 +13116,7 @@ MonoBehaviour:
type: 3}
IncrementField: {fileID: 5486709585343280439, guid: 9c14c92a1a08b0a4fb4f6aa6f8504082,
type: 3}
Content: {fileID: 560317484512439620}
SelectedChild: {fileID: 0}
--- !u!114 &7399108074413661593
MonoBehaviour:

View file

@ -118,13 +118,24 @@ 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));
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;
station.TryDock(ship);
Dock();
// MapButton.onClick.AddListener(() =>
// {
@ -137,6 +148,23 @@ public class ActionGameManager : MonoBehaviour
//InventoryPanel.Display(ItemManager, entity);
}
public void Dock()
{
foreach (var entity in Zone.Entities)
{
if (lengthsq(entity.Position - _currentShip.Position) <
Settings.GameplaySettings.DockingDistance * Settings.GameplaySettings.DockingDistance)
{
var bay = entity.TryDock(_currentShip);
if (bay != null)
{
Inventory.GetPanel.Display(bay);
Inventory.GetPanel.Display(_currentShip);
}
}
}
}
public void SaveZone() => File.WriteAllBytes(
Path.Combine(_filePath.FullName, $"{Zone.Data.Name}.zone"), MessagePackSerializer.Serialize(Zone.Pack()));

View file

@ -14,7 +14,7 @@ namespace UniRx.Triggers
void IPointerClickHandler.OnPointerClick(PointerEventData eventData)
{
if (onPointerClick != null) onPointerClick.OnNext(eventData);
onPointerClick?.OnNext(eventData);
}
public IObservable<PointerEventData> OnPointerClickAsObservable()

View file

@ -292,7 +292,7 @@ public class SectorRenderer : MonoBehaviour
var planetInstance = _zone.PlanetInstances[planet.Key];
var p = _zone.GetOrbitPosition(planetInstance.BodyData.Orbit);
planet.Value.transform.position = new Vector3(p.x, 0, p.y);
planet.Value.Body.transform.position = new Vector3(0, _zone.GetHeight(p) + planetInstance.BodyRadius.Value * 2, 0);
planet.Value.Body.transform.localPosition = new Vector3(0, _zone.GetHeight(p) + planetInstance.BodyRadius.Value * 2, 0);
if(planet.Value is GasGiantObject gasGiantObject)
{
gasGiantObject.GravityWaves.material.SetFloat("_Phase", Time * Settings.PlanetSettings.WaveSpeed.Evaluate(planetInstance.BodyData.Mass.Value));

View file

@ -191,12 +191,12 @@ public abstract class Entity
Equipment.Remove(item);
var hullData = ItemManager.GetData(Hull) as HullData;
var itemData = ItemManager.GetData(item.EquippableItem);
foreach (var i in itemData.Shape.Coordinates)
{
var itemCoord = item.Position + itemData.Shape.Rotate(i, item.EquippableItem.Rotation);
(itemData.HardpointType == HardpointType.Thermal ? ThermalOccupancy : GearOccupancy)[itemCoord.x, itemCoord.y] = null;
}
var itemLayer = (itemData.HardpointType == HardpointType.Thermal ? ThermalOccupancy : GearOccupancy);
foreach (var i in hullData.Shape.Coordinates)
if (itemLayer[i.x, i.y] == item)
itemLayer[i.x, i.y] = null;
return item.EquippableItem;
}
@ -204,6 +204,9 @@ public abstract class Entity
// Check whether the given item will fit when its origin is placed at the given coordinate
private bool ItemFits(EquippableItemData itemData, HullData hullData, EquippableItem item, int2 hullCoord)
{
// If the given coordinate isn't even in the ship it obviously won't fit
if (!hullData.Shape[hullCoord]) return false;
// Items without specific hardpoints on the ship can be freely rotated and placed anywhere
if (itemData.HardpointType == HardpointType.Tool || itemData.HardpointType == HardpointType.Thermal)
{
@ -226,16 +229,21 @@ public abstract class Entity
// If the hardpoint type doesn't match the item, it won't fit
if (hardpoint.Type != itemData.HardpointType) return false;
// Items placed in hardpoints are automatically aligned to hardpoint rotation
item.Rotation = hardpoint.Rotation;
// Inset the shapes of both item and hardpoint
var itemShapeInset = hullData.Shape.Inset(itemData.Shape, hullCoord, item.Rotation);
var hardpointShapeInset = hullData.Shape.Inset(hardpoint.Shape, hardpoint.Position);
// Check every cell of the item's shape
foreach (var i in itemData.Shape.Coordinates)
foreach (var i in itemShapeInset.Coordinates)
{
// If the hardpoint does not have a matching cell, it wont fit
if (!hardpoint.Shape[i]) return false;
if (!hardpointShapeInset[i]) return false;
// If there is any gear already occupying that space, it won't fit
// Items placed in hardpoints are automatically aligned to hardpoint rotation
var itemCoord = hardpoint.Position + itemData.Shape.Rotate(i, hardpoint.Rotation);
if (GearOccupancy[itemCoord.x, itemCoord.y] != null) return false;
if (GearOccupancy[i.x, i.y] != null) return false;
}
}
@ -343,7 +351,7 @@ public abstract class Entity
foreach (var i in itemData.Shape.Coordinates)
{
var occupiedCoord = hullCoord + i;
var occupiedCoord = hullCoord + itemData.Shape.Rotate(i, item.Rotation);
(itemData.HardpointType == HardpointType.Thermal ? ThermalOccupancy : GearOccupancy)[occupiedCoord.x, occupiedCoord.y] = equippedItem;
}
@ -589,7 +597,7 @@ public class EquippedCargoBay : EquippedItem
}
// Check whether the given item will fit when its origin is placed at the given coordinate
private bool ItemFits(ItemInstance item, int2 cargoCoord)
public bool ItemFits(ItemInstance item, int2 cargoCoord)
{
var itemData = _itemManager.GetData(item);
// Check every cell of the item's shape
@ -597,7 +605,7 @@ public class EquippedCargoBay : EquippedItem
{
// If there is an item already occupying that space, it won't fit
var itemCargoCoord = cargoCoord + itemData.Shape.Rotate(i, item.Rotation);
if (Occupancy[itemCargoCoord.x, itemCargoCoord.y] != null) return false;
if (!Data.InteriorShape[itemCargoCoord] || (Occupancy[itemCargoCoord.x, itemCargoCoord.y] != null && Occupancy[itemCargoCoord.x, itemCargoCoord.y] != item)) return false;
}
return true;
@ -641,6 +649,15 @@ public class EquippedCargoBay : EquippedItem
return false;
}
public bool TryStore(ItemInstance item, int2 cargoCoord)
{
if (item is SimpleCommodity simpleCommodity)
return TryStore(simpleCommodity, cargoCoord);
if (item is CraftedItemInstance craftedItem)
return TryStore(craftedItem, cargoCoord);
return false;
}
// Attempts to store all of the given item anywhere in the inventory
// Will attempt to fill existing item stacks first
// Returns true only when ALL of the items are successfully stored
@ -751,8 +768,9 @@ public class EquippedCargoBay : EquippedItem
var itemData = _itemManager.GetData(item);
if(quantity >= item.Quantity)
{
foreach (var pos in itemData.Shape.Coordinates.Select(p => Cargo[item] + itemData.Shape.Rotate(p, item.Rotation)))
Occupancy[pos.x, pos.y] = null;
foreach(var v in Data.InteriorShape.Coordinates)
if (Occupancy[v.x, v.y] == item)
Occupancy[v.x, v.y] = null;
Cargo.Remove(item);
ItemsOfType[item.Data].Remove(item);
@ -779,8 +797,9 @@ public class EquippedCargoBay : EquippedItem
return;
}
var itemData = _itemManager.GetData(item);
foreach (var pos in itemData.Shape.Coordinates.Select(p => Cargo[item] + itemData.Shape.Rotate(p, item.Rotation)))
Occupancy[pos.x, pos.y] = null;
foreach(var v in Data.InteriorShape.Coordinates)
if (Occupancy[v.x, v.y] == item)
Occupancy[v.x, v.y] = null;
Cargo.Remove(item);
ItemsOfType[item.Data].Remove(item);
@ -790,6 +809,14 @@ public class EquippedCargoBay : EquippedItem
Mass -= _itemManager.GetMass(item);
ThermalMass -= _itemManager.GetThermalMass(item);
}
public void Remove(ItemInstance item)
{
if (item is SimpleCommodity simpleCommodity)
Remove(simpleCommodity, simpleCommodity.Quantity);
if (item is CraftedItemInstance craftedItem)
Remove(craftedItem);
}
public bool TryTransferItem(EquippedCargoBay target, SimpleCommodity item, int quantity)
{

View file

@ -116,9 +116,10 @@ public class Shape
}
public bool this[int2 pos] {
get { return pos.x >= 0 && pos.y >= 0 && pos.x < Cells.GetLength(0) && pos.y < Cells.GetLength(1) && Cells[pos.x, pos.y]; }
get { return pos.x >= 0 && pos.y >= 0 && pos.x < Width && pos.y < Height && Cells[pos.x, pos.y]; }
set
{
if (pos.x < 0 || pos.y < 0 || pos.x >= Width || pos.y >= Height) return;
_dirty = true;
Cells[pos.x, pos.y] = value;
}
@ -135,6 +136,30 @@ public class Shape
);
return shape;
}
public Shape Inset(Shape inset, int2 insetPosition, ItemRotation rotation = ItemRotation.None)
{
var shape = new Shape(Width, Height);
foreach (var v in inset.Coordinates)
{
var insetCoord = inset.Rotate(v, rotation) + insetPosition;
shape[insetCoord] = true;
}
return shape;
}
public Shape Expand()
{
var shape = new Shape(Width, Height);
foreach (var shapeCoord in AllCoordinates)
shape[shapeCoord] = (
this[shapeCoord + int2(-1,-1)] || this[shapeCoord + int2(0,-1)] || this[shapeCoord + int2(1,-1)] ||
this[shapeCoord + int2(-1,0)] || this[shapeCoord] || this[shapeCoord + int2(1,0)] ||
this[shapeCoord + int2(-1,1)] || this[shapeCoord + int2(0,1)] || this[shapeCoord + int2(1,1)]
);
return shape;
}
}
[MessagePackObject,
@ -336,9 +361,9 @@ public class HardpointData : ITintInspector
{
if (_tintColors == null)
{
var hardpointTypes = ((HardpointType[]) Enum.GetValues(typeof(HardpointType)));
var hardpointTypes = (HardpointType[]) Enum.GetValues(typeof(HardpointType));
_tintColors = hardpointTypes.ToDictionary(x => x,
x => ColorMath.HsvToRgb(float3((float)(int)x/hardpointTypes.Length, 1, 1)));
x => ColorMath.HsvToRgb(float3(frac((float)(int)x/hardpointTypes.Length + .25f), 1, 1)));
}
return _tintColors.ContainsKey(type) ? _tintColors[type] : _tintColors[HardpointType.Hull];

View file

@ -26,6 +26,7 @@ public class ItemManager
private double _time;
private float _deltaTime;
private Dictionary<Guid, Zone> _zones = new Dictionary<Guid, Zone>();
// private Guid _forceLoadZone;
// public GlobalData GlobalData => _globalData ?? (_globalData = ItemData.GetAll<GlobalData>().FirstOrDefault());
@ -48,6 +49,7 @@ public class ItemManager
public ItemManager(DatabaseCache itemData, GameplaySettings settings, Action<string> logger)
{
ItemData = itemData;
GameplaySettings = settings;
_logger = logger;
}

View file

@ -3,9 +3,12 @@ using System.Collections;
using System.Collections.Generic;
using System.Linq;
using TMPro;
using UniRx;
using UniRx.Triggers;
using UnityEngine;
using UnityEngine.UI;
using Unity.Mathematics;
using UnityEngine.EventSystems;
using static Unity.Mathematics.math;
using int2 = Unity.Mathematics.int2;
@ -18,10 +21,25 @@ public class InventoryPanel : MonoBehaviour
public GridLayoutGroup Grid;
public Sprite[] NodeTextures;
public Prototype NodePrototype;
Subject<InventoryEventData> _onBeginDrag;
Subject<InventoryEventData> _onDrag;
Subject<InventoryEventData> _onEndDrag;
Subject<InventoryEventData> _onClick;
Subject<InventoryEventData> _onPointerEnter;
Subject<InventoryEventData> _onPointerExit;
private Dictionary<int2, GameObject> _nodeInstances = new Dictionary<int2, GameObject>();
private int2[] _offsets = new[]
{
private Entity _displayedEntity;
private EquippedCargoBay _displayedCargo;
public EquippedItem FakeEquipment;
public ItemInstance FakeItem;
public Shape FakeOccupancy;
public Shape IgnoreOccupancy;
public List<GameObject> EmptyCells = new List<GameObject>();
public Dictionary<int2, InventoryCell> CellInstances = new Dictionary<int2, InventoryCell>();
private int2[] _offsets = {
int2(0, 1),
int2(1, 0),
int2(0, -1),
@ -44,138 +62,308 @@ public class InventoryPanel : MonoBehaviour
ContextMenu.AddDropdown(ship.Name,
ship.CargoBays
.Select<EquippedCargoBay, (string text, Action action, bool enabled)>((bay, index) =>
($"Bay {index}", () => Display(GameManager.ItemManager, bay), true))
.Prepend(("Equipment", () => Display(GameManager.ItemManager, ship), true)));
($"Bay {index}", () => Display(bay), true))
.Prepend(("Equipment", () => Display(ship), true)));
}
else ContextMenu.AddOption(ship.Name, () => Display(GameManager.ItemManager, ship));
else ContextMenu.AddOption(ship.Name, () => Display(ship));
}
foreach (var bay in GameManager.AvailableCargoBays())
{
ContextMenu.AddOption(bay.Name, () => Display(GameManager.ItemManager, bay));
ContextMenu.AddOption(bay.Name, () => Display(bay));
}
ContextMenu.Show();
});
}
public void Display(ItemManager manager, Entity entity)
public void Display(Entity entity)
{
foreach(var node in _nodeInstances.Values)
Destroy(node);
_nodeInstances.Clear();
foreach(var empty in EmptyCells)
Destroy(empty);
EmptyCells.Clear();
foreach(var node in CellInstances.Values)
node.GetComponent<Prototype>().ReturnToPool();
CellInstances.Clear();
_displayedEntity = entity;
_displayedCargo = null;
Title.text = entity.Name;
var hullData = manager.GetData(entity.Hull) as HullData;
var hullData = GameManager.ItemManager.GetData(entity.Hull) as HullData;
//FakeOccupancy = new Shape(hullData.Shape.Width, hullData.Shape.Height);
//IgnoreOccupancy = new Shape(hullData.Shape.Width, hullData.Shape.Height);
Grid.constraintCount = hullData.Shape.Width;
_nodeInstances = hullData.Shape.AllCoordinates
.ToDictionary(v => v,
v =>
{
if (!hullData.Shape[v])
{
var empty = new GameObject("Empty Node", typeof(RectTransform));
empty.transform.SetParent(Grid.transform);
return empty;
}
var spriteIndex = 0;
var interior = hullData.InteriorCells[v];
var item = entity.GearOccupancy[v.x, v.y];
var hardpoint = entity.Hardpoints[v.x, v.y];
bool HardpointMatch(int2 offset) => !(hullData.Shape[v + offset] &&
entity.Hardpoints[v.x + offset.x, v.y + offset.y] == hardpoint &&
entity.GearOccupancy[v.x + offset.x, v.y + offset.y] == item);
bool NoHardpointMatch(int2 offset) => !(hullData.Shape[v + offset] && (
!interior && !hullData.InteriorCells[v + offset] && entity.Hardpoints[v.x + offset.x, v.y + offset.y] == null ||
interior && item != null && entity.GearOccupancy[v.x + offset.x, v.y + offset.y] == item));
if (hardpoint != null)
{
for(int i = 0; i < 8; i++)
if (HardpointMatch(_offsets[i]))
spriteIndex += 1 << i;
}
else
{
for(int i = 0; i < 8; i++)
if (NoHardpointMatch(_offsets[i]))
spriteIndex += 1 << i;
}
if (item != null)
spriteIndex += 1 << 8;
if (spriteIndex == 0)
{
var empty = new GameObject("Empty Node", typeof(RectTransform));
empty.transform.SetParent(Grid.transform);
return empty;
}
var node = NodePrototype.Instantiate<Prototype>().gameObject;
var image = node.GetComponentInChildren<Image>();
image.sprite = NodeTextures[spriteIndex];
image.color = hardpoint?.TintColor.ToColor() ?? (interior ? Color.white * .5f : Color.white);
return node;
});
foreach (var v in hullData.Shape.AllCoordinates)
{
if (!hullData.Shape[v])
{
var empty = new GameObject("Empty Node", typeof(RectTransform));
empty.transform.SetParent(Grid.transform);
EmptyCells.Add(empty);
}
else
{
var cell = NodePrototype.Instantiate<InventoryCell>();
cell.PointerClickTrigger.OnPointerClickAsObservable()
.Subscribe(data => _onClick?.OnNext(new InventoryEntityEventData(data, v, entity)));
cell.BeginDragTrigger.OnBeginDragAsObservable()
.Subscribe(data => _onBeginDrag?.OnNext(new InventoryEntityEventData(data, v, entity)));
cell.DragTrigger.OnDragAsObservable()
.Subscribe(data => _onDrag?.OnNext(new InventoryEntityEventData(data, v, entity)));
cell.EndDragTrigger.OnEndDragAsObservable()
.Subscribe(data => _onEndDrag?.OnNext(new InventoryEntityEventData(data, v, entity)));
cell.PointerEnterTrigger.OnPointerEnterAsObservable()
.Subscribe(data => _onPointerEnter?.OnNext(new InventoryEntityEventData(data, v, entity)));
cell.PointerExitTrigger.OnPointerExitAsObservable()
.Subscribe(data => _onPointerExit?.OnNext(new InventoryEntityEventData(data, v, entity)));
CellInstances.Add(v, cell);
}
}
RefreshCells(CellInstances.Keys);
}
public void Display(ItemManager manager, EquippedCargoBay cargo)
public void Display(EquippedCargoBay cargo)
{
foreach(var node in _nodeInstances.Values)
Destroy(node);
_nodeInstances.Clear();
foreach(var empty in EmptyCells)
Destroy(empty);
EmptyCells.Clear();
foreach(var node in CellInstances.Values)
node.GetComponent<Prototype>().ReturnToPool();
CellInstances.Clear();
_displayedEntity = null;
_displayedCargo = cargo;
Title.text = cargo.Name;
// FakeOccupancy = new Shape(cargo.Data.InteriorShape.Width, cargo.Data.InteriorShape.Height);
// IgnoreOccupancy = new Shape(cargo.Data.InteriorShape.Width, cargo.Data.InteriorShape.Height);
Grid.constraintCount = cargo.Data.InteriorShape.Width;
_nodeInstances = cargo.Data.InteriorShape.AllCoordinates
.ToDictionary(v => v,
v =>
{
if (!cargo.Data.InteriorShape[v])
{
var empty = new GameObject("Empty Node", typeof(RectTransform));
empty.transform.SetParent(Grid.transform);
return empty;
}
var spriteIndex = 0;
var item = cargo.Occupancy[v.x, v.y];
bool ItemMatch(int2 offset) =>
!cargo.Data.InteriorShape[v + offset] ||
item == null ||
cargo.Occupancy[v.x + offset.x, v.y + offset.y] != item;
for(int i = 0; i < 8; i++)
if (ItemMatch(_offsets[i]))
spriteIndex += 1 << i;
if (item != null)
spriteIndex += 1 << 8;
if (spriteIndex == 0)
{
var empty = new GameObject("Empty Node", typeof(RectTransform));
empty.transform.SetParent(Grid.transform);
return empty;
}
var node = NodePrototype.Instantiate<Prototype>().gameObject;
var image = node.GetComponentInChildren<Image>();
image.sprite = NodeTextures[spriteIndex];
if (item == null)
image.color = Color.white * .5f;
else if (manager.GetData(item) is EquippableItemData equippable)
image.color = HardpointData.GetColor(equippable.HardpointType).ToColor();
else
image.color = Color.white;
return node;
});
foreach (var v in cargo.Data.InteriorShape.AllCoordinates)
{
if (!cargo.Data.InteriorShape[v])
{
var empty = new GameObject("Empty Node", typeof(RectTransform));
empty.transform.SetParent(Grid.transform);
EmptyCells.Add(empty);
}
else
{
var cell = NodePrototype.Instantiate<InventoryCell>();
cell.PointerClickTrigger.OnPointerClickAsObservable()
.Subscribe(data => _onClick?.OnNext(new InventoryCargoEventData(data, v, cargo)));
cell.BeginDragTrigger.OnBeginDragAsObservable()
.Subscribe(data => _onBeginDrag?.OnNext(new InventoryCargoEventData(data, v, cargo)));
cell.DragTrigger.OnDragAsObservable()
.Subscribe(data => _onDrag?.OnNext(new InventoryCargoEventData(data, v, cargo)));
cell.EndDragTrigger.OnEndDragAsObservable()
.Subscribe(data => _onEndDrag?.OnNext(new InventoryCargoEventData(data, v, cargo)));
cell.PointerEnterTrigger.OnPointerEnterAsObservable()
.Subscribe(data => _onPointerEnter?.OnNext(new InventoryCargoEventData(data, v, cargo)));
cell.PointerExitTrigger.OnPointerExitAsObservable()
.Subscribe(data => _onPointerExit?.OnNext(new InventoryCargoEventData(data, v, cargo)));
CellInstances.Add(v, cell);
}
}
RefreshCells();
}
public void RefreshCells()
{
RefreshCells(CellInstances.Keys);
}
public void RefreshCells(IEnumerable<int2> cells)
{
if (_displayedEntity != null)
{
foreach (var v in cells)
{
if(!CellInstances.ContainsKey(v)) continue;
var hullData = GameManager.ItemManager.GetData(_displayedEntity.Hull) as HullData;
var spriteIndex = 0;
var interior = hullData.InteriorCells[v];
var item = FakeOccupancy?[v]??false ? FakeEquipment : IgnoreOccupancy?[v]??false ? null : _displayedEntity.GearOccupancy[v.x, v.y];
var hardpoint = _displayedEntity.Hardpoints[v.x, v.y];
bool HardpointMatch(int2 offset)
{
var v2 = v + offset;
return !(
hullData.Shape[v2] &&
_displayedEntity.Hardpoints[v2.x, v2.y] == hardpoint &&
(FakeOccupancy?[v2]??false ? FakeEquipment : IgnoreOccupancy?[v2]??false ? null : _displayedEntity.GearOccupancy[v2.x, v2.y]) == item
);
}
bool NoHardpointMatch(int2 offset)
{
var v2 = v + offset;
return !(
hullData.Shape[v2] && (
!interior && !hullData.InteriorCells[v2] && _displayedEntity.Hardpoints[v2.x, v2.y] == null ||
interior && item != null &&
(FakeOccupancy?[v2]??false ? FakeEquipment : IgnoreOccupancy?[v2]??false ? null : _displayedEntity.GearOccupancy[v2.x, v2.y]) == item
)
);
}
if (hardpoint != null)
{
for(int i = 0; i < 8; i++)
if (HardpointMatch(_offsets[i]))
spriteIndex += 1 << i;
}
else
{
for(int i = 0; i < 8; i++)
if (NoHardpointMatch(_offsets[i]))
spriteIndex += 1 << i;
}
if (item != null)
spriteIndex += 1 << 8;
var image = CellInstances[v].GetComponentInChildren<Image>();
image.sprite = NodeTextures[spriteIndex];
image.color = GetColor(v);
}
}
else if(_displayedCargo != null)
{
foreach (var v in cells)
{
if(!CellInstances.ContainsKey(v)) continue;
var spriteIndex = 0;
var item = FakeOccupancy?[v]??false ? FakeItem : IgnoreOccupancy?[v]??false ? null : _displayedCargo.Occupancy[v.x, v.y];
bool ItemMatch(int2 offset)
{
var v2 = v + offset;
return !_displayedCargo.Data.InteriorShape[v2] || item == null ||
(FakeOccupancy?[v2]??false ? FakeItem : IgnoreOccupancy?[v2]??false ? null : _displayedCargo.Occupancy[v2.x, v2.y]) != item;
}
for(int i = 0; i < 8; i++)
if (ItemMatch(_offsets[i]))
spriteIndex += 1 << i;
if (item != null)
spriteIndex += 1 << 8;
var image = CellInstances[v].GetComponentInChildren<Image>();
image.sprite = NodeTextures[spriteIndex];
image.color = GetColor(v);
}
}
}
public Color GetColor(int2 position, bool highlight = false)
{
if (_displayedEntity != null)
{
var hullData = GameManager.ItemManager.GetData(_displayedEntity.Hull) as HullData;
var interior = hullData.InteriorCells[position];
var item = FakeOccupancy?[position]??false ? FakeEquipment : IgnoreOccupancy?[position]??false ? null : _displayedEntity.GearOccupancy[position.x, position.y];
var hardpoint = _displayedEntity.Hardpoints[position.x, position.y];
if (hardpoint == null)
{
if(!interior)
return Color.white;
if (item == null)
{
return Color.white * .25f;
}
if(highlight)
return Color.white;
return Color.white * .5f;
}
var tint = hardpoint.TintColor;
if (!highlight || item == null)
tint *= .7071f;
return tint.ToColor();
}
else
{
var item = FakeOccupancy?[position] ?? false ? FakeItem : IgnoreOccupancy?[position] ?? false ? null : _displayedCargo.Occupancy[position.x, position.y];
if (item == null)
return Color.white * .25f;
var c = float3(1);
if (GameManager.ItemManager.GetData(item) is EquippableItemData equippable)
c = HardpointData.GetColor(equippable.HardpointType);
if(!highlight)
c *= .7071f;
return c.ToColor();
}
}
public void DropItem(ItemInstance item, int2 position)
{
if (_displayedEntity != null && item is EquippableItem equippableItem)
{
_displayedEntity.TryEquip(equippableItem, position);
}
else
{
_displayedCargo?.TryStore(item, position);
}
}
public UniRx.IObservable<InventoryEventData> OnClickAsObservable() => _onClick ?? (_onClick = new Subject<InventoryEventData>());
public UniRx.IObservable<InventoryEventData> OnBeginDragAsObservable() => _onBeginDrag ?? (_onBeginDrag = new Subject<InventoryEventData>());
public UniRx.IObservable<InventoryEventData> OnDragAsObservable() => _onDrag ?? (_onDrag = new Subject<InventoryEventData>());
public UniRx.IObservable<InventoryEventData> OnEndDragAsObservable() => _onEndDrag ?? (_onEndDrag = new Subject<InventoryEventData>());
public UniRx.IObservable<InventoryEventData> OnPointerEnterAsObservable() => _onPointerEnter ?? (_onPointerEnter = new Subject<InventoryEventData>());
public UniRx.IObservable<InventoryEventData> OnPointerExitAsObservable() => _onPointerExit ?? (_onPointerExit = new Subject<InventoryEventData>());
}
public abstract class InventoryEventData
{
protected InventoryEventData(PointerEventData pointerEventData, int2 position)
{
PointerEventData = pointerEventData;
Position = position;
}
public PointerEventData PointerEventData { get; }
public int2 Position { get; }
}
public class InventoryEntityEventData : InventoryEventData
{
public InventoryEntityEventData(PointerEventData pointerEventData, int2 position, Entity entity) :
base(pointerEventData, position)
{
Entity = entity;
}
public Entity Entity { get; }
}
public class InventoryCargoEventData : InventoryEventData
{
public InventoryCargoEventData(PointerEventData pointerEventData, int2 position, EquippedCargoBay cargoBay) :
base(pointerEventData, position)
{
CargoBay = cargoBay;
}
public EquippedCargoBay CargoBay { get; }
}

View file

@ -29,6 +29,7 @@ public class PropertiesPanel : MonoBehaviour
public PropertyButton PropertyButton;
public ButtonField ButtonField;
public IncrementField IncrementField;
public RectTransform Content;
[HideInInspector] public FlatFlatButton SelectedChild;
[HideInInspector] public ItemManager Context;
@ -82,7 +83,7 @@ public class PropertiesPanel : MonoBehaviour
public RectTransform AddSection(string name)
{
var section = Instantiate(Section, transform);
var section = Instantiate(Section, Content ?? transform);
section.GetComponentInChildren<TextMeshProUGUI>().text = name;
Properties.Add(section.gameObject);
OnPropertyAdded?.Invoke(section.gameObject);
@ -93,9 +94,9 @@ public class PropertiesPanel : MonoBehaviour
{
Property property;
if(read != null)
property = Instantiate(PropertyLabel, transform);
property = Instantiate(PropertyLabel, Content ?? transform);
else
property = Instantiate(Property, transform);
property = Instantiate(Property, Content ?? transform);
property.Label.text = name;
if (read != null)
@ -107,7 +108,7 @@ public class PropertiesPanel : MonoBehaviour
public PropertiesList AddList(string name) //, IEnumerable<(string, Func<string>)> elements)
{
var list = Instantiate(List, transform);
var list = Instantiate(List, Content ?? transform);
list.Context = Context;
list.Dropdown = Dropdown;
list.Title.text = name;
@ -127,7 +128,7 @@ public class PropertiesPanel : MonoBehaviour
public AttributeProperty AddPersonalityProperty(PersonalityAttribute attribute, Func<float> read)
{
var attributeInstance = Instantiate(Attribute, transform);
var attributeInstance = Instantiate(Attribute, Content ?? transform);
attributeInstance.Title.text = attribute.Name;
attributeInstance.HighLabel.text = attribute.HighName;
attributeInstance.LowLabel.text = attribute.LowName;
@ -139,7 +140,7 @@ public class PropertiesPanel : MonoBehaviour
public virtual PropertyButton AddButton(string name, Action onClick)
{
var button = Instantiate(PropertyButton, transform);
var button = Instantiate(PropertyButton, Content ?? transform);
button.Label.text = name;
button.Button.onClick.AddListener(() => onClick());
Properties.Add(button.gameObject);
@ -149,7 +150,7 @@ public class PropertiesPanel : MonoBehaviour
public void AddButton(string name, string label, Action onClick)
{
var button = Instantiate(ButtonField, transform);
var button = Instantiate(ButtonField, Content ?? transform);
button.Label.text = name;
button.ButtonLabel.text = label;
button.Button.onClick.AddListener(() => onClick());
@ -159,7 +160,7 @@ public class PropertiesPanel : MonoBehaviour
public void AddField(string name, Func<string> read, Action<string> write)
{
var field = Instantiate(InputField, transform);
var field = Instantiate(InputField, Content ?? transform);
field.Label.text = name;
field.Field.contentType = TMP_InputField.ContentType.Standard;
field.Field.onValueChanged.AddListener(val => write(val));
@ -184,7 +185,7 @@ public class PropertiesPanel : MonoBehaviour
public void AddField(string name, Func<float> read, Action<float> write)
{
var field = Instantiate(InputField, transform);
var field = Instantiate(InputField, Content ?? transform);
field.Label.text = name;
field.Field.contentType = TMP_InputField.ContentType.DecimalNumber;
field.Field.onValueChanged.AddListener(val => write(float.Parse(val)));
@ -204,7 +205,7 @@ public class PropertiesPanel : MonoBehaviour
public void AddField(string name, Func<int> read, Action<int> write)
{
var field = Instantiate(InputField, transform);
var field = Instantiate(InputField, Content ?? transform);
field.Label.text = name;
field.Field.contentType = TMP_InputField.ContentType.IntegerNumber;
field.Field.onValueChanged.AddListener(val => write(int.Parse(val)));
@ -224,7 +225,7 @@ public class PropertiesPanel : MonoBehaviour
public void AddIncrementField(string name, Func<int> read, Action<int> write, Func<int> min, Func<int> max)
{
var field = Instantiate(IncrementField, transform);
var field = Instantiate(IncrementField, Content ?? transform);
field.Label.text = name;
field.Increment.onClick.AddListener(() => write(read() + 1));
field.Decrement.onClick.AddListener(() => write(read() - 1));
@ -245,7 +246,7 @@ public class PropertiesPanel : MonoBehaviour
public void AddField(string name, Func<float> read, Action<float> write, float min, float max)
{
var field = Instantiate(RangedFloatField, transform);
var field = Instantiate(RangedFloatField, Content ?? transform);
field.Label.text = name;
field.Slider.wholeNumbers = false;
field.Slider.minValue = min;
@ -258,7 +259,7 @@ public class PropertiesPanel : MonoBehaviour
public void AddProgressField(string name, Func<float> read)
{
var field = Instantiate(ProgressField, transform);
var field = Instantiate(ProgressField, Content ?? transform);
field.Label.text = name;
field.Slider.wholeNumbers = false;
field.Slider.minValue = 0;
@ -271,7 +272,7 @@ public class PropertiesPanel : MonoBehaviour
public void AddField(string name, Func<int> read, Action<int> write, int min, int max)
{
var field = Instantiate(RangedFloatField, transform);
var field = Instantiate(RangedFloatField, Content ?? transform);
field.Label.text = name;
field.Slider.wholeNumbers = true;
field.Slider.minValue = min;
@ -284,7 +285,7 @@ public class PropertiesPanel : MonoBehaviour
public void AddField(string name, Func<bool> read, Action<bool> write)
{
var field = Instantiate(BoolField, transform);
var field = Instantiate(BoolField, Content ?? transform);
field.Label.text = name;
field.Toggle.onValueChanged.AddListener(val => write(val));
RefreshPropertyValues += () => field.Toggle.isOn = read();
@ -294,7 +295,7 @@ public class PropertiesPanel : MonoBehaviour
public void AddField(string name, Func<int> read, Action<int> write, string[] enumOptions)
{
var field = Instantiate(EnumField, transform);
var field = Instantiate(EnumField, Content ?? transform);
field.Label.text = name;
field.Dropdown.OnClick += data =>
{
@ -389,6 +390,56 @@ public class PropertiesPanel : MonoBehaviour
}
}
public void AddItemProperties(ItemInstance item)
{
var data = Context.ItemData.Get<ItemData>(item.Data);
AddProperty("Type", () => data.Name);
AddProperty(data.Description).Label.fontStyle = FontStyles.Normal;
// if (item is CraftedItemInstance craftedItemInstance)
// {
// var sourceEntity = Context.ItemData.Get<Entity>(craftedItemInstance.SourceEntity);
// if (sourceEntity != null)
// {
// var corporation = Context.ItemData.Get<Corporation>(sourceEntity.Corporation);
// AddProperty("Manufacturer", () => corporation.Name);
// }
// else
// {
// AddProperty("Manufacturer", () => "GameCult");
// }
// }
// if (item is SimpleCommodity simpleCommodity)
// AddProperty("Quantity", () => simpleCommodity.Quantity.ToString());
AddProperty("Mass", () => Context.GetMass(item).SignificantDigits(Context.GameplaySettings.SignificantDigits));
AddProperty("Thermal Mass", () => Context.GetThermalMass(item).SignificantDigits(Context.GameplaySettings.SignificantDigits));
if (item is EquippableItem gear)
{
var gearData = Context.GetData(gear);
AddProperty("Durability", () =>
$"{gear.Durability.SignificantDigits(Context.GameplaySettings.SignificantDigits)}/{gearData.Durability.SignificantDigits(Context.GameplaySettings.SignificantDigits)}");
foreach (var behavior in gearData.Behaviors)
{
var type = behavior.GetType();
if (type.GetCustomAttribute(typeof(RuntimeInspectable)) != null)
{
foreach (var field in type.GetFields().Where(f => f.GetCustomAttribute<RuntimeInspectable>() != null))
{
var fieldType = field.FieldType;
if (fieldType == typeof(float))
AddProperty(field.Name, () => $"{((float) field.GetValue(behavior)).SignificantDigits(Context.GameplaySettings.SignificantDigits)}");
else if (fieldType == typeof(int))
AddProperty(field.Name, () => $"{(int) field.GetValue(behavior)}");
else if (fieldType == typeof(PerformanceStat))
{
var stat = (PerformanceStat) field.GetValue(behavior);
AddProperty(field.Name, () => $"{Context.Evaluate(stat, gear).SignificantDigits(Context.GameplaySettings.SignificantDigits)}");
}
}
}
}
}
}
public void Inspect(Entity entity, EquippedItem item)
{
if (this is PropertiesList list)

View file

@ -150,8 +150,11 @@ public class Stardust : MonoBehaviour
{
// m_emitterProxies.Release();
// _temperature.Release();
_particlesBuffer.Release();
_quadPoints.Release();
if(_particlesBuffer!=null)
{
_particlesBuffer.Release();
_quadPoints.Release();
}
// m_livingProxyIndices.Release();
}
#endregion