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>()); }
private void Awake() { IPowerSource source = powerSource as IPowerSource; IPowerSink sink = powerSink as IPowerSink; if (source != null && sink != null) { base.ConnectSinkToSource(sink, source); } else { Debug.LogWarning($"Could not connect {powerSource.name} as a source to {powerSink.name} as a sink!"); } }
public void OnDisconnect(IPowerSink sink) { }
public void OnConnect(IPowerSink sink) { }
public virtual void ConnectSinkToSource(IPowerSink sink, IPowerSource source) { source.OnConnect(sink); sink.OnConnect(source); }
public virtual void DisconnectSinkFromSource(IPowerSink sink, IPowerSource source) { source.OnDisconnect(sink); sink.OnDisconnect(source); }
public void OnDisconnect(IPowerSink sink) { //Debug.Log(sink.ToString() + " disconnected"); }