Ejemplo n.º 1
0
 public void Disconnect(Connectible other)
 {
     if (Connected.ContainsKey(other))
     {
         LineRenderer r = Connected[other];
         Destroy(r);
         Connected.Remove(other);
         other.Disconnect(this);
         SetConnections();
     }
 }
Ejemplo n.º 2
0
 private static void SetConnectionRec(Connectible c)
 {
     c.isConnectedToPowerplant = true;
     foreach (Connectible con in c.Connected.Keys)
     {
         if (!con.isConnectedToPowerplant)
         {
             con.isConnectedToPowerplant = true;
             SetConnectionRec(con);
         }
     }
 }
Ejemplo n.º 3
0
    //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;
        }
    }
Ejemplo n.º 4
0
    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);
        }
    }
Ejemplo n.º 5
0
    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);
            }
        }
    }
Ejemplo n.º 7
0
 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);
             }
         }
     }
 }
Ejemplo n.º 8
0
 public void ConnectTemporary(Connectible other)
 {
     Connect(other, TemporaryConnections);
 }
Ejemplo n.º 9
0
 public void Connect(Connectible other)
 {
     Connect(other, Connected);
 }