Merge branch 'refs/heads/feature/player-inventory' into dev
# Conflicts: # Assets/DefaultNetworkPrefabs.asset
This commit is contained in:
@@ -3,4 +3,5 @@ using UnityEngine;
|
||||
public interface IInteractable{
|
||||
public void Interact();
|
||||
public void CancelInteract();
|
||||
public void OnObserverDetected(EnvironmentObserver observer);
|
||||
}
|
||||
|
||||
@@ -3,5 +3,8 @@ using UnityEngine;
|
||||
namespace Reset.Items{
|
||||
public class Ability : Item, IEquipable{
|
||||
public NodeCanvas.Framework.Graph behaviourGraph;
|
||||
public override void DrawItemInfo(Vector3 position){
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ using UnityEngine;
|
||||
|
||||
namespace Reset.Items{
|
||||
public abstract class Item : ScriptableObject{
|
||||
public string itemName{ get; set; }
|
||||
public string itemName;
|
||||
|
||||
public float permanency;
|
||||
public float essenceRequiredForPermanency;
|
||||
@@ -20,5 +20,7 @@ namespace Reset.Items{
|
||||
newItemDrop.item = this;
|
||||
return newItemDrop;
|
||||
}
|
||||
|
||||
public abstract void DrawItemInfo(Vector3 position);
|
||||
}
|
||||
}
|
||||
100
Assets/Scripts/Items/ItemContainer.cs
Normal file
100
Assets/Scripts/Items/ItemContainer.cs
Normal file
@@ -0,0 +1,100 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using Reset.Core.Tools;
|
||||
using Sirenix.OdinInspector;
|
||||
using Unity.Netcode;
|
||||
using UnityEngine;
|
||||
using Random = UnityEngine.Random;
|
||||
|
||||
namespace Reset.Items{
|
||||
public class ItemContainer : NetworkBehaviour, IInteractable{
|
||||
private bool available = true;
|
||||
|
||||
public GameObject itemDrop;
|
||||
|
||||
public int minItemsToSpawn;
|
||||
public int maxItemsToSpawn;
|
||||
|
||||
public float cooldown;
|
||||
|
||||
public GameObject spawnPoint;
|
||||
|
||||
public Vector3 spawnRotationAngle;
|
||||
|
||||
public float spawnForce;
|
||||
|
||||
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
||||
void Start(){
|
||||
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update(){
|
||||
|
||||
}
|
||||
|
||||
[Button]
|
||||
public void Interact(){
|
||||
if (available){
|
||||
StartCoroutine(SpawnItems());
|
||||
}
|
||||
|
||||
available = false;
|
||||
|
||||
if (NetworkManager.Singleton.IsHost || NetworkManager.Singleton.IsConnectedClient) {
|
||||
SetAvailabilityRpc(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
IEnumerator SpawnItems(){
|
||||
for (int i = 0; i < Random.Range(minItemsToSpawn, maxItemsToSpawn); i++) {
|
||||
GameObject newDrop = Instantiate(itemDrop);
|
||||
newDrop.transform.position = spawnPoint.transform.position;
|
||||
newDrop.AddComponent<ItemDrop>();
|
||||
|
||||
Vector3 randomSpawnDirection = new Vector3(
|
||||
Random.Range(-spawnRotationAngle.x, spawnRotationAngle.x),
|
||||
Random.Range(-spawnRotationAngle.y, spawnRotationAngle.y),
|
||||
Random.Range(-spawnRotationAngle.z, spawnRotationAngle.z)
|
||||
);
|
||||
|
||||
Vector3 outputSpawnDirection = Quaternion.Euler(randomSpawnDirection) * spawnPoint.transform.forward;
|
||||
// outputSpawnDirection = transform.TransformDirection(outputSpawnDirection);
|
||||
|
||||
DebugOverlayDrawer.ChangeValue("ItemContainer", "Last Random Spawn Direction", randomSpawnDirection);
|
||||
|
||||
DebugOverlayDrawer.ChangeValue("ItemContainer", "Output Spawn Direction", outputSpawnDirection);
|
||||
|
||||
newDrop.GetComponent<Rigidbody>().AddForce(outputSpawnDirection * spawnForce, ForceMode.VelocityChange);
|
||||
yield return new WaitForSeconds(.2f);
|
||||
}
|
||||
|
||||
StartCoroutine(WaitForCooldown());
|
||||
}
|
||||
|
||||
IEnumerator WaitForCooldown(){
|
||||
yield return new WaitForSeconds(cooldown);
|
||||
|
||||
if (NetworkManager.Singleton.IsHost || NetworkManager.Singleton.IsConnectedClient) {
|
||||
SetAvailabilityRpc(true);
|
||||
}
|
||||
|
||||
available = true;
|
||||
}
|
||||
|
||||
public void CancelInteract(){
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
[Rpc(SendTo.Everyone)]
|
||||
void SetAvailabilityRpc(bool isAvailable){
|
||||
Debug.Log($"I made this {isAvailable}!");
|
||||
available = isAvailable;
|
||||
}
|
||||
|
||||
public void OnObserverDetected(EnvironmentObserver observer){
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
2
Assets/Scripts/Items/ItemContainer.cs.meta
Normal file
2
Assets/Scripts/Items/ItemContainer.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4ef1a4907f7107d4db5a3f19fc18a94b
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using Drawing;
|
||||
using Unity.Netcode;
|
||||
using UnityEngine;
|
||||
|
||||
@@ -8,14 +9,16 @@ namespace Reset.Items{
|
||||
|
||||
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
||||
void Start(){
|
||||
|
||||
if (NetworkManager.Singleton.IsHost || NetworkManager.Singleton.IsConnectedClient) {
|
||||
GetComponent<NetworkObject>().Spawn();
|
||||
}
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update(){
|
||||
|
||||
}
|
||||
|
||||
|
||||
public void Interact(){
|
||||
if (NetworkManager.Singleton.IsHost || NetworkManager.Singleton.IsConnectedClient) {
|
||||
Debug.Log("RPC Sent");
|
||||
@@ -34,5 +37,11 @@ namespace Reset.Items{
|
||||
public void DestroyOnOwnerRpc(){
|
||||
Destroy(gameObject);
|
||||
}
|
||||
|
||||
public void OnObserverDetected(EnvironmentObserver observer){
|
||||
Draw.ingame.Label2D(transform.position + Vector3.up * 2f, item.itemName, 24);
|
||||
|
||||
item.DrawItemInfo(transform.position);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
5
Assets/Scripts/Items/ItemUtilities.cs
Normal file
5
Assets/Scripts/Items/ItemUtilities.cs
Normal file
@@ -0,0 +1,5 @@
|
||||
namespace Reset.Items{
|
||||
public static class ItemUtilities{
|
||||
|
||||
}
|
||||
}
|
||||
3
Assets/Scripts/Items/ItemUtilities.cs.meta
Normal file
3
Assets/Scripts/Items/ItemUtilities.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1b888169dac844aea6cccec5726cebde
|
||||
timeCreated: 1757367627
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using Drawing;
|
||||
using NodeCanvas.StateMachines;
|
||||
using UnityEngine;
|
||||
|
||||
@@ -11,5 +12,11 @@ namespace Reset.Items{
|
||||
void Awake(){
|
||||
|
||||
}
|
||||
|
||||
public override void DrawItemInfo(Vector3 position){
|
||||
Debug.Log("hiuh");
|
||||
Draw.ingame.Label2D(position + Vector3.up * 1.6f, "Damage goes here");
|
||||
Draw.ingame.Label2D(position + Vector3.up * 1.35f, "Speed goes here");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -127,6 +127,9 @@ public class EnvironmentObserver{
|
||||
}
|
||||
|
||||
if (hit.transform != null) {
|
||||
if (hit.transform.GetComponent<IInteractable>() != null) {
|
||||
hit.transform.GetComponent<IInteractable>().OnObserverDetected(this);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user