UnityMol  0.9.6-875
UnityMol viewer / In developement
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:
85 {
87  Vector3 pos;
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:
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:
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  {
142 
143  // Step the animation, and if it has finished
144  // playing, remove it from the playing list:
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)
181  {
182  mesh.RecalculateBounds();
183  updateBounds = false;
184  }
185  }
186  }
187 }
188 
Vector2[] UVs
int mv1
Definition: Sprite.cs:109
ArrayList playingAnimations
void Transform(Sprite sprite)
float animTimeElapsed
bool StepAnim(float time)
Definition: Sprite.cs:351
Vector3 v3
Definition: Sprite.cs:106
int mv2
Definition: Sprite.cs:110
Vector3 v4
Definition: Sprite.cs:107
Vector3[] vertices
int mv3
Definition: Sprite.cs:111
Definition: Sprite.cs:83
Transform clientTransform
Definition: Sprite.cs:97
ArrayList activeBlocks
Vector3 v2
Definition: Sprite.cs:105
Vector3 v1
Definition: Sprite.cs:104
ArrayList activeBillboards
int mv4
Definition: Sprite.cs:112