コード例 #1
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);
                        }
                    }
                });
            }
        }
コード例 #2
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);
                        }
                    }
                });
            }
        }