public void AddMarkerMedia(IVisualMarker marker, string mediaId, MediaElement mediaElement, Action onOpen = null, Action onSelect = null, Action onClose = null) { if (!CheckAdapter()) { return; } if (mediaElement == null || mediaElement.MediaUrl == null) { return; } var markerMedia = new MarkerMedia { Marker = marker, MediaType = mediaElement.MediaItem.MediaType, MediaUrl = mediaElement.MediaUrl, MediaLayout = mediaElement.Layout, Color = mediaElement.Color, ObjectId = mediaId, OnOpen = onOpen, OnSelect = onSelect, OnClose = onClose }; AddMarkerMedia(markerMedia); }
public void AddMarkerImage(ResourceActivationContext ctxt, IVisualMarker marker, string mediaId, string url, Layout layout = null, Action onOpen = null, Action onSelect = null) { if (!CheckAdapter()) { return; } if (DoesObjectExist(marker.GetIdentifier(), mediaId)) { return; } var markerMedia = new MarkerMedia { ActivationContext = ctxt, Marker = marker, MediaType = MediaType.Image, MediaUrl = url, MediaLayout = layout, ObjectId = mediaId, OnSelect = onSelect, OnOpen = onOpen }; AddMarkerMedia(markerMedia); }
public void AddMarkerMedia(ResourceActivationContext context, VisualMarkerMedia resource) { if (!CheckAdapter()) { return; } if (resource.MediaElement == null || resource.MediaElement.MediaUrl == null || resource.Markers == null) { return; } foreach (var marker in resource.Markers.OfType <IVisualMarker>()) { if (marker != null) { var media = new MarkerMedia { ActivationContext = context, Marker = marker, MediaLayout = resource.MediaElement.Layout, MediaType = resource.MediaElement.MediaItem.MediaType, MediaUrl = resource.MediaElement.MediaUrl, Color = resource.MediaElement.Color, ObjectId = context.InstanceId, OnOpen = () => { context.Open(); }, OnSelect = () => { context.FireEvent("select"); }, OnClose = () => { context.Close(); } }; AddMarkerMedia(media); } } }
void AddMarkerMedia(MarkerMedia markerMedia) { if (markerMedia.MediaUrl == null) { return; } m_activeResourceMedia.Add(markerMedia.Marker.Identifier, markerMedia); var objs = m_trackingVuMarkers[markerMedia.Marker.Identifier]; if (markerMedia.Marker.Database != null) { LoadDataSet(markerMedia.Marker.Database); } if (objs != null) { foreach (var obj in objs) { obj.ExtendedTracking = markerMedia.Marker.UseExtendedTracking; AttachMediaObject( markerMedia, //markerMedia.Marker.Identifier, obj.gameObject /*, * markerMedia.ObjectId, * markerMedia.MediaUrl, * markerMedia.MediaType, * markerMedia.MediaLayout, * markerMedia.OnOpen, * markerMedia.OnSelect, * markerMedia.OnClose*/); } } }
void AddMarkerMedia(MarkerMedia markerMedia) { if (markerMedia.MediaUrl == null) { return; } m_activeResourceMedia.Add(markerMedia.Marker.GetIdentifier(), markerMedia); var objs = m_trackingMarkerObjects[markerMedia.Marker.GetIdentifier()]; Adapter.RegisterMarker(markerMedia.Marker); if (objs != null) { foreach (var obj in objs) { AttachMediaObject( markerMedia, obj); } } }
/* * 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(); } } }