VisualMarkerWorldObject CreateWorldObject(ARMarkerObject markerObj, VisualMarkerObject spawnedItem, GameObject animationTarget, ResourceActivationContext context = null) { var worldObj = new VisualMarkerWorldObject { GameObject = spawnedItem.gameObject }; spawnedItem.WorldObject = worldObj; ARWorld.Instance.AddWorldObject(worldObj, context); WorldObjectManager.Instance.AddWorldObject(context, spawnedItem.gameObject, animationTarget, spawnedItem.LayoutObject); m_spawnedObjects.Add(markerObj, spawnedItem); return(worldObj); }
VisualMarkerWorldObject CreateWorldObject(VisualMarkerObject markerObj, GameObject animationTarget, ResourceActivationContext context = null) { var worldObj = new VisualMarkerWorldObject { GameObject = markerObj.gameObject }; markerObj.WorldObject = worldObj; ARWorld.Instance.AddWorldObject(worldObj); WorldObjectManager.Instance.AddWorldObject(context, markerObj.gameObject, animationTarget, markerObj.LayoutObject); if (context != null) { ARWorld.Instance.AttachResourceEvents(worldObj, context); } return(worldObj); }
/* * void AttachAssetObject(VuMarkIdentifier identifier, GameObject parent, string objectId, AssetInstance assetInstance, MediaElement fallbackImage, Action onOpen, Action onSelect) * { * if (fallbackImage != null) * { * AttachAssetObject(identifier, parent, objectId, assetInstance, fallbackImage.MediaUrl, fallbackImage.Layout, onOpen, onSelect); * } * else * { * AttachAssetObject(identifier, parent, objectId, assetInstance, null, null, onOpen); * } * }*/ void AttachMediaObject( MarkerMedia media, //VuMarkIdentifier identifier, GameObject parent /*, * string objectId, * string url, * MediaType mediaType, * Layout layout, * Action onOpen, * Action onSelect, * Action onComplete*/) { var activeObject = GetOrCreateActiveObject(media.ObjectId); VisualMarkerObject markerObj = null; Action onReady = null; VisualMarkerWorldObject worldObj = null; activeObject.MarkerObjects.TryGetValue(media.Marker.Identifier, out worldObj); if (worldObj != null) { markerObj = worldObj.GameObject.GetComponent <VisualMarkerObject>(); switch (media.MediaType) { case Motive.Core.Media.MediaType.Audio: onReady = () => { var player = markerObj.GetComponentInChildren <AudioSubpanel>(); player.Play(media.OnClose); }; break; case Motive.Core.Media.MediaType.Video: onReady = () => { var player = markerObj.GetComponentInChildren <VideoSubpanel>(); player.Play(media.OnClose); }; break; } worldObj.GameObject.SetActive(true); } else { switch (media.MediaType) { case Motive.Core.Media.MediaType.Audio: { markerObj = Instantiate(MarkerAudioObject); onReady = () => { var player = markerObj.GetComponentInChildren <AudioSubpanel>(); player.Play(media.MediaUrl, media.OnClose); }; break; } case Motive.Core.Media.MediaType.Image: { markerObj = Instantiate(MarkerImageObject); onReady = () => { ThreadHelper.Instance.StartCoroutine( ImageLoader.LoadImage(media.MediaUrl, markerObj.RenderObject)); }; break; } case Motive.Core.Media.MediaType.Video: { markerObj = Instantiate(MarkerVideoObject); var renderer = markerObj.RenderObject.GetComponent <Renderer>(); renderer.enabled = false; onReady = () => { var player = markerObj.GetComponentInChildren <VideoSubpanel>(); UnityAction setAspect = () => { renderer.enabled = true; if (media.MediaLayout == null) { var aspect = player.AspectRatio; if (aspect > 1) { // Wider than tall, reduce y scale player.transform.localScale = new Vector3(1, 1 / aspect, 1); } else { // Wider than tall, reduce x scale player.transform.localScale = new Vector3(aspect, 1, 1); } } }; player.ClipLoaded.AddListener(setAspect); player.Play(media.MediaUrl, media.OnClose); }; break; } } if (markerObj) { if (media.MediaLayout != null) { LayoutHelper.Apply(markerObj.LayoutObject.transform, media.MediaLayout); } if (media.Color != null) { var renderer = markerObj.RenderObject.GetComponent <Renderer>(); if (renderer) { renderer.material.color = ColorHelper.ToUnityColor(media.Color); } } worldObj = CreateWorldObject(markerObj, markerObj.RenderObject, media.ActivationContext); activeObject.MarkerObjects[media.Marker.Identifier] = worldObj; worldObj.Clicked += (sender, args) => { if (media.OnSelect != null) { media.OnSelect(); } }; } } if (markerObj) { markerObj.transform.SetParent(parent.transform, false); markerObj.transform.localScale = ItemScale; markerObj.transform.localPosition = Vector3.zero; markerObj.transform.localRotation = Quaternion.identity; if (onReady != null) { onReady(); } if (media.OnOpen != null) { media.OnOpen(); } } }