public void UpdateGraphics(IVitals vitals)
        {
            Vital vital = vitals[monitoredVitalId];

            if (vital == null)
            {
                return;
            }

            if (UIText != null)
            {
                UIText.text = ((int)vital.Value).ToString();
            }

            // Resize the healthbar
            if (UIImage != null)
            {
                if (UIImage.type == Image.Type.Filled && UIImage.sprite != null)
                {
                    UIImage.fillAmount = vital.Value / vital.maxValue;
                }
                else
                {
                    UIImage.rectTransform.localScale = new Vector3(
                        vital.Value / vital.maxValue,
                        UIImage.rectTransform.localScale.y,
                        UIImage.rectTransform.localScale.z);
                }
            }
        }
        public override void OnInspectorGUI()
        {
            NSTSampleHealthUI _target = (NSTSampleHealthUI)target;
            IVitals           ivitals = null;

            base.OnInspectorGUI();

            EditorGUILayout.HelpBox("This component should be placed on a UI Text or UI Image (with Image Type set to Filled ideally). " +
                                    "It can monitor IVitals on the root of this object, or of the local player gameobject.", MessageType.None);

            string monitorTooltip = "Which IVital should be be monitoring? Auto will try to find an IVital interface on the root of this object first, and if it can't find one will subscribe to the local player IVital.";

            _target.monitor = (NSTSampleHealthUI.Monitor)EditorGUILayout.EnumPopup(new GUIContent("IVitals Source", monitorTooltip), _target.monitor);

            //bool monitorSelf =_target.monitor == NSTSampleHealthUI.Monitor.Self;
            //bool monitorLclPlayer = _target.monitor == NSTSampleHealthUI.Monitor.LocalPlayer;

            //// if monitoring self is an option, try to take it - see if we have vitals
            //if (!monitorLclPlayer)
            //	ivitals = _target.transform.root.GetComponent<IVitals>();

            //// failed to find vitals or we are only set to monitor the local player
            //if (ivitals == null && !monitorSelf)
            //{
            //	// make the GO selector available if no vitals were found on this object
            //	string gotooltip = "Used by the editor only. Vital names in the list below are pulled from the IVitals on this gameobject.";
            //	_target.vitalsSrcGO = (GameObject)EditorGUILayout.ObjectField(new GUIContent("Player GameObj", gotooltip), _target.vitalsSrcGO, typeof(GameObject), true);

            //	if (_target.vitalsSrcGO == null)
            //	{
            //		if (MasterNetAdapter.NetLib == NetworkLibrary.UNET)
            //			_target.vitalsSrcGO = MasterNetAdapter.UNET_GetRegisteredPlayerPrefab();

            //		else if (MasterNetAdapter.NetLib == NetworkLibrary.PUN || MasterNetAdapter.NetLib == NetworkLibrary.PUN2)
            //			_target.vitalsSrcGO = PUNSampleLauncher.Single.playerPrefab;
            //	}

            //	if (_target.vitalsSrcGO != null)
            //		ivitals = _target.vitalsSrcGO.GetComponent<IVitals>();
            //}

            int i = 0;

            // if we found an iVitals... scrape out the names
            if (ivitals != null)
            {
                for (i = 0; i < ivitals.Vitals.Count; i++)
                {
                    vitalnames[i] = (new GUIContent(i.ToString() + " " + ivitals.Vitals[i].name));
                }
            }

            // if not, just make a list of numbers
            for (int j = i; j < 16; j++)
            {
                vitalnames[j] = (new GUIContent(j.ToString()));
            }


            string     vitalIdTooltip = "Which vital to monitor.";
            GUIContent label          = new GUIContent("Monitored Vital", vitalIdTooltip);

            _target.monitoredVitalId = EditorGUILayout.Popup(label, _target.monitoredVitalId, vitalnames);

            serializedObject.ApplyModifiedProperties();
        }
 public void OnVitalsChange(IVitals vitals)
 {
     UpdateGraphics(vitals);
 }