Browse Source

Performance Increase

master
laurids 3 years ago
parent
commit
2566c69ba0
8 changed files with 150 additions and 109 deletions
  1. +1
    -1
      Assets/GWConquest/Scenes/GalaxyMap.unity
  2. +1
    -1
      Assets/GWConquest/Scripts/Formation.cs
  3. +18
    -1
      Assets/GWConquest/Scripts/GWCamera.cs
  4. +0
    -6
      Assets/GWConquest/Scripts/GameManager.cs
  5. +5
    -5
      Assets/GWConquest/Scripts/Planet.cs
  6. +95
    -90
      Assets/GWConquest/Scripts/PlanetConnection.cs
  7. +22
    -5
      Assets/GWConquest/Scripts/UI/PlanetIndicatorUI.cs
  8. +8
    -0
      Assets/GWConquest/Scripts/Util.cs

+ 1
- 1
Assets/GWConquest/Scenes/GalaxyMap.unity View File

@ -26287,7 +26287,6 @@ MonoBehaviour:
RevealChanceSelf: 0.1
RevealChanceAttack: 0.3
ShieldsCooldown: 10
ZoomPlanetThreshold: 800
SpawnAIPlayer: 1
--- !u!4 &426309784
Transform:
@ -115944,6 +115943,7 @@ MonoBehaviour:
maxCameraAngle: 90
minCameraZoom: 260
maxCameraZoom: 2130
ZoomPlanetThreshold: 800
--- !u!4 &1992706994
Transform:
m_ObjectHideFlags: 0


+ 1
- 1
Assets/GWConquest/Scripts/Formation.cs View File

@ -607,7 +607,7 @@ namespace GWConquest
if(movingArmyIcon != null && ZoneType == ZoneType.Space)
{
if(!IngameUI.PlanetViewEnabled && (GameManager.Instance.ShowCircles || MovementState == FormationMovementState.Moving))
if(!IngameUI.PlanetViewEnabled && (GWCamera.Instance.ShowCircles || MovementState == FormationMovementState.Moving))
{
movingArmyIcon.SetActive(true);
movingArmyIcon.GetComponent<StickToFormation>().Update();


+ 18
- 1
Assets/GWConquest/Scripts/GWCamera.cs View File

@ -1,4 +1,4 @@
using System.Collections;
using System;
using System.Collections.Generic;
using UnityEngine;
@ -41,6 +41,12 @@ namespace GWConquest
public float minCameraZoom;
public float maxCameraZoom;
public float ZoomPlanetThreshold;
public event Action ZoomThresholdCrossed;
private bool belowZoomThreshold;
private float cameraZoomTarget;
private float cameraZoomVelocity = 0f;
@ -218,6 +224,13 @@ namespace GWConquest
scaling.UpdateScaling();
}
bool threshold = mainCam.orthographicSize < ZoomPlanetThreshold;
if(threshold != belowZoomThreshold)
{
belowZoomThreshold = threshold;
ZoomThresholdCrossed?.Invoke();
}
}
transform.position = Vector3.SmoothDamp(transform.position, transformPositionTarget, ref transformPositionVelocity, cameraTranslationSmooth);
@ -229,6 +242,10 @@ namespace GWConquest
{
mainCam.transform.SetParent(cameraTransform, true);
}
public bool ShowCircles {
get => Camera.main.orthographicSize < ZoomPlanetThreshold;
}
}
public interface IZoomScaling


+ 0
- 6
Assets/GWConquest/Scripts/GameManager.cs View File

@ -50,8 +50,6 @@ namespace GWConquest
public float ShieldsCooldown;
public float ZoomPlanetThreshold;
public bool SpawnAIPlayer;
public bool IsLoaded { get; private set; } = false;
@ -187,9 +185,5 @@ namespace GWConquest
SoundEffects.Instance = null;
}
public bool ShowCircles {
get => Camera.main.orthographicSize < ZoomPlanetThreshold;
}
}
}

+ 5
- 5
Assets/GWConquest/Scripts/Planet.cs View File

@ -347,10 +347,10 @@ namespace GWConquest
{
FormationsChanged?.Invoke();
//if (indicatorUI != null)
//{
// indicatorUI.UpdateIndicator();
//}
if (indicatorUI != null)
{
indicatorUI.UpdateIndicator();
}
formationsChangedSinceLastFrame = false;
}
@ -499,7 +499,7 @@ namespace GWConquest
if(Application.isPlaying)
{
const float CircleSizeMin = 0.001f;
float CircleSizeTarget = GameManager.Instance.ShowCircles ? MaxCircleScale : CircleSizeMin;
float CircleSizeTarget = GWCamera.Instance.ShowCircles ? MaxCircleScale : CircleSizeMin;
float CircleSize = CircleTransform.localScale.x;
CircleSize = Mathf.SmoothDamp(CircleSize, CircleSizeTarget, ref CircleScaleVelocity, CircleTransformDamp);


+ 95
- 90
Assets/GWConquest/Scripts/PlanetConnection.cs View File

@ -37,34 +37,37 @@ namespace GWConquest
private LineRenderer lineRenderer;
private Color neutralColor;
private void FixedUpdate() {
if(Application.isPlaying && !IsPreConnection && GameManager.EntitiesLoaded)
private void FixedUpdate()
{
if (Application.isPlaying && !IsPreConnection && GameManager.EntitiesLoaded)
{
Color color1 = neutralColor;
Color color2 = neutralColor;
Player player1 = null;
Player player2 = null;
if(planet1 != null)
if (planet1 != null && planet2 != null
&& Util.IsPointOnScreen(planet1.transform.position) && Util.IsPointOnScreen(planet2.transform.position))
{
player1 = planet1.ControllingPlayer;
if(player1 != null)
Color color1 = neutralColor;
Color color2 = neutralColor;
Player player1 = null;
Player player2 = null;
if (planet1 != null)
{
color1 = player1.Faction.FactionColor;
}
}
if(planet2 != null)
{
player2 = planet2.ControllingPlayer;
if(player2 != null)
player1 = planet1.ControllingPlayer;
if (player1 != null)
{
color1 = player1.Faction.FactionColor;
}
}
if (planet2 != null)
{
color2 = player2.Faction.FactionColor;
}
}
player2 = planet2.ControllingPlayer;
if (player2 != null)
{
color2 = player2.Faction.FactionColor;
}
}
//if(lineRenderer.colorGradient.alphaKeys.Length == 4)
//{
float connLength = Vector3.Distance(lineRenderer.GetPosition(0), lineRenderer.GetPosition(lineRenderer.positionCount-1));
float connLength = Vector3.Distance(lineRenderer.GetPosition(0), lineRenderer.GetPosition(lineRenderer.positionCount - 1));
var gradient = lineRenderer.colorGradient;
var alpha = gradient.alphaKeys[1].alpha;
var alphaKeys = new GradientAlphaKey[4];
@ -79,92 +82,94 @@ namespace GWConquest
alphaKeys[3].alpha = 0f;
gradient.alphaKeys = alphaKeys;
lineRenderer.colorGradient = gradient;
//}
lineRenderer.startColor = Util.UpdateColorRGB(lineRenderer.startColor, color1);
lineRenderer.endColor = Util.UpdateColorRGB(lineRenderer.endColor, color2);
lineRenderer.startColor = Util.UpdateColorRGB(lineRenderer.startColor, color1);
lineRenderer.endColor = Util.UpdateColorRGB(lineRenderer.endColor, color2);
if(lineRenderer.enabled && player1 != null && player2 != null && player1 == player2)
{
var distance = Vector3.Distance(planet1.transform.position, planet2.transform.position);
var runtime = distance / QuadSpeed;
var chance = QuadCount * Time.deltaTime / runtime;
if(UnityEngine.Random.value <= chance)
if (lineRenderer.enabled && player1 != null && player2 != null && player1 == player2)
{
var quadGO = Instantiate(QuadPrefab);
var quadTrans = quadGO.transform;
quadTrans.SetParent(transform);
var startFirst = UnityEngine.Random.value <= 0.5f;
var start = startFirst ? planet1.transform.position : planet2.transform.position;
var target = startFirst ? planet2.transform.position : planet1.transform.position;
quadTrans.position = start;
quadTrans.rotation = Quaternion.LookRotation(Vector3.down, target - start);
var quadRend = quadGO.GetComponent<Renderer>();
quadRend.material.color = Util.UpdateColorRGB(quadRend.material.color, color1);
Quads.Add(new QuadEffect() {
transform = quadTrans,
target = target
});
var distance = Vector3.Distance(planet1.transform.position, planet2.transform.position);
var runtime = distance / QuadSpeed;
var chance = QuadCount * Time.deltaTime / runtime;
if (UnityEngine.Random.value <= chance)
{
var quadGO = Instantiate(QuadPrefab);
var quadTrans = quadGO.transform;
quadTrans.SetParent(transform);
var startFirst = UnityEngine.Random.value <= 0.5f;
var start = startFirst ? planet1.transform.position : planet2.transform.position;
var target = startFirst ? planet2.transform.position : planet1.transform.position;
quadTrans.position = start;
quadTrans.rotation = Quaternion.LookRotation(Vector3.down, target - start);
var quadRend = quadGO.GetComponent<Renderer>();
quadRend.material.color = Util.UpdateColorRGB(quadRend.material.color, color1);
Quads.Add(new QuadEffect()
{
transform = quadTrans,
target = target
});
}
}
}
}
}
}
private void Update()
{
if (planet1 != null && planet2 != null
&& Util.IsPointOnScreen(planet1.transform.position) && Util.IsPointOnScreen(planet2.transform.position))
{
//if(!Application.isPlaying)
//{
UpdatePositions();
#if UNITY_EDITOR
if (!Application.isPlaying && IsPreConnection)
if (Application.isPlaying && !IsPreConnection)
{
var lineRenderer = GetComponent<LineRenderer>();
lineRenderer.startColor = Util.UpdateColorRGB(lineRenderer.startColor, Color.green);
lineRenderer.endColor = Util.UpdateColorRGB(lineRenderer.endColor, Color.green);
}
//}
#endif
if(Application.isPlaying && !IsPreConnection)
{
Camera cam = Camera.main;
float distance;
Camera cam = Camera.main;
float distance;
if(cam.orthographic)
{
distance = cam.orthographicSize;
}
else
{
distance = Vector3.Distance(transform.position, cam.transform.position);
}
if (cam.orthographic)
{
distance = cam.orthographicSize;
}
else
{
distance = Vector3.Distance(transform.position, cam.transform.position);
}
float scale = distance * 1000f / cam.pixelHeight;
lineRenderer.widthMultiplier = ConstantWidth * scale;
float scale = distance * 1000f / cam.pixelHeight;
lineRenderer.widthMultiplier = ConstantWidth * scale;
var delta = QuadSpeed * Time.deltaTime;
for(int i = Quads.Count-1; i >= 0; i--)
{
var quad = Quads[i];
quad.transform.position = Vector3.MoveTowards(quad.transform.position, quad.target, delta);
quad.transform.localScale = Vector3.one * ConstantQuadScale * scale;
if(Vector3.SqrMagnitude(quad.transform.position - quad.target) <= 0.1)
var delta = QuadSpeed * Time.deltaTime;
for (int i = Quads.Count - 1; i >= 0; i--)
{
Destroy(quad.transform.gameObject);
Quads.RemoveAt(i);
var quad = Quads[i];
quad.transform.position = Vector3.MoveTowards(quad.transform.position, quad.target, delta);
quad.transform.localScale = Vector3.one * ConstantQuadScale * scale;
if (Vector3.SqrMagnitude(quad.transform.position - quad.target) <= 0.1)
{
Destroy(quad.transform.gameObject);
Quads.RemoveAt(i);
}
}
}
}
#if UNITY_EDITOR
if (!Application.isPlaying && IsPreConnection)
{
var lineRenderer = GetComponent<LineRenderer>();
lineRenderer.startColor = Util.UpdateColorRGB(lineRenderer.startColor, Color.green);
lineRenderer.endColor = Util.UpdateColorRGB(lineRenderer.endColor, Color.green);
}
#endif
}
public void UpdatePositions()
@ -172,8 +177,8 @@ namespace GWConquest
if (planet1 != null && planet2 != null)
{
var lr = lineRenderer;
if(lr == null)
if (lr == null)
{
lr = GetComponent<LineRenderer>();
}
@ -191,7 +196,7 @@ namespace GWConquest
Vector3 pos1blend = pos1 + diff * BlendDistance;
Vector3 pos2blend = pos2 - diff * BlendDistance;
if(lr.positionCount != 4)
if (lr.positionCount != 4)
{
lr.positionCount = 4;
}
@ -200,7 +205,7 @@ namespace GWConquest
#if UNITY_EDITOR
@ -223,11 +228,11 @@ namespace GWConquest
private void Start()
{
if(Application.isPlaying)
if (Application.isPlaying)
{
Init();
}
}
public void Init()


+ 22
- 5
Assets/GWConquest/Scripts/UI/PlanetIndicatorUI.cs View File

@ -44,6 +44,8 @@ namespace GWConquest
[System.NonSerialized]
private Planet Planet;
private bool IndicatorShown = true;
public void SetPlanet(Planet planet)
{
Planet = planet;
@ -68,7 +70,7 @@ namespace GWConquest
public void UpdateIndicator()
{
if ((DebugUI.ShowAllPlanets || Planet.VisibilityStatus == PlanetVisibilityStatus.Visible) && !GameManager.Instance.ShowCircles)
if ((DebugUI.ShowAllPlanets || Planet.VisibilityStatus == PlanetVisibilityStatus.Visible) && !GWCamera.Instance.ShowCircles)
{
IEnumerable<Formation> formations = Planet.GetAllFormations(ZoneType.Space);
float playerStrength = formations.Sum(f => f.Player == Player.CurrentPlayer ? f.GetFormationStrength() : 0f);
@ -122,9 +124,9 @@ namespace GWConquest
}
private void FixedUpdate() {
if(GameManager.EntitiesLoaded && Planet != null)
if(GameManager.EntitiesLoaded && Planet != null && Util.IsPointOnScreen(transform.position))
{
UpdateIndicator();
//UpdateIndicator();
if (DebugUI.ShowAllPlanets || Planet.VisibilityStatus == PlanetVisibilityStatus.Visible)
{
@ -134,7 +136,7 @@ namespace GWConquest
if (controllingPlayer != null)
{
if(GameManager.Instance.ShowCircles)
if(GWCamera.Instance.ShowCircles)
{
FactionImage.gameObject.SetActive(false);
}
@ -160,7 +162,7 @@ namespace GWConquest
if (!GameManager.Instance.ShowCircles)
if (!GWCamera.Instance.ShowCircles)
{
DistrictSymbols.gameObject.SetActive(true);
var districts = Planet.GetComponentsInChildren<District>();
@ -207,5 +209,20 @@ namespace GWConquest
}
}
void OnZoomThresholdCrossed()
{
UpdateIndicator();
}
void OnEnable()
{
GWCamera.Instance.ZoomThresholdCrossed += OnZoomThresholdCrossed;
}
void OnDisable()
{
GWCamera.Instance.ZoomThresholdCrossed -= OnZoomThresholdCrossed;
}
}
}

+ 8
- 0
Assets/GWConquest/Scripts/Util.cs View File

@ -298,6 +298,14 @@ namespace GWConquest
}
}
public static bool IsPointOnScreen(Vector3 point, float tolerance = 0.1f)
{
var screenPoint = Camera.main.WorldToViewportPoint(point);
return screenPoint.x >= -tolerance && screenPoint.x <= 1f + tolerance
&& screenPoint.y >= -tolerance && screenPoint.y <= 1f + tolerance;
}
}
}

Loading…
Cancel
Save