Added sector map in Galaxy tab of in-game menu Added player flag to Ship (replaces AGM.PlayerEntities) Refactored sector map to depend on AGM Moved sector generation to main menu Main menu now supports resuming previous playthrough Database and player settings now statically available via AGM AGM saves current game state in PlayerSettings on exit Sector generation is now asynchronous Added progress callbacks to sector gen + progress dialog in menu Confirmation Dialog / properties panel can now display dynamic text entry Added zone title to Zone map Eliminated ZoneData class (properties moved to ZonePack) Sector, Zone and Entity serialization now fully functional Entity settings now separate from player settings Cleaned up old unused networking message classes Name files now integrated with database cache Added ability to save/load additive DB cache files in database panel Cleaned up Wwise sound setup - removed redundant items & fixed spelling errors Deleted Wwise cache + added to .gitignore
111 lines
3.9 KiB
C#
111 lines
3.9 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.EventSystems;
|
|
using UnityEngine.UI;
|
|
using Unity.Mathematics;
|
|
using static Unity.Mathematics.math;
|
|
using float2 = Unity.Mathematics.float2;
|
|
|
|
public class SectorRenderer : MonoBehaviour, IBeginDragHandler, IDragHandler, IScrollHandler
|
|
{
|
|
public ActionGameManager GameManager;
|
|
public Camera SectorCamera;
|
|
public MeshRenderer SectorBackgroundRenderer;
|
|
public float ZoomSpeed;
|
|
public float MinViewSize = .1f;
|
|
public float MaxViewSize = 2;
|
|
|
|
private float2 _startMousePosition;
|
|
private float2 _startMapPosition;
|
|
|
|
private Transform _sectorBackgroundTransform;
|
|
private Transform _sectorCameraTransform;
|
|
private Image _outputImage;
|
|
private RenderTexture _outputTexture;
|
|
private Vector3[] _imageCorners = new Vector3[4];
|
|
private int2 _size;
|
|
private bool _init;
|
|
private float _aspectRatio;
|
|
private float _sectorBackgroundDepth;
|
|
private float _sectorCameraDepth;
|
|
|
|
private float2 _position = float2(0.5f);
|
|
private float _viewSize = .5f;
|
|
|
|
void Start()
|
|
{
|
|
_outputImage = GetComponent<Image>();
|
|
_sectorBackgroundTransform = SectorBackgroundRenderer.transform;
|
|
_sectorBackgroundDepth = _sectorBackgroundTransform.position.z;
|
|
_sectorCameraTransform = SectorCamera.transform;
|
|
_sectorCameraDepth = _sectorCameraTransform.position.z;
|
|
}
|
|
|
|
private void OnEnable()
|
|
{
|
|
_init = true;
|
|
SectorCamera.gameObject.SetActive(true);
|
|
_position = GameManager.Zone.SectorZone.Position;
|
|
_viewSize = .25f;
|
|
}
|
|
|
|
private void OnDisable()
|
|
{
|
|
if (_outputTexture != null)
|
|
{
|
|
_outputTexture.Release();
|
|
_outputTexture = null;
|
|
}
|
|
SectorCamera.gameObject.SetActive(false);
|
|
}
|
|
|
|
void LateUpdate()
|
|
{
|
|
var size = int2(Screen.width, Screen.height);
|
|
if (_init || size.x != _size.x || size.y != _size.y)
|
|
{
|
|
_aspectRatio = (float) size.x / size.y;
|
|
_size = size;
|
|
if (_outputTexture != null)
|
|
{
|
|
_outputTexture.Release();
|
|
}
|
|
_outputTexture = new RenderTexture(_size.x, _size.y, 0, RenderTextureFormat.Default);
|
|
SectorCamera.targetTexture = _outputTexture;
|
|
_outputImage.material.SetTexture("_DetailTex", _outputTexture);
|
|
}
|
|
|
|
var halfSize = _viewSize / 2;
|
|
var bounds = float4(
|
|
_position.x - _aspectRatio * halfSize,
|
|
_position.y - halfSize,
|
|
_position.x + _aspectRatio * halfSize,
|
|
_position.y + halfSize);
|
|
_sectorBackgroundTransform.position = new Vector3(_position.x, _position.y, _sectorBackgroundDepth);
|
|
_sectorBackgroundTransform.localScale = new Vector3(_aspectRatio * _viewSize, _viewSize);
|
|
_sectorCameraTransform.position = new Vector3(_position.x, _position.y, _sectorCameraDepth);
|
|
SectorCamera.orthographicSize = halfSize;
|
|
SectorBackgroundRenderer.material.SetVector("Extents", bounds);
|
|
}
|
|
|
|
public void OnBeginDrag(PointerEventData eventData)
|
|
{
|
|
_startMousePosition = eventData.position;
|
|
_startMapPosition = _position;
|
|
}
|
|
|
|
public void OnDrag(PointerEventData eventData)
|
|
{
|
|
_position = _startMapPosition - ((float2)eventData.position - _startMousePosition) / _size.y * _viewSize;
|
|
}
|
|
|
|
public void OnScroll(PointerEventData eventData)
|
|
{
|
|
var mapCenter = float2((float)Screen.width / 2, (float)Screen.height / 2);
|
|
var oldPointerPosition = _position + ((float2)eventData.position - mapCenter) / Screen.height * _viewSize;
|
|
_viewSize = clamp(_viewSize * (1 - eventData.scrollDelta.y * ZoomSpeed), MinViewSize, MaxViewSize);
|
|
var pointerPosition = _position + ((float2)eventData.position - mapCenter) / Screen.height * _viewSize;
|
|
_position += oldPointerPosition - pointerPosition;
|
|
}
|
|
}
|