Hi Raidenthequick,
I want to know if there is a mechanism of taking every single Articy entity in my project, and automatically generating a Unity GameObject that has an ArticyRef pointing to that Articy entity. This would reduce much of the tedium of mapping Unity to Articy.
It depends a bit if you just want to create them directly into your scene or if you want to create prefabs. But the general approach should be the same
- Code: Select all
var entities = ArticyDatabase.GetAllOfType<IEntity>(); // IEntity because we want even the ones with templates
foreach(var ent in entities)
{
var childGameObject = new GameObject(ent.TechnicalName);
//childGameObject.transform.SetParent(aParent, false); // if you have a parent already in the scene
var articyReference = childGameObject.AddComponent<ArticyReference>();
articyReference.reference = new ArticyRef() { id = child.Id };
}
You can use that code at runtime or use it in the editor.
How do I use Articy's Image Assets within Unity? I'd like to display an image on the UI, or in a sprite, from an image that was exported as an "Asset" within Articy. What code, or editor stuff, needs to be done? I noticed there's an "Articy Asset Caretaker" thing but absolute zero documentation about it anywhere.
Zeldarck already gave you a general direction. Every IAsset has a
LoadAsset() method to load the underlying asset type and a convenience method to load the underlying image as a
Sprite. The rest is just assigning it to the material or SpriteRenderer:
- Code: Select all
var renderer = GetComponent<SpriteRenderer>();
renderer.sprite = myAsset.LoadAssetAsSprite();
And about the
ArticyAssetCaretaker: It is a convenience to keep an unity Image object and an articy image asset always assigned. The reason for that is that if for some reason the unity image file gets deleted, all reference in your unity project are gone, even reimporting the asset would not restore it, because unity assigned a new id to the image. The Caretaker matches the object not the unity file id, and therefore can rebuild the asset reference.
Hope that helps
Best regards
Nico