2020-12-22 03:13:43 +00:00
|
|
|
|
/* 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;
|
2020-12-14 02:56:35 +00:00
|
|
|
|
using System.Collections;
|
|
|
|
|
|
using System.Collections.Generic;
|
2021-03-15 11:40:46 +00:00
|
|
|
|
using TMPro;
|
2020-12-14 02:56:35 +00:00
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
using Unity.Mathematics;
|
|
|
|
|
|
using UnityEngine.UI;
|
|
|
|
|
|
using static Unity.Mathematics.math;
|
|
|
|
|
|
using int2 = Unity.Mathematics.int2;
|
|
|
|
|
|
|
|
|
|
|
|
public class MapRenderer : MonoBehaviour
|
|
|
|
|
|
{
|
2021-03-15 11:40:46 +00:00
|
|
|
|
public ActionGameManager GameManager;
|
|
|
|
|
|
public TextMeshProUGUI Title;
|
2020-12-14 02:56:35 +00:00
|
|
|
|
public Camera MapOverlayCamera;
|
|
|
|
|
|
public Camera GravityCamera;
|
|
|
|
|
|
public Camera TintCamera;
|
2021-05-02 20:59:45 +01:00
|
|
|
|
public Camera InfluenceCamera;
|
2020-12-14 02:56:35 +00:00
|
|
|
|
public Image OverlayDisplay;
|
|
|
|
|
|
public Image GravityDisplay;
|
|
|
|
|
|
public Image TintDisplay;
|
2021-05-02 20:59:45 +01:00
|
|
|
|
public Image InfluenceDisplay;
|
2020-12-14 02:56:35 +00:00
|
|
|
|
public float Scale;
|
|
|
|
|
|
public float2 Position;
|
2021-05-12 00:15:11 +01:00
|
|
|
|
public float IconSize = 1f/128;
|
2020-12-14 02:56:35 +00:00
|
|
|
|
|
|
|
|
|
|
private RectTransform _rect;
|
|
|
|
|
|
private RenderTexture _mapTexture;
|
|
|
|
|
|
private RenderTexture _gravityTexture;
|
|
|
|
|
|
private RenderTexture _tintTexture;
|
2021-05-02 20:59:45 +01:00
|
|
|
|
private RenderTexture _influenceTexture;
|
2020-12-14 02:56:35 +00:00
|
|
|
|
private int2 _size;
|
|
|
|
|
|
private bool _init;
|
|
|
|
|
|
|
|
|
|
|
|
void Start()
|
|
|
|
|
|
{
|
|
|
|
|
|
_rect = GetComponent<RectTransform>();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void OnEnable()
|
|
|
|
|
|
{
|
|
|
|
|
|
_init = true;
|
|
|
|
|
|
MapOverlayCamera.gameObject.SetActive(true);
|
|
|
|
|
|
GravityCamera.gameObject.SetActive(true);
|
|
|
|
|
|
TintCamera.gameObject.SetActive(true);
|
2021-05-02 20:59:45 +01:00
|
|
|
|
InfluenceCamera.gameObject.SetActive(true);
|
2021-03-15 11:40:46 +00:00
|
|
|
|
Title.text = $"Zone: {GameManager.Zone.SectorZone.Name}";
|
2020-12-14 02:56:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void OnDisable()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (_mapTexture != null)
|
|
|
|
|
|
{
|
2021-05-02 20:59:45 +01:00
|
|
|
|
ReleaseTextures();
|
2020-12-14 02:56:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
MapOverlayCamera.gameObject.SetActive(false);
|
|
|
|
|
|
GravityCamera.gameObject.SetActive(false);
|
|
|
|
|
|
TintCamera.gameObject.SetActive(false);
|
2021-05-02 20:59:45 +01:00
|
|
|
|
InfluenceCamera.gameObject.SetActive(false);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ReleaseTextures()
|
|
|
|
|
|
{
|
|
|
|
|
|
_mapTexture.Release();
|
|
|
|
|
|
_mapTexture = null;
|
|
|
|
|
|
_gravityTexture.Release();
|
|
|
|
|
|
_gravityTexture = null;
|
|
|
|
|
|
_tintTexture.Release();
|
|
|
|
|
|
_tintTexture = null;
|
|
|
|
|
|
_influenceTexture.Release();
|
|
|
|
|
|
_influenceTexture = null;
|
2020-12-14 02:56:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void LateUpdate()
|
|
|
|
|
|
{
|
|
|
|
|
|
var size = int2(Screen.width, Screen.height);
|
|
|
|
|
|
if (_init || size.x != _size.x || size.y != _size.y)
|
|
|
|
|
|
{
|
|
|
|
|
|
_init = false;
|
|
|
|
|
|
_size = size;
|
|
|
|
|
|
if (_mapTexture != null)
|
|
|
|
|
|
{
|
2021-05-02 20:59:45 +01:00
|
|
|
|
ReleaseTextures();
|
2020-12-14 02:56:35 +00:00
|
|
|
|
}
|
2021-05-02 20:59:45 +01:00
|
|
|
|
|
2020-12-14 02:56:35 +00:00
|
|
|
|
_mapTexture = new RenderTexture(_size.x, _size.y, 0, RenderTextureFormat.Default);
|
|
|
|
|
|
MapOverlayCamera.targetTexture = _mapTexture;
|
|
|
|
|
|
OverlayDisplay.material.SetTexture("_DetailTex", _mapTexture);
|
2021-05-02 20:59:45 +01:00
|
|
|
|
|
2020-12-14 02:56:35 +00:00
|
|
|
|
_gravityTexture = new RenderTexture(_size.x, _size.y, 0, RenderTextureFormat.RFloat);
|
|
|
|
|
|
GravityCamera.targetTexture = _gravityTexture;
|
|
|
|
|
|
GravityDisplay.material.SetTexture("_DetailTex", _gravityTexture);
|
2021-05-02 20:59:45 +01:00
|
|
|
|
|
2020-12-14 02:56:35 +00:00
|
|
|
|
_tintTexture = new RenderTexture(_size.x / 2, _size.y / 2, 0, RenderTextureFormat.RGB111110Float);
|
|
|
|
|
|
TintCamera.targetTexture = _tintTexture;
|
|
|
|
|
|
TintDisplay.material.SetTexture("_DetailTex", _tintTexture);
|
2021-05-02 20:59:45 +01:00
|
|
|
|
|
|
|
|
|
|
_influenceTexture = new RenderTexture(_size.x, _size.y, 0, RenderTextureFormat.RFloat);
|
|
|
|
|
|
InfluenceCamera.targetTexture = _influenceTexture;
|
|
|
|
|
|
InfluenceDisplay.material.SetTexture("_DetailTex", _influenceTexture);
|
2020-12-14 02:56:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-12-18 13:48:03 +00:00
|
|
|
|
var pos = ((Vector2) Position).Flatland(1);
|
2020-12-14 02:56:35 +00:00
|
|
|
|
|
|
|
|
|
|
MapOverlayCamera.transform.position = pos;
|
|
|
|
|
|
MapOverlayCamera.orthographicSize = _size.y * Scale * .5f;
|
|
|
|
|
|
|
|
|
|
|
|
GravityCamera.transform.position = pos;
|
|
|
|
|
|
GravityCamera.orthographicSize = _size.y * Scale * .5f;
|
2020-12-27 22:18:22 +00:00
|
|
|
|
GravityDisplay.material.SetFloat("_Scale", Scale / 2);
|
2020-12-14 02:56:35 +00:00
|
|
|
|
|
|
|
|
|
|
TintCamera.transform.position = pos;
|
|
|
|
|
|
TintCamera.orthographicSize = _size.y * Scale * .5f;
|
2021-05-02 20:59:45 +01:00
|
|
|
|
|
|
|
|
|
|
InfluenceCamera.transform.position = pos;
|
|
|
|
|
|
InfluenceCamera.orthographicSize = _size.y * Scale * .5f;
|
2021-05-12 00:15:11 +01:00
|
|
|
|
|
|
|
|
|
|
GameManager.ZoneRenderer.SetIconSize(IconSize * Scale);
|
2020-12-14 02:56:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|