Example #1
0
        private void Awake()
        {
            FoodContents   = GetComponent <ReagentContainer>();
            item           = GetComponent <RegisterItem>();
            itemAttributes = GetComponent <ItemAttributesV2>();
            stackable      = GetComponent <Stackable>();

            FoodContents.Add(new ReagentMix(Nutriment, StartingNutrients, TemperatureUtils.ToKelvin(20f, TemeratureUnits.C)));

            if (itemAttributes != null)
            {
                itemAttributes.AddTrait(CommonTraits.Instance.Food);
            }
            else
            {
                Logger.LogErrorFormat("{0} prefab is missing ItemAttributes", Category.Objects, name);
            }
        }
    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    {
        var type = property.propertyType;

        if (type != SerializedPropertyType.Float)
        {
            EditorGUI.PropertyField(position, property, label);
            return;
        }

        var enumRect = new Rect(position.x + position.width - SelectorSize, position.y,
                                SelectorSize, position.height);

        selectedUnit = (TemeratureUnits)EditorGUI.EnumPopup(enumRect, selectedUnit);

        var tempK = property.floatValue;

        if (tempK < 0)
        {
            // you can't get lower than absolute zero
            tempK = 0f;
        }

        var temp = TemperatureUtils.FromKelvin(tempK, selectedUnit);

        var propRect = new Rect(position.x, position.y,
                                position.width - SelectorSize, position.height);

        var newTemp  = EditorGUI.FloatField(propRect, label, temp);
        var newTempK = TemperatureUtils.ToKelvin(newTemp, selectedUnit);

        if (Mathf.Abs(newTempK - tempK) > 0.001f)
        {
            // temperature has changed - update it
            property.floatValue = TemperatureUtils.ToKelvin(newTemp, selectedUnit);
        }
    }