Angepasste Garage, verbessertes Icon Asset system, range der türme vorschau beim ziehen
This commit is contained in:
1 parent
5486444dde
commit
5af8655c97
59 files changed
+12079
-457
No files matched your search
@@ -0,0 +1,57 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace DepthsOfGreed.HandbookUI
|
||||
{
|
||||
public enum WallBoundarySource { SpriteRenderers, CustomRadii }
|
||||
|
||||
[DisallowMultipleComponent]
|
||||
public sealed class WallBuildArea : MonoBehaviour
|
||||
{
|
||||
[Header("Mauer-Baugrenzen")]
|
||||
public WallBoundarySource boundarySource = WallBoundarySource.CustomRadii;
|
||||
[Tooltip("Äußere Kante dieses Sprites ergibt die innere Baugrenze. Kreisförmiges Sprite, zentriert auf BuildArea verwenden.")]
|
||||
public SpriteRenderer innerBoundarySprite;
|
||||
[Tooltip("Äußere Kante dieses Sprites ergibt die äußere Baugrenze. Kreisförmiges Sprite, zentriert auf BuildArea verwenden.")]
|
||||
public SpriteRenderer outerBoundarySprite;
|
||||
[Tooltip("Eigener Innenradius in Welt-Einheiten. Wird nur bei Custom Radii verwendet; unabhängig von der Transform-Skalierung.")]
|
||||
[Min(0)] public float innerRadius = 3f;
|
||||
[Tooltip("Eigener Außenradius in Welt-Einheiten. Muss größer als der Innenradius sein.")]
|
||||
[Min(0.01f)] public float outerRadius = 4f;
|
||||
public bool showSelectedGizmos = true;
|
||||
public Vector3 Center => transform.position;
|
||||
|
||||
public bool TryGetRadii(out float inner, out float outer, out string error)
|
||||
{
|
||||
inner = innerRadius; outer = outerRadius; error = null;
|
||||
if (boundarySource == WallBoundarySource.SpriteRenderers)
|
||||
{
|
||||
if (!innerBoundarySprite || !outerBoundarySprite || !innerBoundarySprite.sprite || !outerBoundarySprite.sprite)
|
||||
{ error = "Beide Baugrenzen benötigen einen zugewiesenen SpriteRenderer mit Sprite."; return false; }
|
||||
inner = Mathf.Min(innerBoundarySprite.bounds.extents.x, innerBoundarySprite.bounds.extents.y);
|
||||
outer = Mathf.Min(outerBoundarySprite.bounds.extents.x, outerBoundarySprite.bounds.extents.y);
|
||||
}
|
||||
if (float.IsNaN(inner) || float.IsInfinity(inner) || float.IsNaN(outer) || float.IsInfinity(outer) || inner < 0 || outer <= inner)
|
||||
{ error = "Ungültige Mauer-Baugrenzen: 0 <= Innenradius < Außenradius erforderlich."; return false; }
|
||||
return true;
|
||||
}
|
||||
|
||||
private void OnDrawGizmosSelected()
|
||||
{
|
||||
if (!showSelectedGizmos || !TryGetRadii(out float inner, out float outer, out _)) return;
|
||||
var old = Gizmos.color;
|
||||
Gizmos.color = new Color(1f,.65f,.15f); Circle(inner);
|
||||
Gizmos.color = new Color(.2f,.8f,1f); Circle(outer);
|
||||
Gizmos.color = old;
|
||||
}
|
||||
private void Circle(float radius)
|
||||
{
|
||||
var previous = Center + Vector3.right * radius;
|
||||
for(int i=1;i<=128;i++)
|
||||
{
|
||||
float angle=i*Mathf.PI*2f/128;
|
||||
var next=Center+new Vector3(Mathf.Cos(angle),Mathf.Sin(angle),0)*radius;
|
||||
Gizmos.DrawLine(previous,next);previous=next;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user