public void Disconnect(Connectible other) { if (Connected.ContainsKey(other)) { LineRenderer r = Connected[other]; Destroy(r); Connected.Remove(other); other.Disconnect(this); SetConnections(); } }
private static void SetConnectionRec(Connectible c) { c.isConnectedToPowerplant = true; foreach (Connectible con in c.Connected.Keys) { if (!con.isConnectedToPowerplant) { con.isConnectedToPowerplant = true; SetConnectionRec(con); } } }
//Find all connectibles in a GO including children (mainly cause of power stations) void SetTemporaryConnectibles(GameObject go) { Connectible c = go.GetComponent <Connectible>(); if (c != null) { c.isTemporary = true; } foreach (Connectible con in go.GetComponentsInChildren <Connectible>()) { con.isTemporary = true; } }
private static void SetConnections() { //reset all connections Connectible[] connectibles = FindObjectsOfType <Connectible>(); foreach (Connectible con in connectibles) { con.isConnectedToPowerplant = false; } Powerplant[] plants = FindObjectsOfType <Powerplant>(); foreach (Powerplant plant in plants) { Connectible c = plant.GetComponent <Connectible>(); SetConnectionRec(c); } }
private void Connect(Connectible other, Dictionary <Connectible, LineRenderer> list) { if (list.ContainsKey(other) || other == this) { return; } //do some distance checking perhaps? = no, should be handled by the thing calling this code; // GameObject chord = Instantiate(chordPrefab) as GameObject; LineRenderer line = SetLine(chord.GetComponent <LineRenderer>(), point.position, other.point.position); //make sure to know this list.Add(other, line); SetConnections(); }
void Update() { Connectible[] connectiblesInRange = Connectible.ConnectiblesInRange(transform.position); foreach (Connectible c in connectiblesInRange) { foreach (Connectible mine in myConnectibles) { if (c.transform.parent != null && mine.transform.parent == c.transform.parent) { continue; } //Temporarily connect them c.ConnectTemporary(mine); } } }
public static void ConnectConnectibles(float radius, params Connectible[] toConnect) { foreach (Connectible con in toConnect) { foreach (Connectible p in Connectible.ConnectiblesInRange(con.transform.position)) { if (!p.isTemporary && p.gameObject != con.gameObject) { if (p.transform.parent != null && p.transform.parent == con.transform.parent) { continue; } //BEWARE - LINE RENDERER DUPLICITY con.Connect(p); p.Connect(con); } } } }
public void ConnectTemporary(Connectible other) { Connect(other, TemporaryConnections); }
public void Connect(Connectible other) { Connect(other, Connected); }