protected override void OnLoaded() { switch (this.worldObject.ProtoStaticWorldObject) { case IProtoObjectElectricityProducer: { var publicState = this.worldObject.GetPublicState <IObjectElectricityProducerPublicState>(); this.viewModel = new ViewModelPowerStateOverlay(publicState); break; } case IProtoObjectElectricityConsumer: { var publicState = this.worldObject.GetPublicState <IObjectElectricityConsumerPublicState>(); this.viewModel = new ViewModelPowerStateOverlay(publicState); break; } default: Api.Logger.Error("The object is not an electricity consumer or producer: " + this.worldObject); return; } this.DataContext = this.viewModel; }
protected override void OnUnloaded() { this.DataContext = null; this.viewModel?.Dispose(); this.viewModel = null; }