Generating and Displaying Zones

This commit is contained in:
hyperion51 2020-03-29 04:19:24 +01:00
commit f756c5fe6a
67 changed files with 1343 additions and 826 deletions

View file

@ -1,70 +0,0 @@
using System;
using System.Collections;
using System.Collections.Generic;
using Unity.Mathematics;
using UnityEngine;
// TODO: USE THIS EVERYWHERE
using static Unity.Mathematics.math;
public class Orbit : MonoBehaviour
{
public Transform Target;
public float Period;
public bool ApplyOrbitRotation = false;
public float Phase;
public float Distance;
public bool CalculatePosition;
//private float _period;
// Use this for initialization
void Start ()
{
if (Target == null)
{
enabled = false;
return;
}
var diff = Target.position - transform.position;
Distance = !CalculatePosition ? Distance : diff.magnitude;
Phase = !CalculatePosition ? Phase : Mathf.Atan2(-diff.x, -diff.z);
if (Mathf.Approximately(Period,0))
{
Period = diff.sqrMagnitude / 100;
}
}
// Update is called once per frame
void Update ()
{
if (Target == null)
{
enabled = false;
Debug.Log("Orbit script updating without target. HOW DOES THIS HAPPEN?!");
return;
}
var time = Time.time;//(GameManager.Instance!=null ? GameManager.Instance.ServerTime : Time.time);
// var p = _phase + time / (Period / (Mathf.PI * 2));
var pos = OrbitInstance.Evaluate(Phase + time / Period);
transform.position = new Vector3(Target.position.x + Distance * pos.x,
transform.position.y,
Target.position.z + Distance * pos.y);
var rot = transform.localRotation.eulerAngles;
if(ApplyOrbitRotation)
transform.rotation = Quaternion.Euler(rot.x,(rot.y*Mathf.Deg2Rad-Time.fixedDeltaTime * Period) * Mathf.Rad2Deg,rot.z);
}
void Parent(Transform parent)
{
Target = parent;
}
}

View file

@ -1,20 +0,0 @@
using System.Collections;
using System.Collections.Generic;
using Unity.Mathematics;
using static Unity.Mathematics.math;
public class OrbitInstance
{
private OrbitData _data;
public OrbitInstance(OrbitData data)
{
_data = data;
}
public static float2 Evaluate(float phase)
{
phase *= (PI * 2);
return new float2(sin(phase), cos(phase));
}
}

View file

@ -4,6 +4,7 @@ using System.Collections.Generic;
using MessagePack;
using Newtonsoft.Json;
using Unity.Mathematics;
using static Unity.Mathematics.math;
[RethinkTable("Galaxy")]
[MessagePackObject]
@ -28,6 +29,12 @@ public class ZoneData : DatabaseEntry, INamedEntry
[JsonProperty("orbits")] [Key(6)]
public List<Guid> Orbits = new List<Guid>();
[JsonProperty("radius")] [Key(7)]
public float Radius = 2000;
[JsonProperty("visited")] [Key(8)]
public bool Visited;
[IgnoreMember] public string EntryName
{
get => Name;
@ -86,6 +93,9 @@ public class PlanetData : DatabaseEntry, INamedEntry
[JsonProperty("zone")] [Key(4)]
public Guid Zone;
[JsonProperty("radius")] [Key(5)]
public float GravityRadius;
[IgnoreMember] public string EntryName
{
get => Name;
@ -99,7 +109,7 @@ public class PlanetData : DatabaseEntry, INamedEntry
public class OrbitData : DatabaseEntry
{
[JsonProperty("parent")] [Key(1)]
public Guid? Parent;
public Guid Parent;
[JsonProperty("distance")] [Key(2)]
public float Distance;
@ -112,4 +122,10 @@ public class OrbitData : DatabaseEntry
[JsonProperty("zone")] [Key(5)]
public Guid Zone;
public static float2 Evaluate(float phase)
{
phase *= (PI * 2);
return new float2(sin(phase), cos(phase));
}
}

View file

@ -159,7 +159,7 @@ public class Planet
var p0 = new float2(0, dist);
// Position of second child
var p1 = OrbitInstance.Evaluate(1.0f / vertices) * dist;
var p1 = OrbitData.Evaluate(1.0f / vertices) * dist;
// Maximum child distance is half the distance to the neighbor minus the neighbor's radius
var p0ChildDist = distance(p0, p1) * proportion - Context.PlanetRadius(sharedMass * (1 - proportion));
@ -217,10 +217,13 @@ public class Planet
masses[i] = masses[i] / massTotal * Mass * massFraction;
// Map child distances to range between minimum and maximum
var oldDistances = (float[]) distances.Clone();
for (var i = 0; i < count; i++)
distances[i] = lerp(ChildDistanceMinimum, ChildDistanceMaximum,
(oldDistances[i] - oldDistances[0]) / (oldDistances[count - 1] - oldDistances[0])) + Context.PlanetRadius(masses[i]);
if (count > 1)
{
var oldDistances = (float[]) distances.Clone();
for (var i = 0; i < count; i++)
distances[i] = lerp(ChildDistanceMinimum, ChildDistanceMaximum,
(oldDistances[i] - oldDistances[0]) / (oldDistances[count - 1] - oldDistances[0])) + Context.PlanetRadius(masses[i]);
}
for (var i = 0; i < count; i++)
{

View file

@ -0,0 +1,243 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using Unity.Mathematics;
using static Unity.Mathematics.math;
using float2 = Unity.Mathematics.float2;
public class StrategyGameManager : MonoBehaviour
{
public Camera Camera;
public TabGroup PrimaryTabGroup;
public TabButton GalaxyTabButton;
public TabButton ZoneTabButton;
public Prototype GalaxyZonePrototype;
public Prototype GalaxyZoneLinkPrototype;
public MeshRenderer GalaxyBackground;
public float GalaxyScale;
public ZoneObject ZoneObjectPrefab;
public Transform ZoneRoot;
public Texture2D PlanetSprite;
public Texture2D GasGiantSprite;
public Texture2D OrbitalSprite;
public Texture2D SunSprite;
public Texture2D WormholeSprite;
public Color SelectedColor;
public Color UnselectedColor;
public float ZoneSizeScale = .01f;
public float ZoneMassScale = .01f;
public float ZoneMassPower = .5f;
public float ZoneOrbitSpeed = 10;
public MeshRenderer ZoneBackground;
private DatabaseCache _cache;
private GameContext _context;
private GalaxyResponseMessage _galaxy;
private TabButton _currentTab;
private bool _galaxyPopulated;
private Guid _populatedZone;
private Guid _selectedZone;
private GalaxyZone _selectedGalaxyZone;
private ZoneResponseMessage _zoneResponse;
private Dictionary<Guid, GalaxyResponseZone> _galaxyResponseZones;
private Dictionary<Guid, ZoneObject> _zoneObjects = new Dictionary<Guid, ZoneObject>();
private List<ZoneObject> _wormholes = new List<ZoneObject>();
private Dictionary<Guid, float2> _orbitPositions = new Dictionary<Guid, float2>();
private Vector3 _galaxyCameraPos = -Vector3.forward;
private float _galaxyOrthoSize = 50;
void Start()
{
_cache = new DatabaseCache();
// Request galaxy description from the server
CultClient.Send(new GalaxyRequestMessage());
// Listen for the server's galaxy description
CultClient.AddMessageListener<GalaxyResponseMessage>(galaxy =>
{
_galaxy = galaxy;
_galaxyResponseZones = _galaxy.Zones.ToDictionary(z => z.ZoneID);
_cache.Add(_galaxy.GlobalData, true);
_context = new GameContext(_cache);
if (_currentTab == GalaxyTabButton && !_galaxyPopulated) PopulateGalaxy();
});
// Listen for zone descriptions from the server
CultClient.AddMessageListener<ZoneResponseMessage>(zone =>
{
_zoneResponse = zone;
// Cache zone data and contents
_cache.Add(zone.Zone);
foreach (var entry in zone.Contents) _cache.Add(entry);
if (_currentTab == ZoneTabButton && _populatedZone != zone.Zone.ID) PopulateZone();
});
PrimaryTabGroup.OnTabChange += button =>
{
_currentTab = button;
if (_currentTab == GalaxyTabButton)
{
if (!_galaxyPopulated) PopulateGalaxy();
Camera.transform.position = _galaxyCameraPos;
Camera.orthographicSize = _galaxyOrthoSize;
}
if (_currentTab == ZoneTabButton)
{
if (_populatedZone != _selectedZone && _zoneResponse?.Zone.ID == _selectedZone)
PopulateZone();
Camera.transform.position = -Vector3.forward;
}
};
}
private void Update()
{
if (_currentTab == GalaxyTabButton)
{
_galaxyCameraPos = Camera.transform.position;
_galaxyOrthoSize = Camera.orthographicSize;
}
if (_currentTab == ZoneTabButton && _populatedZone == _selectedZone)
{
_orbitPositions.Clear();
foreach (var planet in _zoneObjects)
{
var planetData = _cache.Get<PlanetData>(planet.Key);
planet.Value.transform.position = (Vector2) GetOrbitPosition(planetData.Orbit) * ZoneSizeScale;
}
}
}
// Determine orbital position recursively, caching parent positions to avoid repeated calculations
private float2 GetOrbitPosition(Guid orbit)
{
// Root orbit is fixed at center
if(orbit==Guid.Empty)
return float2.zero;
if (!_orbitPositions.ContainsKey(orbit))
{
var orbitData = _cache.Get<OrbitData>(orbit);
_orbitPositions[orbit] = GetOrbitPosition(orbitData.Parent) + (orbitData.Period < .01f ? float2.zero :
OrbitData.Evaluate(Time.time * ZoneOrbitSpeed / orbitData.Period + orbitData.Phase) *
orbitData.Distance);
}
var position = _orbitPositions[orbit];
if (float.IsNaN(position.x))
{
Debug.Log("Orbit position is NaN, something went very wrong!");
return float2.zero;
}
return _orbitPositions[orbit];
}
void PopulateGalaxy()
{
_galaxyPopulated = true;
GalaxyBackground.transform.localScale = Vector3.one * GalaxyScale;
var galaxyMat = GalaxyBackground.material;
galaxyMat.SetFloat("Arms", _galaxy.GlobalData.Arms);
galaxyMat.SetFloat("Twist", _galaxy.GlobalData.Twist);
galaxyMat.SetFloat("TwistPower", _galaxy.GlobalData.TwistPower);
galaxyMat.SetFloat("SpokeOffset", _galaxy.StarDensity.SpokeOffset);
galaxyMat.SetFloat("SpokeScale", _galaxy.StarDensity.SpokeScale);
galaxyMat.SetFloat("CoreBoost", _galaxy.StarDensity.CoreBoost);
galaxyMat.SetFloat("CoreBoostOffset", _galaxy.StarDensity.CoreBoostOffset);
galaxyMat.SetFloat("CoreBoostPower", _galaxy.StarDensity.CoreBoostPower);
galaxyMat.SetFloat("EdgeReduction", _galaxy.StarDensity.EdgeReduction);
galaxyMat.SetFloat("NoisePosition", _galaxy.StarDensity.NoisePosition);
galaxyMat.SetFloat("NoiseAmplitude", _galaxy.StarDensity.NoiseAmplitude);
galaxyMat.SetFloat("NoiseOffset", _galaxy.StarDensity.NoiseOffset);
galaxyMat.SetFloat("NoiseGain", _galaxy.StarDensity.NoiseGain);
galaxyMat.SetFloat("NoiseLacunarity", _galaxy.StarDensity.NoiseLacunarity);
galaxyMat.SetFloat("NoiseFrequency", _galaxy.StarDensity.NoiseFrequency);
var zones = _galaxy.Zones.ToDictionary(z=>z.ZoneID);
var linkedZones = new List<Guid>();
foreach (var zone in _galaxy.Zones)
{
linkedZones.Add(zone.ZoneID);
var instance = GalaxyZonePrototype.Instantiate<Transform>();
instance.position = float3((Vector2) zone.Position - Vector2.one * .5f,0) * GalaxyScale;
var instanceZone = instance.GetComponent<GalaxyZone>();
instanceZone.Label.text = zone.Name;
instanceZone.Background.GetComponent<ClickableCollider>().OnClick += (_, pointer) =>
{
if (_selectedGalaxyZone != null)
_selectedGalaxyZone.Background.material.SetColor("_TintColor", UnselectedColor);
if(_selectedZone != zone.ZoneID)
CultClient.Send(new ZoneRequestMessage{ZoneID = zone.ZoneID});
_selectedZone = zone.ZoneID;
_selectedGalaxyZone = instanceZone;
_selectedGalaxyZone.Background.material.SetColor("_TintColor", SelectedColor);
_selectedZone = zone.ZoneID;
// If the user double clicks on a zone, switch to the zone tab
if(pointer.clickCount == 2) ZoneTabButton.OnPointerClick(pointer);
};
foreach (var linkedZone in zone.Links.Where(l=>!linkedZones.Contains(l)))
{
var link = GalaxyZoneLinkPrototype.Instantiate<Transform>();
var diff = zones[linkedZone].Position - zone.Position;
link.position = instance.position + Vector3.forward*.1f;
link.rotation = Quaternion.Euler(0,0,atan2(diff.y, diff.x) * Mathf.Rad2Deg);
link.localScale = new Vector3(length(diff) * GalaxyScale, 1, 1);
}
}
}
void PopulateZone()
{
// Delete all the existing zone contents
foreach (var zoneObject in _zoneObjects.Values) Destroy(zoneObject.gameObject);//zoneObject.GetComponent<Prototype>().ReturnToPool();
_zoneObjects.Clear();
foreach (var zoneObject in _wormholes) Destroy(zoneObject.gameObject); //zoneObject.GetComponent<Prototype>().ReturnToPool();
_wormholes.Clear();
_populatedZone = _selectedZone;
float zoneDepth = 0;
foreach (var entry in _zoneResponse.Contents)
{
if (entry is PlanetData planet)
{
var planetObject = Instantiate(ZoneObjectPrefab, ZoneRoot);
_zoneObjects[planet.ID] = planetObject;
planetObject.Label.text = planet.Name;
planetObject.GravityMesh.gameObject.SetActive(true);
planetObject.GravityMesh.transform.localScale = Vector3.one * (planet.GravityRadius * 2 * ZoneSizeScale);
var depth = pow(planet.Mass, ZoneMassPower) * ZoneMassScale;
if (depth > zoneDepth)
zoneDepth = depth;
planetObject.GravityMesh.material.SetFloat("_Depth", depth);
planetObject.Icon.material.SetTexture("_MainTex",
planet.Mass > _context.GlobalData.SunMass ? SunSprite :
planet.Mass > _context.GlobalData.GasGiantMass ? GasGiantSprite :
PlanetSprite);
}
}
ZoneBackground.material.SetFloat("_HeightRange", zoneDepth);
foreach (var wormhole in _zoneResponse.Zone.Wormholes)
{
var otherZone = _galaxyResponseZones[wormhole];
var wormholeObject = Instantiate(ZoneObjectPrefab);
_wormholes.Add(wormholeObject);
var direction = otherZone.Position - _zoneResponse.Zone.Position;
wormholeObject.transform.position = (Vector2) (normalize(direction) * _zoneResponse.Zone.Radius * .95f * ZoneSizeScale);
wormholeObject.GravityMesh.gameObject.SetActive(false);
wormholeObject.Icon.material.SetTexture("_MainTex", WormholeSprite);
wormholeObject.Label.text = otherZone.Name;
}
}
}

View file

@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: fc9a1d6d35b2ac14eb8c1092432ae217
guid: 1c1faf0a46b9cf24498cd5ec93c34c71
MonoImporter:
externalObjects: {}
serializedVersion: 2

8
Assets/Scripts/UI.meta Normal file
View file

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: af274c1630940f246869637f44bc484e
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -6,11 +6,13 @@ using UnityEngine;
public class BackgroundRenderer : MonoBehaviour
{
public Transform Background;
public Transform Background2;
// public float RotationSpeed1 = 1;
// public float RotationSpeed2 = 1;
private Camera _camera;
private float _ratio;
private Material _material;
private Material _material2;
private float _depth;
private void Start()
@ -18,14 +20,16 @@ public class BackgroundRenderer : MonoBehaviour
_camera = GetComponent<Camera>();
_depth = Background.position.z;
_material = Background.GetComponent<MeshRenderer>().material;
_material2 = Background2.GetComponent<MeshRenderer>().material;
}
private void OnPreRender()
{
_material.SetVector("ParallaxDirection", transform.position);
_ratio = (float) Screen.height / Screen.width;
Background.position = new Vector3(transform.position.x, transform.position.y, _depth);
_material2.SetVector("ParallaxDirection", transform.position);
_ratio = (float) Screen.width / Screen.height;
Background2.position = Background.position = new Vector3(transform.position.x, transform.position.y, _depth);
var size = _camera.orthographicSize;
Background.localScale = new Vector3(size * 4, size * 4 * _ratio, 1);
Background2.localScale = Background.localScale = new Vector3(size * 2 * _ratio, size * 2, 1);
}
}

View file

@ -7,14 +7,12 @@ using UnityEngine.EventSystems;
public class ClickCatcher : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler, IPointerClickHandler
{
public bool EnableMouse => PointerIsInside && !_catching;
//public bool EnableMouse => PointerIsInside && !_catching;
public bool PointerIsInside { get; private set; }
public PointerEnterEvent OnEnter = new PointerEnterEvent();
public PointerExitEvent OnExit = new PointerExitEvent();
private bool _catching;
private UnityEvent _catchClick;
public event Action<PointerEventData> OnEnter;
public event Action<PointerEventData> OnExit;
public event Action<PointerEventData> OnClick;
public static ClickCatcher Background
{
@ -27,43 +25,23 @@ public class ClickCatcher : MonoBehaviour, IPointerEnterHandler, IPointerExitHan
}
private static ClickCatcher _background;
public UnityEvent Catch()
{
_catching = true;
_catchClick = new UnityEvent();
return _catchClick;
}
public void Release()
{
_catching = false;
}
public void OnPointerEnter(PointerEventData eventData)
{
//Debug.Log("Pointer Entered");
OnEnter.Invoke();
OnEnter?.Invoke(eventData);
PointerIsInside = true;
}
public void OnPointerExit(PointerEventData eventData)
{
//Debug.Log("Pointer Exited");
OnExit.Invoke();
OnExit?.Invoke(eventData);
PointerIsInside = false;
}
public void OnPointerClick(PointerEventData eventData)
{
if (!_catching) return;
_catchClick.Invoke();
_catching = false;
OnClick?.Invoke(eventData);
}
[Serializable]
public class PointerEnterEvent : UnityEvent { }
[Serializable]
public class PointerExitEvent : UnityEvent { }
}

View file

@ -0,0 +1,25 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ClickRaycaster : MonoBehaviour
{
public Camera RayCamera;
private ClickCatcher _clickCatcher;
void Start()
{
_clickCatcher = GetComponent<ClickCatcher>();
_clickCatcher.OnClick += pointer =>
{
RaycastHit hit;
Physics.Raycast(RayCamera.ScreenPointToRay(pointer.position), out hit);
if (hit.collider != null)
{
var clickable = hit.collider.GetComponent<ClickableCollider>();
if (clickable != null)
clickable.Click(pointer);
}
};
}
}

View file

@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 9f1a6147e441c0847b784d31a9f6b315
guid: ba30ab714c5cf6943957d3e4ae549c84
MonoImporter:
externalObjects: {}
serializedVersion: 2

View file

@ -0,0 +1,12 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
public class ClickableCollider : MonoBehaviour
{
public event Action<ClickableCollider, PointerEventData> OnClick;
public void Click(PointerEventData eventData) => OnClick?.Invoke(this, eventData);
}

View file

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

View file

@ -0,0 +1,29 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using static Unity.Mathematics.math;
public class DragHandler : MonoBehaviour
{
public Camera Camera;
public float Scaling;
private Vector2 _previousPosition;
void Update()
{
var newPosition = Camera.ScreenToWorldPoint(Input.mousePosition);
if(Input.GetMouseButtonDown(0))
_previousPosition = newPosition;
if (Input.GetMouseButton(0))
{
Camera.transform.position -= (Vector3)((Vector2) newPosition - _previousPosition);
}
if (abs(Input.mouseScrollDelta.y) > .01f)
{
var previousPosition = Camera.ScreenToWorldPoint(Input.mousePosition);
Camera.orthographicSize *= 1 + Input.mouseScrollDelta.y * Scaling;
Camera.transform.position -= Camera.ScreenToWorldPoint(Input.mousePosition) - previousPosition;
}
}
}

View file

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

View file

@ -0,0 +1,11 @@
using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
public class GalaxyZone : MonoBehaviour
{
public MeshRenderer Background;
public MeshRenderer Icon;
public TextMeshPro Label;
}

View file

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

View file

@ -0,0 +1,85 @@
using System;
using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.SceneManagement;
public class LoginScreen : MonoBehaviour
{
public FlatButton LoginButton;
public FlatButton RegisterButton;
public TMP_InputField Server;
public TMP_InputField EmailUsername;
public TMP_InputField Email;
public TMP_InputField Username;
public TMP_InputField Password;
public TextMeshProUGUI Error;
private bool _registering;
void Start()
{
Error.text = " ";
LoginButton.CurrentState = FlatButtonState.Selected;
CultClient.AddMessageListener<LoginSuccessMessage>(success => SceneManager.LoadScene("Main"));
CultClient.OnError += s => Error.text = s;
RegisterButton.OnClick += _ =>
{
if(!CultClient.Connected)
CultClient.Connect(Server.text);
if (_registering)
{
CultClient.Register(Email.text, Username.text, Password.text);
}
else
{
_registering = true;
EmailUsername.gameObject.SetActive(false);
Email.gameObject.SetActive(true);
Username.gameObject.SetActive(true);
LoginButton.CurrentState = FlatButtonState.Unselected;
RegisterButton.CurrentState = FlatButtonState.Selected;
}
};
LoginButton.OnClick += _ =>
{
if(!CultClient.Connected)
CultClient.Connect(Server.text);
if (_registering)
{
_registering = false;
EmailUsername.gameObject.SetActive(true);
Email.gameObject.SetActive(false);
Username.gameObject.SetActive(false);
LoginButton.CurrentState = FlatButtonState.Selected;
RegisterButton.CurrentState = FlatButtonState.Unselected;
}
else
{
CultClient.Login(EmailUsername.text, Password.text);
}
};
}
private void Update()
{
if (Input.GetKeyDown(KeyCode.Tab) || Input.GetKeyDown(KeyCode.Return))
{
if (Server.isFocused)
{
if(_registering)
Email.Select();
else EmailUsername.Select();
}
else if (EmailUsername.isFocused)
Password.Select();
else if (Email.isFocused)
Username.Select();
else if (Username.isFocused)
Password.Select();
else if (Password.isFocused && Input.GetKeyDown(KeyCode.Return))
(_registering ? RegisterButton : LoginButton).OnPointerClick(null);
}
}
}

View file

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

View file

@ -0,0 +1,13 @@
using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
public class ZoneObject : MonoBehaviour
{
public MeshRenderer GravityMesh;
public MeshRenderer Icon;
public TextMeshPro Label;
}

View file

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

View file

@ -6,7 +6,6 @@ using UnityEngine;
public class ZoneRenderer : MonoBehaviour
{
public Camera FollowCamera;
public Material BackgroundMaterial;
public RenderTexture GravityTexture;
public MeshRenderer GravityRenderer;
@ -26,7 +25,7 @@ public class ZoneRenderer : MonoBehaviour
{
_resX = Screen.width;
_resY = Screen.height;
_ratio = (float) _resY / _resX;
_ratio = (float) _resX / _resY;
if (GravityTexture != null)
{
GravityTexture?.Release();
@ -34,11 +33,12 @@ public class ZoneRenderer : MonoBehaviour
GravityTexture = new RenderTexture(_resX, _resY, 0, RenderTextureFormat.RFloat);
}
BackgroundMaterial.mainTexture = GravityTexture;
GravityRenderer.material.mainTexture = GravityTexture;
var size = _camera.orthographicSize = FollowCamera.orthographicSize;
GravityRenderer.transform.position = new Vector3(transform.position.x, transform.position.y, 0);
var size = _camera.orthographicSize;
GravityRenderer.transform.localScale = new Vector3(size * 4, size * 4 * _ratio, 1);
GravityRenderer.transform.localScale = new Vector3(size * 2 * _ratio, size * 2, 1);
_camera.targetTexture = GravityTexture;
}