-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBuyPanelScript.cs
More file actions
136 lines (116 loc) · 4.37 KB
/
Copy pathBuyPanelScript.cs
File metadata and controls
136 lines (116 loc) · 4.37 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 System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class BuyPanelScript : MonoBehaviour {
public float speed = 0.4f;
private PlayerController pScript;
private RectTransform rect;
[System.NonSerialized]
private float minX, maxX, dX, old;
private float vel, vel2;
private int compAct, compSpec;
bool movePanelIn;
bool movePanelOut;
// Use this for initialization
void Awake () {
minX = -Screen.width - 5;
old = minX;
maxX = 0;
pScript = GameObject.FindGameObjectWithTag("PlayerController").GetComponent<PlayerController>();
if (pScript == null)
Debug.Log("Buy panel script could not get a reference to the player controller.");
rect = GetComponent<RectTransform>();
if (rect == null)
{
Debug.Log("Buy Panel Script couldnt get reference to its own rect transform");
}
else
{
rect.localPosition = new Vector3(minX, rect.localPosition.y, rect.localPosition.z);
}
movePanelIn = false;
movePanelOut = false;
}
// Update is called once per frame
void Update () {
Image img = GetComponent<Image>();
Color cA = pScript.GetCharColorA();
Color cB = pScript.GetCharColorB();
Color foo = Color.Lerp(cA, cB, pScript.GetLerpVal());
foo.a = 255f;
img.color = foo;
// calculate minX as it can change
minX = -Screen.width - 5;
// if a screen size change did happen, then reset the transform and update the old variable
if(minX != old)
{
rect.localPosition = new Vector3(minX, rect.localPosition.y, rect.localPosition.z);
old = minX;
}
if (movePanelIn == true && movePanelOut == false)
{
compAct = Mathf.RoundToInt(rect.localPosition.x);
compSpec = Mathf.RoundToInt(maxX);
if (compAct < compSpec) // this is not necessary for the move in, but im doing it anyways. Not sure why this worked and moveOut did not
{
dX = Mathf.SmoothDamp(rect.localPosition.x, maxX, ref vel, speed);
rect.localPosition = new Vector3(dX, rect.localPosition.y, rect.localPosition.z);
}
else
{
rect.localPosition = new Vector3(maxX, rect.localPosition.y, rect.localPosition.z);
movePanelIn = false;
}
}
if (movePanelOut == true && movePanelIn == false)
{
compAct = Mathf.RoundToInt(rect.localPosition.x);
compSpec = Mathf.RoundToInt(minX);
if (compAct > compSpec) // this is asinine. Im not sure if its .NET or Unity but this is to account for floating point / rounding errors apparently
{
dX = Mathf.SmoothDamp(rect.localPosition.x, minX, ref vel2, speed);
rect.localPosition = new Vector3(dX, rect.localPosition.y, rect.localPosition.z);
}
else
{
rect.localPosition = new Vector3(minX, rect.localPosition.y, rect.localPosition.z);
movePanelOut = false;
}
}
}
public void SetMovePanelIn()
{
movePanelIn = true;
movePanelOut = false;
rect = GetComponent<RectTransform>();
if (rect == null)
{
Debug.Log("Buy Panel Script couldnt get reference to its own rect transform");
}
}
public void SetMovePanelOut()
{
movePanelIn = false;
movePanelOut = true;
rect = GetComponent<RectTransform>();
if (rect == null)
{
Debug.Log("Buy Panel Script couldnt get reference to its own rect transform");
}
}
public bool IsPanelMovedOut()
{
minX = Screen.width - 5;
compAct = Mathf.RoundToInt(rect.localPosition.x);
compSpec = Mathf.RoundToInt(minX);
return (movePanelOut == false && compAct <= compSpec);
}
public bool IsPanelMovedIn()
{
maxX = 0;
compAct = Mathf.RoundToInt(rect.localPosition.x);
compSpec = Mathf.RoundToInt(maxX);
return (movePanelOut == false && compAct >= compSpec);
}
}