farming items network
This commit is contained in:
parent
99eaf514fd
commit
c4c2440961
BIN
Archive.7z
Normal file
BIN
Archive.7z
Normal file
Binary file not shown.
|
|
@ -266,8 +266,11 @@ MonoBehaviour:
|
|||
m_Script: {fileID: 11500000, guid: 29959bf55db1a418ba39aac04044d9c1, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
syncDirection: 0
|
||||
syncMode: 0
|
||||
syncInterval: 0
|
||||
lootDrop: Stone
|
||||
farmingTime: 20
|
||||
farmingTime: 15
|
||||
isAvailable: 1
|
||||
--- !u!1 &2990825496447302589
|
||||
GameObject:
|
||||
|
|
|
|||
|
|
@ -9200,10 +9200,14 @@ MonoBehaviour:
|
|||
m_Script: {fileID: 11500000, guid: cc0fc6fd9451f42fabe633caed1c322c, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
syncDirection: 0
|
||||
syncMode: 0
|
||||
syncInterval: 0
|
||||
inventory: {fileID: 242513768880542571}
|
||||
uiPopUp: {fileID: 8752608139095817020}
|
||||
fillupImage: {fileID: 2871093018211352661}
|
||||
activeItem: {fileID: 0}
|
||||
farmingItem: {fileID: 0}
|
||||
--- !u!1 &2496517864824674819
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
|
|
|
|||
|
|
@ -2296,7 +2296,6 @@ GameObject:
|
|||
- component: {fileID: 608202480}
|
||||
- component: {fileID: 608202479}
|
||||
- component: {fileID: 608202478}
|
||||
- component: {fileID: 608202481}
|
||||
m_Layer: 0
|
||||
m_Name: GameManager
|
||||
m_TagString: Untagged
|
||||
|
|
@ -2437,46 +2436,6 @@ Transform:
|
|||
m_Children: []
|
||||
m_Father: {fileID: 0}
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
--- !u!114 &608202481
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 608202477}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 9ea6f817f8724449e9b1709662a6dadb, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
syncDirection: 0
|
||||
syncMode: 0
|
||||
syncInterval: 0
|
||||
timeToReSpawn: 180
|
||||
farmingPoints:
|
||||
- pointsParent: {fileID: 2014487983}
|
||||
prefab: {fileID: 2594491518497105690, guid: 308d74973efa2417ca2dd03e2180d086, type: 3}
|
||||
farmingItems:
|
||||
- spawnLocation: {fileID: 751758746}
|
||||
prefab: {fileID: 2594491518497105690, guid: 308d74973efa2417ca2dd03e2180d086, type: 3}
|
||||
spawnedItem: {fileID: 0}
|
||||
destroyedTime: 0
|
||||
- spawnLocation: {fileID: 71647862}
|
||||
prefab: {fileID: 7314453758228745757, guid: 1b5c9a9caaab249ad81249532138171d, type: 3}
|
||||
spawnedItem: {fileID: 0}
|
||||
destroyedTime: 0
|
||||
- spawnLocation: {fileID: 1406134478}
|
||||
prefab: {fileID: 4134986944254134534, guid: cee69715c142a430a91cd41712c7fdc6, type: 3}
|
||||
spawnedItem: {fileID: 0}
|
||||
destroyedTime: 0
|
||||
- spawnLocation: {fileID: 2107036849}
|
||||
prefab: {fileID: 3211890613285232087, guid: aae730f0e834e4f50986153abe934152, type: 3}
|
||||
spawnedItem: {fileID: 0}
|
||||
destroyedTime: 0
|
||||
- spawnLocation: {fileID: 692403612}
|
||||
prefab: {fileID: 6824144230845280838, guid: d4c151ebff06447ec90bc966677d793f, type: 3}
|
||||
spawnedItem: {fileID: 0}
|
||||
destroyedTime: 0
|
||||
--- !u!1 &622437270
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
|
|
@ -248403,7 +248362,7 @@ MonoBehaviour:
|
|||
offlineScene:
|
||||
onlineScene:
|
||||
transport: {fileID: 1650164940}
|
||||
networkAddress: vps.playpoolstudios.com
|
||||
networkAddress: localhost
|
||||
maxConnections: 100
|
||||
disconnectInactiveConnections: 0
|
||||
disconnectInactiveTimeout: 60
|
||||
|
|
@ -248587,6 +248546,97 @@ Transform:
|
|||
- {fileID: 1565000659}
|
||||
m_Father: {fileID: 264730818}
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
--- !u!1 &1708388593
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
serializedVersion: 6
|
||||
m_Component:
|
||||
- component: {fileID: 1708388595}
|
||||
- component: {fileID: 1708388594}
|
||||
- component: {fileID: 1708388596}
|
||||
m_Layer: 0
|
||||
m_Name: FarmingManager
|
||||
m_TagString: Untagged
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
m_StaticEditorFlags: 0
|
||||
m_IsActive: 1
|
||||
--- !u!114 &1708388594
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 1708388593}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 9ea6f817f8724449e9b1709662a6dadb, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
syncDirection: 0
|
||||
syncMode: 0
|
||||
syncInterval: 0
|
||||
timeToReSpawn: 180
|
||||
farmingPoints:
|
||||
- pointsParent: {fileID: 2014487983}
|
||||
prefab: {fileID: 2594491518497105690, guid: 308d74973efa2417ca2dd03e2180d086, type: 3}
|
||||
farmingItems:
|
||||
- spawnLocation: {fileID: 751758746}
|
||||
prefab: {fileID: 2594491518497105690, guid: 308d74973efa2417ca2dd03e2180d086, type: 3}
|
||||
spawnedItem: {fileID: 0}
|
||||
destroyedTime: 0
|
||||
- spawnLocation: {fileID: 71647862}
|
||||
prefab: {fileID: 7314453758228745757, guid: 1b5c9a9caaab249ad81249532138171d, type: 3}
|
||||
spawnedItem: {fileID: 0}
|
||||
destroyedTime: 0
|
||||
- spawnLocation: {fileID: 1406134478}
|
||||
prefab: {fileID: 4134986944254134534, guid: cee69715c142a430a91cd41712c7fdc6, type: 3}
|
||||
spawnedItem: {fileID: 0}
|
||||
destroyedTime: 0
|
||||
- spawnLocation: {fileID: 2107036849}
|
||||
prefab: {fileID: 3211890613285232087, guid: aae730f0e834e4f50986153abe934152, type: 3}
|
||||
spawnedItem: {fileID: 0}
|
||||
destroyedTime: 0
|
||||
- spawnLocation: {fileID: 692403612}
|
||||
prefab: {fileID: 6824144230845280838, guid: d4c151ebff06447ec90bc966677d793f, type: 3}
|
||||
spawnedItem: {fileID: 0}
|
||||
destroyedTime: 0
|
||||
--- !u!4 &1708388595
|
||||
Transform:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 1708388593}
|
||||
serializedVersion: 2
|
||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_LocalPosition: {x: 0, y: 0, z: 0}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children: []
|
||||
m_Father: {fileID: 0}
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
--- !u!114 &1708388596
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 1708388593}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 9b91ecbcc199f4492b9a91e820070131, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
clientStarted: 0
|
||||
sceneId: 2302455019
|
||||
_assetId: 0
|
||||
serverOnly: 1
|
||||
visible: 0
|
||||
hasSpawned: 0
|
||||
--- !u!1 &1739800983
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
|
|
@ -779859,3 +779909,4 @@ SceneRoots:
|
|||
- {fileID: 1801753870729451374}
|
||||
- {fileID: 1550539858}
|
||||
- {fileID: 1114463420}
|
||||
- {fileID: 1708388595}
|
||||
|
|
|
|||
|
|
@ -1,11 +1,13 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using Mirror;
|
||||
using UnityEngine;
|
||||
|
||||
public class FarmItem : MonoBehaviour
|
||||
public class FarmItem : NetworkBehaviour
|
||||
{
|
||||
public string lootDrop;
|
||||
public float farmingTime = 30f;
|
||||
[SyncVar]
|
||||
public bool isAvailable = true;
|
||||
private void OnTriggerStay2D(Collider2D other) {
|
||||
if(other.tag == "Player"){
|
||||
|
|
@ -18,8 +20,9 @@ public class FarmItem : MonoBehaviour
|
|||
if(other.tag == "Player"){
|
||||
//
|
||||
Debug.Log("GameObject : " + gameObject);
|
||||
Debug.Log("active item : "+ other.GetComponent<FarmManager>().activeItem);
|
||||
if(other.GetComponent<FarmManager>()==null){return;}
|
||||
|
||||
Debug.Log("active item : "+ other.GetComponent<FarmManager>().activeItem);
|
||||
if(other.GetComponent<FarmManager>().activeItem.gameObject == gameObject){
|
||||
other.GetComponent<FarmManager>().HidePopUp();
|
||||
Debug.Log("**** player exit from farm item ! ****");
|
||||
|
|
@ -28,6 +31,28 @@ public class FarmItem : MonoBehaviour
|
|||
}
|
||||
|
||||
public void Farm(){
|
||||
isAvailable = false;
|
||||
|
||||
CmdSetAvailability(false);
|
||||
|
||||
}
|
||||
|
||||
[Command]
|
||||
void CmdSetAvailability(bool val){
|
||||
Debug.Log("This farming item is being used", gameObject);
|
||||
|
||||
isAvailable = val;
|
||||
}
|
||||
|
||||
public void DestroySelf(){
|
||||
if(isServer){
|
||||
NetworkServer.Destroy(gameObject);
|
||||
}else{
|
||||
CmdDestroySelf();
|
||||
}
|
||||
}
|
||||
|
||||
[Command]
|
||||
void CmdDestroySelf(){
|
||||
NetworkServer.Destroy(gameObject);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,16 +2,18 @@ using System.Collections;
|
|||
using System.Collections.Generic;
|
||||
using Mirror;
|
||||
using TMPro;
|
||||
using Unity.VisualScripting;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class FarmManager : MonoBehaviour
|
||||
public class FarmManager : NetworkBehaviour
|
||||
{
|
||||
public InventoryManager inventory;
|
||||
public RectTransform uiPopUp;
|
||||
|
||||
public Image fillupImage;
|
||||
public FarmItem activeItem;
|
||||
public FarmItem farmingItem;
|
||||
|
||||
private void Awake() {
|
||||
HidePopUp();
|
||||
|
|
@ -20,6 +22,8 @@ public class FarmManager : MonoBehaviour
|
|||
}
|
||||
|
||||
public void ShowPopUp(FarmItem item){
|
||||
if(farmingItem != null && farmingItem != item){return;}
|
||||
if(!item.isAvailable && farmingItem != item){return;}
|
||||
activeItem = item;
|
||||
uiPopUp.gameObject.SetActive(true);
|
||||
Vector3 offsetUiPopUp = new Vector3(100, 50, 50);
|
||||
|
|
@ -35,12 +39,20 @@ public class FarmManager : MonoBehaviour
|
|||
void Interact(){
|
||||
if(activeItem ==null){Debug.LogError("Cant farm an item without having one"); return;}
|
||||
if(!activeItem.isAvailable){Debug.Log("This item is already being farmed",gameObject); return;}
|
||||
|
||||
activeItem.Farm();
|
||||
|
||||
if(isServer){
|
||||
activeItem.isAvailable=false;
|
||||
}else{
|
||||
CmdDeactivateItem(activeItem.gameObject);
|
||||
}
|
||||
farmingItem= activeItem;
|
||||
StartCoroutine(CoroutineFarm());
|
||||
}
|
||||
|
||||
[Command]
|
||||
void CmdDeactivateItem(GameObject item){
|
||||
item.GetComponent<FarmItem>().isAvailable = false;
|
||||
}
|
||||
|
||||
IEnumerator CoroutineFarm(){
|
||||
float timer =0f;
|
||||
uiPopUp.GetComponentInChildren<TMP_Text>().text = "Farming";
|
||||
|
|
@ -53,10 +65,26 @@ public class FarmManager : MonoBehaviour
|
|||
uiPopUp.gameObject.SetActive(true);
|
||||
yield return null;
|
||||
}
|
||||
|
||||
HidePopUp();
|
||||
FarmingManager.instance.DestroyItem(activeItem.gameObject);
|
||||
// FarmingManager.instance.DestroyItem(activeItem.gameObject);
|
||||
DestroyItem(farmingItem.GetComponent<NetworkIdentity>().netId);
|
||||
Debug.Log("Requesting to delete this item ", farmingItem);
|
||||
farmingItem=null;
|
||||
|
||||
uiPopUp.GetComponentInChildren<TMP_Text>().text = "Farm";
|
||||
inventory.AddInvItem(activeItem.lootDrop);
|
||||
}
|
||||
|
||||
void DestroyItem(uint itemNetId){
|
||||
if(isServer){
|
||||
FarmingManager.instance.DestroyItemByID(itemNetId);
|
||||
}else{
|
||||
CmdDestroyItem(itemNetId);
|
||||
}
|
||||
}
|
||||
|
||||
[Command]
|
||||
void CmdDestroyItem(uint itemNetId){
|
||||
FarmingManager.instance.DestroyItemByID(itemNetId);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -50,7 +50,7 @@ public class FarmingManager : NetworkBehaviour
|
|||
FarmingPositionEntry item = farmingItems[index];
|
||||
GameObject spawn = Instantiate(item.prefab , item.spawnLocation.position , Quaternion.identity);
|
||||
farmingItems[index].spawnedItem = spawn;
|
||||
NetworkServer.Spawn(spawn);
|
||||
NetworkServer.Spawn(spawn, NetworkConnectionToServer.LocalConnectionId);
|
||||
}
|
||||
|
||||
public void DestroyItem(GameObject item){
|
||||
|
|
@ -68,6 +68,22 @@ public class FarmingManager : NetworkBehaviour
|
|||
NetworkServer.Destroy(item);
|
||||
}
|
||||
|
||||
public void DestroyItemByID(uint itemNetId){
|
||||
Debug.Log("Destroying farming item " + itemNetId);
|
||||
int targetIndex = 0;
|
||||
for(int i =0; i < farmingItems.Count; i++){
|
||||
if(farmingItems[i].spawnedItem == null){continue;}
|
||||
if(farmingItems[i].spawnedItem.GetComponent<NetworkIdentity>().netId == itemNetId){
|
||||
targetIndex =i;
|
||||
farmingItems[i].spawnedItem.GetComponent<FarmItem>().DestroySelf();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
farmingItems[targetIndex].destroyedTime = Time.time;
|
||||
farmingItems[targetIndex].spawnedItem = null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
{
|
||||
"dependencies": {
|
||||
"com.hwaet.projectcloner": "https://github.com/hwaet/UnityProjectCloner.git",
|
||||
"com.unity.collab-proxy": "2.2.0",
|
||||
"com.unity.feature.2d": "2.0.0",
|
||||
"com.unity.ide.rider": "3.0.27",
|
||||
|
|
|
|||
|
|
@ -1,5 +1,12 @@
|
|||
{
|
||||
"dependencies": {
|
||||
"com.hwaet.projectcloner": {
|
||||
"version": "https://github.com/hwaet/UnityProjectCloner.git",
|
||||
"depth": 0,
|
||||
"source": "git",
|
||||
"dependencies": {},
|
||||
"hash": "f8c8347af3a144069dffd6120f1c4142f8120891"
|
||||
},
|
||||
"com.unity.2d.animation": {
|
||||
"version": "9.0.3",
|
||||
"depth": 1,
|
||||
|
|
@ -18,8 +25,8 @@
|
|||
"depth": 1,
|
||||
"source": "registry",
|
||||
"dependencies": {
|
||||
"com.unity.2d.sprite": "1.0.0",
|
||||
"com.unity.2d.common": "6.0.6",
|
||||
"com.unity.2d.sprite": "1.0.0",
|
||||
"com.unity.mathematics": "1.2.6",
|
||||
"com.unity.modules.animation": "1.0.0"
|
||||
},
|
||||
|
|
@ -30,11 +37,11 @@
|
|||
"depth": 2,
|
||||
"source": "registry",
|
||||
"dependencies": {
|
||||
"com.unity.burst": "1.7.3",
|
||||
"com.unity.2d.sprite": "1.0.0",
|
||||
"com.unity.mathematics": "1.1.0",
|
||||
"com.unity.modules.uielements": "1.0.0",
|
||||
"com.unity.modules.animation": "1.0.0",
|
||||
"com.unity.burst": "1.7.3"
|
||||
"com.unity.modules.uielements": "1.0.0"
|
||||
},
|
||||
"url": "https://packages.unity.com"
|
||||
},
|
||||
|
|
@ -50,9 +57,9 @@
|
|||
"depth": 1,
|
||||
"source": "registry",
|
||||
"dependencies": {
|
||||
"com.unity.2d.animation": "9.0.1",
|
||||
"com.unity.2d.common": "8.0.1",
|
||||
"com.unity.2d.sprite": "1.0.0"
|
||||
"com.unity.2d.sprite": "1.0.0",
|
||||
"com.unity.2d.animation": "9.0.1"
|
||||
},
|
||||
"url": "https://packages.unity.com"
|
||||
},
|
||||
|
|
@ -67,8 +74,8 @@
|
|||
"depth": 1,
|
||||
"source": "registry",
|
||||
"dependencies": {
|
||||
"com.unity.mathematics": "1.1.0",
|
||||
"com.unity.2d.common": "8.0.1",
|
||||
"com.unity.mathematics": "1.1.0",
|
||||
"com.unity.modules.physics2d": "1.0.0"
|
||||
},
|
||||
"url": "https://packages.unity.com"
|
||||
|
|
@ -87,9 +94,9 @@
|
|||
"depth": 1,
|
||||
"source": "registry",
|
||||
"dependencies": {
|
||||
"com.unity.modules.tilemap": "1.0.0",
|
||||
"com.unity.2d.tilemap": "1.0.0",
|
||||
"com.unity.ugui": "1.0.0",
|
||||
"com.unity.2d.tilemap": "1.0.0",
|
||||
"com.unity.modules.tilemap": "1.0.0",
|
||||
"com.unity.modules.jsonserialize": "1.0.0"
|
||||
},
|
||||
"url": "https://packages.unity.com"
|
||||
|
|
@ -215,9 +222,9 @@
|
|||
"depth": 0,
|
||||
"source": "registry",
|
||||
"dependencies": {
|
||||
"com.unity.modules.audio": "1.0.0",
|
||||
"com.unity.modules.director": "1.0.0",
|
||||
"com.unity.modules.animation": "1.0.0",
|
||||
"com.unity.modules.audio": "1.0.0",
|
||||
"com.unity.modules.particlesystem": "1.0.0"
|
||||
},
|
||||
"url": "https://packages.unity.com"
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user