-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPickupObject.cs
More file actions
139 lines (116 loc) · 3.32 KB
/
PickupObject.cs
File metadata and controls
139 lines (116 loc) · 3.32 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
using System.Collections.Generic;
using UnityEngine;
[RequireComponent(typeof(Visibility))]
[RequireComponent(typeof(ObjectId))]
[RequireComponent(typeof(Collider))]
[RequireComponent(typeof(PointOfInterest))]
public class PickupObject : Item
{
[SerializeField] private bool locked = false;
//[SerializeField] private TimelineType timelineDependency = TimelineType.Present;
private TimelineType timelineDependency = TimelineType.Present;
private Visibility visibility;
private ObjectId objectId;
public override bool CanPickup()
{
return (!locked && GetComponent<PointOfInterest>().IsFocused);
}
public override void Pickup()
{
if(!CanPickup()) { return; }
pickedUp = true;
Inventory.Instance.AddToInventory(objectId);
SetVisible(false);
SetCollideable(false);
GameState.Instance.Save();
}
public override void SetLocked(bool lockstate)
{
locked = lockstate;
}
public override void SetVisible(bool newVisibility)
{
visibility.SetVisible(newVisibility);
}
public override void SetCollideable(bool collideable)
{
visibility.AfterSetCollider(collideable);
}
private void Awake()
{
objectId = GetComponent<ObjectId>();
visibility = GetComponent<Visibility>();
if (objectId == null)
{
Debug.Assert(false, "There is no objectId!", gameObject);
}
}
public override void Init(bool newPickedUp, bool newPlaced, Vector3 placeLocation, Vector3 placeRotation)
{
pickedUp = newPickedUp;
placed = newPlaced;
if(placed)
{
//TODO set pos & rot
transform.position = placeLocation;
transform.rotation = Quaternion.Euler(placeRotation);
}
UpdateInterable();
}
public void UpdateInterable()
{
bool correctTimeline = timelineDependency == TimelineHelper.Instance.CurrentTimeline;
if(pickedUp)
{
SetVisible(false);
SetCollideable(false);
}
else if(placed)
{
if(!correctTimeline)
{
SetVisible(true);
SetCollideable(false);
}
else
{
SetVisible(false);
SetCollideable(false);
}
}
else if(correctTimeline)
{
SetVisible(true);
SetCollideable(true);
}
else
{
SetVisible(false);
SetCollideable(false);
}
}
public override void SetPlaced(Objective objective)
{
pickedUp = false;
placed = true;
}
private void OnSwitchedTimeline(TimelineType newTimeline)
{
UpdateInterable();
}
private void OnEnable()
{
TimelineHelper.SwitchedTimelineEvent += OnSwitchedTimeline;
}
private void OnDisable()
{
TimelineHelper.SwitchedTimelineEvent -= OnSwitchedTimeline;
}
private void OnValidate()
{
if (ItemSprite == null)
{
Debug.LogWarning("Object has no sprite assigned.", gameObject);
}
}
}