UnityMol
0.9.6-875
UnityMol viewer / In developement
Main Page
Related Pages
Packages
Classes
Files
File List
File Members
LinkedSpriteManager.cs
Go to the documentation of this file.
1
66
//-----------------------------------------------------------------
67
// LinkedSpriteManager v0.632 (7-24-2009)
68
// Copyright 2009 Brady Wright and Above and Beyond Software
69
// All rights reserved
70
//-----------------------------------------------------------------
71
// A class to allow the drawing of multiple "quads" as part of a
72
// single aggregated mesh so as to achieve multiple, independently
73
// moving objects using a single draw call.
74
//-----------------------------------------------------------------
75
76
77
using
UnityEngine
;
78
using
System
.Collections;
79
80
// A variation on the SpriteManager that automatically links all
81
// translations and rotations of the client GameObjects to the
82
// associated sprite - meaning the client need not worry about
83
// micromanaging all transformations:
84
public
class
LinkedSpriteManager
:
SpriteManager
85
{
86
Transform
t
;
87
Vector3
pos
;
88
Sprite
s
;
89
90
91
// Use this for initialization
92
void
Start
()
93
{
94
95
}
96
97
// Transforms all sprites by their associated GameObject's
98
// transforms:
99
void
TransformSprites
()
100
{
101
for
(
int
i
=0;
i
<
activeBlocks
.Count; ++
i
)
102
{
103
((
Sprite
)
activeBlocks
[
i
]).Transform();
104
}
105
106
// Handle any billboarded sprites:
107
if
(
activeBillboards
.Count > 0)
108
{
109
t = Camera.main.transform;
110
111
for
(
int
i
=0;
i
<
activeBillboards
.Count; ++
i
)
112
{
113
s = (
Sprite
)
activeBillboards
[
i
];
114
pos = s.
clientTransform
.position;
115
116
vertices
[s.
mv1
] = pos + t.TransformDirection(s.
v1
);
117
vertices
[s.
mv2
] = pos + t.TransformDirection(s.
v2
);
118
vertices
[s.
mv3
] = pos + t.TransformDirection(s.
v3
);
119
vertices
[s.
mv4
] = pos + t.TransformDirection(s.
v4
);
120
}
121
}
122
}
123
124
// LateUpdate is called once per frame
125
new
void
LateUpdate
()
126
{
127
// Transform all sprites according to their
128
// client GameObject's transforms:
129
TransformSprites
();
130
131
// Copy over the changes:
132
mesh
.vertices =
vertices
;
133
134
// See if we have any active animations:
135
if
(
playingAnimations
.Count > 0)
136
{
137
animTimeElapsed
= Time.deltaTime;
138
139
for
(
i
= 0;
i
<
playingAnimations
.Count; ++
i
)
140
{
141
tempSprite
= (
Sprite
)
playingAnimations
[
i
];
142
143
// Step the animation, and if it has finished
144
// playing, remove it from the playing list:
145
if
(!
tempSprite
.
StepAnim
(
animTimeElapsed
))
146
playingAnimations
.Remove(
tempSprite
);
147
}
148
149
uvsChanged
=
true
;
150
}
151
152
if
(
vertCountChanged
)
153
{
154
mesh
.uv =
UVs
;
155
mesh
.colors =
colors
;
156
mesh
.triangles =
triIndices
;
157
158
vertCountChanged
=
false
;
159
uvsChanged
=
false
;
160
colorsChanged
=
false
;
161
}
162
else
163
{
164
if
(
uvsChanged
)
165
{
166
mesh
.uv =
UVs
;
167
uvsChanged
=
false
;
168
}
169
170
if
(
colorsChanged
)
171
{
172
colorsChanged
=
false
;
173
174
mesh
.colors =
colors
;
175
}
176
177
// Explicitly recalculate bounds since
178
// we didn't assign new triangles (which
179
// implicitly recalculates bounds)
180
if
(
updateBounds
||
autoUpdateBounds
)
181
{
182
mesh
.RecalculateBounds();
183
updateBounds
=
false
;
184
}
185
}
186
}
187
}
188
LinkedSpriteManager.t
Transform t
Definition:
LinkedSpriteManager.cs:86
SpriteManager
Definition:
SpriteManager.cs:225
SpriteManager.UVs
Vector2[] UVs
Definition:
SpriteManager.cs:268
SpriteManager.colorsChanged
bool colorsChanged
Definition:
SpriteManager.cs:251
LinkedSpriteManager
Definition:
LinkedSpriteManager.cs:84
Sprite.mv1
int mv1
Definition:
Sprite.cs:109
SpriteManager.playingAnimations
ArrayList playingAnimations
Definition:
SpriteManager.cs:257
SpriteManager.updateBounds
bool updateBounds
Definition:
SpriteManager.cs:253
SpriteManager.Transform
void Transform(Sprite sprite)
Definition:
SpriteManager.cs:895
SpriteManager.uvsChanged
bool uvsChanged
Definition:
SpriteManager.cs:250
LinkedSpriteManager.pos
Vector3 pos
Definition:
LinkedSpriteManager.cs:87
SpriteManager.animTimeElapsed
float animTimeElapsed
Definition:
SpriteManager.cs:275
Sprite.StepAnim
bool StepAnim(float time)
Definition:
Sprite.cs:351
LinkedSpriteManager.Start
void Start()
Definition:
LinkedSpriteManager.cs:92
System
LinkedSpriteManager.LateUpdate
new void LateUpdate()
Definition:
LinkedSpriteManager.cs:125
Sprite.v3
Vector3 v3
Definition:
Sprite.cs:106
SpriteManager.i
int i
Definition:
SpriteManager.cs:273
UnityEngine
Sprite.mv2
int mv2
Definition:
Sprite.cs:110
Sprite.v4
Vector3 v4
Definition:
Sprite.cs:107
SpriteManager.vertices
Vector3[] vertices
Definition:
SpriteManager.cs:266
Sprite.mv3
int mv3
Definition:
Sprite.cs:111
SpriteManager.mesh
Mesh mesh
Definition:
SpriteManager.cs:264
Sprite
Definition:
Sprite.cs:83
LinkedSpriteManager.s
Sprite s
Definition:
LinkedSpriteManager.cs:88
Sprite.clientTransform
Transform clientTransform
Definition:
Sprite.cs:97
LinkedSpriteManager.TransformSprites
void TransformSprites()
Definition:
LinkedSpriteManager.cs:99
SpriteManager.activeBlocks
ArrayList activeBlocks
Definition:
SpriteManager.cs:255
SpriteManager.vertCountChanged
bool vertCountChanged
Definition:
SpriteManager.cs:252
SpriteManager.colors
Color[] colors
Definition:
SpriteManager.cs:269
Sprite.v2
Vector3 v2
Definition:
Sprite.cs:105
SpriteManager.tempSprite
Sprite tempSprite
Definition:
SpriteManager.cs:274
Sprite.v1
Vector3 v1
Definition:
Sprite.cs:104
SpriteManager.triIndices
int[] triIndices
Definition:
SpriteManager.cs:267
SpriteManager.activeBillboards
ArrayList activeBillboards
Definition:
SpriteManager.cs:256
Sprite.mv4
int mv4
Definition:
Sprite.cs:112
SpriteManager.autoUpdateBounds
bool autoUpdateBounds
Definition:
SpriteManager.cs:246
Assets
Scripts
Molecule
View
DisplayAtom
Sprite
LinkedSpriteManager.cs
Generated on Wed Aug 3 2016 15:10:26 for UnityMol by
1.8.11