Skip to content

Commit 51e992f

Browse files
author
lawwong
committed
Update to v1.12.2
* New Features - Add ControllerButtonMask to able to mask out multiple buttin input simultaneously ```csharp // return true if right controller trigger or pad button pressed ViveInput.GetAnyPress(HandRole.RightHand, new ControllerButtonMask(ControllerButton.Trigger, ControllerButton.Pad)) // return true if both right controller trigger and pad button pressed ViveInput.GetAllPress(HandRole.RightHand, new ControllerButtonMask(ControllerButton.Trigger, ControllerButton.Pad)) ``` * Bug Fixes - Fix error when Wave Essence RenderModel module is installed - Fix teleport in wrong height for some device in example 6
2 parents dfcd064 + 4b39ba6 commit 51e992f

26 files changed

+775
-411
lines changed

Assets/HTC.UnityPlugin/UPMRegistryTool/Editor/Resources/RegistryToolSettings.asset

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ MonoBehaviour:
1313
m_Name: RegistryToolSettings
1414
m_EditorClassIdentifier:
1515
ProjectManifestPath: Packages/manifest.json
16-
LicenseResourcePath: LICENSE
17-
ViveRegistry:
18-
name: VIVE
19-
url: https://npm-registry.vive.com
20-
scopes:
16+
AutoCheckEnabled: 1
17+
Registry:
18+
Name: VIVE
19+
Url: https://npm-registry.vive.com
20+
Scopes:
2121
- com.htc.upm

Assets/HTC.UnityPlugin/UPMRegistryTool/Editor/Resources/RegistryToolSettings.asset.meta

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 22 additions & 218 deletions
Original file line numberDiff line numberDiff line change
@@ -1,242 +1,46 @@
1-
#pragma warning disable 0649
2-
using HTC.UnityPlugin.UPMRegistryTool.SimpleJSON;
1+
#if UNITY_2018_1_OR_NEWER
2+
using HTC.UnityPlugin.UPMRegistryTool.Editor.Utils;
33
using System;
4-
using System.Collections.Generic;
5-
using System.IO;
64
using System.Text.RegularExpressions;
75
using UnityEngine;
86

9-
namespace HTC.UnityPlugin.UPMRegistryTool
7+
namespace HTC.UnityPlugin.UPMRegistryTool.Editor.Configs
108
{
11-
[CreateAssetMenu(menuName = "RegistryToolSettings", fileName = "RegistryToolSettings")]
129
public class RegistryToolSettings : ScriptableObject
1310
{
14-
[Serializable]
15-
public struct ScopedRegistry
16-
{
17-
public string name;
18-
public string url;
19-
public List<string> scopes;
20-
21-
public bool Equals(ScopedRegistry otherInfo)
22-
{
23-
if (name != otherInfo.name || url != otherInfo.url) { return false; }
24-
25-
if (scopes == null || otherInfo.scopes == null)
26-
{
27-
if (scopes == null && otherInfo.scopes == null) { return true; }
28-
return false;
29-
}
30-
31-
if (scopes.Count != otherInfo.scopes.Count) { return false; }
32-
33-
for (int i = 0, imax = scopes.Count; i < imax; i++)
34-
{
35-
if (scopes[i] != otherInfo.scopes[i])
36-
{
37-
return false;
38-
}
39-
}
40-
41-
return true;
42-
}
43-
}
44-
45-
[SerializeField]
46-
public string ProjectManifestPath;
47-
[SerializeField]
48-
public string LicenseResourcePath;
49-
[SerializeField]
50-
public ScopedRegistry ViveRegistry;
51-
52-
[NonSerialized]
53-
public string ViveRegistryHost;
54-
[NonSerialized]
55-
public int ViveRegistryPort;
56-
5711
private const string RESOURCES_PATH = "RegistryToolSettings";
58-
private static RegistryToolSettings instance;
59-
60-
public static RegistryToolSettings Instance
61-
{
62-
get
63-
{
64-
if (instance == null)
65-
{
66-
instance = Resources.Load<RegistryToolSettings>(RESOURCES_PATH);
67-
68-
if (instance != null)
69-
{
70-
var match = Regex.Match(instance.ViveRegistry.url, @"^https?:\/\/(.+?)(?::(\d+))?\/?$");
71-
instance.ViveRegistryHost = match.Success && match.Groups.Count > 1 ? match.Groups[1].Value : default(string);
72-
73-
if (!int.TryParse(match.Groups[2].Value, out instance.ViveRegistryPort)) { instance.ViveRegistryPort = 80; }
74-
}
75-
else
76-
{
77-
Debug.LogErrorFormat("RegistrySettings.asset not found. ({0})", RESOURCES_PATH);
78-
}
79-
}
80-
81-
return instance;
82-
}
83-
}
84-
85-
public static bool IsRegistryExists(ScopedRegistry reg)
86-
{
87-
JSONNode manifestNode;
88-
if (!LoadManifestNode(out manifestNode)) { return false; }
89-
90-
return IsRegistryExists(manifestNode, reg);
91-
}
92-
93-
public static void AddRegistry(ScopedRegistry reg)
94-
{
95-
JSONNode manifestNode;
96-
if (!LoadManifestNode(out manifestNode)) { return; }
97-
98-
int nameMatchIndex;
99-
if (!IsRegistryExists(manifestNode, reg, out nameMatchIndex))
100-
{
101-
if (nameMatchIndex < 0)
102-
{
103-
AddRegistry(EnsureRegistriesNode(manifestNode), reg);
104-
}
105-
else
106-
{
107-
AddRegistryAt(EnsureRegistriesNode(manifestNode), reg, nameMatchIndex);
108-
}
109-
}
110-
111-
SaveManifestNode(manifestNode);
112-
}
113-
114-
public static void RemoveRegistry(ScopedRegistry reg)
115-
{
116-
JSONNode manifestNode;
117-
if (!LoadManifestNode(out manifestNode)) { return; }
118-
119-
int nameMatchIndex;
120-
IsRegistryExists(manifestNode, reg, out nameMatchIndex);
121-
if (nameMatchIndex > 0)
122-
{
123-
RemoveRegistryAt(manifestNode, nameMatchIndex);
124-
}
125-
126-
SaveManifestNode(manifestNode);
127-
}
128-
129-
private static bool IsRegistryExists(JSONNode manifestNode, ScopedRegistry reg)
130-
{
131-
int i;
132-
return IsRegistryExists(manifestNode, reg, out i);
133-
}
134-
135-
private static bool IsRegistryExists(JSONNode manifestNode, ScopedRegistry reg, out int index)
136-
{
137-
index = -1;
138-
var regsNode = manifestNode["scopedRegistries"];
139-
140-
if (!regsNode.IsArray) { return false; }
141-
if (regsNode.Count == 0) { return false; }
14212

143-
for (int i = 0, imax = regsNode.Count; i < imax; ++i)
144-
{
145-
var regNode = regsNode[i];
146-
var nameNode = regNode["name"];
147-
var urlNode = regNode["url"];
148-
var scopesNode = regNode["scopes"];
149-
150-
if (!nameNode.IsString || nameNode.Value != reg.name) { continue; }
151-
index = i;
152-
153-
if (!urlNode.IsString || urlNode.Value != reg.url) { break; }
154-
if (!scopesNode.IsArray) { break; }
155-
if (scopesNode.Count != (reg.scopes == null ? 0 : reg.scopes.Count)) { break; }
156-
157-
var allMatch = true;
158-
for (int j = scopesNode.Count - 1; j >= 0; --j)
159-
{
160-
var scopeNode = scopesNode[j];
161-
if (!scopeNode.IsString) { allMatch = false; break; }
162-
if (scopeNode.Value != reg.scopes[j]) { allMatch = false; break; }
163-
}
164-
return allMatch;
165-
}
13+
private static RegistryToolSettings PrivateInstance;
16614

167-
return false;
168-
}
169-
170-
private static JSONArray EnsureRegistriesNode(JSONNode manifestNode)
171-
{
172-
var regsNode = manifestNode["scopedRegistries"];
173-
if (!regsNode.IsArray)
174-
{
175-
manifestNode.Add("scopedRegistries", regsNode = new JSONArray());
176-
}
177-
return regsNode.AsArray;
178-
}
15+
public string ProjectManifestPath;
16+
public RegistryInfo Registry;
17917

180-
private static void AddRegistry(JSONArray regsNode, ScopedRegistry reg)
181-
{
182-
if (regsNode.Count == 0) { regsNode.Add(new JSONObject()); }
183-
AddRegistryAt(regsNode, reg, regsNode.Count - 1);
184-
}
18+
[NonSerialized] public string RegistryHost;
19+
[NonSerialized] public int RegistryPort;
18520

186-
private static void AddRegistryAt(JSONArray regsNode, ScopedRegistry reg, int index)
21+
public static RegistryToolSettings Instance()
18722
{
188-
var regNode = regsNode[index];
189-
var nameNode = regNode["name"];
190-
var urlNode = regNode["url"];
191-
var scopesNode = regNode["scopes"];
192-
193-
if (nameNode.IsString) { nameNode.Value = reg.name; }
194-
else { regNode.Add("name", new JSONString(reg.name)); }
195-
196-
if (urlNode.IsString) { urlNode.Value = reg.url; }
197-
else { regNode.Add("url", new JSONString(reg.url)); }
198-
199-
if (!scopesNode.IsArray) { regNode.Add("scopes", scopesNode = new JSONArray()); }
200-
201-
int i = 0;
202-
foreach (var scope in reg.scopes)
23+
if (PrivateInstance == null)
20324
{
204-
var scopeNode = scopesNode[i];
205-
if (scopeNode.IsString) { scopeNode.Value = scope; }
206-
else { scopesNode[i] = new JSONString(scope); }
207-
++i;
25+
PrivateInstance = Resources.Load<RegistryToolSettings>(RESOURCES_PATH);
26+
PrivateInstance.Init();
20827
}
20928

210-
while (scopesNode.Count > i) { scopesNode.Remove(scopesNode.Count - 1); }
29+
return PrivateInstance;
21130
}
21231

213-
private static void RemoveRegistryAt(JSONNode manifestNode, int index)
32+
private void Init()
21433
{
215-
manifestNode["scopedRegistries"].Remove(index);
216-
}
217-
218-
private static bool LoadManifestNode(out JSONNode node)
219-
{
220-
node = default(JSONNode);
34+
Match match = Regex.Match(Registry.Url, @"^https?:\/\/(.+?)(?::(\d+))?\/?$");
35+
RegistryHost = match.Groups[1].Value;
22136

222-
if (Instance == null) { return false; }
223-
224-
var json = File.ReadAllText(instance.ProjectManifestPath);
225-
node = JSON.Parse(json);
226-
if (!node.IsObject)
37+
int port = 0;
38+
RegistryPort = 80;
39+
if (int.TryParse(match.Groups[2].Value, out port))
22740
{
228-
Debug.LogError("Parse pkg manifest from " + instance.ProjectManifestPath + " faild, json=\n" + json, instance);
229-
return false;
41+
RegistryPort = port;
23042
}
231-
232-
return true;
233-
}
234-
235-
private static void SaveManifestNode(JSONNode node)
236-
{
237-
if (Instance == null) { return; }
238-
239-
File.WriteAllText(instance.ProjectManifestPath, node.ToString(2));
24043
}
24144
}
242-
}
45+
}
46+
#endif

Assets/HTC.UnityPlugin/UPMRegistryTool/Editor/Scripts/Configs/RegistryToolSettings.cs.meta

Lines changed: 1 addition & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
#if UNITY_2018_1_OR_NEWER
2+
using HTC.UnityPlugin.UPMRegistryTool.Editor.Configs;
3+
using HTC.UnityPlugin.UPMRegistryTool.Editor.Utils.SimpleJSON;
4+
using System.IO;
5+
6+
namespace HTC.UnityPlugin.UPMRegistryTool.Editor.Utils
7+
{
8+
public static class ManifestUtils
9+
{
10+
public const string SCOPED_REGISTRIES_KEY = "scopedRegistries";
11+
public const int JSON_INDENT_SPACE_COUNT = 2;
12+
13+
public static bool CheckRegistryExists(RegistryInfo registryInfo)
14+
{
15+
JSONObject manifestJson = LoadProjectManifest();
16+
if (!manifestJson.HasKey(SCOPED_REGISTRIES_KEY))
17+
{
18+
return false;
19+
}
20+
21+
JSONArray registries = manifestJson[SCOPED_REGISTRIES_KEY].AsArray;
22+
foreach (JSONNode regNode in registries)
23+
{
24+
RegistryInfo regInfo = RegistryInfo.FromJson(regNode.AsObject);
25+
if (registryInfo.Equals(regInfo))
26+
{
27+
return true;
28+
}
29+
}
30+
31+
return false;
32+
}
33+
34+
public static void AddRegistry(RegistryInfo registryInfo)
35+
{
36+
RemoveRegistry(registryInfo.Name);
37+
38+
JSONObject manifestJson = LoadProjectManifest();
39+
if (!manifestJson.HasKey(SCOPED_REGISTRIES_KEY))
40+
{
41+
manifestJson.Add(SCOPED_REGISTRIES_KEY, new JSONArray());
42+
}
43+
44+
JSONArray registries = manifestJson[SCOPED_REGISTRIES_KEY].AsArray;
45+
registries.Add(registryInfo.ToJson());
46+
47+
Save(manifestJson);
48+
}
49+
50+
public static void RemoveRegistry(string registryName)
51+
{
52+
JSONObject manifestJson = LoadProjectManifest();
53+
if (!manifestJson.HasKey(SCOPED_REGISTRIES_KEY))
54+
{
55+
return;
56+
}
57+
58+
JSONArray registries = manifestJson[SCOPED_REGISTRIES_KEY].AsArray;
59+
for (int i = registries.Count - 1; i >= 0; i--)
60+
{
61+
RegistryInfo reg = RegistryInfo.FromJson(registries[i].AsObject);
62+
if (reg.Name == registryName)
63+
{
64+
registries.Remove(i);
65+
}
66+
}
67+
68+
Save(manifestJson);
69+
}
70+
71+
private static JSONObject LoadProjectManifest()
72+
{
73+
string manifestString = File.ReadAllText(RegistryToolSettings.Instance().ProjectManifestPath);
74+
JSONObject manifestJson = JSONNode.Parse(manifestString).AsObject;
75+
76+
return manifestJson;
77+
}
78+
79+
private static void Save(JSONObject newJson)
80+
{
81+
string jsonString = newJson.ToString(JSON_INDENT_SPACE_COUNT);
82+
File.WriteAllText(RegistryToolSettings.Instance().ProjectManifestPath, jsonString);
83+
}
84+
}
85+
}
86+
#endif

0 commit comments

Comments
 (0)