Esempio n. 1
0
        /// <summary>Gets a batch from the pool. Null if the pool is empty.</summary>
        public static UIBatch Get(Renderman renderer)
        {
            if (First == null)
            {
                return(null);
            }

            UIBatch result = First;

            First             = result.BatchAfter;
            result.BatchAfter = null;
            result.Setup      = false;

            // Show it:
                        #if PRE_UNITY4
            result.Mesh.OutputGameObject.active = true;
                        #else
            result.Mesh.OutputGameObject.SetActive(true);
                        #endif

            if (result.Renderer != renderer)
            {
                result.ChangeRenderer(renderer);
            }

            return(result);
        }
        /// <summary>Adds the given chain of batches to the pool.</summary>
        public static void AddAll(UIBatch first, UIBatch last)
        {
            if (first == null)
            {
                return;
            }

            last.BatchAfter = First;
            First           = first;
        }
		/// <summary>Adds the given chain of batches to the pool.</summary>
		public static void AddAll(UIBatch first,UIBatch last){
			
			if(first==null){
				return;
			}
			
			last.BatchAfter=First;
			First=first;
			
		}
		/// <summary>Clears the pool.</summary>
		public static void Clear(){
			
			UIBatch current=First;
			First=null;
			
			while(current!=null){
				current.Destroy();
				current=current.BatchAfter;
			}
			
		}
		/// <summary>Creates a new dynamic mesh which uses the hybrid shader and a texture atlas.</summary>
		public DynamicMesh(UIBatch batch){
			Batch=batch;
			
			if(UIShader==null){
				UIShader=Shader.Find("StandardUI Unlit");
			}
			
			GlobalMaterial=new Material(UIShader);
			
			Setup();
		}
        /// <summary>Clears the pool.</summary>
        public static void Clear()
        {
            UIBatch current = First;

            First = null;

            while (current != null)
            {
                current.Destroy();
                current = current.BatchAfter;
            }
        }
        /// <summary>Adds the given batch to the pool.</summary>
        public static void Add(UIBatch batch)
        {
            batch.BatchAfter = First;
            First            = batch;

            // Hide it:
                        #if PRE_UNITY4
            batch.Mesh.OutputGameObject.active = false;
                        #else
            batch.Mesh.OutputGameObject.SetActive(false);
                        #endif
        }
        /// <summary>Creates a new dynamic mesh which uses the hybrid shader and a texture atlas.</summary>
        public DynamicMesh(UIBatch batch)
        {
            Batch = batch;

            if (UIShader == null)
            {
                UIShader = Shader.Find("StandardUI Unlit");
            }

            GlobalMaterial = new Material(UIShader);

            Setup();
        }
		/// <summary>Adds the given batch to the pool.</summary>
		public static void Add(UIBatch batch){
			
			batch.BatchAfter=First;
			First=batch;
			
			// Hide it:
			#if PRE_UNITY4
			batch.Mesh.OutputGameObject.active=false;
			#else
			batch.Mesh.OutputGameObject.SetActive(false);
			#endif
			
		}
Esempio n. 10
0
        /// <summary>Attempts to find the element from the set WorldUI; if there is no WorldUI, the main UI is used.
        /// This search uses the triangle of the hit to figure out exactly which element was clicked.</summary>
        /// <param name="hit">The hit in 3D that must be resolved to an element.</param>
        public void FindElement(RaycastHit hit)
        {
            // Which triangle was hit, and as a result, which element did it come from?
            // If the element is found, apply it to our result; otherwise assume unsuccessful hit.
            Renderman renderer = null;

            if (OnWorldUI != null)
            {
                renderer = OnWorldUI.Renderer;
            }
            else
            {
                renderer = UI.GetRenderer();
            }

            if (renderer == null)
            {
                return;
            }

            Transform transform = hit.transform;

            // Which batch? Will only be from the non-pooled ones:
            UIBatch current = renderer.FirstBatch;

            while (current != null)
            {
                if (current.Mesh.OutputTransform == transform)
                {
                    // Got it!
                    break;
                }
                current = current.BatchAfter;
            }

            if (current == null)
            {
                return;
            }

            // Current is the batch the hit was on. Next, resolve to the MeshBlock and finally to the element that made it.
        }
Esempio n. 11
0
        /// <summary>Hides all the pooled batches.</summary>
        public static void HideAll()
        {
            UIBatch current = First;

            while (current != null)
            {
                UnityEngine.GameObject obj = current.Mesh.OutputGameObject;

                if (obj != null)
                {
                    // Hide it:
                                        #if PRE_UNITY4
                    obj.active = false;
                                        #else
                    obj.SetActive(false);
                                        #endif
                }

                current = current.BatchAfter;
            }
        }
Esempio n. 12
0
        /// <summary>Gets a batch from the pool. Null if the pool is empty.</summary>
        public static UIBatch Get(Renderman renderer)
        {
            if (First == null)
            {
                return(null);
            }

            UIBatch result = First;

            First             = result.BatchAfter;
            result.BatchAfter = null;
            result.Setup      = false;

            // Get the GO:
            UnityEngine.GameObject gameobject = result.Mesh.OutputGameObject;

            if (gameobject == null)
            {
                // This occurs when a WorldUI gets destroyed but put its batches in the pool.
                // We've already removed the first so just go recursive - chances are the next one will be ok.
                return(Get(renderer));
            }

            // Show it:
                        #if PRE_UNITY4
            gameobject.active = true;
                        #else
            gameobject.SetActive(true);
                        #endif

            if (result.Renderer != renderer)
            {
                result.ChangeRenderer(renderer);
            }

            return(result);
        }
Esempio n. 13
0
		/// <summary>Sets up the current batch based on the isolation settings requested by a property.</summary>
		/// <param name="property">The displayable property which wants the batch.</param>
		/// <param name="fontTexture">The font texture to use with this batch.</param>
		public void SetupBatch(DisplayableProperty property,TextureAtlas graphics,TextureAtlas font){
			
			if(UI.MainCameraPool!=null && InWorldUI==null){
				// This is the main UI and it also has a camera pool.
				// Are we now attempting to create a batch on top of an inline camera?
				
				// Let the camera pool check:
				if(UI.MainCameraPool.CheckCameraRequired()){
					// Clear the current batch - it can't be shared any further.
					CurrentBatch=null;
				}
				
			}
			
			if(property.Isolated){
				if(property.GotBatchAlready){
					// The property already got a batch on this layout - it doesn't need another.
					return;
				}
				
				// Isolated properties always get a new batch every time.
				CurrentBatch=UIBatchPool.Get(this);
				
				if(CurrentBatch==null){
					CurrentBatch=new UIBatch(this);
				}
				
				property.GotBatchAlready=true;
				
				// And push it to the active stack:
				AddBatch(CurrentBatch);
				
				// Make sure it knows it's isolated:
				CurrentBatch.IsIsolated(property);
				
			}else{
				
				if(CurrentBatch!=null && !CurrentBatch.Isolated){
					// Re-use existing batch?
					
					if(font!=null){
						
						if(CurrentBatch.FontAtlas==null){
							// Didn't have one assigned before. Assign now:
							CurrentBatch.SetFontAtlas(font,FontAliasing);
						}else if(font!=CurrentBatch.FontAtlas){
							// Font atlas changed. Can't share.
							CurrentBatch=null;
						}
						
					}
					
					if(graphics!=null){
						
						if(CurrentBatch.GraphicsAtlas==null){
							// Didn't have one assigned before. Assign now:
							CurrentBatch.SetGraphicsAtlas(graphics);
						}else if(graphics!=CurrentBatch.GraphicsAtlas){
							// Atlas changed. Can't share.
							CurrentBatch=null;
						}
						
					}
					
					if(CurrentBatch!=null){
						// Yep - reuse it.
						return;
					}
					
				}
				
				// Pull a batch from the pool and set it to currentbatch. May need to generate a new one.
				CurrentBatch=UIBatchPool.Get(this);
				
				if(CurrentBatch==null){
					CurrentBatch=new UIBatch(this);
				}
				
				// And push it to the active stack:
				AddBatch(CurrentBatch);
				
				// Make sure it knows it's not isolated:
				CurrentBatch.NotIsolated(graphics,font,FontAliasing);
				
			}
			
			// Finally, prepare it for layout:
			CurrentBatch.PrepareForLayout();
			
		}
Esempio n. 14
0
		/// <summary>Adds the given batch to the main linked list for processing.</summary>
		public void AddBatch(UIBatch batch){
			if(FirstBatch==null){
				FirstBatch=LastBatch=batch;
			}else{
				LastBatch=LastBatch.BatchAfter=batch;
			}
		}
Esempio n. 15
0
 /// <summary>Creates a new dynamic mesh which uses the hybrid shader and a texture atlas.</summary>
 public DynamicMesh(UIBatch batch)
 {
     Batch = batch;
     Setup();
 }
		/// <summary>Gets a batch from the pool. Null if the pool is empty.</summary>
		public static UIBatch Get(Renderman renderer){
			if(First==null){
				return null;
			}
			
			UIBatch result=First;
			First=result.BatchAfter;
			result.BatchAfter=null;
			result.Setup=false;
			
			// Show it:
			#if PRE_UNITY4
			result.Mesh.OutputGameObject.active=true;
			#else
			result.Mesh.OutputGameObject.SetActive(true);
			#endif
			
			if(result.Renderer!=renderer){
				result.ChangeRenderer(renderer);
			}
			
			return result;
		}
Esempio n. 17
0
		/// <summary>Relocates all DOM elements by calculating their onscreen position.
		/// Each element may allocate sections of the 3D mesh (blocks) which are then flushed out
		/// into the unity mesh and onto the screen.</summary>
		public void Layout(){
			DoLayout=false;
			Reset();
			
			// First, push all batches to the pool - inlined for speed:
			// Note that no isolated batches enter either the queue or the pool until their no longer isolated.
			if(FirstBatch!=null){
				LastBatch.BatchAfter=UIBatchPool.First;
				UIBatchPool.First=FirstBatch;
			}
			
			FirstBatch=LastBatch=null;
			
			// Note: Batches are Prepared For Layout as they are added.
			
			LayoutOccuring=true;
			
			// Position elements locally.
			// This sets their ParentOffset values and as a result finds their PixelWidth.
			RootDocument.html.PositionLocally();
			
			if(Input.Focused!=null){
				Input.Focused.Handler.OnRenderPass();
				
				// Make sure it didn't schedule anything.
				if(StylesToPaint!=null){
					Css.ElementStyle style=StylesToPaint;
					StylesToPaint=null;
					
					while(style!=null){
						style.IsPainting=false;
						style=style.Next;
					}
				}
				DoLayout=false;
			}
			
			// Next up, position them globally:
			// This calculates OffsetLeft/Top and also fires the render event on the computed style object.
			RootDocument.html.PositionGlobally(null);
			
			LayoutOccuring=false;
			
			// Tell each batch we're done laying them out:
			UIBatch currentBatch=FirstBatch;
			
			while(currentBatch!=null){
				currentBatch.CompletedLayout();
				currentBatch=currentBatch.BatchAfter;
			}
			
			if(StylesToPaint!=null){
				// Clear the isPainting flag.
				Css.ElementStyle style=StylesToPaint;
				StylesToPaint=null;
				
				while(style!=null){
					style.IsPainting=false;
					style=style.Next;
				}
			}
			
			// Hide all pool entries:
			UIBatchPool.HideAll();
		}
Esempio n. 18
0
 /// <summary>Sets an index in a batch. Used in paint mode.</summary>
 public void SetBatchIndex(UIBatch batch, int blockIndex)
 {
     Buffer     = null;
     Mesh       = batch.Mesh;
     BlockIndex = blockIndex;
 }
Esempio n. 19
0
		/// <summary>Resets all values in the renderer. Called before each layout.</summary>
		public void Reset(){
			LineStart=0;
			PenX=0;
			PenY=0;
			Depth=0f;
			Baseline=0;
			MaxDepth=0f;
			BatchDepth=0;
			LineHeight=0;
			ActiveFloats=null;
			FontAliasing=InfiniText.Fonts.Aliasing;
			
			ResetBoundary();
			DepthUsed=false;
			CurrentBatch=null;
			CustomShader=null;
			
			if(InWorldUI==null){
				// This is the main UI renderer.
				
				// Clear the root node:
				Node=null;
				
				if(UI.MainCameraPool!=null){
					UI.MainCameraPool.Reset();
				}
			}
		}