Files
QuestAppLauncher/Assets/Scripts/Config.cs
tverona1 3eb5fd2198 Preliminary support for tabs and also fix an issue with scroll view collider
- Added preliminary support for tabs: Added config support for "categoryType" specifying "none" or "auto". None means no tabs. Auto means that we create 3 tabs - Quest, Go/GearVR and 2D. These apps types are distinguished based on package information.
- Added support in UI for showing / hiding 2D apps.
- Fixed an issue with scroll view collider: Looks like Unity UI scroll view object does not interact very well in a VR environment. This one was a doozy. I noticed, although the scroll view masks UI that falls outside its rectangle (as it should), it does not suppress colliders. This means that it's possible to interact with colliders that get scrolled above the scroll view (i.e. like clicking on a cell to launch an app when that cell is outside the scroll view). The bigger problem is that this interfered with the tabs, which are above the scroll view. After contemplating several solutions, I ended up with a simple but effective one:
            // To fix this issue, we cast a ray from current pointer to the scroll view's box collider.
            // If we get a hit, it means we're inside the scroll view - so we enable all the children box
            // colliders, which will behave as expected.
            // If we do not get a hit, it means that we're outside the scroll view - so we disable all the children
            // box colliders, which addresses the issue above.
2019-07-27 16:48:07 -07:00

92 lines
2.7 KiB
C#

using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEngine;
namespace QuestAppLauncher
{
/// <summary>
/// Root config object
/// </summary>
[Serializable]
public class Config
{
// Supported category types
public const string Category_None = "none";
public const string Category_Auto = "auto";
public const string Category_Custom = "custom";
/// <summary>
/// Grid size
/// </summary>
[Serializable]
public class GridSize
{
public int rows = 3;
public int cols = 3;
}
public GridSize gridSize = new GridSize();
public bool show2D = false;
// Category types: "none", "automatic", "custom"
public string categoryType = Category_Auto;
}
/// <summary>
/// Class responsible for loading / saving config into a config.json file.
/// </summary>
public class ConfigPersistence
{
// File name of app name overrides
const string ConfigFileName = "config.json";
/// <summary>
/// Load config from file
/// </summary>
/// <param name="config">Config object that will be overwritten</param>
static public void LoadConfig(Config config)
{
var configFilePath = Path.Combine(UnityEngine.Application.persistentDataPath, ConfigFileName);
if (File.Exists(configFilePath))
{
Debug.Log("Found config file: " + configFilePath);
var jsonConfig = File.ReadAllText(configFilePath);
try
{
JsonUtility.FromJsonOverwrite(jsonConfig, config);
}
catch (Exception e)
{
Debug.Log(string.Format("Failed to read config: {0}", e.Message));
}
}
else
{
Debug.Log("Did not find config file: " + configFilePath);
}
}
/// <summary>
/// Save config to a file
/// </summary>
/// <param name="config"></param>
static public void SaveConfig(Config config)
{
var configFilePath = Path.Combine(UnityEngine.Application.persistentDataPath, ConfigFileName);
Debug.Log("Saving config file: " + configFilePath);
try
{
File.WriteAllText(configFilePath, JsonUtility.ToJson(config, true));
}
catch (Exception e)
{
Debug.Log(string.Format("Failed to read config: {0}", e.Message));
}
}
}
}