resource limits added
This commit is contained in:
@ -69,5 +69,6 @@ public class Inventory : MonoBehaviour
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
67
Assets/Scripts/Inventory/TempInventory.cs
Normal file
67
Assets/Scripts/Inventory/TempInventory.cs
Normal file
@ -0,0 +1,67 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
[System.Serializable]
|
||||
public class TempInventoryBuilderItem
|
||||
{
|
||||
public string name;
|
||||
public int quantity;
|
||||
}
|
||||
|
||||
public class TempInventory : MonoBehaviour
|
||||
{
|
||||
|
||||
private Dictionary<string,int> inventory = new Dictionary<string,int>();
|
||||
[SerializeField]
|
||||
private List<TempInventoryBuilderItem> initialInvent = new List<TempInventoryBuilderItem>();
|
||||
|
||||
public int GetQuantityOf(string name)
|
||||
{
|
||||
if (inventory.ContainsKey(name))
|
||||
{
|
||||
return inventory[name];
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
public bool Add(string name,int quantity=1)
|
||||
{
|
||||
if (inventory.ContainsKey(name))
|
||||
{
|
||||
inventory[name] += quantity;
|
||||
}
|
||||
else
|
||||
{
|
||||
inventory.Add(name, quantity);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Remove(string name,int quantity=1)
|
||||
{
|
||||
if (inventory.ContainsKey(name))
|
||||
{
|
||||
inventory[name] = Mathf.Max(inventory[name] - quantity, 0);
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
foreach(TempInventoryBuilderItem item in initialInvent)
|
||||
{
|
||||
inventory[item.name] = item.quantity;
|
||||
}
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
11
Assets/Scripts/Inventory/TempInventory.cs.meta
Normal file
11
Assets/Scripts/Inventory/TempInventory.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0409b6b23ffc72640a6491311e0f6a26
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -21,7 +21,25 @@ public class FlareBeacon : MonoBehaviour
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
|
||||
transform.localEulerAngles = new Vector3(-89.98f, 0, 0);
|
||||
Ray r = new Ray();
|
||||
r.direction = -transform.forward;
|
||||
r.origin = transform.position;
|
||||
RaycastHit hit;
|
||||
RaycastHit[] rays = Physics.RaycastAll(r);
|
||||
foreach(RaycastHit _hit in rays)
|
||||
{
|
||||
if (_hit.transform.gameObject.GetComponent<FlareBeacon>() != null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
transform.position = _hit.point;
|
||||
break;
|
||||
}
|
||||
if(Physics.Raycast(r,out hit)){
|
||||
// transform.position = hit.point;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
|
8
Assets/Scripts/Item/FlareBeacon.meta
Normal file
8
Assets/Scripts/Item/FlareBeacon.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d8f50dd997a71e548881cf0a65dff80f
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -7,6 +7,9 @@ public class BulletComponent : MonoBehaviour
|
||||
[SerializeField]
|
||||
private float duration = 5f;
|
||||
private float existed = 0f;
|
||||
[SerializeField]
|
||||
private string type = "flare";
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
|
@ -15,7 +15,9 @@ public class PistolComponent : MonoBehaviour
|
||||
[SerializeField]
|
||||
GameObject targetObjectPrefab;
|
||||
[SerializeField]
|
||||
private GameObject projectilePrefab;
|
||||
public GameObject projectilePrefab;
|
||||
[SerializeField]
|
||||
public string projectileName;
|
||||
[SerializeField]
|
||||
private Transform bulletSpawnPoint;
|
||||
[SerializeField]
|
||||
|
127
Assets/Scripts/Item/SpecialItemCycler.cs
Normal file
127
Assets/Scripts/Item/SpecialItemCycler.cs
Normal file
@ -0,0 +1,127 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using TMPro;
|
||||
|
||||
[System.Serializable]
|
||||
public class ItemImageRef
|
||||
{
|
||||
public string name;
|
||||
public GameObject item;
|
||||
public Sprite icon;
|
||||
}
|
||||
|
||||
public class SpecialItemCycler : MonoBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
private List<ItemImageRef> spawnableItems =new List<ItemImageRef>();
|
||||
[SerializeField]
|
||||
private List<ItemImageRef> shootableItems = new List<ItemImageRef>();
|
||||
|
||||
[SerializeField]
|
||||
private PlayerInteractionHandler interactionHandler;
|
||||
[SerializeField]
|
||||
private PistolComponent pistol;
|
||||
private int spawnableIndex = 0;
|
||||
private int shootableIndex = 0;
|
||||
[SerializeField]
|
||||
//private Inventory invent;
|
||||
private TempInventory invent;
|
||||
[SerializeField]
|
||||
private Image selectedImage;
|
||||
[SerializeField]
|
||||
private TMP_Text selectedQuantityText;
|
||||
private Color sqtInitColor;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
sqtInitColor = selectedQuantityText.color;
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
if (interactionHandler.GunEnabled)
|
||||
{
|
||||
pistol.projectilePrefab = shootableItems[shootableIndex % shootableItems.Count].item;
|
||||
pistol.projectileName = shootableItems[shootableIndex % shootableItems.Count].name;
|
||||
}
|
||||
SetImage();
|
||||
if (Input.GetButtonDown("CycleItems"))
|
||||
{
|
||||
if (interactionHandler.GunEnabled)
|
||||
{
|
||||
this.shootableIndex = (shootableIndex + 1) % shootableItems.Count;
|
||||
selectedImage.sprite = shootableItems[this.shootableIndex].icon;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.spawnableIndex = (spawnableIndex+1)%spawnableItems.Count;
|
||||
selectedImage.sprite = spawnableItems[this.spawnableIndex].icon;
|
||||
|
||||
}
|
||||
if (selectedImage.sprite == null)
|
||||
{
|
||||
selectedImage.color = new Color(selectedImage.color.r, selectedImage.color.g, selectedImage.color.b, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
selectedImage.color = new Color(selectedImage.color.r, selectedImage.color.g, selectedImage.color.b, 1);
|
||||
}
|
||||
}
|
||||
if (Input.GetButtonDown("TempPlace"))
|
||||
{
|
||||
if (invent.GetQuantityOf(spawnableItems[spawnableIndex].name)>0)
|
||||
if (!interactionHandler.GunEnabled && spawnableItems[spawnableIndex].item!= null)
|
||||
{
|
||||
GameObject prefab = spawnableItems[spawnableIndex].item;
|
||||
GameObject instance = Instantiate(prefab,interactionHandler.CarryingPos);
|
||||
instance.transform.localPosition = Vector3.zero;
|
||||
instance.transform.parent = null;
|
||||
invent.Remove(spawnableItems[spawnableIndex].name);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
void SetImage()
|
||||
{
|
||||
|
||||
if (interactionHandler.GunEnabled)
|
||||
{
|
||||
|
||||
selectedImage.sprite = shootableItems[this.shootableIndex].icon;
|
||||
selectedQuantityText.text = invent.GetQuantityOf(shootableItems[this.shootableIndex].name).ToString();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
selectedImage.sprite = spawnableItems[this.spawnableIndex].icon;
|
||||
selectedQuantityText.text = invent.GetQuantityOf(spawnableItems[this.spawnableIndex].name).ToString();
|
||||
|
||||
}
|
||||
if (selectedImage.sprite == null)
|
||||
{
|
||||
selectedImage.color = new Color(selectedImage.color.r, selectedImage.color.g, selectedImage.color.b, 0);
|
||||
selectedQuantityText.gameObject.SetActive(false);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
selectedImage.color = new Color(selectedImage.color.r, selectedImage.color.g, selectedImage.color.b, 1);
|
||||
selectedQuantityText.gameObject.SetActive(true);
|
||||
if (selectedQuantityText.text == "0")
|
||||
{
|
||||
selectedQuantityText.color = Color.red;
|
||||
}
|
||||
else
|
||||
{
|
||||
selectedQuantityText.color = sqtInitColor;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/Item/SpecialItemCycler.cs.meta
Normal file
11
Assets/Scripts/Item/SpecialItemCycler.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 57edf3fe88ab13c42b4f2b0cab83a3b8
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -12,6 +12,7 @@ public class PlayerInteractionHandler : MonoBehaviour
|
||||
private List<InteractableItem> itemsInRange= new List<InteractableItem>();
|
||||
private List<HeavyInteractableItem> heavyItemsInRange = new List<HeavyInteractableItem>();
|
||||
private Inventory invent;
|
||||
private TempInventory tempInvent;
|
||||
public Inventory Inventory { get { return invent; } }
|
||||
public static PlayerInteractionHandler instance;
|
||||
[SerializeField]
|
||||
@ -30,6 +31,7 @@ public class PlayerInteractionHandler : MonoBehaviour
|
||||
private bool gunEnabled = false;
|
||||
[SerializeField]
|
||||
private Transform carryingPos;
|
||||
public Transform CarryingPos { get { return this.carryingPos; } }
|
||||
|
||||
private ItemSelector itemSelector;
|
||||
[SerializeField]
|
||||
@ -43,6 +45,9 @@ public class PlayerInteractionHandler : MonoBehaviour
|
||||
{
|
||||
instance = this;
|
||||
invent = this.transform.parent.GetComponent<Inventory>();
|
||||
//TEMP FIELD
|
||||
tempInvent = this.transform.parent.GetComponent<TempInventory>();
|
||||
|
||||
initColor = flashlight3D.GetComponent<MeshRenderer>().materials[materialIndex].GetColor("_BaseColor");
|
||||
selMaterial = flashlight3D.GetComponent<MeshRenderer>().materials[materialIndex];
|
||||
itemSelector = ItemSelector.instance;
|
||||
@ -75,7 +80,12 @@ public class PlayerInteractionHandler : MonoBehaviour
|
||||
{
|
||||
if (this.GunEnabled)
|
||||
{
|
||||
this.pistol.Fire();
|
||||
if (tempInvent.GetQuantityOf(this.pistol.projectileName) > 0)
|
||||
{
|
||||
this.pistol.Fire();
|
||||
tempInvent.Remove(this.pistol.projectileName);
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
|
Reference in New Issue
Block a user