-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
📅☢️ -> #5 Set up canvas for scriptable objects
- Loading branch information
1 parent
e4cd79c
commit 441a110
Showing
330 changed files
with
59,879 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using UnityEngine; | ||
using System.Linq; | ||
|
||
public class Database : MonoBehaviour { | ||
public ItemDatabase items; | ||
private static Database instance; // Ensure we only ever have 1 instance of the database at any time | ||
|
||
private void Awake() { | ||
if(instance == null) { // If null, we don't currently have a database instance | ||
instance = this; | ||
DontDestroyOnLoad(gameObject); // Ensure this object is not destroyed when loading a new scene | ||
} | ||
else { | ||
Destroy(gameObject); // If we already have a database instance, destroy this one | ||
} | ||
} | ||
|
||
public static Item GetItemById(string ID) { | ||
// foreach(IEqualityComparer item in instance.items.allItems) { | ||
// if(item.itemID == ID) | ||
// return item; | ||
// } | ||
|
||
// // If we get here, we didn't find an item with the given ID | ||
// return null; | ||
|
||
// System.Linq fetch [iem] method | ||
return instance.items.allItems.FirstOrDefault(i => i.itemID == ID); | ||
} | ||
|
||
//Get random item -> e.g. random items that an enemy might drop | ||
public static Item GetRandomItem() { | ||
return instance.items.allItems[Random.Range(0, instance.items.allItems.Count())]; | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
using UnityEngine; | ||
using UnityEngine.UI; | ||
using TMPro; | ||
|
||
public class Tester : MonoBehaviour { | ||
public Text itemNameText; // should be TextMeshProGUI, currently debugging this (type or namespace not found) | ||
public Text itemDescriptionText; // should be TextMeshProGUI, currently debugging this (type or namespace not found) | ||
public Text itemCostText; // should be TextMeshProGUI, currently debugging this (type or namespace not found) | ||
public Image itemSprite; | ||
[Space] | ||
public string searchItemID; // This will be set based on whatever item we need to be generated at that point (e.g. after opening up a shop window or finishing a quest) | ||
|
||
public void GetNewRandomItem() { | ||
SetUI(Database.GetRandomItem()); | ||
} | ||
|
||
public void GetItemById() { | ||
SetUI(Database.GetItemById(searchItemID)); | ||
} | ||
|
||
private void SetUI(Item i) { | ||
itemNameText.text = i.itemName; | ||
itemDescriptionText.text = i.itemDescription; | ||
itemCostText.text = i.itemCost + "$"; | ||
itemSprite.sprite = i.itemSprite; | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Binary file not shown.
Oops, something went wrong.