-
Notifications
You must be signed in to change notification settings - Fork 6
/
GrassyBox.cs
37 lines (33 loc) · 1.04 KB
/
GrassyBox.cs
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
using System;
using UnityEngine;
namespace GrassyKnight
{
// A handy box to store some grass in. Used to store a reference to the
// grass that ShouldCut is getting called for because ShouldCut is a
// static function.
class GrassyBox : IDisposable {
private static GameObject _value = null;
private static bool _hasValue = false;
public static GameObject GetValue() {
if (_hasValue) {
return _value;
} else {
throw new InvalidOperationException("Nothing in box");
}
}
public GrassyBox(GameObject value) {
if (_hasValue) {
GrassyKnight.Instance.LogError(
$"Already have value in box (current value is {_value}, " +
$"trying to store value {value}).");
} else {
_value = value;
_hasValue = true;
}
}
public void Dispose() {
_value = null;
_hasValue = false;
}
}
}