Skip to content

Commit 07031dd

Browse files
committed
Moved layer manager functionality into LayerManager class.
1 parent 67e867e commit 07031dd

17 files changed

Lines changed: 391 additions & 205 deletions

Source/Assets/TouchScript/Editor/TouchManagerEditor.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -200,13 +200,13 @@ private void refresh()
200200
{
201201
if (Application.isPlaying)
202202
{
203-
var l = TouchManager.Instance.Layers;
204203
layers.arraySize = 0;
205-
for (var i = 0; i < l.Count; i++)
204+
LayerManager.Instance.ForEach((l) =>
206205
{
207206
layers.arraySize++;
208-
layers.GetArrayElementAtIndex(layers.arraySize - 1).objectReferenceValue = l[i];
209-
}
207+
layers.GetArrayElementAtIndex(layers.arraySize - 1).objectReferenceValue = l;
208+
return true;
209+
});
210210
}
211211
else
212212
{

Source/Assets/TouchScript/Examples/_misc/Scripts/Runner.cs

Lines changed: 38 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,13 @@
55
using UnityEngine;
66
using TouchScript.Layers;
77
using System.Collections;
8-
98
#if UNITY_EDITOR
109
using UnityEditor;
1110
using System;
1211
#endif
13-
1412
#if UNITY_5_3_OR_NEWER
1513
using UnityEngine.SceneManagement;
14+
1615
#endif
1716

1817
namespace TouchScript.Examples
@@ -25,14 +24,14 @@ public class Runner : MonoBehaviour
2524
private static Runner instance;
2625
private TouchLayer layer;
2726

28-
public void LoadLevel(string name)
29-
{
27+
public void LoadLevel(string name)
28+
{
3029
#if UNITY_5_3_OR_NEWER
31-
SceneManager.LoadScene(name);
30+
SceneManager.LoadScene(name);
3231
#else
3332
Application.LoadLevel(name);
3433
#endif
35-
}
34+
}
3635

3736
public void LoadNextLevel()
3837
{
@@ -43,47 +42,48 @@ public void LoadNextLevel()
4342
#endif
4443
}
4544

46-
public void LoadPreviousLevel()
47-
{
45+
public void LoadPreviousLevel()
46+
{
4847
#if UNITY_5_3_OR_NEWER
49-
var newLevel = SceneManager.GetActiveScene().buildIndex - 1;
50-
if (newLevel == 0) newLevel = SceneManager.sceneCountInBuildSettings - 1;
51-
SceneManager.LoadScene(newLevel);
48+
var newLevel = SceneManager.GetActiveScene().buildIndex - 1;
49+
if (newLevel == 0) newLevel = SceneManager.sceneCountInBuildSettings - 1;
50+
SceneManager.LoadScene(newLevel);
5251
#else
5352
var newLevel = Application.loadedLevel - 1;
5453
if (newLevel == 0) newLevel = Application.levelCount - 1;
5554
Application.LoadLevel(newLevel);
5655
#endif
57-
}
56+
}
5857

59-
private void Start()
58+
private void Start()
6059
{
6160
if (instance == null)
6261
{
6362
instance = this;
6463
DontDestroyOnLoad(gameObject);
6564
}
6665

67-
layer = GetComponent<TouchLayer>();
66+
layer = GetComponent<TouchLayer>();
6867

6968
#if UNITY_EDITOR
70-
var guids = AssetDatabase.FindAssets("t:Scene", new string[]{"Assets/TouchScript/Examples"});
71-
if (EditorBuildSettings.scenes.Length != guids.Length)
72-
{
73-
if (EditorUtility.DisplayDialog("Add Example Scenes to Build Settings?",
74-
"You are running Examples scene but example scenes are not added to Build Settings. Do you want to add them now?", "Yes", "No"))
75-
{
76-
var importers = Array.ConvertAll(guids, (string guid) => AssetImporter.GetAtPath(AssetDatabase.GUIDToAssetPath(guid)));
77-
Array.Sort(importers, (AssetImporter a, AssetImporter b) => {
78-
var i1 = string.IsNullOrEmpty(a.userData) ? 42 : Convert.ToInt32(a.userData);
79-
var i2 = string.IsNullOrEmpty(b.userData) ? 42 : Convert.ToInt32(b.userData);
80-
if (i1 == i2) return 0;
81-
return i1 - i2;
82-
});
83-
EditorBuildSettings.scenes = Array.ConvertAll(importers, (AssetImporter i) => new EditorBuildSettingsScene(i.assetPath, true));
84-
EditorUtility.DisplayDialog("Success", "Example scenes were added to Build Settings. Please restart Play Mode.", "OK");
85-
}
86-
}
69+
var guids = AssetDatabase.FindAssets("t:Scene", new string[] {"Assets/TouchScript/Examples"});
70+
if (EditorBuildSettings.scenes.Length != guids.Length)
71+
{
72+
if (EditorUtility.DisplayDialog("Add Example Scenes to Build Settings?",
73+
"You are running Examples scene but example scenes are not added to Build Settings. Do you want to add them now?", "Yes", "No"))
74+
{
75+
var importers = Array.ConvertAll(guids, (string guid) => AssetImporter.GetAtPath(AssetDatabase.GUIDToAssetPath(guid)));
76+
Array.Sort(importers, (AssetImporter a, AssetImporter b) =>
77+
{
78+
var i1 = string.IsNullOrEmpty(a.userData) ? 42 : Convert.ToInt32(a.userData);
79+
var i2 = string.IsNullOrEmpty(b.userData) ? 42 : Convert.ToInt32(b.userData);
80+
if (i1 == i2) return 0;
81+
return i1 - i2;
82+
});
83+
EditorBuildSettings.scenes = Array.ConvertAll(importers, (AssetImporter i) => new EditorBuildSettingsScene(i.assetPath, true));
84+
EditorUtility.DisplayDialog("Success", "Example scenes were added to Build Settings. Please restart Play Mode.", "OK");
85+
}
86+
}
8787
#endif
8888

8989
#if UNITY_5_4_OR_NEWER
@@ -103,14 +103,15 @@ private void Start()
103103
private void OnDestroy()
104104
{
105105
#if UNITY_5_4_OR_NEWER
106-
SceneManager.sceneLoaded -= sceneLoadedHandler;
106+
SceneManager.sceneLoaded -= sceneLoadedHandler;
107107
#endif
108-
}
108+
}
109109

110110
private void Update()
111111
{
112112
if (Input.GetKeyDown(KeyCode.Escape)) Application.Quit();
113113
}
114+
114115
#if UNITY_5_4_OR_NEWER
115116
private void sceneLoadedHandler(Scene scene, LoadSceneMode mode)
116117
{
@@ -124,9 +125,9 @@ private void OnLevelWasLoaded(int num)
124125
#endif
125126

126127
private IEnumerator resetUILayer()
127-
{
128-
yield return new WaitForEndOfFrame();
129-
TouchManager.Instance.AddLayer(layer, 0);
130-
}
128+
{
129+
yield return new WaitForEndOfFrame();
130+
LayerManager.Instance.AddLayer(layer, 0);
131+
}
131132
}
132133
}

Source/Assets/TouchScript/Scripts/Devices/Display/GenericDisplayDevice.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,6 @@ protected override void OnEnable()
5656
updateNativeResulotion();
5757
updateNativeDPI();
5858
UpdateDPI();
59-
60-
Debug.LogFormat("{0}x{1} {2}x{3}", Screen.width, Screen.height, Screen.currentResolution.width, Screen.currentResolution.height);
61-
Debug.LogFormat("Device Model: {0}, Device Name: {1}, GPU: {2}", SystemInfo.deviceModel, SystemInfo.deviceName, SystemInfo.graphicsDeviceName);
6259
}
6360

6461
private void updateNativeResulotion()

Source/Assets/TouchScript/Scripts/GestureManager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ namespace TouchScript
1212
/// <remarks>
1313
/// <para>Why IList instead of Pointer in pointer events?</para>
1414
/// <para>Right now touchesBegan/touchesMoved/touchesEnded methods in Gesture class accept IList as their argument which seems to overcomplicate a lot of stuff and just calling touchBegan(TouchPoint) would be easier.</para>
15-
/// <para>The later approach was tried in 7.0 and reverted in 8.0 since it introduced a really hard to fix gesture priority issue.If with lists a gesture knows all touches changed during current frame, individual touchMoved calls have to be buffered till the end of frame.But there's no way to execute gesture recognition logic at the end of frame in the right hierarchical order. This concern resulted in the following issue: https://github.com/TouchScript/TouchScript/issues/203
15+
/// <para>The later approach was tried in 7.0 and reverted in 8.0 since it introduced a really hard to fix gesture priority issue. If with lists a gesture knows all touches changed during current frame, individual touchMoved calls have to be buffered till the end of frame. But there's no way to execute gesture recognition logic at the end of frame in the right hierarchical order. This concern resulted in the following issue: https://github.com/TouchScript/TouchScript/issues/203
1616
/// </para>
1717
/// </remarks>
1818
public sealed class GestureManager : MonoBehaviour

Source/Assets/TouchScript/Scripts/Gestures/Gesture.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -647,7 +647,7 @@ public virtual HitData GetScreenPositionHitData()
647647
{
648648
HitData hit;
649649
fakePointer.Position = ScreenPosition;
650-
touchManager.INTERNAL_GetHitTarget(fakePointer, out hit);
650+
LayerManager.Instance.GetHitTarget(fakePointer, out hit);
651651
return hit;
652652
}
653653

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
* @author Valentin Simonov / http://va.lent.in/
3+
*/
4+
5+
using System;
6+
using System.Collections.Generic;
7+
using TouchScript.Hit;
8+
using TouchScript.Layers;
9+
using TouchScript.Pointers;
10+
11+
namespace TouchScript
12+
{
13+
public interface ILayerManager
14+
{
15+
/// <summary>
16+
/// Gets the list of <see cref="TouchLayer"/>.
17+
/// </summary>
18+
/// <value>A sorted list of currently active layers.</value>
19+
IList<TouchLayer> Layers { get; }
20+
21+
int LayerCount { get; }
22+
23+
/// <summary>
24+
/// Adds a layer in a specific position.
25+
/// </summary>
26+
/// <param name="layer">The layer to add.</param>
27+
/// <param name="index">Layer index to add the layer to or <c>-1</c> to add to the end of the list.</param>
28+
/// <param name="addIfExists">if set to <c>true</c> move the layer to another index if it is already added; don't move otherwise.</param>
29+
/// <returns>
30+
/// True if the layer was added.
31+
/// </returns>
32+
bool AddLayer(TouchLayer layer, int index = -1, bool addIfExists = true);
33+
34+
/// <summary>
35+
/// Removes a layer.
36+
/// </summary>
37+
/// <param name="layer">The layer to remove.</param>
38+
/// <returns>True if the layer was removed.</returns>
39+
bool RemoveLayer(TouchLayer layer);
40+
41+
/// <summary>
42+
/// Swaps layers.
43+
/// </summary>
44+
/// <param name="at">Layer index 1.</param>
45+
/// <param name="to">Layer index 2.</param>
46+
void ChangeLayerIndex(int at, int to);
47+
48+
void ForEach(Func<TouchLayer, bool> action);
49+
50+
bool GetHitTarget(IPointer pointer, out HitData hit);
51+
52+
}
53+
}

Source/Assets/TouchScript/Scripts/ILayerManager.cs.meta

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Source/Assets/TouchScript/Scripts/ITouchManager.cs

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
using System.Collections.Generic;
77
using TouchScript.Devices.Display;
88
using TouchScript.InputSources;
9-
using TouchScript.Layers;
109
using TouchScript.Pointers;
1110

1211
namespace TouchScript
@@ -107,12 +106,6 @@ public interface ITouchManager
107106
/// <remarks>This is usually a desired behavior but sometimes you would want to turn this off.</remarks>
108107
bool ShouldCreateStandardInput { get; set; }
109108

110-
/// <summary>
111-
/// Gets the list of <see cref="TouchLayer"/>.
112-
/// </summary>
113-
/// <value>A sorted list of currently active layers.</value>
114-
IList<TouchLayer> Layers { get; }
115-
116109
/// <summary>
117110
/// Gets the list of <see cref="IInputSource"/>
118111
/// </summary>
@@ -146,31 +139,6 @@ public interface ITouchManager
146139
/// <value>An unsorted list of all pointers which were pressed but not released yet.</value>
147140
IList<Pointer> PressedPointers { get; }
148141

149-
/// <summary>
150-
/// Adds a layer in a specific position.
151-
/// </summary>
152-
/// <param name="layer">The layer to add.</param>
153-
/// <param name="index">Layer index to add the layer to or <c>-1</c> to add to the end of the list.</param>
154-
/// <param name="addIfExists">if set to <c>true</c> move the layer to another index if it is already added; don't move otherwise.</param>
155-
/// <returns>
156-
/// True if the layer was added.
157-
/// </returns>
158-
bool AddLayer(TouchLayer layer, int index = -1, bool addIfExists = true);
159-
160-
/// <summary>
161-
/// Removes a layer.
162-
/// </summary>
163-
/// <param name="layer">The layer to remove.</param>
164-
/// <returns>True if the layer was removed.</returns>
165-
bool RemoveLayer(TouchLayer layer);
166-
167-
/// <summary>
168-
/// Swaps layers.
169-
/// </summary>
170-
/// <param name="at">Layer index 1.</param>
171-
/// <param name="to">Layer index 2.</param>
172-
void ChangeLayerIndex(int at, int to);
173-
174142
/// <summary>
175143
/// Adds an input source.
176144
/// </summary>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/*
2+
* @author Valentin Simonov / http://va.lent.in/
3+
*/
4+
5+
using UnityEngine;
6+
7+
namespace TouchScript
8+
{
9+
public sealed class LayerManager : MonoBehaviour
10+
{
11+
public static ILayerManager Instance
12+
{
13+
get { return LayerManagerInstance.Instance; }
14+
}
15+
}
16+
}

Source/Assets/TouchScript/Scripts/LayerManager.cs.meta

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)