This can be seen as the initial state of the project after the released demo.
The changes include:
- New ship models
- Singleton manager structure to keep project scaleable in the future
- Managing players, their settings, character choices, statistics, match setups, controls etc. in a separate decoupled scene
- Main menu with transitions to the arena scene
- Beginnings of a custom audio solution
- Logging with Log4Net
It is really a complete overhaul of the projects structure and management.
55 lines
1.2 KiB
C#
55 lines
1.2 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using Unity.VisualScripting;
|
|
using UnityEngine;
|
|
using static System.Math;
|
|
using static UnityEngine.Mathf;
|
|
|
|
public class CameraOperator : MonoBehaviour
|
|
{
|
|
private Dictionary<int, GameObject> players = new Dictionary<int, GameObject>();
|
|
|
|
public void AddPlayer(GameObject player)
|
|
{
|
|
players[player.GetInstanceID()] = player;
|
|
}
|
|
|
|
public void RemovePlayer(int id)
|
|
{
|
|
players.Remove(id);
|
|
}
|
|
|
|
// Update is called once per frame
|
|
void LateUpdate()
|
|
{
|
|
if (players.Count < 1)
|
|
{
|
|
return;
|
|
}
|
|
float x = 0;
|
|
float y = 0;
|
|
float z = 30;
|
|
foreach (GameObject p in players.Values)
|
|
{
|
|
if (p.IsDestroyed())
|
|
continue;
|
|
Vector3 position = p.transform.localPosition;
|
|
z = position.z;
|
|
x += position.x;
|
|
y += position.y;
|
|
}
|
|
x /= players.Count();
|
|
y /= players.Count();
|
|
float a = z - transform.localPosition.z;
|
|
float cXAxis = (float)Sqrt(Pow(a, 2) + Pow(x, 2));
|
|
float cYAxis = (float)Sqrt(Pow(a, 2) + Pow(y, 2));
|
|
Vector3 xyRotation = new Vector3(Rad2Deg * Acos(a / cYAxis) * -Math.Sign(y),
|
|
Rad2Deg * Acos(a / cXAxis) * Math.Sign(x), 0);
|
|
if (transform.localEulerAngles != xyRotation / 2)
|
|
{
|
|
transform.localEulerAngles = xyRotation / 2;
|
|
}
|
|
}
|
|
}
|