// Scans all child objects looking for IUIObjects and other panels public void ScanChildren() { uiObjs.Clear(); // Reuse for IUIObjects: IUIObject obj; Component[] objs = transform.GetComponentsInChildren(typeof(IUIObject), true); for (int i = 0; i < objs.Length; ++i) { // Don't add ourselves as children: if (objs[i] == this || objs[i].gameObject == gameObject) { continue; } #if AUTO_SET_LAYER // Only reset the child object layers if we're in-line // with the UIManager: if (gameObject.layer == UIManager.instance.gameObject.layer) #if SET_LAYERS_RECURSIVELY { UIPanelManager.SetLayerRecursively(objs[i].gameObject, gameObject.layer); } #else { objs[i].gameObject.layer = gameObject.layer; } #endif #endif obj = (IUIObject)objs[i]; uiObjs.Add(new EZLinkedListNode <IUIObject>(obj)); obj.RequestContainership(this); } // Reuse for UIPanelBase objects: UIPanelBase panel; objs = transform.GetComponentsInChildren(typeof(UIPanelBase), true); for (int i = 0; i < objs.Length; ++i) { // Don't add ourselves as children: if (objs[i] == this || objs[i].gameObject == gameObject) { continue; } #if AUTO_SET_LAYER // Only reset the child object layers if we're in-line // with the UIManager: if (gameObject.layer == UIManager.instance.gameObject.layer) #if SET_LAYERS_RECURSIVELY { UIPanelManager.SetLayerRecursively(objs[i].gameObject, gameObject.layer); } #else { objs[i].gameObject.layer = gameObject.layer; } #endif #endif panel = (UIPanelBase)objs[i]; childPanels.Add(new EZLinkedListNode <UIPanelBase>(panel)); panel.RequestContainership(this); } }
/// <summary> /// Adds the specified sprite to the SpriteManager. /// </summary> /// <param name="go">Reference to the desired sprite.</param> /// <returns>A reference to the sprite's managed mesh.</returns> public SpriteMesh_Managed AddSprite(SpriteRoot sprite) { int spriteIndex; // See if the sprite is already added: if(sprite.manager == this && sprite.AddedToManager) return (SpriteMesh_Managed)sprite.spriteMesh; /* if (ensureUnique) if (AlreadyAdded(sprite)) return (SpriteMesh_Managed) sprite.spriteMesh; */ // See if we're ready to add sprites yet, // and if not, add the sprite to our deferred // add queue: if(!initialized) { if (spriteAddQueue == null) spriteAddQueue = new List<SpriteRoot>(); spriteAddQueue.Add(sprite); return null; } // Get an available sprite: if (availableBlocks.Empty) EnlargeArrays(allocBlockSize); // If we're out of available sprites, allocate some more: // Use a sprite from the list of available blocks: spriteIndex = availableBlocks.Head.index; availableBlocks.Remove(availableBlocks.Head); // Now that we're using this one, remove it from the available list // Assign the new sprite: SpriteMesh_Managed newSpritesMesh = sprites[spriteIndex]; sprite.spriteMesh = newSpritesMesh; sprite.manager = this; sprite.AddedToManager = true; newSpritesMesh.drawLayer = sprite.drawLayer; // Associate the sprite's bone: bones[spriteIndex] = sprite.gameObject.transform; // meshRenderer.bones = bones; bindPoses[spriteIndex] = bones[spriteIndex].worldToLocalMatrix * sprite.transform.localToWorldMatrix; /* // Save this to an active list now that it is in-use: if (billboarded) { newSprite.billboarded = true; activeBillboards.Add(newSprite); } else */ activeBlocks.Add(newSpritesMesh); newSpritesMesh.Init(); // Sort the draw layers: SortDrawingOrder(); // Set our flags: vertCountChanged = true; vertsChanged = true; uvsChanged = true; return newSpritesMesh; }
// Enlarges the sprite array by the specified count and also resizes // the UV and vertex arrays by the necessary corresponding amount. // Returns the index of the first newly allocated element // (ex: if the sprite array was already 10 elements long and is // enlarged by 10 elements resulting in a total length of 20, // EnlargeArrays() will return 10, indicating that element 10 is the // first of the newly allocated elements.) protected int EnlargeArrays(int count) { int firstNewElement; if (sprites == null) { InitArrays(); firstNewElement = 0; count = count - 1; // Allocate one less since InitArrays already allocated one sprite for us } else firstNewElement = sprites.Length; // Resize sprite array: SpriteMesh_Managed[] tempSprites = sprites; sprites = new SpriteMesh_Managed[sprites.Length + count]; tempSprites.CopyTo(sprites, 0); // Resize the bone array: Transform[] tempBones = bones; bones = new Transform[bones.Length + count]; tempBones.CopyTo(bones, 0); // Resize the bind poses array: Matrix4x4[] tempPoses = bindPoses; bindPoses = new Matrix4x4[bindPoses.Length + count]; tempPoses.CopyTo(bindPoses, 0); // Vertices: Vector3[] tempVerts = vertices; vertices = new Vector3[vertices.Length + count * 4]; tempVerts.CopyTo(vertices, 0); // BoneWeights: BoneWeight[] tempWeights = boneWeights; boneWeights = new BoneWeight[boneWeights.Length + count * 4]; tempWeights.CopyTo(boneWeights, 0); // UVs: Vector2[] tempUVs = UVs; UVs = new Vector2[UVs.Length + count * 4]; tempUVs.CopyTo(UVs, 0); // Colors: Color[] tempColors = colors; colors = new Color[colors.Length + count * 4]; tempColors.CopyTo(colors, 0); // Triangle indices: int[] tempTris = triIndices; triIndices = new int[triIndices.Length + count * 6]; tempTris.CopyTo(triIndices, 0); // Inform existing sprites of the new vertex and UV buffers: for (int i = 0; i < firstNewElement; ++i) { sprites[i].SetBuffers(vertices, UVs, colors); } // Setup the newly-added sprites and Add them to the list of available // sprite blocks. Also initialize the triangle indices while we're at it: for (int i = firstNewElement; i < sprites.Length; ++i) { // Create and setup sprite: sprites[i] = new SpriteMesh_Managed(); sprites[i].index = i; sprites[i].manager = this; sprites[i].SetBuffers(vertices, UVs, colors); // Setup indices of the sprite's vertices in the vertex buffer: sprites[i].mv1 = i * 4 + 0; sprites[i].mv2 = i * 4 + 1; sprites[i].mv3 = i * 4 + 2; sprites[i].mv4 = i * 4 + 3; // Setup the indices of the sprite's UV entries in the UV buffer: sprites[i].uv1 = i * 4 + 0; sprites[i].uv2 = i * 4 + 1; sprites[i].uv3 = i * 4 + 2; sprites[i].uv4 = i * 4 + 3; // Setup the indices to the color values: sprites[i].cv1 = i * 4 + 0; sprites[i].cv2 = i * 4 + 1; sprites[i].cv3 = i * 4 + 2; sprites[i].cv4 = i * 4 + 3; // Add as an available sprite: availableBlocks.Add(sprites[i]); // Init triangle indices: /* if (winding == SpriteRoot.WINDING_ORDER.CCW) { // Counter-clockwise winding triIndices[i * 6 + 0] = i * 4 + 0; // 0_ 2 0 ___ 3 triIndices[i * 6 + 1] = i * 4 + 1; // | / Verts: | /| triIndices[i * 6 + 2] = i * 4 + 3; // 1|/ 1|/__|2 triIndices[i * 6 + 3] = i * 4 + 3; // 3 triIndices[i * 6 + 4] = i * 4 + 1; // /| triIndices[i * 6 + 5] = i * 4 + 2; // 4/_|5 } else */ { // Clockwise winding triIndices[i * 6 + 0] = i * 4 + 0; // 0_ 1 0 ___ 3 triIndices[i * 6 + 1] = i * 4 + 3; // | / Verts: | /| triIndices[i * 6 + 2] = i * 4 + 1; // 2|/ 1|/__|2 triIndices[i * 6 + 3] = i * 4 + 3; // 3 triIndices[i * 6 + 4] = i * 4 + 2; // /| triIndices[i * 6 + 5] = i * 4 + 1; // 5/_|4 } // Add the index of this sprite to the draw order list spriteDrawOrder.Add(sprites[i]); // Give the bones something to point to: bones[i] = transform; // Setup a default bindpose: bindPoses[i] = bones[i].worldToLocalMatrix * transform.localToWorldMatrix; // Setup the weights: SetupBoneWeights(sprites[i]); } vertsChanged = true; uvsChanged = true; colorsChanged = true; vertCountChanged = true; return firstNewElement; }