This commit is contained in:
d-hain 2022-06-03 00:07:30 +02:00
parent 98b571c2aa
commit f7b593045f
9 changed files with 49 additions and 132 deletions

View file

@ -75,7 +75,7 @@ SpriteRenderer:
m_SortingLayerID: -2016319409 m_SortingLayerID: -2016319409
m_SortingLayer: 1 m_SortingLayer: 1
m_SortingOrder: 0 m_SortingOrder: 0
m_Sprite: {fileID: 7482667652216324306, guid: 311925a002f4447b3a28927169b83ea6, type: 3} m_Sprite: {fileID: 21300000, guid: 2700e06d970d112489ff23cfb58c3f78, type: 3}
m_Color: {r: 1, g: 1, b: 1, a: 1} m_Color: {r: 1, g: 1, b: 1, a: 1}
m_FlipX: 0 m_FlipX: 0
m_FlipY: 0 m_FlipY: 0

View file

@ -4906,7 +4906,7 @@ MonoBehaviour:
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
menu: {fileID: 1395531174} menu: {fileID: 1395531174}
dayCountTextMeshProUGUI: {fileID: 1089918735} dayCountTextMeshProUGUI: {fileID: 0}
--- !u!212 &1278234715 --- !u!212 &1278234715
SpriteRenderer: SpriteRenderer:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -5010,7 +5010,7 @@ MonoBehaviour:
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
tile: {fileID: 4752245148499717901, guid: ea81011a3ce83fb4386934728a92ee2d, type: 3} tile: {fileID: 4752245148499717901, guid: ea81011a3ce83fb4386934728a92ee2d, type: 3}
CameraGameObject: {fileID: 598358736} cameraGameObject: {fileID: 0}
--- !u!4 &1291863651 --- !u!4 &1291863651
Transform: Transform:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0

View file

@ -1,55 +0,0 @@
using System.Linq;
using UnityEngine;
public class ItemStorageUI : MonoBehaviour {
public Transform itemsParent;
public GameObject inventoryUI;
private Inventory _inventory;
private InventorySlot[] _slots;
private void Start() {
// Get Inventory instance and add UpdateUI method to OnItemChanged delegate
_inventory = Inventory.instance;
_inventory.onItemChangedCallback += UpdateUI;
// Add all InventorySlot GameObjects to _slots and turn off the Inventory UI
_slots = itemsParent.GetComponentsInChildren<InventorySlot>();
ToggleInventory();
// Set the icon to not be a raycast target for the Description Hovering to work
foreach(InventorySlot slot in _slots) {
slot.icon.raycastTarget = false;
}
}
private void Update() {
// When "Inventory" button is pressed turn on/off Inventory UI
if(Input.GetButtonDown("Inventory")) {
ToggleInventory();
}
}
/**
* Turn on/off the Inventory UI
*/
private void ToggleInventory() {
inventoryUI.SetActive(!inventoryUI.activeSelf);
}
/**
* Is called when something in the Inventory UI should update
*/
private void UpdateUI() {
// Add all items to the correct slots and clear the ones where no item should be
for(int i = 0; i < _slots.Length; i++) {
if(i < _inventory.items.Count) {
_slots[i].AddItem(_inventory.items.ElementAt(i).Key);
if(_inventory.items[_inventory.items.ElementAt(i).Key] > 1) {
_slots[i].amountText.text = "" + _inventory.items[_inventory.items.ElementAt(i).Key];
}
} else {
_slots[i].ClearSlot();
}
}
}
}

View file

@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 21b91c5ff9ffa4d45a5e71b08b141657
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -6,12 +6,12 @@ public class ShopUI : MonoBehaviour {
public GameObject shopUI; public GameObject shopUI;
private Shop _shop; private Shop _shop;
private ShopSlot[] _slots; private ShopSlot[] _slots;
private void Start() { private void Start() {
// Get Shop instance and add UpdateUI method to OnItemChanged delegate // Get Shop instance and add UpdateUI method to OnItemChanged delegate
_shop = Shop.instance; _shop = Shop.instance;
_shop.onItemChangedCallback += UpdateUI; _shop.onItemChangedCallback += UpdateUI;
// Add all ShopSlot GameObjects to _slots and turn off the Shop UI // Add all ShopSlot GameObjects to _slots and turn off the Shop UI
_slots = itemsParent.GetComponentsInChildren<ShopSlot>(); _slots = itemsParent.GetComponentsInChildren<ShopSlot>();
ToggleShop(); ToggleShop();
@ -45,7 +45,7 @@ public class ShopUI : MonoBehaviour {
if(i < _shop.items.Count) { if(i < _shop.items.Count) {
_slots[i].AddItem(_shop.items.ElementAt(i).Key); _slots[i].AddItem(_shop.items.ElementAt(i).Key);
_slots[i].nameText.text = _slots[i].Item.displayName; _slots[i].nameText.text = _slots[i].Item.displayName;
_slots[i].costText.text = _slots[i].Item.cost + " "; _slots[i].costText.text = _slots[i].Item.cost + " µ";
_slots[i].amountText.text = _shop.items[_shop.items.ElementAt(i).Key] + " #"; _slots[i].amountText.text = _shop.items[_shop.items.ElementAt(i).Key] + " #";
} else { } else {
_slots[i].ClearSlot(); _slots[i].ClearSlot();

View file

@ -5,52 +5,39 @@ using Items.TerraformingTools;
using Tiles; using Tiles;
using UnityEngine; using UnityEngine;
public class TileBehaviour : MonoBehaviour public class TileBehaviour : MonoBehaviour {
{ private BaseTile _tile;
private BaseTile tile;
// Start is called before the first frame update // Start is called before the first frame update
void Start() private void Start() {
{
Debug.Log("Created"); Debug.Log("Created");
SetTile(new GrassTile()); SetTile(new GrassTile());
HouseController.NewDayEvent.AddListener(tile.DayLightStep); HouseController.NewDayEvent.AddListener(_tile.DayLightStep);
} }
// Update is called once per frame private void OnMouseDown() {
void Update()
{
}
void OnMouseDown()
{
Debug.Log("Clicked"); Debug.Log("Clicked");
UsableItem usable = PlayerController.instance.GetSelectedItem(); UsableItem usable = PlayerController.instance.GetSelectedItem();
BaseTile tileToSetTo = null; BaseTile tileToSetTo = null;
if (usable.GetType() == typeof(TerraformingTool)) if(usable.GetType() == typeof(TerraformingTool)) {
{ TerraformingTool terraformingTool = (TerraformingTool)usable;
TerraformingTool terraformingTool = (TerraformingTool) usable;
Type tileTypeToSetTo = terraformingTool.TileType; Type tileTypeToSetTo = terraformingTool.TileType;
tileToSetTo = (BaseTile) Activator.CreateInstance(tileTypeToSetTo); tileToSetTo = (BaseTile)Activator.CreateInstance(tileTypeToSetTo);
} } else {
else tileToSetTo = _tile.Clicked(usable);
{
tileToSetTo = tile.Clicked(usable);
Debug.Log("AMOGUS " + tileToSetTo.ToString()); Debug.Log("AMOGUS " + tileToSetTo.ToString());
} }
if (tileToSetTo != null)
{ if(tileToSetTo != null) {
SetTile(tileToSetTo); SetTile(tileToSetTo);
} }
} }
void SetTile(BaseTile tileToSet) private void SetTile(BaseTile tileToSet) {
{
Debug.Log("Set tile to " + tileToSet.ToString()); Debug.Log("Set tile to " + tileToSet.ToString());
tile = tileToSet; _tile = tileToSet;
GetComponent<SpriteRenderer>().color = tile.getColor; // TODO: Change to Sprite GetComponent<SpriteRenderer>().color = _tile.getColor; // TODO: Change to Sprite
} }
} }

View file

@ -3,38 +3,25 @@ using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using UnityEngine; using UnityEngine;
public class TileController : MonoBehaviour public class TileController : MonoBehaviour {
{
public GameObject tile; public GameObject tile;
public GameObject CameraGameObject; public GameObject cameraGameObject;
// Start is called before the first frame update // Start is called before the first frame update
void Start() void Start() {
{ Camera camera = cameraGameObject.GetComponent<Camera>();
Camera camera = CameraGameObject.GetComponent<Camera>(); Vector3 screen = camera.ViewportToWorldPoint(new Vector3(1, 1, camera.nearClipPlane));
Vector3 screen = camera.ViewportToWorldPoint(new Vector3(1,1,camera.nearClipPlane));
int x = Convert.ToInt32(Math.Ceiling(screen.x)); int x = Convert.ToInt32(Math.Ceiling(screen.x));
int y = Convert.ToInt32(Math.Ceiling(screen.y)); int y = Convert.ToInt32(Math.Ceiling(screen.y));
Debug.Log(screen); Debug.Log(screen);
for (int xx = -x; xx <= x; xx++) for(int xx = -x; xx <= x; xx++) {
{ for(int yy = -y; yy <= y; yy++) {
for (int yy = -y; yy <= y; yy++) if(tile != null) {
{
if (tile != null)
{
Instantiate(tile, new Vector3(xx, yy, 0), Quaternion.identity); Instantiate(tile, new Vector3(xx, yy, 0), Quaternion.identity);
} }
} }
} }
} }
}
// Update is called once per frame
void Update()
{
}
}

View file

@ -137,12 +137,21 @@
"dependencies": {}, "dependencies": {},
"url": "https://packages.unity.com" "url": "https://packages.unity.com"
}, },
"com.unity.nuget.newtonsoft-json": {
"version": "3.0.2",
"depth": 2,
"source": "registry",
"dependencies": {},
"url": "https://packages.unity.com"
},
"com.unity.services.core": { "com.unity.services.core": {
"version": "1.0.1", "version": "1.3.1",
"depth": 1, "depth": 1,
"source": "registry", "source": "registry",
"dependencies": { "dependencies": {
"com.unity.modules.unitywebrequest": "1.0.0" "com.unity.modules.unitywebrequest": "1.0.0",
"com.unity.nuget.newtonsoft-json": "3.0.2",
"com.unity.modules.androidjni": "1.0.0"
}, },
"url": "https://packages.unity.com" "url": "https://packages.unity.com"
}, },

View file

@ -1,2 +1,2 @@
m_EditorVersion: 2021.3.1f1 m_EditorVersion: 2021.3.2f1
m_EditorVersionWithRevision: 2021.3.1f1 (3b70a0754835) m_EditorVersionWithRevision: 2021.3.2f1 (d6360bedb9a0)