// Use this for initialization
        void Start()
        {
            var iVitalsComp = GetComponentInChildren <IVitalsSystem>();


            if (iVitalsComp == null || !(iVitalsComp as SyncObject).PhotonView.IsMine)
            {
                Destroy(this);
            }
            else
            {
                vitals = iVitalsComp.Vitals;
            }
        }
Example #2
0
        public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
        {
            property.serializedObject.Update();

            SerializedProperty vitalDefs = property.FindPropertyRelative("vitalDefs");
            Vitals             ivitals   = (PropertyDrawerUtility.GetParent(vitalDefs) as Vitals);
            int vitalsCount = ivitals.vitalDefs.Count;

            float h = 0;

            for (int i = 0; i < vitalsCount; ++i)
            {
                h += EditorGUI.GetPropertyHeight(vitalDefs.GetArrayElementAtIndex(i));
                h += ADD_BUTTON_HGHT + VitalDefinitionDrawer.PAD * 2 + 2;
            }

            return(h);
        }
Example #3
0
        public override IVitalsSystem ApplyVitalsSource(Object vs)
        {
            var ivc = base.ApplyVitalsSource(vs);

            /// Apply this to Vitals to trigger its properties for dealing with changing Vitals
            Vitals     = (ivc != null) ? ivc.Vitals : null;
            vitalIndex = ivc == null ? -1 : ivc.Vitals.GetVitalIndex(targetVital);

#if UNITY_EDITOR
            /// Changes to index should update the default bars and such in the editor.
            if (vitalIndex != prevIndex)
            {
                Recalculate();
            }

            prevIndex = vitalIndex;
#endif
            return(ivc);
        }
Example #4
0
 public Frame(int frameId, Vitals vitals) : base(frameId)
 {
     vitalsData = new VitalsData(vitals);
 }
Example #5
0
        public override void OnGUI(Rect r, SerializedProperty property, GUIContent label)
        {
            property.serializedObject.Update();

            SerializedProperty vitalDefs = property.FindPropertyRelative("vitalDefs");
            Vitals             ivitals   = (PropertyDrawerUtility.GetParent(vitalDefs) as Vitals);

            int vitalsCount = vitalDefs.arraySize;

            int addIndex = -1;

            //int delIndex = -1;
            for (int i = 0; i < vitalsCount; ++i)
            {
                var element = vitalDefs.GetArrayElementAtIndex(i);
                r.height = EditorGUI.GetPropertyHeight(element);

                EditorGUI.PropertyField(new Rect(r), element, false);

                if (i > 0)
                {
                    const int XWIDTH = 18;
                    Rect      xr     = r;
                    xr.xMin   = xr.xMax - XWIDTH - VitalDefinitionDrawer.PAD;
                    xr.yMin  += VitalDefinitionDrawer.PAD;
                    xr.height = ADD_BUTTON_HGHT;
                    xr.width  = XWIDTH;
                    if (GUI.Button(xr, "X"))
                    {
                        Undo.RecordObject(vitalDefs.serializedObject.targetObject, "Delete Vital");
                        ivitals.VitalDefs.Remove(ivitals.VitalDefs[i]);
                        EditorUtility.SetDirty(vitalDefs.serializedObject.targetObject);
                        AssetDatabase.Refresh();
                        break;
                    }
                }

                r.yMin += r.height + VitalDefinitionDrawer.PAD + 2;

                r.height = ADD_BUTTON_HGHT;

                const int ADDMARGIN = 80;
                Rect      addrect   = new Rect(r)
                {
                    xMin = r.xMin + 4 + ADDMARGIN, xMax = r.xMax - ADDMARGIN
                };
                if (GUI.Button(addrect, "Add Vital", (GUIStyle)"MiniToolbarButton"))
                {
                    addIndex = i + 1;
                }

                r.yMin += r.height + VitalDefinitionDrawer.PAD;
            }

            if (addIndex != -1)
            {
                Undo.RecordObject(vitalDefs.serializedObject.targetObject, "Add Vital");
                vitalDefs.InsertArrayElementAtIndex(addIndex);
                EditorUtility.SetDirty(vitalDefs.serializedObject.targetObject);
                property.serializedObject.ApplyModifiedProperties();
                AssetDatabase.Refresh();
            }
        }