关闭

增强现实的解密游戏

标签: 增强现实解密游戏unity3d
1736人阅读 评论(3) 收藏 举报
分类:


有兴趣的朋友可以试试,不过好像不很稳定。

游戏过程的视频:http://www.bilibili.com/video/av3375068/

游戏的APK下载地址:http://www.nshworkshop.cn/demo/12/arpuzzlegame.apk

游戏用到的图片下载:http://www.nshworkshop.cn/demo/12/pic.zip

 游戏源码:https://code.csdn.net/wuyt2008/arpuzzlegame






最近在弄增强现实,主要是基于Unity3D和vuforia AR SDK。有个想做真人密室逃脱游戏的朋友看到了,就说这个可以用在真人密室逃脱游戏里,于是就有了这个demo。

这个演示其实很简单,就是在识别率特定图片以后,会载入新的场景来推动游戏进程。

Unity3D制作AR图片识别请看以前的文章:http://blog.csdn.net/wuyt2008/article/details/48326767


Vuforia给的例子中的视频播放脚本稍微修改下

/*============================================================================== 
 * Copyright (c) 2012-2014 Qualcomm Connected Experiences, Inc. All Rights Reserved. 
 * ==============================================================================*/

using UnityEngine;
using Vuforia;

/// <summary>
/// A custom handler that implements the ITrackableEventHandler interface.
/// </summary>
public class TrackableEventHandler : MonoBehaviour,
                                     ITrackableEventHandler
{
    #region PRIVATE_MEMBER_VARIABLES

    private TrackableBehaviour mTrackableBehaviour;

    private bool mHasBeenFound = false;
    private bool mLostTracking;
    private float mSecondsSinceLost;

    #endregion // PRIVATE_MEMBER_VARIABLES

	private bool track=false;

    #region UNITY_MONOBEHAVIOUR_METHODS

    void Start()
    {
        mTrackableBehaviour = GetComponent<TrackableBehaviour>();
        if (mTrackableBehaviour)
        {
            mTrackableBehaviour.RegisterTrackableEventHandler(this);
        }

        OnTrackingLost();
    }


    void Update()
    {
        // Pause the video if tracking is lost for more than two seconds
        if (mHasBeenFound && mLostTracking)
        {
            if (mSecondsSinceLost > 0.5f)
            {
                VideoPlaybackBehaviour video = GetComponentInChildren<VideoPlaybackBehaviour>();
                if (video != null &&
                    video.CurrentState == VideoPlayerHelper.MediaState.PLAYING)
                {
                    video.VideoPlayer.Pause();
                }

                mLostTracking = false;
            }

            mSecondsSinceLost += Time.deltaTime;
        }
    }

    #endregion // UNITY_MONOBEHAVIOUR_METHODS



    #region PUBLIC_METHODS

    /// <summary>
    /// Implementation of the ITrackableEventHandler function called when the
    /// tracking state changes.
    /// </summary>
    public void OnTrackableStateChanged(
                                    TrackableBehaviour.Status previousStatus,
                                    TrackableBehaviour.Status newStatus)
    {
        if (newStatus == TrackableBehaviour.Status.DETECTED ||
            newStatus == TrackableBehaviour.Status.TRACKED ||
            newStatus == TrackableBehaviour.Status.EXTENDED_TRACKED)
        {
            OnTrackingFound();
        }
        else
        {
            OnTrackingLost();
        }
    }

    #endregion // PUBLIC_METHODS



    #region PRIVATE_METHODS

    private void OnTrackingFound()
    {
        Renderer[] rendererComponents = GetComponentsInChildren<Renderer>();
        Collider[] colliderComponents = GetComponentsInChildren<Collider>();

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

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

        Debug.Log("Trackable " + mTrackableBehaviour.TrackableName + " found");

        // Optionally play the video automatically when the target is found

        VideoPlaybackBehaviour video = GetComponentInChildren<VideoPlaybackBehaviour>();
        if (video != null && video.AutoPlay)
        {
            if (video.VideoPlayer.IsPlayableOnTexture())
            {
                VideoPlayerHelper.MediaState state = video.VideoPlayer.GetStatus();
                if (state == VideoPlayerHelper.MediaState.PAUSED ||
                    state == VideoPlayerHelper.MediaState.READY ||
                    state == VideoPlayerHelper.MediaState.STOPPED)
                {
                    // Pause other videos before playing this one
                    PauseOtherVideos(video);

                    // Play this video on texture where it left off
                    video.VideoPlayer.Play(false, video.VideoPlayer.GetCurrentPosition());
                }
                else if (state == VideoPlayerHelper.MediaState.REACHED_END)
                {
                    // Pause other videos before playing this one
                    PauseOtherVideos(video);

                    // Play this video from the beginning
                    video.VideoPlayer.Play(false, 0);
                }
            }
        }

        mHasBeenFound = true;
        mLostTracking = false;
		track = true;
    }


    private void OnTrackingLost()
    {
        Renderer[] rendererComponents = GetComponentsInChildren<Renderer>();
        Collider[] colliderComponents = GetComponentsInChildren<Collider>();

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

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

        Debug.Log("Trackable " + mTrackableBehaviour.TrackableName + " lost");

        mLostTracking = true;
        mSecondsSinceLost = 0;

		if (track) {
			GameManager.TrackLost(gameObject.name);
		} 

		track = false;
    }


    // Pause all videos except this one
    private void PauseOtherVideos(VideoPlaybackBehaviour currentVideo)
    {
        VideoPlaybackBehaviour[] videos = (VideoPlaybackBehaviour[])
                FindObjectsOfType(typeof(VideoPlaybackBehaviour));

        foreach (VideoPlaybackBehaviour video in videos)
        {
            if (video != currentVideo)
            {
                if (video.CurrentState == VideoPlayerHelper.MediaState.PLAYING)
                {
                    video.VideoPlayer.Pause();
                }
            }
        }
    }

    #endregion // PRIVATE_METHODS
}

这个是控制游戏的类

using UnityEngine;
using System.Collections;

public static class GameManager {

	public static int currentScene=0;
	public static string[] tips = {"努力加载中","开始游戏吧","你找到一个锁着的箱子","再问问宫森葵,她知道的更多","快去找宫森葵,你找到资料了","恭喜你,游戏已经通关","请把手机放到Cardboard里,请小心周围情况。"};
	public static string[] scene = {"Open","SceneOne","SceneTow","SceneSAO","SceneFour","SceneEnd","BoxAR"};
	private static string[] rnd = {"SceneAB","SceneSAO","SceneKoto","SceneSuzumiya"};

	public static void TrackLost(string information){
		switch (currentScene) {
		case 0:
			break;
		case 1:
			if(information=="Box"){
				currentScene=2;
				Application.LoadLevel("LoadScene");
			}
			break;
		case 2:
			if(information=="Miyamori"){
				currentScene=3;
				scene[3]=RandomScene();
				Application.LoadLevel("LoadScene");
			}
			break;
		case 3:
			if(information=="SAO"||information=="AB"||information=="Koto"||information=="Suzumiya"){
				currentScene=4;
				Application.LoadLevel("LoadScene");
			}
			break;
		case 4:
			if(information=="Box"){
				currentScene=5;
				Application.LoadLevel("LoadScene");
			}
			break;
		default:
			break;
		}
	}

	private static string RandomScene(){
		string strReturn = PlayerPrefs.GetString("scene","SceneAB");
		int temp = Random.Range (0, 4);
		if(strReturn==rnd[temp]){
			temp=temp+1;
		}
		if(temp>=rnd.Length){
			temp=0;
		}
		strReturn = rnd [temp];
		PlayerPrefs.SetString ("scene",strReturn);
		return strReturn;
	}
}



0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:585927次
    • 积分:6502
    • 等级:
    • 排名:第3688名
    • 原创:138篇
    • 转载:4篇
    • 译文:0篇
    • 评论:175条
    最新评论