// 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;
		
	}
Example #2
0
        public override void OnEnable()
        {
            // Watch for any file changes:
            Watch();

            // Get the UnityUI image panel from the GO:
            UnityEngine.UI.RawImage img = GetComponent <UnityEngine.UI.RawImage>();

            // Generate a new UI:
            HtmlUI = new FlatWorldUI("HtmlContent");

            // Get dimensions:
            RectTransform dimensions = GetComponent <RectTransform>();

            RectTransform = dimensions;

            Rect rect = dimensions.rect;

            // The virtual screen size:
            HtmlUI.SetDimensions((int)rect.width, (int)rect.height);

            // Load from HtmlFile or Src using the PowerUIManager.Navigate function:
            Navigate(document);

            // The UI should accept input:
            HtmlUI.AcceptInput = true;

            // Apply texture:
            img.texture = HtmlUI.Texture;

            // Add an updater which looks out for resizes right before the FWUI redraws:
            HtmlUI.OnUpdate = delegate(){
                // Get the current rectangle:
                Rect currentRect = dimensions.rect;

                if (HtmlUI.SetDimensions((int)currentRect.width, (int)currentRect.height))
                {
                    // Resized! Get the texture again:
                    img.texture = HtmlUI.Texture;
                }
            };

            // Include the Unity UI when handling input:
            if (PowerUI.Input.UnityUICaster == null)
            {
                // Get the caster:
                PowerUI.Input.UnityUICaster = img.canvas.GetComponent <UnityEngine.UI.GraphicRaycaster>();
            }
        }
Example #3
0
        public override void OnEnable()
        {
            // Get the UnityUI image panel from the GO:
            UnityEngine.UI.RawImage img = GetComponent <UnityEngine.UI.RawImage>();

            // Generate a new UI:
            HtmlUI = new FlatWorldUI("HtmlContent", 100, 100);

            // Get dimensions:
            RectTransform dimensions = GetComponent <RectTransform>();

            RectTransform = dimensions;

            Rect rect = dimensions.rect;

            // The virtual screen size:
            HtmlUI.SetDimensions((int)rect.width, (int)rect.height);

            // Load from HtmlFile or Src using the PowerUIManager.Navigate function:
            Navigate(document);

            // The UI should accept input:
            HtmlUI.AcceptInput = true;

            // Grab the texture:
            Texture texture = HtmlUI.Texture;

            // Apply material:
            img.texture = texture;

            // Include the Unity UI when handling input:
            if (PowerUI.Input.UnityUICaster == null)
            {
                // Get the caster:
                PowerUI.Input.UnityUICaster = img.canvas.GetComponent <UnityEngine.UI.GraphicRaycaster>();
            }
        }
        public override void OnEnable()
        {
            // Watch for any file changes:
            Watch();

            // Dump renderer/filter, unless it's flat:
            MeshRenderer mr = gameObject.GetComponent <MeshRenderer>();

            // True if we've got the visual guide:
            bool hasGuide = false;

            if (!MakeItFlat && mr != null && mr.material != null && mr.material.name.StartsWith("worldUIMaterial"))
            {
                // Remove it:
                GameObject.Destroy(mr);

                hasGuide = true;

                // Remove filter too:
                MeshFilter filter = gameObject.GetComponent <MeshFilter>();

                if (filter != null)
                {
                    GameObject.Destroy(filter);
                }
            }

            // First, figure out the 'aspect ratio' of the scale:
            Vector3 scale   = transform.localScale;
            float   yAspect = scale.z / scale.x;

            // Calc the number of pixels:
            int height = (int)((float)PixelWidth * yAspect);

            if (MakeItFlat)
            {
                // Create it as a FlatWorldUI instead:
                FlatWorldUI fwUI = new FlatWorldUI(PixelWidth, height);
                WorldUI = fwUI;

                // Grab the texture and apply it to the material:
                if (mr != null)
                {
                    Material mat = new Material(mr.material.shader);
                    mat.mainTexture = fwUI.texture;
                    mr.material     = mat;

                    // The flat version is upside down relative to the 3D one:
                    mat.mainTextureScale  = new Vector2(-1f, -1f);
                    mat.mainTextureOffset = new Vector2(1f, 1f);
                }

                // Give it some content using PowerUI.Manager's Navigate method:
                // (Just so we can use the same Html/ Url fields - it's completely optional)
                Navigate(WorldUI.document);

                if (InputEnabled)
                {
                    // Create a box collider:
                    BoxCollider bc = gameObject.AddComponent <BoxCollider>();

                    // Accept input from it:
                    fwUI.AcceptInputFrom(bc);
                }
            }
            else
            {
                // Reset local scale:
                // transform.localScale=Vector3.one;

                // Generate a new UI (the name is optional).
                // The two numbers are the dimensions of our virtual screen:
                WorldUI = new WorldUI(gameObject.name, PixelWidth, height);

                // Settings:
                WorldUI.PixelPerfect     = PixelPerfect;
                WorldUI.AlwaysFaceCamera = AlwaysFaceTheCamera;

                if (Expiry != 0f)
                {
                    WorldUI.SetExpiry(Expiry);
                }

                // Give it some content using PowerUI.Manager's Navigate method:
                // (Just so we can use the same Html/ Url fields - it's completely optional)
                Navigate(WorldUI.document);

                // Parent it to the GO:
                WorldUI.ParentToOrigin(transform);

                if (hasGuide)
                {
                    // Rotate it 90 degrees about x (to match up with the guide):
                    // WorldUI.transform.localRotation=Quaternion.AngleAxis(90f,new Vector3(1f,0f,0f));
                }

                // Set the scale such that the width "fits".
                // The panel will be PixelWidth wide, so we want to divide by that to get to '1'.
                // Note that the 10 is because a plane is 10 units wide.
                // We then multiply it by whatever scale (on x) the user originally wanted.
                // The y scale is accounted for by the computed pixel height (we don't want to distort it).
                float scaleFactor = (10f * scale.x) / (float)PixelWidth;

                WorldUI.transform.localScale = new Vector3(scaleFactor, scaleFactor, scaleFactor);

                // Optionally accept input:
                WorldUI.AcceptInput = InputEnabled;
            }

            // Input is always inverted for these:
            WorldUI.InvertResolve = true;
        }