Skip to content

Instantly share code, notes, and snippets.

@joshiaj7
Created November 2, 2017 09:00
Show Gist options
  • Save joshiaj7/39784df478309d964de76b397fa8e4f1 to your computer and use it in GitHub Desktop.
Save joshiaj7/39784df478309d964de76b397fa8e4f1 to your computer and use it in GitHub Desktop.
My Augmented Reality + 360 view scripts using Unity3D and Vuforia SDK
/*
Scene : Brosur_Test
Component : TouchScreen
*/
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class AndroidBackButtonScript : MonoBehaviour {
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if (Input.GetKeyDown(KeyCode.Escape))
{
Application.Quit();
}
}
}
/*
Scene : 360_Test
Component : TouchScreen
*/
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class BackButtonScript : MonoBehaviour {
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if (Input.GetKeyDown(KeyCode.Escape))
{
SceneManager.LoadScene("Brosur_Test", LoadSceneMode.Single);
}
}
}
// this shader is used for inverting image of 360 view in a sphere
Shader "Unlit/360Shader"
{
Properties
{
_MainTex ("Base (RGB)", 2D) = "white" {}
_Color ("Main Color", Color) = (1,1,1,0.5)
}
SubShader
{
Tags { "RenderType" = "Opaque" }
//This is used to print the texture inside of the sphere
Cull Front
CGPROGRAM
#pragma surface surf SimpleLambert
half4 LightingSimpleLambert (SurfaceOutput s, half3 lightDir, half atten)
{
half4 c;
c.rgb = s.Albedo;
return c;
}
sampler2D _MainTex;
struct Input
{
float2 uv_MainTex;
float4 myColor : COLOR;
};
fixed3 _Color;
void surf (Input IN, inout SurfaceOutput o)
{
//This is used to mirror the image correctly when printing it inside of the sphere
IN.uv_MainTex.x = 1 - IN.uv_MainTex.x;
fixed3 result = tex2D(_MainTex, IN.uv_MainTex)*_Color;
o.Albedo = result.rgb;
o.Alpha = 1;
}
ENDCG
}
Fallback "Diffuse"
}
/*
Scene : Brosur_Test
Component : BrosurTarget
This is the code for virtual button actions.
In this project, the virtual button linked to the 360 view scene
*/
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using Vuforia;
public class vButtonScript : MonoBehaviour, IVirtualButtonEventHandler {
private GameObject vButton;
// Use this for initialization
void Start () {
vButton = GameObject.Find("vButton360");
vButton.GetComponent<VirtualButtonBehaviour>().RegisterEventHandler(this);
}
public void OnButtonPressed (VirtualButtonAbstractBehaviour vb)
{
SceneManager.LoadScene("360_Test", LoadSceneMode.Single);
}
public void OnButtonReleased(VirtualButtonAbstractBehaviour vb)
{
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment