Beispiel #1
0
        public void Add3DAsset(ResourceActivationContext ctxt, IVisualMarker marker, string mediaId, AssetInstance assetInstance, string fallbackImageUrl = null, Layout layout = null, Action onOpen = null, Action onSelect = null)
        {
            if (!CheckAdapter())
            {
                return;
            }

            if (DoesObjectExist(marker.GetIdentifier(), mediaId))
            {
                return;
            }

            var markerAsset = new MarkerAsset
            {
                ActivationContext = ctxt,
                AssetInstance     = assetInstance,
                Marker            = marker,
                MediaType         = MediaType.Image,
                MediaUrl          = fallbackImageUrl,
                MediaLayout       = layout,
                ObjectId          = mediaId,
                OnSelect          = onSelect,
                OnOpen            = onOpen
            };

            Add3DAsset(markerAsset);
        }
Beispiel #2
0
        public void Add3dAsset(IVuforiaMarker marker, string objectId, AssetInstance assetInstance, MediaElement fallbackImage)
        {
            var markerAsset = new MarkerAsset
            {
                AssetInstance = assetInstance,
                Marker        = marker,
                ObjectId      = objectId
            };

            if (fallbackImage != null)
            {
                markerAsset.MediaUrl    = fallbackImage.MediaUrl;
                markerAsset.MediaLayout = fallbackImage.Layout;
            }

            Add3dAsset(markerAsset);
        }
Beispiel #3
0
        internal void Add3DAsset(ResourceActivationContext context, VisualMarker3DAsset resource)
        {
            if (!CheckAdapter())
            {
                return;
            }

            if (resource.AssetInstance == null ||
                resource.Markers == null)
            {
                return;
            }

            foreach (var marker in resource.Markers)
            {
                var vumark = marker as IVisualMarker;

                if (vumark != null)
                {
                    var asset = new MarkerAsset
                    {
                        ActivationContext = context,
                        AssetInstance     = resource.AssetInstance,
                        Marker            = vumark,
                        MediaLayout       = resource.FallbackImage == null ? null : resource.FallbackImage.Layout,
                        MediaUrl          = resource.FallbackImage == null ? null : resource.FallbackImage.MediaUrl,
                        ObjectId          = context.InstanceId,
                        OnOpen            = () =>
                        {
                            context.Open();
                        },
                        OnSelect = () =>
                        {
                            context.FireEvent("select");
                        },
                        OnClose = () =>
                        {
                            context.Close();
                        }
                    };

                    Add3DAsset(asset);
                }
            }
        }
Beispiel #4
0
        public void Add3DAsset(IVisualMarker marker, string objectId, AssetInstance assetInstance, MediaElement fallbackImage)
        {
            if (!CheckAdapter())
            {
                return;
            }

            var markerAsset = new MarkerAsset
            {
                AssetInstance = assetInstance,
                Marker        = marker,
                ObjectId      = objectId
            };

            if (fallbackImage != null)
            {
                markerAsset.MediaUrl    = fallbackImage.MediaUrl;
                markerAsset.MediaLayout = fallbackImage.Layout;
            }

            Add3DAsset(markerAsset);
        }
Beispiel #5
0
        void Add3DAsset(MarkerAsset markerAsset)
        {
            Adapter.RegisterMarker(markerAsset.Marker);

            var objs = m_trackingMarkerObjects[markerAsset.Marker.GetIdentifier()];

            m_activeResourceAssets.Add(markerAsset.Marker.GetIdentifier(), markerAsset);

            if (objs != null && objs.Count() > 0)
            {
                foreach (var obj in objs)
                {
                    //obj.ExtendedTracking = markerAsset.Marker.UseExtendedTracking;

                    AttachAssetObject(markerAsset, obj);
                }
            }
            else
            {
                // Cache the asset if supported
                AssetLoader.PreloadAsset(markerAsset.AssetInstance.Asset);
            }
        }
Beispiel #6
0
        void Add3dAsset(MarkerAsset markerAsset)
        {
            if (markerAsset.Marker.Database != null)
            {
                LoadDataSet(markerAsset.Marker.Database);
            }

            var objs = m_trackingVuMarkers[markerAsset.Marker.Identifier];

            m_activeResourceAssets.Add(markerAsset.Marker.Identifier, markerAsset);

            if (objs != null && objs.Count() > 0)
            {
                foreach (var obj in objs)
                {
                    obj.ExtendedTracking = markerAsset.Marker.UseExtendedTracking;

                    AttachAssetObject(
                        markerAsset,
                        //markerAsset.Marker.Identifier,
                        obj.gameObject

                        /*,
                         * markerAsset.ObjectId,
                         * markerAsset.AssetInstance,
                         * markerAsset.MediaUrl,
                         * markerAsset.MediaLayout,
                         * markerAsset.OnOpen,
                         * markerAsset.OnSelect*/);
                }
            }
            else
            {
                // Preload the asset even if there's no marker yet
                UnityAssetLoader.LoadAsset <GameObject>((UnityAsset)markerAsset.AssetInstance.Asset, (obj) => { });
            }
        }
Beispiel #7
0
        void AttachAssetObject(MarkerAsset asset, GameObject parent)
        {
            var activeObject = GetOrCreateActiveObject(asset.ObjectId);

            VisualMarkerWorldObject worldObj = null;

            activeObject.MarkerObjects.TryGetValue(asset.Marker.Identifier, out worldObj);

            if (worldObj != null)
            {
                worldObj.GameObject.transform.SetParent(parent.transform, false);
                worldObj.GameObject.transform.localPosition = Vector3.zero;
                worldObj.GameObject.transform.localScale    = ItemScale;
                worldObj.GameObject.transform.localRotation = Quaternion.identity;

                if (asset.OnOpen != null)
                {
                    asset.OnOpen();
                }

                worldObj.GameObject.SetActive(true);
            }
            else
            {
                if (activeObject.PendingLoads.Contains(asset.Marker.Identifier))
                {
                    return;
                }

                activeObject.PendingLoads.Add(asset.Marker.Identifier);

                UnityAssetLoader.LoadAsset <GameObject>(asset.AssetInstance.Asset as UnityAsset, (prefab) =>
                {
                    activeObject.PendingLoads.Remove(asset.Marker.Identifier);

                    // parent object could have been destroyed
                    if (prefab && parent)
                    {
                        var gameObj = Instantiate(prefab);

                        var markerObj = Instantiate(MarkerAssetObject);

                        worldObj = CreateWorldObject(markerObj, gameObj, asset.ActivationContext);

                        worldObj.Clicked += (sender, args) =>
                        {
                            if (asset.OnSelect != null)
                            {
                                asset.OnSelect();
                            }
                        };

                        gameObj.transform.SetParent(markerObj.LayoutObject.transform, false);
                        gameObj.transform.localPosition = Vector3.zero;

                        markerObj.transform.SetParent(parent.transform, false);
                        markerObj.transform.localPosition = Vector3.zero;
                        markerObj.transform.localScale    = ItemScale;
                        markerObj.transform.localRotation = Quaternion.identity;

                        if (asset.AssetInstance.Layout != null)
                        {
                            LayoutHelper.Apply(markerObj.LayoutObject.transform, asset.AssetInstance.Layout);
                        }

                        var collider = gameObj.GetComponent <Collider>();

                        if (!collider)
                        {
                            gameObj.AddComponent <SphereCollider>();
                        }

                        activeObject.MarkerObjects.Add(asset.Marker.Identifier, worldObj);

                        if (asset.OnOpen != null)
                        {
                            asset.OnOpen();
                        }
                    }
                    else
                    {
                        if (asset.MediaUrl != null)
                        {
                            AttachMediaObject(asset, parent);
                        }
                    }
                });
            }
        }
Beispiel #8
0
        void AttachAssetObject(MarkerAsset asset, ARMarkerObject markerObj)
        {
            var activeObject = GetOrCreateActiveObject(asset.ObjectId);

            var worldObj = activeObject.HoldingMarkerObjects.GetFirstOrDefault(markerObj.MarkerIdentifier);

            if (worldObj != null)
            {
                activeObject.HoldingMarkerObjects.Remove(markerObj.MarkerIdentifier, worldObj);
                activeObject.TrackingMarkerObjects.Add(markerObj.GameObject, worldObj);

                worldObj.GameObject.transform.SetParent(markerObj.GameObject.transform, false);
                worldObj.GameObject.transform.localPosition = Vector3.zero;
                worldObj.GameObject.transform.localScale    = ItemScale;
                worldObj.GameObject.transform.localRotation = Quaternion.identity;

                if (asset.OnOpen != null)
                {
                    asset.OnOpen();
                }

                worldObj.GameObject.SetActive(true);
            }
            else
            {
                if (activeObject.PendingLoads.Contains(asset.Marker.GetIdentifier()))
                {
                    return;
                }

                activeObject.PendingLoads.Add(asset.Marker.GetIdentifier());

                AssetLoader.LoadAsset <GameObject>(asset.AssetInstance.Asset, (gameObj) =>
                {
                    activeObject.PendingLoads.Remove(asset.Marker.GetIdentifier());

                    // parent object could have been destroyed
                    if (gameObj && markerObj.GameObject)
                    {
                        var assetObj = Instantiate(MarkerAssetObject);

                        worldObj = CreateWorldObject(markerObj, assetObj, gameObj, asset.ActivationContext);

                        worldObj.Clicked += (sender, args) =>
                        {
                            if (asset.OnSelect != null)
                            {
                                asset.OnSelect();
                            }
                        };

                        gameObj.transform.SetParent(assetObj.LayoutObject.transform, false);
                        gameObj.transform.localPosition = Vector3.zero;

                        assetObj.transform.SetParent(markerObj.GameObject.transform, false);
                        assetObj.transform.localPosition = Vector3.zero;
                        assetObj.transform.localScale    = ItemScale;
                        assetObj.transform.localRotation = Quaternion.identity;

                        if (asset.AssetInstance.Layout != null)
                        {
                            LayoutHelper.Apply(assetObj.LayoutObject.transform, asset.AssetInstance.Layout);
                        }

                        var collider = gameObj.GetComponent <Collider>();

                        if (!collider)
                        {
                            gameObj.AddComponent <SphereCollider>();
                        }

                        activeObject.TrackingMarkerObjects.Add(markerObj.GameObject, worldObj);

                        if (asset.OnOpen != null)
                        {
                            asset.OnOpen();
                        }
                    }
                    else
                    {
                        if (asset.MediaUrl != null)
                        {
                            AttachMediaObject(asset, markerObj);
                        }
                    }
                });
            }
        }