MoviePlayNode.cs
3.35 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
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class MoviePlayNode : MonoBehaviour
{
public string objTag;
[SerializeField]
private Image _arrow;
[SerializeField]
private Color _arrowStart;
[SerializeField]
private Color _arrowHighlight;
[SerializeField]
private Image _highlight;
[SerializeField]
private Transform _dragTarget;
[SerializeField]
private float _moveSpeed;
[SerializeField]
private Collider2D _button;
private string _filename;
private NetworkUser _netNode;
private Vector3 _initPos;
private RectTransform _xform;
private void Awake()
{
_initPos = _button.transform.localPosition;
_xform = _button.transform.GetComponent<RectTransform>();
}
private void Start()
{
_arrow.CrossFadeColor(_arrowStart, 0, true, false);
_highlight.CrossFadeAlpha(0, 0, true);
}
public void Initialize(string filename, NetworkUser parent)
{
_filename = filename;
_netNode = parent;
}
private bool _isDragging = false;
private float _lastVel = 0;
public void Drag(UnityEngine.EventSystems.BaseEventData test)
{
print ("dragging");
_isDragging = true;
_canReset = false;
iTween.Stop(_button.gameObject);
var ped = (UnityEngine.EventSystems.PointerEventData)test;
_button.transform.localPosition += Vector3.up * ped.delta.y;
_lastVel = ped.delta.y;
}
public void DragEnd()
{
_isDragging = false;
_canPlay = true;
}
public void Highlight()
{
_arrow.CrossFadeColor(_arrowHighlight, 0.2f, true, false);
_highlight.CrossFadeAlpha(1, 0.2f, true);
}
public void UnHighlight()
{
_arrow.CrossFadeColor(_arrowStart, 0.4f, true, false);
_highlight.CrossFadeAlpha(0, 0.4f, true);
_canPlay = true;
}
private bool _canReset = false;
private void Update()
{
if (_button.transform.localPosition.y >= _dragTarget.localPosition.y)
{
_isDragging = false;
PlayMovie();
}
if (_isDragging) return;
_lastVel /= 1.15f;
if (_lastVel < 0) _lastVel = 0;
_button.transform.localPosition += Vector3.up * _lastVel;
if (_lastVel <= 0.1f)
_canReset = true;
if (_canReset)
{
_canReset = false;
iTween.MoveUpdate(_button.gameObject, iTween.Hash(
"y", _initPos.y,
"speed", _moveSpeed,
"islocal", true
));
}
}
private void LateUpdate()
{
if (_button.transform.localPosition.y > _dragTarget.localPosition.y)
{
_lastVel = 0;
_button.transform.localPosition = new Vector3(_button.transform.localPosition.x, _dragTarget.localPosition.y, _button.transform.localPosition.z);
}
if (_button.transform.localPosition.y < _initPos.y)
{
_lastVel = 0;
_button.transform.localPosition = new Vector3(_button.transform.localPosition.x, _initPos.y, _button.transform.localPosition.z);
}
}
private bool _canPlay = true;
public void PlayMovie()
{
if (!_canPlay || _isDragging) return;
_netNode.CmdLoadVideo(_filename);
_canPlay = false;
}
}