public GameElementView CreateVisualElement(GameElementType name) { var elementsDescription = _elementsProvider.Elements.FirstOrDefault(e => e.Name == name); if (elementsDescription == null) { throw new System.Exception($"No elements description for item {name}"); } var gameElementView = Object.Instantiate(elementsDescription.View); _cache.Add(gameElementView); return(gameElementView); }
public void SetProgress(string key, int value = 0, GameElementType type = default(GameElementType)) { GameElementData newData = null; int index = _data.progress.GetIndex(key); if (index == -1) { newData = new GameElementData(type, key, value); _data.progress.Add(newData); Save(); } else { newData = _data.progress[index]; newData.value = value; Save(); } }
public GameElementData ToGameElement(ItemConfigData item) { GameElementType eType = GameElementType.Item; string key = item.id; switch (item.itemType) { case ItemType.Currency: eType = GameElementType.Currency; key = item.itemTypeKey; break; // A Pack cost does not give any game elements, it only significes costs - so we'll give 0 soft currencies case ItemType.PackCost: return(new GameElementData(GameElementType.Currency, CurrenciesType.soft.ToString(), 0)); } GameElementData ge = new GameElementData(eType, key, item.quantity); return(ge); }
/// <summary> /// /Draws the single game element data.*/ /// </summary> /// <returns><c>true</c>, if single game element data was marked for removal, <c>false</c> otherwise.</returns> /// <param name="element">Element.</param> /// <param name="dirty">Dirty.</param> public static bool DrawSingleGameElementData(GameElementData element, ref bool dirty, bool enableDelete = true) { EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Type:", GUILayout.Width(100)); GameElementType oldType = element.type; element.type = (GameElementType)EditorGUILayout.EnumPopup(element.type, GUILayout.Width(150)); if (element.type != oldType) { dirty = true; } bool removed = false; if (enableDelete) { GUI.backgroundColor = redColor; if (GUILayout.Button("Delete this entry", GUILayout.Width(100))) { removed = true; } GUI.backgroundColor = backgroundColor; } EditorGUILayout.EndHorizontal(); if (element.type == GameElementType.Item) { if (allItems == null) { EditorGUILayout.HelpBox("Items are not loaded properly.", MessageType.Error); } else if (allItems.Count == 0) { EditorGUILayout.HelpBox("There are no Items. Use Item Editor to add some.", MessageType.Info); } else { EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Item:", GUILayout.Width(100)); int oldIntValue = IndexFromName(element.key, itemConfigNames); int newIntValue = EditorGUILayout.Popup(oldIntValue, itemConfigNames, GUILayout.Width(150)); if (oldIntValue != newIntValue) { element.key = itemConfigNames[newIntValue]; dirty = true; } EditorGUILayout.EndHorizontal(); } } else if (element.type == GameElementType.State) { if (allCollectibles == null) { EditorGUILayout.HelpBox("Collectibles are not loaded properly.", MessageType.Error); } else if (allCollectibles.Count == 0) { EditorGUILayout.HelpBox("There are no Collectibles. Use Collectibles Editor to add some.", MessageType.Info); } else { EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Collectible:", GUILayout.Width(100)); int oldIntValue = IndexFromName(element.key, collectibleConfigNames); int newIntValue = EditorGUILayout.Popup(oldIntValue, collectibleConfigNames, GUILayout.Width(150)); if (oldIntValue != newIntValue) { element.key = collectibleConfigNames[newIntValue]; dirty = true; } EditorGUILayout.EndHorizontal(); } } else if (element.type == GameElementType.Currency) { EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Key:", GUILayout.Width(100)); string oldStringValue = element.key; element.key = EditorGUILayout.TextField(element.key, GUILayout.Width(150)); if (element.key != oldStringValue) { dirty = true; } EditorGUILayout.EndHorizontal(); } // public string value; EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Value:", GUILayout.Width(100)); int oldValue = element.value; element.value = EditorGUILayout.IntField(element.value, GUILayout.Width(150)); if (element.value != oldValue) { dirty = true; } EditorGUILayout.EndHorizontal(); return(removed); }
public CreateVisualElementModel(FieldCoords cellCoords, GameElementType name) { CellCoords = cellCoords; Name = name; }
public GameElementData(GameElementType type, string key, int value) { this.type = type; this.key = key; this.value = value; }
public VisualElementModel(GameElementView view, GameElementType name) { View = view; Name = name; }