Portal belajar membuat aplikasi Augmented Reality dan Virtual Reality

Minggu, 14 Oktober 2018

Login with Facebook

20.03 Posted by Dicky Rachmat Iskandar No comments
using UnityEngine; using UnityEngine.UI; using System.Collections; using System.Collections.Generic; using Facebook.Unity; public class FBscript : MonoBehaviour { public GameObject DialogLoggedIn; public GameObject DialogLoggedOut; public GameObject DialogUsername; public GameObject DialogProfilePic; void Awake() { FB.Init (SetInit, OnHideUnity); } void SetInit() { if (FB.IsLoggedIn) { Debug.Log ("FB is logged in"); } else { Debug.Log ("FB is not logged in"); } DealWithFBMenus (FB.IsLoggedIn); } void OnHideUnity(bool isGameShown) { if (!isGameShown) { Time.timeScale = 0; } else { Time.timeScale = 1; } } public void FBlogin() { List<string> permissions = new List<string> (); permissions.Add ("public_profile"); FB.LogInWithReadPermissions (permissions, AuthCallBack); } void AuthCallBack(IResult result) { if (result.Error != null) { Debug.Log (result.Error); } else { if (FB.IsLoggedIn) { Debug.Log ("FB is logged in"); } else { Debug.Log ("FB is not logged in"); } DealWithFBMenus (FB.IsLoggedIn); } } void DealWithFBMenus(bool isLoggedIn) { if (isLoggedIn) { DialogLoggedIn.SetActive (true); DialogLoggedOut.SetActive (false); FB.API ("/me?fields=first_name", HttpMethod.GET, DisplayUsername); FB.API ("/me/picture?type=square&height=128&width=128", HttpMethod.GET, DisplayProfilePic); } else { DialogLoggedIn.SetActive (false); DialogLoggedOut.SetActive (true); } } void DisplayUsername(IResult result) { Text UserName = DialogUsername.GetComponent<Text> (); if (result.Error == null) { UserName.text = "Hi there, " + result.ResultDictionary ["first_name"]; } else { Debug.Log (result.Error); } } void DisplayProfilePic(IGraphResult result) { if (result.Texture != null) { Image ProfilePic = DialogProfilePic.GetComponent<Image> (); ProfilePic.sprite = Sprite.Create (result.Texture, new Rect (0, 0, 128, 128), new Vector2 ()); } } }

Rabu, 19 September 2018

AssetBundle Loader

01.06 Posted by Dicky Rachmat Iskandar No comments
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;
using UnityEngine.Video;

public class Loader : MonoBehaviour {
    
    public string assetBundleName;
    public GameObject videoPlane;
    public GameObject imagePlane;

    // Use this for initialization
    void Start () {
        //StartCoroutine(InstantiateVideoClip());
    }
    
    // Update is called once per frame
    void Update () {
        CloudContentLoader loader = GameObject.Find("System").GetComponent<CloudContentLoader>();
        if (loader.IsDone)
        {
            if (Input.GetKeyDown("space"))
            {
                AssetBundle bundle = loader.GetAssetBundleByKey(assetBundleName);
                PlayVideoClip(bundle.LoadAsset<VideoClip>("Video"));
                DisplayImageFile(bundle.LoadAsset<Texture2D>("Image"));

                Debug.Log("[Loader] " + assetBundleName + " is loaded");
            }
        }
    }
    

    void PlayVideoClip(VideoClip videoClip)
    {
        var VideoPlayer = videoPlane.GetComponent<VideoPlayer>();
        VideoPlayer.clip = videoClip;
        VideoPlayer.Play();
    }

    void DisplayImageFile(Texture2D image)
    {
        var material = imagePlane.GetComponent<Renderer>().material;
        material.SetTexture("_MainTex", image);
    }
}

Kamis, 05 Juli 2018

Android Double Click Escape to Exit

20.59 Posted by Dicky Rachmat Iskandar No comments
public GameObject quitobject;
private bool clickedBefore = false;

void Update()
{
    //Check input for the first time
    if (Input.GetKeyDown(KeyCode.Escape) && !clickedBefore)
    {
        Debug.Log("Back Button pressed for the first time");
        //Set to false so that this input is not checked again. It will be checked in the coroutine function instead
        clickedBefore = true;

        //Activate Quit Object
        quitobject.SetActive(true);

        //Start quit timer
        StartCoroutine(quitingTimer());
    }
}

IEnumerator quitingTimer()
{
    //Wait for a frame so that Input.GetKeyDown is no longer true
    yield return null;

    //3 seconds timer
    const float timerTime = 3f;
    float counter = 0;

    while (counter < timerTime)
    {
        //Increment counter while it is < timer time(3)
        counter += Time.deltaTime;

        //Check if Input is pressed again while timer is running then quit/exit if is
        if (Input.GetKeyDown(KeyCode.Escape))
        {
            Debug.Log("Back Button pressed for the second time. EXITING.....");
            Quit();
        }

        //Wait for a frame so that Unity does not freeze
        yield return null;
    }

    Debug.Log("Timer finished...Back Button was NOT pressed for the second time within: '" + timerTime + "' seconds");

    //Timer has finished and NO QUIT(NO second press) so deactivate
    quitobject.SetActive(false);
    //Reset clickedBefore so that Input can be checked again in the Update function
    clickedBefore = false;
}

void Quit()
{
    #if UNITY_EDITOR
    UnityEditor.EditorApplication.isPlaying = false;
    #else
    //Application.Quit();
    System.Diagnostics.Process.GetCurrentProcess().Kill();
    #endif
}
//Wait for a frame so that Unity does not freeze yield return null; } Debug.Log("Timer finished...Back Button was NOT pressed for the second time within: '" + timerTime + "' seconds"); //Timer has finished and NO QUIT(NO second press) so deactivate quitobject.SetActive(false); //Reset clickedBefore so that Input can be checked again in the Update function clickedBefore = false; } void Quit() { #if UNITY_EDITOR UnityEditor.EditorApplication.isPlaying = false; #else //Application.Quit(); System.Diagnostics.Process.GetCurrentProcess().Kill(); #endif }