Portal belajar membuat aplikasi Augmented Reality dan Virtual Reality

Rabu, 23 November 2016

Rotation GameObject by Touch

23.43 Posted by Dicky Rachmat Iskandar No comments

using UnityEngine;
using System.Collections;

public class Rotasi : MonoBehaviour
{
 
    float rotSpeed = 1000;

    void OnMouseDrag()
    {
            float rotY = Input.GetAxis("Mouse X") * rotSpeed * Mathf.Deg2Rad;
            transform.Rotate(0, 0, -rotY, Space.Self);
             float rotY = Input.GetAxis("Mouse Y") * rotSpeed * Mathf.Deg2Rad;
            transform.Rotate(0, -rotY, 0, Space.Self); 
    }

}

Vuforia Camera Swap

23.37 Posted by Dicky Rachmat Iskandar No comments
using UnityEngine;
using System.Collections;
using Vuforia;
using UnityEngine.UI;
using System.Collections.Generic;
public class SRSw : MonoBehaviour {
public bool swap = false;
public void Swapper( GameObject swapactive)
    {
        if (swap == false)
        {
            // Stop tracker
            //TrackerManager.Instance.GetTracker(Tracker.Type.IMAGE_TRACKER).Stop();
            TrackerManager.Instance.GetTracker<ObjectTracker>().Stop();
            // Stop and deinit camera
            CameraDevice.Instance.Stop();
            Everyplay.PauseRecording();
            CameraDevice.Instance.Deinit();

            // Reinit and restart camera, selecting front camera
            CameraDevice.Instance.Init(CameraDevice.CameraDirection.CAMERA_FRONT);
            Everyplay.ResumeRecording();
            CameraDevice.Instance.Start();

            // Restart tracker
            //TrackerManager.Instance.GetTracker(Tracker.Type.IMAGE_TRACKER).Start();
            TrackerManager.Instance.GetTracker<ObjectTracker>().Start();
            swapactive.SetActive(true);
            swap = true;
        }
        else
        {
            // Stop tracker
            // TrackerManager.Instance.GetTracker(Tracker.Type.IMAGE_TRACKER).Stop();
            TrackerManager.Instance.GetTracker<ObjectTracker>().Stop();
            // Stop and deinit camera
            CameraDevice.Instance.Stop();
            Everyplay.PauseRecording();
            CameraDevice.Instance.Deinit();

            // Reinit and restart camera, selecting back camera
            CameraDevice.Instance.Init(CameraDevice.CameraDirection.CAMERA_BACK);
            Everyplay.ResumeRecording();
            CameraDevice.Instance.Start();

            // Restart tracker
            // TrackerManager.Instance.GetTracker(Tracker.Type.IMAGE_TRACKER).Start();
            TrackerManager.Instance.GetTracker<ObjectTracker>().Start();
            swapactive.SetActive(false);
            swap = false;
        }
    }
 
}
}

Snap Page

23.34 Posted by Dicky Rachmat Iskandar No comments

using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using UnityEngine.EventSystems;
using System.Collections.Generic;
public class HoloChoiceMenu : MonoBehaviour {
    public Scrollbar myscrollbar;
    public List<Button> Holo;
    public List<Button> ico;
    public bool[] holom;
    public Sprite EnableEye, DisableEye, EnableEar, DisableEar, EnableBrain, DisableBrain, EnableSkin, DisableSkin, EnableResp, DisableResp;

    void Start() {
        holom = new bool[5];
        for(int i=0;i<holom.Length;i++){
            holom [i] = false;
        }
    }

    void Update() {
        if (holom[0])
        {
            myscrollbar.GetComponent<Scrollbar>().value = Mathf.Lerp(myscrollbar.GetComponent<Scrollbar>().value, 0.25f, 0.2f);

        }

        if (holom[1])
        {
            myscrollbar.GetComponent<Scrollbar>().value = Mathf.Lerp(myscrollbar.GetComponent<Scrollbar>().value, 0.50f, 0.2f);
        }

        if (holom[2])
        {
            myscrollbar.GetComponent<Scrollbar>().value = Mathf.Lerp(myscrollbar.GetComponent<Scrollbar>().value, 0.75f, 0.2f);
        }

        if (holom[3])
        {
            myscrollbar.GetComponent<Scrollbar>().value = Mathf.Lerp(myscrollbar.GetComponent<Scrollbar>().value, 1, 0.2f);
        }

        if (holom[4])
        {
            myscrollbar.GetComponent<Scrollbar>().value = Mathf.Lerp(myscrollbar.GetComponent<Scrollbar>().value, 0, 0.2f);
        }

        //=========================================================================

        if (myscrollbar.GetComponent<Scrollbar>().value <= 0.13f && myscrollbar.GetComponent<Scrollbar>().value >= 0)
        {
            Holo[0].transform.localScale = Vector2.Lerp(Holo[0].transform.localScale, new Vector2(1.5f, 1.5f), 0.1f);
            ico[0].GetComponent<Image>().sprite= EnableResp;
        }
        else
        {
            Holo[0].transform.localScale = Vector2.Lerp(Holo[0].transform.localScale, new Vector2(1, 1), 0.1f);
            ico[0].GetComponent<Image>().sprite=DisableResp;
        }

         if (myscrollbar.GetComponent<Scrollbar>().value < 0.26f && myscrollbar.GetComponent<Scrollbar>().value > 0.18f)
        {
            Holo[1].transform.localScale = Vector2.Lerp(Holo[1].transform.localScale, new Vector2(1.5f, 1.5f), 0.1f);
            ico[1].GetComponent<Image>().sprite = EnableEye;
        }
         else
        {
            Holo[1].transform.localScale = Vector2.Lerp(Holo[1].transform.localScale, new Vector2(1, 1), 0.1f);
            ico[1].GetComponent<Image>().sprite = DisableEye;
        }
        if (myscrollbar.GetComponent<Scrollbar>().value < 0.52f && myscrollbar.GetComponent<Scrollbar>().value >= 0.36f)
        {
            Holo[2].transform.localScale = Vector2.Lerp(Holo[2].transform.localScale, new Vector2(1.5f, 1.5f), 0.1f);
            ico[2].GetComponent<Image>().sprite = EnableBrain;
        }
        else
        {
            Holo[2].transform.localScale = Vector2.Lerp(Holo[2].transform.localScale, new Vector2(1, 1), 0.1f);
            ico[2].GetComponent<Image>().sprite = DisableBrain;
        }
        if (myscrollbar.GetComponent<Scrollbar>().value < 0.76f && myscrollbar.GetComponent<Scrollbar>().value > 0.62f)
        {
            Holo[3].transform.localScale = Vector2.Lerp(Holo[3].transform.localScale, new Vector2(1.5f, 1.5f), 0.1f);
            ico[3].GetComponent<Image>().sprite = EnableEar;
        }
        else
        {
            Holo[3].transform.localScale = Vector2.Lerp(Holo[3].transform.localScale, new Vector2(1, 1), 0.1f);
            ico[3].GetComponent<Image>().sprite = DisableEar;
        }
        if (myscrollbar.GetComponent<Scrollbar>().value <= 1f && myscrollbar.GetComponent<Scrollbar>().value >0.86f)
        {
            Holo[4].transform.localScale = Vector2.Lerp(Holo[4].transform.localScale, new Vector2(1.5f, 1.5f), 0.1f);
            ico[4].GetComponent<Image>().sprite= EnableSkin;
        }
        else
        {
            Holo[4].transform.localScale = Vector2.Lerp(Holo[4].transform.localScale, new Vector2(1, 1), 0.1f);
            ico[4].GetComponent<Image>().sprite= DisableSkin;
        }



    }


    public void nexto()
    {
        for(int i=0;i<holom.Length;i++){
            holom [i] = false;
        }
        if (myscrollbar.GetComponent<Scrollbar>().value <= 0.20f && myscrollbar.GetComponent<Scrollbar>().value >= 0)
        {
           
            holom [0] = true;
            StartCoroutine(enableslide());
        }
        else if (myscrollbar.GetComponent<Scrollbar>().value < 0.40f && myscrollbar.GetComponent<Scrollbar>().value > 0.20f)
        {
           
            holom [1] = true;
            StartCoroutine(enableslide());
        }
        else if (myscrollbar.GetComponent<Scrollbar>().value < 0.65f && myscrollbar.GetComponent<Scrollbar>().value >= 0.40f)
        {
           
            holom [2] = true;
            StartCoroutine(enableslide());
        }
        else if (myscrollbar.GetComponent<Scrollbar>().value < 0.95f && myscrollbar.GetComponent<Scrollbar>().value > 0.65f)
        {
           
            holom [3] = true;
            StartCoroutine(enableslide());
        }
    }

    public void prevto()
    {
        for(int i=0;i<holom.Length;i++){
            holom [i] = false;
        }
        if (myscrollbar.GetComponent<Scrollbar>().value <= 1 && myscrollbar.GetComponent<Scrollbar>().value > 0.76f)
        {
           
            holom [2] = true;
            StartCoroutine(enableslide());
        }
        else if (myscrollbar.GetComponent<Scrollbar>().value < 0.76f && myscrollbar.GetComponent<Scrollbar>().value > 0.52f)
        {
           
            holom [1] = true;
            StartCoroutine(enableslide());
        }
        else if (myscrollbar.GetComponent<Scrollbar>().value < 0.52f && myscrollbar.GetComponent<Scrollbar>().value > 0.27f)
        {
           
            holom [0] = true;
            StartCoroutine(enableslide());
        }
        else if (myscrollbar.GetComponent<Scrollbar>().value < 0.27f && myscrollbar.GetComponent<Scrollbar>().value > 0)
        {
           
            holom [4] = true;
            StartCoroutine(enableslide());
        }

    }

    public IEnumerator enableslide ()
    {
        yield return new WaitForSeconds(0.7f);
        for(int i=0;i<holom.Length;i++){
            holom [i] = false;
        }
    }
}

Vuforia Auto Focus

23.31 Posted by Dicky Rachmat Iskandar No comments

using UnityEngine;
using System.Collections;
using Vuforia;
public class autofocus : MonoBehaviour {

    // Use this for initialization
    void Start () {
        VuforiaBehaviour.Instance.RegisterVuforiaStartedCallback(OnVuforiaStarted);
        VuforiaBehaviour.Instance.RegisterOnPauseCallback(OnPaused);
    }

    private void OnVuforiaStarted()
    {
        CameraDevice.Instance.SetFocusMode(CameraDevice.FocusMode.FOCUS_MODE_CONTINUOUSAUTO );
    }

    private void OnPaused(bool paused)
    {
        if (!paused)
        {
            // resumed
            // Set again autofocus mode when app is resumed
            CameraDevice.Instance.SetFocusMode (CameraDevice.FocusMode.FOCUS_MODE_CONTINUOUSAUTO);
        }
    }   
    // Update is called once per frame
    void Update ()
    {
        bool focusModeSet = CameraDevice.Instance.SetFocusMode(CameraDevice.FocusMode.FOCUS_MODE_CONTINUOUSAUTO);
        if (!focusModeSet)
        {
            Debug.Log("Failed to set focus mode (unsupported mode).");
        }
    }
}

Parameter Animator Handler

23.29 Posted by Dicky Rachmat Iskandar No comments
public Animator contentPanel;
    public Animator sidemenu;


    public void Slidding()
    {
        bool isHidden = contentPanel.GetBool("isHidden");
        contentPanel.SetBool("isHidden", !isHidden);
    }


//----- or


    public void sideslide()
    {
        bool isHidden = sidemenu.GetBool("isHidden");
        if (isHidden)
        {
            sidemenu.SetBool("isHidden", !isHidden);
        }
    }
 

Draw Line in Runtime Unity [1]

21.51 Posted by Dicky Rachmat Iskandar No comments
using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class testaja : MonoBehaviour {
    private LineRenderer lineRenderer;
    private float counter;
    private float dist;

    public Transform origin;
    public Transform destination;

    public float lineDrawSpeed = 6f;

    void Start()
    {
        lineRenderer = GetComponent<LineRenderer> ();
        lineRenderer.SetPosition (0, origin.position);
        lineRenderer.SetWidth (.45f, .45f);

        dist = Vector3.Distance (origin.position,destination.position);

    }

    void Update()
    {
        lineRenderer.SetPosition (0,this.transform.position);
        lineRenderer.SetPosition (1,destination.position);

    }
}
 

Draw Line in Runtime Unity3D

17.44 Posted by Dicky Rachmat Iskandar No comments
using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class testaja : MonoBehaviour {
    public Material lineMat;

    public float radius = 0.05f;

    // Connect all of the `points` to the `mainPoint`
    public GameObject mainPoint;
    public GameObject[] points;

    // Fill in this with the default Unity Cylinder mesh
    // We will account for the cylinder pivot/origin being in the middle.
    public Mesh cylinderMesh;


    GameObject[] ringGameObjects;

    // Use this for initialization
    void Start () {
        this.ringGameObjects = new GameObject[points.Length];
        //this.connectingRings = new ProceduralRing[points.Length];
        for(int i = 0; i < points.Length; i++) {
            // Make a gameobject that we will put the ring on
            // And then put it as a child on the gameobject that has this Command and Control script
            this.ringGameObjects[i] = new GameObject();
            this.ringGameObjects[i].name = "Connecting ring #" + i;
            this.ringGameObjects[i].transform.parent = this.gameObject.transform;

            // We make a offset gameobject to counteract the default cylindermesh pivot/origin being in the middle
            GameObject ringOffsetCylinderMeshObject = new GameObject();
            ringOffsetCylinderMeshObject.transform.parent = this.ringGameObjects[i].transform;

            // Offset the cylinder so that the pivot/origin is at the bottom in relation to the outer ring gameobject.
            ringOffsetCylinderMeshObject.transform.localPosition = new Vector3(0f, 1f, 0f);
            // Set the radius
            ringOffsetCylinderMeshObject.transform.localScale = new Vector3(radius, 1f, radius);

            // Create the the Mesh and renderer to show the connecting ring
            MeshFilter ringMesh = ringOffsetCylinderMeshObject.AddComponent<MeshFilter>();
            ringMesh.mesh = this.cylinderMesh;

            MeshRenderer ringRenderer = ringOffsetCylinderMeshObject.AddComponent<MeshRenderer>();
            ringRenderer.material = lineMat;

        }
    }

    // Update is called once per frame
    void Update () {
        for(int i = 0; i < points.Length; i++) {
            // Move the ring to the point
            this.ringGameObjects[i].transform.position = this.points[i].transform.position;

            // Match the scale to the distance
            float cylinderDistance = 0.5f*Vector3.Distance(this.points[i].transform.position, this.mainPoint.transform.position);
            this.ringGameObjects[i].transform.localScale = new Vector3(this.ringGameObjects[i].transform.localScale.x, cylinderDistance, this.ringGameObjects[i].transform.localScale.z);

            // Make the cylinder look at the main point.
            // Since the cylinder is pointing up(y) and the forward is z, we need to offset by 90 degrees.
            this.ringGameObjects[i].transform.LookAt(this.mainPoint.transform, Vector3.up);
            this.ringGameObjects[i].transform.rotation *= Quaternion.Euler(90, 0, 0);
        }
    }
}

Random Array Index untuk Kuis

17.23 Posted by Dicky Rachmat Iskandar No comments
using UnityEngine;
using System.Collections;

public class testaja : MonoBehaviour {
    public string [] puzzleskeletal;
    public string akua;
    public int integer = 0;
    // Use this for initialization
    void Start () {
        for (int t = 0; t < puzzleskeletal.Length; t++ )
        {
            string tmp = puzzleskeletal[t];
            int r = Random.Range(t, puzzleskeletal.Length);
            puzzleskeletal[t] = puzzleskeletal[r];
            puzzleskeletal[r] = tmp;
            akua = puzzleskeletal [integer];
        }
    }
   
    // Update is called once per frame
    void Update () {
       
    }

    public void ke()
    {
        integer++;
        akua = puzzleskeletal [integer];
    }
}
 

Kamis, 17 November 2016

Movie Texture Unity 5

19.19 Posted by Dicky Rachmat Iskandar No comments
using UnityEngine;
using System.Collections;
[RequireComponent(typeof(AudioSource))]

public class movtex : MonoBehaviour {
public MovieTexture myMovie;

// Use this for initialization
void Start () {
Debug.Log ("start intro");
GetComponent<Renderer>().material.mainTexture = myMovie;// Get movie
myMovie.Play ();// play movie
}
void Update(){
myMovie.loop =true;
}
}