Can I autogenerate Unity GameObjects for each Articy Entity?

Sat 29. Apr 2017, 08:13

Title says it all. 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.

Also sneaking another question in here:

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.

I'm on articy:draft version 3.0.7.
Raidenthequick
 

Re: Can I autogenerate Unity GameObjects for each Articy Ent

Sat 29. Apr 2017, 08:20

For handle an image asset it's like

Sprite s = ((Asset)imageAsset).LoadasSprite();

for me I put image on a template so it's

imageAsset = element.Template.Media.Media

For the first, I think you can do like a getAll Entity from database, and handle them with your code to create unity object adapt to them.
I don't have my project under my eyes to give you exact code
User avatar
Zeldarck
 
Posts: 55
Joined: Thu 9. Mar 2017, 16:03

Re: Can I autogenerate Unity GameObjects for each Articy Ent

Tue 2. May 2017, 07:24

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
Nico Probst
Senior Software Engineer | Articy | LinkedIn
User avatar
[Articy] Nico Probst
Articy Staff
Articy Staff
 
Posts: 217
Joined: Wed 23. Nov 2011, 09:45
Location: Bochum

Re: Can I autogenerate Unity GameObjects for each Articy Ent

Thu 4. May 2017, 03:25

Thanks, that really helped! Got a bunch of early prototype stuff going right now.
Guest
 

Return to articy:draft Unity Importer

Who is online

Users browsing this forum: No registered users and 8 guests

Who We Are
Contact Us
Social Links