Fullscreen Map View
New MapView class which shows a fullscreen map
This commit is contained in:
parent
eef34a2de5
commit
88ae36d137
14 changed files with 361 additions and 26 deletions
|
|
@ -15,8 +15,10 @@ public class ActionGameManager : MonoBehaviour
|
|||
{
|
||||
public GameSettings Settings;
|
||||
public SectorRenderer SectorRenderer;
|
||||
public MapView MapView;
|
||||
public CinemachineVirtualCamera TopDownCamera;
|
||||
public CinemachineVirtualCamera FollowCamera;
|
||||
public GameObject GameplayUI;
|
||||
//public PlayerInput Input;
|
||||
|
||||
private DirectoryInfo _filePath;
|
||||
|
|
@ -55,6 +57,8 @@ public class ActionGameManager : MonoBehaviour
|
|||
|
||||
_input = new AetheriaInput();
|
||||
_input.Player.Enable();
|
||||
_input.Global.Enable();
|
||||
_input.UI.Enable();
|
||||
|
||||
_zoomLevelIndex = Settings.DefaultMinimapZoom;
|
||||
_input.Player.MinimapZoom.performed += context =>
|
||||
|
|
@ -63,6 +67,22 @@ public class ActionGameManager : MonoBehaviour
|
|||
SectorRenderer.MinimapDistance = Settings.MinimapZoomLevels[_zoomLevelIndex];
|
||||
};
|
||||
|
||||
_input.Global.MapToggle.performed += context =>
|
||||
{
|
||||
MapView.enabled = !MapView.enabled;
|
||||
GameplayUI.SetActive(!MapView.enabled);
|
||||
if (MapView.enabled)
|
||||
{
|
||||
MapView.BindInput(_input.UI);
|
||||
_input.Player.Disable();
|
||||
}
|
||||
else
|
||||
{
|
||||
_input.Player.Enable();
|
||||
SectorRenderer.MinimapDistance = Settings.MinimapZoomLevels[_zoomLevelIndex];
|
||||
}
|
||||
};
|
||||
|
||||
ConsoleController.AddCommand("editmode", _ => ToggleEditMode());
|
||||
ConsoleController.AddCommand("savezone", args =>
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
// GENERATED AUTOMATICALLY FROM 'Assets/Resources/Aetheria-Economy.inputactions'
|
||||
// GENERATED AUTOMATICALLY FROM 'Assets/Resources/Aetheria.inputactions'
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
|
|
@ -12,7 +12,7 @@ public class @AetheriaInput : IInputActionCollection, IDisposable
|
|||
public @AetheriaInput()
|
||||
{
|
||||
asset = InputActionAsset.FromJson(@"{
|
||||
""name"": ""Aetheria-Economy"",
|
||||
""name"": ""Aetheria"",
|
||||
""maps"": [
|
||||
{
|
||||
""name"": ""Player"",
|
||||
|
|
@ -346,6 +346,14 @@ public class @AetheriaInput : IInputActionCollection, IDisposable
|
|||
""expectedControlType"": ""Quaternion"",
|
||||
""processors"": """",
|
||||
""interactions"": """"
|
||||
},
|
||||
{
|
||||
""name"": ""Drag"",
|
||||
""type"": ""Value"",
|
||||
""id"": ""0c96ec22-9571-46c8-94bf-199e70e919ed"",
|
||||
""expectedControlType"": ""Vector2"",
|
||||
""processors"": """",
|
||||
""interactions"": """"
|
||||
}
|
||||
],
|
||||
""bindings"": [
|
||||
|
|
@ -766,6 +774,44 @@ public class @AetheriaInput : IInputActionCollection, IDisposable
|
|||
""action"": ""TrackedDeviceOrientation"",
|
||||
""isComposite"": false,
|
||||
""isPartOfComposite"": false
|
||||
},
|
||||
{
|
||||
""name"": """",
|
||||
""id"": ""618fb60f-5dc7-47ec-8dbf-fdc3d4c515a1"",
|
||||
""path"": ""<Mouse>/delta"",
|
||||
""interactions"": """",
|
||||
""processors"": ""ScaleVector2(x=1.25,y=1.25)"",
|
||||
""groups"": """",
|
||||
""action"": ""Drag"",
|
||||
""isComposite"": false,
|
||||
""isPartOfComposite"": false
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
""name"": ""Global"",
|
||||
""id"": ""2e2023b8-ce3b-4cb3-a12a-ff4ac610f11b"",
|
||||
""actions"": [
|
||||
{
|
||||
""name"": ""Map Toggle"",
|
||||
""type"": ""Button"",
|
||||
""id"": ""e43f020b-dec0-43d2-a83b-1390d45819be"",
|
||||
""expectedControlType"": ""Button"",
|
||||
""processors"": """",
|
||||
""interactions"": """"
|
||||
}
|
||||
],
|
||||
""bindings"": [
|
||||
{
|
||||
""name"": """",
|
||||
""id"": ""7eadec25-7b3f-4d69-92b7-c756f5f9b0dd"",
|
||||
""path"": ""<Keyboard>/m"",
|
||||
""interactions"": """",
|
||||
""processors"": """",
|
||||
""groups"": ""Keyboard&Mouse"",
|
||||
""action"": ""Map Toggle"",
|
||||
""isComposite"": false,
|
||||
""isPartOfComposite"": false
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
@ -851,6 +897,10 @@ public class @AetheriaInput : IInputActionCollection, IDisposable
|
|||
m_UI_RightClick = m_UI.FindAction("RightClick", throwIfNotFound: true);
|
||||
m_UI_TrackedDevicePosition = m_UI.FindAction("TrackedDevicePosition", throwIfNotFound: true);
|
||||
m_UI_TrackedDeviceOrientation = m_UI.FindAction("TrackedDeviceOrientation", throwIfNotFound: true);
|
||||
m_UI_Drag = m_UI.FindAction("Drag", throwIfNotFound: true);
|
||||
// Global
|
||||
m_Global = asset.FindActionMap("Global", throwIfNotFound: true);
|
||||
m_Global_MapToggle = m_Global.FindAction("Map Toggle", throwIfNotFound: true);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
|
|
@ -967,6 +1017,7 @@ public class @AetheriaInput : IInputActionCollection, IDisposable
|
|||
private readonly InputAction m_UI_RightClick;
|
||||
private readonly InputAction m_UI_TrackedDevicePosition;
|
||||
private readonly InputAction m_UI_TrackedDeviceOrientation;
|
||||
private readonly InputAction m_UI_Drag;
|
||||
public struct UIActions
|
||||
{
|
||||
private @AetheriaInput m_Wrapper;
|
||||
|
|
@ -981,6 +1032,7 @@ public class @AetheriaInput : IInputActionCollection, IDisposable
|
|||
public InputAction @RightClick => m_Wrapper.m_UI_RightClick;
|
||||
public InputAction @TrackedDevicePosition => m_Wrapper.m_UI_TrackedDevicePosition;
|
||||
public InputAction @TrackedDeviceOrientation => m_Wrapper.m_UI_TrackedDeviceOrientation;
|
||||
public InputAction @Drag => m_Wrapper.m_UI_Drag;
|
||||
public InputActionMap Get() { return m_Wrapper.m_UI; }
|
||||
public void Enable() { Get().Enable(); }
|
||||
public void Disable() { Get().Disable(); }
|
||||
|
|
@ -1020,6 +1072,9 @@ public class @AetheriaInput : IInputActionCollection, IDisposable
|
|||
@TrackedDeviceOrientation.started -= m_Wrapper.m_UIActionsCallbackInterface.OnTrackedDeviceOrientation;
|
||||
@TrackedDeviceOrientation.performed -= m_Wrapper.m_UIActionsCallbackInterface.OnTrackedDeviceOrientation;
|
||||
@TrackedDeviceOrientation.canceled -= m_Wrapper.m_UIActionsCallbackInterface.OnTrackedDeviceOrientation;
|
||||
@Drag.started -= m_Wrapper.m_UIActionsCallbackInterface.OnDrag;
|
||||
@Drag.performed -= m_Wrapper.m_UIActionsCallbackInterface.OnDrag;
|
||||
@Drag.canceled -= m_Wrapper.m_UIActionsCallbackInterface.OnDrag;
|
||||
}
|
||||
m_Wrapper.m_UIActionsCallbackInterface = instance;
|
||||
if (instance != null)
|
||||
|
|
@ -1054,10 +1109,46 @@ public class @AetheriaInput : IInputActionCollection, IDisposable
|
|||
@TrackedDeviceOrientation.started += instance.OnTrackedDeviceOrientation;
|
||||
@TrackedDeviceOrientation.performed += instance.OnTrackedDeviceOrientation;
|
||||
@TrackedDeviceOrientation.canceled += instance.OnTrackedDeviceOrientation;
|
||||
@Drag.started += instance.OnDrag;
|
||||
@Drag.performed += instance.OnDrag;
|
||||
@Drag.canceled += instance.OnDrag;
|
||||
}
|
||||
}
|
||||
}
|
||||
public UIActions @UI => new UIActions(this);
|
||||
|
||||
// Global
|
||||
private readonly InputActionMap m_Global;
|
||||
private IGlobalActions m_GlobalActionsCallbackInterface;
|
||||
private readonly InputAction m_Global_MapToggle;
|
||||
public struct GlobalActions
|
||||
{
|
||||
private @AetheriaInput m_Wrapper;
|
||||
public GlobalActions(@AetheriaInput wrapper) { m_Wrapper = wrapper; }
|
||||
public InputAction @MapToggle => m_Wrapper.m_Global_MapToggle;
|
||||
public InputActionMap Get() { return m_Wrapper.m_Global; }
|
||||
public void Enable() { Get().Enable(); }
|
||||
public void Disable() { Get().Disable(); }
|
||||
public bool enabled => Get().enabled;
|
||||
public static implicit operator InputActionMap(GlobalActions set) { return set.Get(); }
|
||||
public void SetCallbacks(IGlobalActions instance)
|
||||
{
|
||||
if (m_Wrapper.m_GlobalActionsCallbackInterface != null)
|
||||
{
|
||||
@MapToggle.started -= m_Wrapper.m_GlobalActionsCallbackInterface.OnMapToggle;
|
||||
@MapToggle.performed -= m_Wrapper.m_GlobalActionsCallbackInterface.OnMapToggle;
|
||||
@MapToggle.canceled -= m_Wrapper.m_GlobalActionsCallbackInterface.OnMapToggle;
|
||||
}
|
||||
m_Wrapper.m_GlobalActionsCallbackInterface = instance;
|
||||
if (instance != null)
|
||||
{
|
||||
@MapToggle.started += instance.OnMapToggle;
|
||||
@MapToggle.performed += instance.OnMapToggle;
|
||||
@MapToggle.canceled += instance.OnMapToggle;
|
||||
}
|
||||
}
|
||||
}
|
||||
public GlobalActions @Global => new GlobalActions(this);
|
||||
private int m_KeyboardMouseSchemeIndex = -1;
|
||||
public InputControlScheme KeyboardMouseScheme
|
||||
{
|
||||
|
|
@ -1122,5 +1213,10 @@ public class @AetheriaInput : IInputActionCollection, IDisposable
|
|||
void OnRightClick(InputAction.CallbackContext context);
|
||||
void OnTrackedDevicePosition(InputAction.CallbackContext context);
|
||||
void OnTrackedDeviceOrientation(InputAction.CallbackContext context);
|
||||
void OnDrag(InputAction.CallbackContext context);
|
||||
}
|
||||
public interface IGlobalActions
|
||||
{
|
||||
void OnMapToggle(InputAction.CallbackContext context);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
104
Assets/Scripts/Sector Display/MapView.cs
Normal file
104
Assets/Scripts/Sector Display/MapView.cs
Normal file
|
|
@ -0,0 +1,104 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
|
||||
public class MapView : MonoBehaviour
|
||||
{
|
||||
public Camera Main;
|
||||
public Camera MinimapGravity;
|
||||
public Camera Minimap;
|
||||
public MeshRenderer GravityRenderer;
|
||||
public float ZoomSpeed;
|
||||
|
||||
private Transform _minimapTransform;
|
||||
private CopyTransform _minimapCopyTransform;
|
||||
private RenderTexture _minimapTexture;
|
||||
private Transform _minimapGravityTransform;
|
||||
private CopyTransform _minimapGravityCopyTransform;
|
||||
private RenderTexture _minimapGravityTexture;
|
||||
private Transform _gravityRendererTransform;
|
||||
private CopyTransform _gravityRendererCopyTransform;
|
||||
private RenderTexture _fullscreenGravityTexture;
|
||||
private AetheriaInput.UIActions _input;
|
||||
private float _viewDistance = 1024;
|
||||
private float _aspectRatio;
|
||||
private Vector3 _previousGravityRendererScale;
|
||||
|
||||
void OnEnable()
|
||||
{
|
||||
_aspectRatio = (float) Screen.width / Screen.height;
|
||||
Main.gameObject.SetActive(false);
|
||||
_minimapTexture = Minimap.targetTexture;
|
||||
_minimapTransform = Minimap.transform;
|
||||
_minimapCopyTransform = Minimap.GetComponent<CopyTransform>();
|
||||
_minimapCopyTransform.enabled = false;
|
||||
_minimapGravityTexture = MinimapGravity.targetTexture;
|
||||
_minimapGravityTransform = MinimapGravity.transform;
|
||||
_minimapGravityCopyTransform = MinimapGravity.GetComponent<CopyTransform>();
|
||||
_minimapGravityCopyTransform.enabled = false;
|
||||
_gravityRendererTransform = GravityRenderer.transform;
|
||||
_gravityRendererCopyTransform = GravityRenderer.GetComponent<CopyTransform>();
|
||||
_gravityRendererCopyTransform.enabled = false;
|
||||
_previousGravityRendererScale = _gravityRendererTransform.localScale;
|
||||
|
||||
_fullscreenGravityTexture = new RenderTexture(Screen.width / 2, Screen.height / 2, 1, RenderTextureFormat.RFloat);
|
||||
GravityRenderer.material.mainTexture = _fullscreenGravityTexture;
|
||||
MinimapGravity.targetTexture = _fullscreenGravityTexture;
|
||||
Minimap.targetTexture = null;
|
||||
SetZoom();
|
||||
}
|
||||
|
||||
void SetZoom()
|
||||
{
|
||||
Minimap.orthographicSize = MinimapGravity.orthographicSize = _viewDistance;
|
||||
_gravityRendererTransform.localScale = new Vector3(_viewDistance*_aspectRatio*2, _viewDistance*2, 1);
|
||||
}
|
||||
|
||||
public void BindInput(AetheriaInput.UIActions input)
|
||||
{
|
||||
_input = input;
|
||||
_input.ScrollWheel.performed += OnScroll;
|
||||
}
|
||||
|
||||
private void OnScroll(InputAction.CallbackContext context)
|
||||
{
|
||||
_viewDistance *= (1 - context.ReadValue<Vector2>().y * ZoomSpeed);
|
||||
SetZoom();
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
if (_input.Click.ReadValue<float>() > .5f)
|
||||
{
|
||||
var delta = _input.Drag.ReadValue<Vector2>();
|
||||
|
||||
var pos = _minimapTransform.position;
|
||||
pos.x -= delta.x * _viewDistance / Screen.height;
|
||||
pos.z -= delta.y * _viewDistance / Screen.height;
|
||||
|
||||
var gravPos = _gravityRendererTransform.position;
|
||||
gravPos.x = pos.x;
|
||||
gravPos.z = pos.z;
|
||||
|
||||
_gravityRendererTransform.position = gravPos;
|
||||
_minimapTransform.position = _minimapGravityTransform.position = pos;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
_input.ScrollWheel.performed -= OnScroll;
|
||||
|
||||
Main.gameObject.SetActive(true);
|
||||
_minimapGravityCopyTransform.enabled = true;
|
||||
_minimapCopyTransform.enabled = true;
|
||||
_gravityRendererCopyTransform.enabled = true;
|
||||
|
||||
Minimap.targetTexture = _minimapTexture;
|
||||
MinimapGravity.targetTexture = _minimapGravityTexture;
|
||||
GravityRenderer.material.mainTexture = _minimapGravityTexture;
|
||||
_fullscreenGravityTexture.Release();
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Sector Display/MapView.cs.meta
Normal file
11
Assets/Scripts/Sector Display/MapView.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 76d9e45f376fcfe409f3a4f26ccb4f3e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Loading…
Reference in a new issue