Skip to content

Commit

Permalink
📅☢️ -> #5 Set up canvas for scriptable objects
Browse files Browse the repository at this point in the history
  • Loading branch information
Gizmotronn committed Jan 26, 2022
1 parent e4cd79c commit 441a110
Show file tree
Hide file tree
Showing 330 changed files with 59,879 additions and 0 deletions.
Binary file modified Assets/.DS_Store
Binary file not shown.
37 changes: 37 additions & 0 deletions Assets/DB/Database.cs
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())];
}
}
11 changes: 11 additions & 0 deletions Assets/DB/Database.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 27 additions & 0 deletions Assets/DB/Tester.cs
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;
}
}
11 changes: 11 additions & 0 deletions Assets/DB/Tester.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified Assets/EverythingEth/.DS_Store
Binary file not shown.
Loading

0 comments on commit 441a110

Please sign in to comment.