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
47
Assets/Scripts/Sector Display/CopyTransform.cs
Normal file
47
Assets/Scripts/Sector Display/CopyTransform.cs
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class CopyTransform : MonoBehaviour
|
||||
{
|
||||
public Transform Target;
|
||||
public bool CopyXPosition = false;
|
||||
public bool CopyYPosition = false;
|
||||
public bool CopyZPosition = false;
|
||||
public bool CopyRotation = false;
|
||||
//public Vector3 RotationOffsetEulerAngles = Vector3.zero;
|
||||
public Camera PixelSnapCamera;
|
||||
public float PixelSnapIncrement = 1;
|
||||
|
||||
private float _snapLength;
|
||||
|
||||
void Update ()
|
||||
{
|
||||
var snap = PixelSnapCamera != null;
|
||||
if(snap)
|
||||
_snapLength = PixelSnapCamera.orthographicSize * PixelSnapIncrement / PixelSnapCamera.targetTexture.width;
|
||||
|
||||
var x = CopyXPosition ? Target.position.x : transform.position.x;
|
||||
if (snap)
|
||||
{
|
||||
var x1 = (int) (x / _snapLength);
|
||||
x = x1 * _snapLength;
|
||||
}
|
||||
|
||||
var z = CopyZPosition ? Target.position.z : transform.position.z;
|
||||
if (snap)
|
||||
{
|
||||
var z1 = (int) (z / _snapLength);
|
||||
z = z1 * _snapLength;
|
||||
}
|
||||
|
||||
transform.position = new Vector3(x, CopyYPosition ? Target.position.y : transform.position.y, z);
|
||||
|
||||
if (CopyRotation)
|
||||
{
|
||||
var flatForward = Target.forward;
|
||||
flatForward.y = 0;
|
||||
transform.rotation = Quaternion.LookRotation(Vector3.down, flatForward.normalized);
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Sector Display/CopyTransform.cs.meta
Normal file
11
Assets/Scripts/Sector Display/CopyTransform.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 7ec4eea2d4fa2f64f80e17d11987e6f6
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
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