mirror of
https://github.com/Xevion/Rebirth.git
synced 2025-12-10 14:08:19 -06:00
Vignette, Bloom, Boids-like sim
This commit is contained in:
@@ -27,12 +27,59 @@ public class Network : MonoBehaviour
|
||||
|
||||
public void AddPlanet()
|
||||
{
|
||||
var first = _planets.Count == 0;
|
||||
|
||||
EnsureReady();
|
||||
var planet = Instantiate(planetPrefab);
|
||||
if (!first) planet.Size *= Random.Range(0.6f, 1.35f);
|
||||
planet.Render();
|
||||
planet.name = $"Planet {_planets.Count + 1}";
|
||||
planet.transform.parent = transform;
|
||||
_planets.Add(planet);
|
||||
|
||||
if (first) return;
|
||||
|
||||
var minimumDistance = 2.25f;
|
||||
var maximumDistance = 2.75f;
|
||||
|
||||
// Attempt to find a suitable position for the new planet
|
||||
int indexOffset = Random.Range(0, _planets.Count);
|
||||
for (int i = 0; i < _planets.Count; i++)
|
||||
{
|
||||
Planet potentialNeighbor = _planets[(i + indexOffset) % _planets.Count];
|
||||
if (potentialNeighbor == planet) continue;
|
||||
|
||||
// Pick a random angle
|
||||
float angle = Random.Range(0, 360) * Mathf.Deg2Rad;
|
||||
float distance = (potentialNeighbor.Size + planet.Size) * Random.Range(minimumDistance, maximumDistance);
|
||||
|
||||
// Calculate the position
|
||||
Vector3 position = potentialNeighbor.transform.position + new Vector3(Mathf.Cos(angle), Mathf.Sin(angle)) * (distance / 100f);
|
||||
|
||||
// Check if the position is valid
|
||||
bool valid = true;
|
||||
foreach (var other in _planets)
|
||||
{
|
||||
if (other == potentialNeighbor) continue;
|
||||
if (Vector3.Distance(position, other.transform.position) < (other.Size + planet.Size) * minimumDistance / 100f)
|
||||
{
|
||||
valid = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (valid)
|
||||
{
|
||||
planet.transform.position = position;
|
||||
// planet.neighbors.Add(potentialNeighbor);
|
||||
// potentialNeighbor.neighbors.Add(planet);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// All attempts failed
|
||||
Debug.LogWarning("Failed to find a suitable position for the new planet");
|
||||
Destroy(planet.gameObject);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -55,11 +102,8 @@ public class Network : MonoBehaviour
|
||||
|
||||
if (_planets.Count == 0)
|
||||
{
|
||||
for (int i = 0; i < 5; i++)
|
||||
AddPlanet();
|
||||
}
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,7 +31,10 @@ public class Planet : MonoBehaviour
|
||||
_units = new List<Unit>();
|
||||
_query = new KDQuery();
|
||||
_tree = new KDTree();
|
||||
}
|
||||
|
||||
void Start()
|
||||
{
|
||||
while (_units.Count < 10)
|
||||
SpawnUnit();
|
||||
|
||||
@@ -40,6 +43,7 @@ public class Planet : MonoBehaviour
|
||||
|
||||
void OnMouseDown()
|
||||
{
|
||||
Debug.Log($"Clicked on {name}");
|
||||
SpawnUnit();
|
||||
}
|
||||
|
||||
@@ -61,6 +65,7 @@ public class Planet : MonoBehaviour
|
||||
var unitPrefab = Resources.Load<GameObject>("BaseUnit");
|
||||
var unitObject = Instantiate(unitPrefab);
|
||||
unitObject.transform.position = transform.position;
|
||||
Debug.Log($"Spawned unit at {unitObject.transform.position} for planet {name}");
|
||||
unitObject.transform.parent = transform;
|
||||
var unit = unitObject.GetComponent<Unit>();
|
||||
_units.Add(unit);
|
||||
@@ -82,6 +87,8 @@ public class Planet : MonoBehaviour
|
||||
|
||||
void ChangeUnits()
|
||||
{
|
||||
if (_units.Count < 50) return;
|
||||
|
||||
// Delete 3 units
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
|
||||
@@ -255,7 +255,7 @@ Transform:
|
||||
m_GameObject: {fileID: 517509222}
|
||||
serializedVersion: 2
|
||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_LocalPosition: {x: 0, y: 0, z: -10}
|
||||
m_LocalPosition: {x: 0.80113673, y: -0.036982335, z: -13.224452}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children: []
|
||||
|
||||
@@ -21,10 +21,10 @@ MonoBehaviour:
|
||||
m_Value: 0.27
|
||||
intensity:
|
||||
m_OverrideState: 1
|
||||
m_Value: 0.35
|
||||
m_Value: 1.78
|
||||
scatter:
|
||||
m_OverrideState: 0
|
||||
m_Value: 0.7
|
||||
m_OverrideState: 1
|
||||
m_Value: 0.34
|
||||
clamp:
|
||||
m_OverrideState: 0
|
||||
m_Value: 65472
|
||||
@@ -61,3 +61,32 @@ MonoBehaviour:
|
||||
m_EditorClassIdentifier:
|
||||
components:
|
||||
- {fileID: -315830951645749855}
|
||||
- {fileID: 1220353792692202144}
|
||||
--- !u!114 &1220353792692202144
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 3
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 0}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 899c54efeace73346a0a16faa3afe726, type: 3}
|
||||
m_Name: Vignette
|
||||
m_EditorClassIdentifier:
|
||||
active: 1
|
||||
color:
|
||||
m_OverrideState: 0
|
||||
m_Value: {r: 0, g: 0, b: 0, a: 1}
|
||||
center:
|
||||
m_OverrideState: 0
|
||||
m_Value: {x: 0.5, y: 0.5}
|
||||
intensity:
|
||||
m_OverrideState: 0
|
||||
m_Value: 0
|
||||
smoothness:
|
||||
m_OverrideState: 0
|
||||
m_Value: 0.2
|
||||
rounded:
|
||||
m_OverrideState: 0
|
||||
m_Value: 0
|
||||
|
||||
@@ -28,26 +28,55 @@ public class Unit : MonoBehaviour
|
||||
BobbingOffset = Random.Range(0, (float)(2 * Math.PI));
|
||||
|
||||
transform.position = planet.GetSurfacePosition(Random.Range(0, 360), 0.3f);
|
||||
|
||||
Debug.Log($"{name} belongs to {planet.name}");
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
// Rotate itself slightly
|
||||
transform.Rotate(new Vector3(0, 0, Time.deltaTime * RotationSpeed));
|
||||
transform.RotateAround(planet.transform.position, Vector3.forward, planetaryVelocity.x * Time.deltaTime);
|
||||
|
||||
// Bobbing motion
|
||||
var unitAngle = planet.GetUnitAngle(this);
|
||||
var targetDistance = (Mathf.Sin(BobbingOffset + Time.time) + 1) / 2;
|
||||
targetDistance = Mathf.Lerp(0.35f, 0.8f, targetDistance);
|
||||
transform.position = planet.GetSurfacePosition(unitAngle, targetDistance);
|
||||
transform.Translate(Vector3.up * Time.deltaTime);
|
||||
|
||||
// Get distance from planet
|
||||
var distance = Vector2.Distance(transform.position, planet.transform.position) - planet.Size / 100f;
|
||||
var maxDistance = 1f;
|
||||
var minDistance = 0.2f;
|
||||
|
||||
bool isTooFar = distance > maxDistance;
|
||||
bool isTooClose = distance < minDistance;
|
||||
|
||||
// If incorrect distance, rotate
|
||||
if (isTooFar || isTooClose)
|
||||
{
|
||||
var directionToPlanet = (planet.transform.position - transform.position).normalized;
|
||||
var projectionOnRight = Vector3.Dot(directionToPlanet, transform.right);
|
||||
var planetOnRight = projectionOnRight < 0;
|
||||
|
||||
var direction = planetOnRight == isTooFar ? 1 : -1;
|
||||
var turningSpeed = 200f;
|
||||
if (isTooClose) turningSpeed *= 3;
|
||||
else if (isTooFar) turningSpeed *= (distance - maxDistance);
|
||||
transform.Rotate(new Vector3(0, 0, direction * turningSpeed * Time.deltaTime));
|
||||
|
||||
// var angle = Mathf.Atan2(transform.position.y, transform.position.x) * Mathf.Rad2Deg;
|
||||
// angle += Random.Range(-10, 10);
|
||||
// transform.rotation = Quaternion.Euler(0, 0, angle);
|
||||
}
|
||||
|
||||
planet.Tree.Points[TreeIndex] = transform.position;
|
||||
}
|
||||
|
||||
public void OnDrawGizmos()
|
||||
{
|
||||
// Draw a line forward
|
||||
Gizmos.color = Color.red;
|
||||
Gizmos.DrawLine(transform.position, transform.position + transform.up);
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
if (planet == null) return;
|
||||
planet.UnitDestroyed(this);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user