public SaveItem(InventoryItem item) { if (item is ToolItem) { type = ItemType.TOOL; } else if (item is MineralItem) { type = ItemType.MINERAL; } else if (item is ConsumableItem) { type = ItemType.CONSUMABLE; } else { type = ItemType.OTHER; } itemName = item.ItemName; itemText = item.ItemText; value = item.Value; spriteName = item.SpriteName; switch (type) { case ItemType.TOOL: ToolItem t = item as ToolItem; toolType = t.Type; inputType = t.InputType; power = t.Power; precision = t.Precision; sustainedBreakCooldown = t.SustainedBreakCooldown; breakRadius = t.BreakRadius; break; case ItemType.MINERAL: MineralItem m = item as MineralItem; modelName = m.ModelName; colorR = m.Color.r; colorG = m.Color.g; colorB = m.Color.b; break; case ItemType.CONSUMABLE: ConsumableItem c = item as ConsumableItem; consumableType = c.Type; strength = c.Strength; duration = c.Duration; break; } }
public void SetValues(string itemName, string itemText, int value, string spriteName, ToolType type, ToolInputType inputType, int power, float precision, float sustainedBreakCooldown, float breakRadius) { this.spriteName = spriteName; this.itemName = itemName; this.itemText = itemText; this.value = value; this.type = type; this.inputType = inputType; this.power = power; this.precision = precision; this.sustainedBreakCooldown = sustainedBreakCooldown; this.breakRadius = breakRadius; }
public override void OnInspectorGUI() { serializedObject.Update(); EditorGUILayout.PropertyField(itemName); EditorGUILayout.PropertyField(itemText); EditorGUILayout.PropertyField(spriteName); EditorGUILayout.PropertyField(itemValue); EditorGUILayout.Space(); EditorGUILayout.PropertyField(type); ToolType toolType = (ToolType)type.enumValueIndex; ToolInputType toolInputType = (ToolInputType)inputType.enumValueIndex; // Draw property fields based on which should be shown // given the tool and input enum types. switch (toolType) { case ToolType.POINT: EditorGUILayout.PropertyField(inputType); EditorGUILayout.PropertyField(power, new GUIContent("Power")); EditorGUILayout.PropertyField(precision, new GUIContent("Precision")); break; case ToolType.AREA: EditorGUILayout.PropertyField(inputType); EditorGUILayout.PropertyField(power, new GUIContent("Power")); EditorGUILayout.PropertyField(precision, new GUIContent("Precision")); EditorGUILayout.PropertyField(breakRadius, new GUIContent("Break Radius")); break; case ToolType.CHISEL: break; } switch (toolInputType) { case ToolInputType.SUSTAINED: EditorGUILayout.PropertyField(sustainedBreakCooldown, new GUIContent("Sustained Break Cooldown")); break; } serializedObject.ApplyModifiedProperties(); }