Ejemplo n.º 1
0
 public override void OnCleanUp()
 {
     joulesAvailable?.Dispose();
     wattageGenerated?.Dispose();
     wattageConsumed?.Dispose();
     potentialWattageConsumed?.Dispose();
     maxSafeWattage?.Dispose();
     noCircuit?.Dispose();
     noCircuit       = null;
     consumerParent  = null;
     batteryParent   = null;
     generatorParent = null;
     lastSelected    = default;
     foreach (var pair in cache)
     {
         pair.Value.Dispose();
     }
     cache.Clear();
     batteryLabels.Clear();
     consumerLabels.Clear();
     generatorLabels.Clear();
     wasValid = false;
     base.OnCleanUp();
     Instance = null;
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Initializes labels that need only be updated once.
        /// </summary>
        public override void OnSpawn()
        {
            var op = es.overviewPanel;

            base.OnSpawn();
            op.SetActive(true);
            if (op.TryGetComponent(out CollapsibleDetailContentPanel panel))
            {
                var overviewParent = panel.Content.gameObject;
                joulesAvailable = new EnergyInfoLabel(es.labelTemplate, overviewParent,
                                                      nameof(joulesAvailable));
                joulesAvailable.tooltip.toolTip = ENERGYGENERATOR.AVAILABLE_JOULES_TOOLTIP;
                wattageGenerated = new EnergyInfoLabel(es.labelTemplate, overviewParent,
                                                       nameof(wattageGenerated));
                wattageGenerated.tooltip.toolTip = ENERGYGENERATOR.WATTAGE_GENERATED_TOOLTIP;
                wattageConsumed = new EnergyInfoLabel(es.labelTemplate, overviewParent, nameof(
                                                          wattageConsumed));
                wattageConsumed.tooltip.toolTip = ENERGYGENERATOR.WATTAGE_CONSUMED_TOOLTIP;
                potentialWattageConsumed        = new EnergyInfoLabel(es.labelTemplate,
                                                                      overviewParent, nameof(potentialWattageConsumed));
                potentialWattageConsumed.tooltip.toolTip = ENERGYGENERATOR.
                                                           POTENTIAL_WATTAGE_CONSUMED_TOOLTIP;
                maxSafeWattage = new EnergyInfoLabel(es.labelTemplate, overviewParent, nameof(
                                                         maxSafeWattage));
                maxSafeWattage.tooltip.toolTip = ENERGYGENERATOR.MAX_SAFE_WATTAGE_TOOLTIP;
                noCircuit = new EnergyInfoLabel(es.labelTemplate, overviewParent, nameof(
                                                    noCircuit));
                noCircuit.tooltip.toolTip = ENERGYGENERATOR.DISCONNECTED;
            }
            else
            {
                noCircuit = null;
            }
            if (es.generatorsPanel.TryGetComponent(out panel))
            {
                generatorParent = panel.Content.gameObject;
            }
            else
            {
                generatorParent = null;
            }
            if (es.batteriesPanel.TryGetComponent(out panel))
            {
                batteryParent = panel.Content.gameObject;
            }
            else
            {
                batteryParent = null;
            }
            if (es.consumersPanel.TryGetComponent(out panel))
            {
                consumerParent = panel.Content.gameObject;
            }
            else
            {
                consumerParent = null;
            }
            lastSelected = default;
            dirty        = true;
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Retrieves a label for displaying energy information.
 /// </summary>
 /// <param name="prefab">The prefab to copy if a new label is needed.</param>
 /// <param name="parent">The parent of the label.</param>
 /// <param name="id">The label's unique ID.</param>
 /// <returns>A label with that ID, possibly cached if the ID was used before.</returns>
 private EnergyInfoLabel AddOrGetLabel(GameObject prefab, GameObject parent, string id)
 {
     if (cache.TryGetValue(id, out EnergyInfoLabel label))
     {
         label.SetActive(true);
     }
     else
     {
         label     = new EnergyInfoLabel(prefab, parent, id);
         cache[id] = label;
     }
     return(label);
 }