|
|
@ -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() |
|
|
|