/// <summary> /// Draws the consumable item. /// </summary> private void DrawConsumableItem(PrimaryItemType.UseableConsumableItem consumableItem) { if (consumableItem.ItemType != null) { EditorGUI.indentLevel++; EditorGUILayout.BeginHorizontal(); var prevInfinity = (consumableItem.Capacity == int.MaxValue); GUI.enabled = !prevInfinity; consumableItem.Capacity = EditorGUILayout.IntField("Capacity", consumableItem.Capacity); GUI.enabled = true; var infinity = EditorGUILayout.ToggleLeft("Infinity", prevInfinity, GUILayout.Width(70)); if (prevInfinity != infinity) { if (infinity) { consumableItem.Capacity = int.MaxValue; } else { consumableItem.Capacity = 1; } } EditorGUILayout.EndHorizontal(); EditorGUI.indentLevel--; } }
/// <summary> /// Builds the ItemType. /// </summary> private void BuildItemType() { var path = EditorUtility.SaveFilePanel("Save Character", "Assets", "ItemType.asset", "asset"); if (path.Length != 0 && Application.dataPath.Length < path.Length) { ItemType itemType = null; switch (m_Type) { case ItemTypes.Primary: var primaryItem = ScriptableObject.CreateInstance <Opsive.ThirdPersonController.Wrappers.PrimaryItemType>(); itemType = primaryItem; if (m_UseableConsumableItem != null) { var useableConsumableItem = new PrimaryItemType.UseableConsumableItem(m_UseableConsumableItem, m_Capacity); primaryItem.ConsumableItem = useableConsumableItem; } break; case ItemTypes.Consumable: itemType = ScriptableObject.CreateInstance <Opsive.ThirdPersonController.Wrappers.ConsumableItemType>(); break; case ItemTypes.Secondary: var secondaryItem = ScriptableObject.CreateInstance <Opsive.ThirdPersonController.Wrappers.SecondaryItemType>(); secondaryItem.Capacity = m_Capacity; itemType = secondaryItem; break; case ItemTypes.DualWield: itemType = ScriptableObject.CreateInstance <Opsive.ThirdPersonController.Wrappers.DualWieldItemType>(); break; } #if UNITY_5_3 Random.seed = System.Environment.TickCount; #else Random.InitState(System.Environment.TickCount); #endif itemType.ID = Random.Range(0, int.MaxValue); path = string.Format("Assets/{0}", path.Substring(Application.dataPath.Length + 1)); AssetDatabase.DeleteAsset(path); AssetDatabase.CreateAsset(itemType, path); AssetDatabase.ImportAsset(path); Selection.activeObject = itemType; } }