예제 #1
0
    public override void OnTrackSuccess(Vector3 translation, Quaternion orientation, Vector2 size)
    {
        Renderer[]           rendererComponents = GetComponentsInChildren <Renderer>(true);
        Collider[]           colliderComponents = GetComponentsInChildren <Collider>(true);
        VideoPlayerBehaviour videoPlayer        = GetComponentInChildren <VideoPlayerBehaviour>();

        // Enable rendering:
        foreach (Renderer component in rendererComponents)
        {
            component.enabled = true;
        }

        // Enable colliders:
        foreach (Collider component in colliderComponents)
        {
            component.enabled = true;
        }

        if (videoPlayer != null)
        {
            videoPlayer.ResumeVideo(true);
        }

        transform.position = translation;
        transform.rotation = orientation;
    }
예제 #2
0
    public override void ConfigCloudObject(IHsGameObject target)
    {
        try
        {//兼容老版本识别包
            HiARObjectMonoBehaviour oldScript = target.HsGameObjectInstance.GetComponent <HiARObjectMonoBehaviour>();
            if (oldScript != null && target.HsGameObjectInstance.transform.childCount > 0)
            {
                GameObject child = target.HsGameObjectInstance.transform.GetChild(0).gameObject;
                VideoPlayerMonoBehaviour oldVideo = child.GetComponent <VideoPlayerMonoBehaviour>();
                if (oldVideo != null)
                {
                    child.AddComponent <VideoPlayerBehaviour>();
                    VideoPlayerBehaviour player = child.GetComponent <VideoPlayerBehaviour>();
                    player.m_isLocal = false;
                    player.m_webUrl  = oldVideo.m_webUrl;
                    if (string.IsNullOrEmpty(player.m_webUrl))
                    {
                        player.m_isLocal   = true;
                        player.m_localPath = oldVideo.m_localPath;
                    }
                }
                target.HsGameObjectInstance = child;
            }
        }
        catch (Exception e)
        {
            LogUtil.Log(e.ToString());
        }

        VideoPlayerBehaviour playerSrc = target.HsGameObjectInstance.GetComponent <VideoPlayerBehaviour>();

        if (playerSrc != null)
        {
            target.HsGameObjectInstance.name = "VideoPlayer";
        }

        Transform  trans    = target.HsGameObjectInstance.transform;
        Vector3    scale    = trans.localScale;
        Vector3    position = trans.position;
        Quaternion rotation = trans.rotation;

        trans.position = transform.position;
        trans.rotation = transform.rotation;

        trans.SetParent(transform);

        trans.localPosition = position;
        trans.localRotation = rotation;

        trans.gameObject.SetActive(true);
    }
예제 #3
0
    public override void OnInspectorGUI()
    {
        if (PrefabUtility.GetPrefabType(target) == PrefabType.Prefab)
        {
            return;
        }

        videoPlayerBehaviour = (VideoPlayerBehaviour)target;

        isDirty = false;

        string prevVideoName = videoPlayerBehaviour.VideoName;

        videoPlayerBehaviour.VideoName = EditorGUILayout.TextField("Video Name", videoPlayerBehaviour.VideoName);
        if (string.Equals(prevVideoName, videoPlayerBehaviour.VideoName) == false)
        {
            isDirty = true;
        }

        bool prevContinuousMode = videoPlayerBehaviour.ContinuousPlaying;

        videoPlayerBehaviour.ContinuousPlaying = EditorGUILayout.Toggle("Continuous Playing", videoPlayerBehaviour.ContinuousPlaying);
        if (prevContinuousMode != videoPlayerBehaviour.ContinuousPlaying)
        {
            isDirty = true;
        }

        bool prevAlpha = videoPlayerBehaviour.Transparent;

        videoPlayerBehaviour.Transparent = EditorGUILayout.Toggle("Transparent", videoPlayerBehaviour.Transparent);
        if (prevAlpha != videoPlayerBehaviour.Transparent)
        {
            isDirty = true;
        }

        if (GUI.changed)
        {
            if (videoPlayerBehaviour != null)
            {
                if (isDirty)
                {
                    EditorUtility.SetDirty(videoPlayerBehaviour);
                }
            }

            SceneManager.Instance.SceneUpdated();
        }
    }
예제 #4
0
    GameObject CreateVideoObject(string videoFile, int imgWidth, int imgHeight)
    {
        GameObject videoObject = GameObject.CreatePrimitive(PrimitiveType.Plane);

        videoObject.name = "VideoPlayer";
        videoObject.transform.localScale = new Vector3(imgWidth * 0.001f, 0, imgHeight * 0.001f);
        videoObject.SetActive(false);
        videoObject.AddComponent <VideoPlayerBehaviour>();
        VideoPlayerBehaviour videoPlayer = videoObject.GetComponent <VideoPlayerBehaviour>();

        //videoPlayer.VideoUrl = videoFile;
        //videoPlayer.LocalPath = videoFile;
        videoPlayer.AbsolutePath  = videoFile;
        videoPlayer.IsLocal       = true;
        videoPlayer.IsTransparent = true;
        videoObject.SetActive(true);
        return(videoObject);
    }
예제 #5
0
    public void Click()
    {
        GameObject[] objs = GameObject.FindGameObjectsWithTag("Video");

        foreach (GameObject obj in objs)
        {
            VideoPlayerBehaviour video = obj.GetComponent <VideoPlayerBehaviour> ();
            if (video.Video.isPlaying)
            {
                video.Video.Stop();
            }
        }

        GameObject player = GameObject.FindGameObjectWithTag("Player");

        iTween.MoveTo(player,
                      iTween.Hash("position", gameObject.transform.position,
                                  "time", 1.5f, "easytype", "Linear", "oncomplete", "OnPlayerSound", "oncompletetarget", this.gameObject));
    }
예제 #6
0
    public override void OnTrackFail()
    {
        Renderer[]           rendererComponents = GetComponentsInChildren <Renderer>(true);
        Collider[]           colliderComponents = GetComponentsInChildren <Collider>(true);
        VideoPlayerBehaviour videoPlayer        = GetComponentInChildren <VideoPlayerBehaviour>();

        // Enable rendering:
        foreach (Renderer component in rendererComponents)
        {
            component.enabled = false;
        }

        // Enable colliders:
        foreach (Collider component in colliderComponents)
        {
            component.enabled = false;
        }

        if (videoPlayer != null)
        {
            videoPlayer.ResumeVideo(false);
        }
    }
예제 #7
0
    public override void ConfigCloudObject(IHsGameObject target)
    {
        try
        {//兼容老版本识别包
            HiARObjectMonoBehaviour oldScript = target.HsGameObjectInstance.GetComponent <HiARObjectMonoBehaviour>();
            if (oldScript != null && target.HsGameObjectInstance.transform.childCount > 0)
            {
                GameObject child = target.HsGameObjectInstance.transform.GetChild(0).gameObject;
                VideoPlayerMonoBehaviour oldVideo = child.GetComponent <VideoPlayerMonoBehaviour>();
                if (oldVideo != null)
                {
                    child.AddComponent <VideoPlayerBehaviour>();
                    VideoPlayerBehaviour player = child.GetComponent <VideoPlayerBehaviour>();
                    player.m_isLocal = false;
                    player.m_webUrl  = oldVideo.m_webUrl;
                    if (string.IsNullOrEmpty(player.m_webUrl))
                    {
                        player.m_isLocal   = true;
                        player.m_localPath = oldVideo.m_localPath;
                    }
                }
                target.HsGameObjectInstance = child;
            }
        }
        catch (Exception e)
        {
            LogUtil.Log(e.ToString());
        }

        VideoPlayerBehaviour playerSrc = target.HsGameObjectInstance.GetComponent <VideoPlayerBehaviour>();

        if (playerSrc != null)
        {
            target.HsGameObjectInstance.name = "VideoPlayer";
            VideoPlayer.TransParentOptions option = playerSrc.TransParentOption;
            Material material = Resources.Load <Material>("Materials/VIDEO");
            switch (option)
            {
            case VideoPlayer.TransParentOptions.None:
                if (playerSrc.IsTransparent)
                {
                    material        = Instantiate(Resources.Load <Material>("Materials/VIDEO"));
                    material.shader = Instantiate(Resources.Load <Shader>("Shaders/Transparent_Color"));
                }
                else
                {
                    material.shader = Resources.Load <Shader>("Shaders/video");
                }
                break;

            case VideoPlayer.TransParentOptions.TransparentColor:
                material        = Instantiate(Resources.Load <Material>("Materials/VIDEO"));
                material.shader = Instantiate(Resources.Load <Shader>("Shaders/Transparent_Color"));
                break;

            case VideoPlayer.TransParentOptions.TransparentLeftAndRight:
                material.shader = Resources.Load <Shader>("Shaders/TransparentVideo_LeftAndRight");
                break;

            case VideoPlayer.TransParentOptions.TransparentUpAndDown:
                material.shader = Resources.Load <Shader>("Shaders/TransparentVideo_UpAndDown");
                break;

            default:
                break;
            }
            playerSrc.PlayMaterial = material;
            if (playerSrc.IsTransparent || (playerSrc.TransParentOption == VideoPlayer.TransParentOptions.TransparentColor))
            {
                playerSrc.PlayMaterial.SetFloat("_DeltaColor", playerSrc.DeltaColor);
                playerSrc.PlayMaterial.SetColor("_MaskColor", playerSrc.MaskColor);
            }
        }

        Transform trans = target.HsGameObjectInstance.transform;
        //Vector3 scale = trans.localScale;
        Vector3    position = trans.position;
        Quaternion rotation = trans.rotation;

        trans.position = transform.position;
        trans.rotation = transform.rotation;

        trans.SetParent(transform);

        trans.localPosition = position;
        trans.localRotation = rotation;

        trans.gameObject.SetActive(true);
    }
예제 #8
0
    private void OnGUI()
    {
        GUI.Label(new Rect(Screen.width * 2 / 5, Screen.height * 2 / 5, Screen.width / 5, Screen.height / 5), text, labstyle);


        //暂停
        if (GUI.Button(new Rect(Screen.width / 5, Screen.height * 4 / 5, Screen.width / 5, Screen.width / 10), "", pause))
        {
            video = null;
            //对每个imagetarget进行判断,获取当前video
            foreach (GameObject game in gameObject)
            {
                found = game.activeSelf;
                Debug.Log(found);
                if (found)
                {
                    video = game.GetComponentInChildren <VideoPlayerBehaviour>();
                    Debug.Log(video.Path);
                    break;
                }
            }

            if (video != null)
            {
                video.Pause();
            }

            else
            {
                text = "亲,请先识别图片哦";
            }
        }

        //播放
        if (GUI.Button(new Rect(Screen.width * 3 / 5, Screen.height * 4 / 5, Screen.width / 5, Screen.width / 10), "", play))
        {
            video = null;
            //对每个imagetarget进行判断,获取当前video
            foreach (GameObject game in gameObject)
            {
                found = game.activeSelf;
                if (found)
                {
                    video = game.GetComponentInChildren <VideoPlayerBehaviour>();
                    Debug.Log(video.Path);
                    break;
                }
            }
            if (video != null)
            {
                video.Play();
            }

            else
            {
                text = "亲,请先识别图片哦";
            }
        }
        if (GUI.Button(new Rect(Screen.width - 100, 0, 100, 100), "", image))
        {
            SceneManager.LoadScene("main");
        }
    }
 protected override void Start()
 {
     if (Application.platform == RuntimePlatform.Android || Application.platform == RuntimePlatform.IPhonePlayer)
         videoPlayerBehaviour = gameObject.GetComponentInChildren<VideoPlayerBehaviour>();
     base.Start();
     HideObjects(transform);
     if (videoPlayerBehaviour != null)
         StartCoroutine(LoadVideo());
 }