Hi, I have an object with an attached script that contains information, and I need to display in the scene this information.
I am using Tridify to import BIM data to Unity. They provide a script that allows you to display this data in the console but I need to display this data in the scene.
I think that basically I need to change the Debug.Log for another function to display the information in the scene, not in the console.
Unity has no direct way of displaying console data in the game itself. But you can either get one of the many console Windows from the asset store, of simply use a canvas with a large text object. Instead of Debug.Log, you’d link to the Canvas’s text object, and set the Contents of the text to whatever you would have logged. This is exceedingly primitive, as it Shows only the very last message, but you may get buy until your get a better handle on displaying Information during runtime.
When I need to display several text messages at the same time, like a running log, a quick and dirty way is to just create a list of strings. You add the new message to the list, if the list exceeds some arbitrary count you remove the string at index 0. Then you take all strings in the list and create a single string with “\n” in between them, and throw that all into your text box. Works pretty well and even someone inexperienced should be able to do it in less than an hour of trial and error.
Hi @Time3 , Here’s a simple example how to show data in runtime. Basically we create Gui element if we hit (raycast) to an object. Just add this script to your scene (e.g empty object) and define Raycast Camera in to the script in inspector. Remember to add colliders to your objects in scene, or there’s nothing where the rays could hit. Easiest way to test this is to add Tridify-FPScamera (Assets\ Tridify\ DemoAssets\ Prefabs) prefab to your scene, and set its child object (FirstPersonCharacter) to Raycast Camera. Now you’re good to go. Let me know if you need more help?
using UnityEngine;
using Tridify;
using System;
using System.Linq;
public class ShowBimData : MonoBehaviour {
public Camera raycastCamera;
private GameObject _selectedObject;
private string onGuiText = "";
void Update()
{
if (Input.GetButtonDown("Fire1"))
{
Ray ray = raycastCamera.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
if (Physics.Raycast(ray, out hit, 1000))
{
_selectedObject = hit.transform.gameObject;
var ifcType = _selectedObject.GetComponent<IfcType>();
if (ifcType != null)
{
var attributeStrings = ifcType.Attributes
.Select(attr => attr.Name + ": " + attr.Value);
var attributesString =
string.Join(Environment.NewLine, attributeStrings);
onGuiText = ("Selected: " + ifcType.GetType().Name
+ Environment.NewLine + attributesString);
}
else
{
onGuiText = ("No IfcType found on object: " + _selectedObject.name);
}
}
else
{
onGuiText = ("");
}
}
}
private void OnGUI()
{
if (!string.IsNullOrEmpty(onGuiText))
{
GUIContent content = new GUIContent(onGuiText);
GUIStyle style = GUI.skin.box;
style.alignment = TextAnchor.UpperLeft;
Vector2 size = style.CalcSize(content);
GUI.Box(new Rect(1, 1, size.x, size.y), content, style);
}
}
}
Hi Guys, for some unknown reason Unity has removed our Tridify BIM Tools plugin from Asset Store.
But don’t worry, You can still download Tridify BIM Tools plugin from here https://www.tridify.com/developers/unity/