// Use this for initialization void Start() { // Next, generate a new UI: FlatWorldUI ui = new FlatWorldUI("BillboardContent"); // It's representing a TV, so lets use some standard TV screen dimensions: ui.SetDimensions(800, 600); // As this example only uses a WorldUI, we'll set the filter mode to bilinear so it looks smoother. ui.TextFilterMode = FilterMode.Bilinear; // Give it some content: if (HtmlFile != null) { ui.document.innerHTML = HtmlFile.text; } if (InputEnabled) { // World UI's should accept input: UI.WorldInputMode = InputMode.Screen; } // Grab the texture: Texture texture = ui.Texture; // Assign it to the parents material: Material material = gameObject.GetComponent <MeshRenderer>().sharedMaterial; // Apply it: material.mainTexture = texture; }
/// <summary>Destroys this RDP.</summary> public void Destroy() { // Destroy it: if (Renderer != null) { Renderer.Destroy(); Renderer = null; } }
internal override void NowOffScreen() { if (Renderer != null) { FlatWorldUI fwui = Renderer; Renderer = null; // Make sure we're on the main thread: Callback.MainThread(delegate(){ // Destroy it: fwui.Destroy(); }); } }
// OnEnable is called when the game starts, or when the manager script component is enabled. public override void OnEnable() { // Next, generate a new UI using the given virtual screen dimensions (the name is optional but helps debug the document): FlatUI = new FlatWorldUI(gameObject.name, Width, Height); // Use PowerUI.Manager's Navigate function (which reads either Url or HtmlFile depending on which you set): Navigate(FlatUI.document); // Optionally accept input: FlatUI.AcceptInput = InputEnabled; // Apply to the material on this gameObjects mesh renderer: // (Note: You can also just grab FlatUI.Texture - this is just a convenience function) FlatUI.ApplyTo(gameObject); }
internal override void Layout(LayoutBox box, Renderman renderer) { // Dimensions: float width = box.Width; float height = box.Height; if (Renderer == null) { // Create the FWUI now: Renderer = new FlatWorldUI("#Internal-PowerUI-Raster-" + RasterID, (int)width, (int)height); RasterID++; if (Filter != null) { // Set source: Filter.Set("source0", Renderer.Texture); } // Grab the output texture: Output = Renderer.Texture; } // Does the given renderer belong to the worldUI? if (renderer == Renderer.Renderer) { // Yes! We're actually drawing the element. return; } // Next we'll draw the rastered image. // It's essentially just the output from the renderer. // Get the top left inner corner (inside margin and border): float top = box.Y; float left = box.X; // Update the FlatWorldUI next: UpdateRenderer(box, width, height); // Always isolated: Isolate(); // Make sure the renderer stalls and doesn't draw anything else of this element or its kids. renderer.StallStatus = 2; // Setup boundary: BoxRegion boundary = new BoxRegion(left, top, width, height); if (!boundary.Overlaps(renderer.ClippingBoundary)) { if (Visible) { SetVisibility(false); } return; } else if (!Visible) { // ImageLocation will allocate here if it's needed. SetVisibility(true); } // Texture time - get its location on that atlas: if (LocatedAt == null) { LocatedAt = new AtlasLocation(width, height); } else { // Dimensions changed? int w = (int)width; int h = (int)height; if (LocatedAt.Width != w || LocatedAt.Height != h) { // Update it: LocatedAt.UpdateFixed(width, height); } } boundary.ClipBy(renderer.ClippingBoundary); // Ensure we have a batch: renderer.SetupBatch(this, null, null); if (Material == null) { // Create the material now using the isolated shader: Material = new Material(renderer.CurrentShaderSet.Isolated); // Hook up the output: Material.SetTexture("_MainTex", Output); } // Allocate the block: MeshBlock block = Add(renderer); // Set current material: SetBatchMaterial(renderer, Material); // Set the (overlay) colour: block.SetColour(renderer.ColorOverlay); block.TextUV = null; // Z-index (same as a background-image): float zIndex = (RenderData.computedStyle.ZIndex - 0.003f); BoxRegion screenRegion = new BoxRegion(); screenRegion.Set(left, top, width, height); // Setup the block: block.ImageUV = block.SetClipped(boundary, screenRegion, renderer, zIndex, LocatedAt, block.ImageUV); // Flush it: block.Done(renderer.Transform); }