Exemplo n.º 1
0
    public void ConnectOutlet(PowerOutlet outlet)
    {
        var mySink      = GetComponentInParent <IPowerSink>();
        var otherSource = outlet.GetComponent <IPowerSource>();

        var mySource  = GetComponentInParent <IPowerSource>();
        var otherSink = outlet.GetComponent <IPowerSink>();

        // I want to draw power from other
        /* Me(Sink) -----> Other(source)*/
        if (mySink != null && otherSource != null)
        {
            _sink   = mySink;
            _source = otherSource;
        }
        else
        // Other wants to draw power from me
        /* Me(Source) <----- Other(sink)*/
        if (mySource != null && otherSink != null)
        {
            _sink   = otherSink;
            _source = mySource;
        }

        base.ConnectSinkToSource(_sink, _source);

        outlet.ConnectPlug(this);
        connectedOutlet = outlet;

        pluggedIn?.Invoke(outlet.GetComponent <Rigidbody2D>());
    }
Exemplo n.º 2
0
    private void OnTriggerEnter2D(Collider2D collision)
    {
        PowerOutlet outlet = collision.GetComponentInParent <PowerOutlet>();

        if (outlet != null)
        {
            ConnectOutlet(outlet);
        }
    }
Exemplo n.º 3
0
    public void DisconnectOutlet()
    {
        if (_sink != null && _source != null)
        {
            base.DisconnectSinkFromSource(_sink, _source);
        }

        if (connectedOutlet != null)
        {
            disconnected?.Invoke(connectedOutlet.GetComponent <Rigidbody2D>());
            connectedOutlet.DisconnectPlug();
            connectedOutlet = null;
        }
    }
Exemplo n.º 4
0
    /// <summary>
    /// Creates and places a lighting unit at the power outlet position with the largest range.
    /// </summary>
    /// <param name="p">Current power outlet with the largest range.</param>
    /// <param name="type">Lighting unit type which should be created.</param>
    private void PlaceLightingUnit(PowerOutlet p, string type)
    {
        // Creating a lighting unit and set its properties
        GameObject bulb = Instantiate(bulbPrefab, gameObject.transform);

        bulb.transform.position = p.lampPosition;
        LightingUnit unit = new LightingUnit(p.lampPosition, p.surfacePlane.Type, bulb, p.hits.Select(d => d.distance).Max(), 0, type);

        LightingUnitConfigurationHandler confgurator = bulb.GetComponent <LightingUnitConfigurationHandler>();

        if (confgurator != null)
        {
            confgurator.Init(unit, LightBulbs.Count);
        }

        LightBulbs.Add(unit);

        SetupMesh(unit);
        StartCoroutine(CreateSphereRayCasts(unit));
    }