-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathObservableStack.cs
More file actions
56 lines (46 loc) · 1.18 KB
/
Copy pathObservableStack.cs
File metadata and controls
56 lines (46 loc) · 1.18 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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
// 델리게이트
public delegate void UpdateStackEvent();
public class ObservableStack<T> : Stack<T>
{
// 이벤트
public event UpdateStackEvent OnPush;
public event UpdateStackEvent OnPop;
public event UpdateStackEvent OnClear;
// 아이템을 Stack 배열에 넣을때
public new void Push(T item)
{
// 원래 기능을 작동시키고
base.Push(item);
if (OnPush != null)
{
// OnPush 에 등록된 함수를 호출한다.
OnPush();
}
}
// 아이템을 Stack 배열에서 꺼낼때
public new T Pop()
{
// 원래 기능을 작동시키고
T item = base.Pop();
// OnPop 에 등록된 함수를 호출한다.
if (OnPop != null)
{
OnPop();
}
return item;
}
// Stack 배열을 초기화
public new void Clear()
{
// 원래 기능을 작동시키고
base.Clear();
if (OnClear != null)
{
// OnClear 에 등록된 함수를 호출한다.
OnClear();
}
}
}