Пример #1
0
        void AddSpawnedAsset(ResourceActivationContext context, AssetSpawner resource, UnityAsset asset, GameObject obj)
        {
            GameObject rootObject = new GameObject(asset.AssetName);

            rootObject.transform.position   = Vector3.zero;
            rootObject.transform.localScale = Vector3.one;
            rootObject.transform.rotation   = Quaternion.Euler(Vector3.zero);

            var worldObj = AddWorldObject(context, obj, rootObject);

            worldObj.Asset = asset;

            obj.transform.position   = Vector3.zero;
            obj.transform.localScale = Vector3.one;
            obj.transform.rotation   = Quaternion.Euler(Vector3.zero);

            obj.transform.SetParent(rootObject.transform);

            if (resource.SpawnPosition is FixedWorldPosition)
            {
                var fixedPos = resource.SpawnPosition as FixedWorldPosition;

                if (fixedPos.Position != null)
                {
                    rootObject.transform.position = LayoutHelper.ToVector3(fixedPos.Position);
                }

                if (resource.AssetInstance.Layout != null)
                {
                    LayoutHelper.Apply(obj.transform, resource.AssetInstance.Layout);
                }
            }

            m_objectsById[resource.AssetInstance.Id] = worldObj;
        }
Пример #2
0
        internal static void LoadAsset(Motive._3D.Models.AssetInstance assetInstance, GameObject parent)
        {
            var unityAsset = assetInstance.Asset as UnityAsset;

            if (unityAsset == null)
            {
                return;
            }

            LoadAsset <GameObject>(unityAsset, (prefab) =>
            {
                if (prefab != null)
                {
                    var obj = GameObject.Instantiate(prefab);

                    obj.transform.SetParent(parent.transform);

                    obj.transform.localPosition = Vector3.zero;
                    obj.transform.localRotation = Quaternion.identity;

                    if (assetInstance.Layout != null)
                    {
                        LayoutHelper.Apply(obj.transform, assetInstance.Layout);
                    }
                }
            });
        }
Пример #3
0
        public static GameObject ConfigureAsset(
            GameObject gameObj,
            AssetInstance assetInstance,
            Transform parent = null,
            bool applyLayout = true,
            bool addCollider = true)
        {
            var layoutObj = new GameObject("Layout");

            layoutObj.transform.localPosition = Vector3.zero;
            layoutObj.transform.localRotation = Quaternion.identity;
            layoutObj.transform.localScale    = Vector3.one;

            var animationObj = new GameObject("Scripted Animation");

            animationObj.transform.localPosition = Vector3.zero;
            animationObj.transform.localRotation = Quaternion.identity;
            animationObj.transform.localScale    = Vector3.one;

            animationObj.transform.SetParent(layoutObj.transform);

            gameObj.transform.localPosition = Vector3.zero;
            gameObj.transform.localRotation = Quaternion.identity;

            gameObj.transform.SetParent(animationObj.transform);

            if (assetInstance.Layout != null)
            {
                LayoutHelper.Apply(layoutObj.transform, assetInstance.Layout);
            }

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

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

            if (parent)
            {
                layoutObj.transform.SetParent(parent.transform, false);
            }

            return(layoutObj);
        }
Пример #4
0
        public void LoadMediaElement(MediaElement element)
        {
            if (element.MediaUrl != null)
            {
                if (element.Layout != null)
                {
                    LayoutHelper.Apply(LayoutElement ?? this.transform, element.Layout);
                }

                ImageLoader.LoadImageOnThread(element.MediaUrl, (ImageRenderer != null) ? ImageRenderer.gameObject : this.gameObject, AspectFit);

                if (element.Color != null)
                {
                    var renderer = ImageRenderer ?? (this.gameObject.GetComponent <Renderer>());

                    if (renderer)
                    {
                        renderer.material.color = ColorHelper.ToUnityColor(element.Color);
                    }
                }
            }
        }
Пример #5
0
        /*
         * 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();
                }
            }
        }
Пример #6
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);
                        }
                    }
                });
            }
        }
Пример #7
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);
                        }
                    }
                });
            }
        }