﻿//----------------------------------------------------------------------------------
// GVRNavi | Garpix Virtual Reality Navigation
// Copyright (c) 2017 Garpix Ltd.
//
// Plugin Homepage: https://gvrnavi.garpix.com
// Author Homepage: https://garpix.com
// Support: support@garpix.com
// License: Asset Store Terms of Service and EULA
// License URI: See LICENSE file in the project root for full license information.
//----------------------------------------------------------------------------------

using UnityEngine;
using GVRNavi;

public class VRExampleManager : MonoBehaviour
{
    #region variables

    public Light lisghtSun;
    public VRScrollBarGaze scrollBarSun;
    public VRToggleGaze toggleSun;
    public VRPlayerController player;

    #endregion

    
    void Start ()
    {
        if (scrollBarSun != null)
            scrollBarSun.OnValueChanged.AddListener(OnScrollBarSunValueChanged);
        if (toggleSun != null)
            toggleSun.OnValueChanged.AddListener(OnToggleSunValueChanged);

    }

    void OnDestroy()
    {
        if (scrollBarSun != null)
            scrollBarSun.OnValueChanged.RemoveListener(OnScrollBarSunValueChanged);
        if (toggleSun != null)
            toggleSun.OnValueChanged.RemoveListener(OnToggleSunValueChanged);
    }

    public void SetPlayerToDefaultPosition()
    {
        player.transform.localPosition = new Vector3(0f, 0f, -8f);
    }

    private void OnScrollBarSunValueChanged(VRObjectGaze gaze, float f)
    {
        if (lisghtSun != null)
        {
            Vector3 v = lisghtSun.transform.rotation.eulerAngles;
            v.y = Mathf.Lerp(-120f, 40f, f);
            lisghtSun.transform.rotation = Quaternion.Euler(v);
        }
    }

    private void OnToggleSunValueChanged(VRObjectGaze gaze, bool b)
    {
        if (lisghtSun != null)
            lisghtSun.enabled = !b;
    }
}