-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPickUp.cs
More file actions
70 lines (61 loc) · 1.82 KB
/
PickUp.cs
File metadata and controls
70 lines (61 loc) · 1.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[RequireComponent(typeof(UniqueID))]
public class PickUp : MonoBehaviour
{
public InventoryIteamData IteamData;
[SerializeField] IteamPickUpData IteamSaveData;
[SerializeField] string id;
private void Awake()
{
SaveLoad.OnLoadGame += LoadGame;
id = GetComponent<UniqueID>().ID;
IteamSaveData = new IteamPickUpData(transform.position, transform.rotation, IteamData);
}
void Start()
{
SaveGameManager.data.activeIteam.Add(id,IteamSaveData);
}
private void LoadGame(SaveData arg0)
{
Debug.Log(SaveGameManager.data.collectedItems.Count);
if (SaveGameManager.data.collectedItems.Contains(id))
{
Debug.Log(id);
Destroy(this.gameObject);
}
}
private void OnDestroy()
{
if (SaveGameManager.data.activeIteam.ContainsKey(id))
{
SaveGameManager.data.activeIteam.Remove(id);
}
SaveLoad.OnLoadGame -= LoadGame;
}
private void OnTriggerEnter(Collider other)
{
var inventory=other.GetComponent<PlayerInventoryHolder>();
if (!inventory) return;
if (inventory.AddToInventory(IteamData,1))
{
SaveGameManager.data.collectedItems.Add(id);
Destroy(gameObject);
}
}
}
[System.Serializable]
public struct IteamPickUpData
{
public InventoryIteamData SaveData;
public Vector3 Position;
public Quaternion rotation;
public IteamPickUpData(Vector3 position, Quaternion rotation, InventoryIteamData SaveData)
{
Position = position;
this.rotation = rotation;
this.SaveData = SaveData;
}
}