﻿//----------------------------------------------------------------------------------
// 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;

[RequireComponent(typeof(MeshRenderer))]
public class VRCube : VRObjectGaze
{
    #region variables

    public Vector2 rangeX, rangeY, rangeZ;

    private Vector3 _defaultPosition;
    private MeshRenderer _mesh;

    #endregion


    protected override void Start()
    {
        base.Start();
        _defaultPosition = transform.position;
        _mesh = GetComponent<MeshRenderer>();
    }

    public override void OnGazeEnter()
    {
        base.OnGazeEnter();
        if (_mesh != null)
            _mesh.material.color = Color.green;
    }

    public override void OnGazeExit()
    {
        base.OnGazeExit();
        if (_mesh != null)
            _mesh.material.color = Color.red;
    }

    public void SetToDefaultPosition()
    {
        transform.position = _defaultPosition;
    }

    public void SetToRandomPosition()
    {
        transform.localPosition = new Vector3(
            Random.Range(rangeX.x, rangeX.y),
            Random.Range(rangeY.x, rangeY.y),
            Random.Range(rangeZ.x, rangeZ.y));
    }
}