2025-09-15 23:01:07 +02:00
|
|
|
using UnityEngine;
|
2025-09-17 17:05:48 +02:00
|
|
|
using System.Collections.Generic;
|
2025-09-15 23:01:07 +02:00
|
|
|
|
2025-09-16 00:08:50 +02:00
|
|
|
[ExecuteAlways]
|
2025-09-15 23:01:07 +02:00
|
|
|
public class Node : MonoBehaviour
|
|
|
|
|
{
|
2025-09-16 14:20:19 +02:00
|
|
|
[Range(-1, 1)]
|
|
|
|
|
[SerializeField]
|
2025-09-17 10:12:15 +02:00
|
|
|
public int Owner = -1;
|
2025-09-16 18:19:40 +02:00
|
|
|
public Material materialOwnerSelf, materialOwnerOther, materialOwnerNone;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Awake()
|
|
|
|
|
{
|
|
|
|
|
UpdateColor();
|
|
|
|
|
}
|
2025-09-16 14:20:19 +02:00
|
|
|
|
2025-09-15 23:01:07 +02:00
|
|
|
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
|
|
|
|
void Start()
|
|
|
|
|
{
|
2025-09-16 16:50:21 +02:00
|
|
|
|
2025-09-15 23:01:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Update is called once per frame
|
|
|
|
|
void Update()
|
2025-09-16 18:19:40 +02:00
|
|
|
{
|
|
|
|
|
UpdateTransform();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnValidate()
|
|
|
|
|
{
|
|
|
|
|
UpdateColor();
|
|
|
|
|
UpdateTransform();
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-17 17:05:48 +02:00
|
|
|
private void OnDestroy()
|
|
|
|
|
{
|
|
|
|
|
GameManager gm = FindFirstObjectByType<GameManager>();
|
|
|
|
|
|
|
|
|
|
List<GameManager.Connection> looseConnections = gm.connections.FindAll(c => c.nodeA == this || c.nodeB == this);
|
|
|
|
|
|
|
|
|
|
foreach(GameManager.Connection c in looseConnections)
|
|
|
|
|
{
|
|
|
|
|
DestroyImmediate(c.lineRenderer.gameObject);
|
|
|
|
|
gm.connections.Remove(c);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
gm.FetchAllNodes();
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-16 18:19:40 +02:00
|
|
|
public void UpdateTransform()
|
|
|
|
|
{
|
2025-09-16 16:50:21 +02:00
|
|
|
transform.localPosition = transform.localPosition.normalized * 20f;
|
2025-09-17 17:05:48 +02:00
|
|
|
if(transform.position != Vector3.zero)
|
|
|
|
|
transform.forward = transform.position;
|
2025-09-16 18:19:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void UpdateColor()
|
|
|
|
|
{
|
2025-09-16 14:20:19 +02:00
|
|
|
switch (Owner)
|
|
|
|
|
{
|
2025-09-16 18:19:40 +02:00
|
|
|
case -1: transform.GetChild(0).GetComponent<Renderer>().sharedMaterial = materialOwnerNone; break;
|
|
|
|
|
case 0: transform.GetChild(0).GetComponent<Renderer>().sharedMaterial = materialOwnerSelf; break;
|
|
|
|
|
case 1: transform.GetChild(0).GetComponent<Renderer>().sharedMaterial = materialOwnerOther; break;
|
|
|
|
|
}
|
2025-09-16 16:50:21 +02:00
|
|
|
}
|
2025-09-16 17:40:34 +02:00
|
|
|
|
2025-09-15 23:01:07 +02:00
|
|
|
}
|