Skip to content

Commit

Permalink
Moved layer manager functionality into LayerManager class.
Browse files Browse the repository at this point in the history
  • Loading branch information
valyard committed Jul 22, 2017
1 parent 67e867e commit 07031dd
Show file tree
Hide file tree
Showing 17 changed files with 391 additions and 205 deletions.
8 changes: 4 additions & 4 deletions Source/Assets/TouchScript/Editor/TouchManagerEditor.cs
Expand Up @@ -200,13 +200,13 @@ private void refresh()
{ {
if (Application.isPlaying) if (Application.isPlaying)
{ {
var l = TouchManager.Instance.Layers;
layers.arraySize = 0; layers.arraySize = 0;
for (var i = 0; i < l.Count; i++) LayerManager.Instance.ForEach((l) =>
{ {
layers.arraySize++; layers.arraySize++;
layers.GetArrayElementAtIndex(layers.arraySize - 1).objectReferenceValue = l[i]; layers.GetArrayElementAtIndex(layers.arraySize - 1).objectReferenceValue = l;
} return true;
});
} }
else else
{ {
Expand Down
75 changes: 38 additions & 37 deletions Source/Assets/TouchScript/Examples/_misc/Scripts/Runner.cs
Expand Up @@ -5,14 +5,13 @@
using UnityEngine; using UnityEngine;
using TouchScript.Layers; using TouchScript.Layers;
using System.Collections; using System.Collections;

#if UNITY_EDITOR #if UNITY_EDITOR
using UnityEditor; using UnityEditor;
using System; using System;
#endif #endif

#if UNITY_5_3_OR_NEWER #if UNITY_5_3_OR_NEWER
using UnityEngine.SceneManagement; using UnityEngine.SceneManagement;

#endif #endif


namespace TouchScript.Examples namespace TouchScript.Examples
Expand All @@ -25,14 +24,14 @@ public class Runner : MonoBehaviour
private static Runner instance; private static Runner instance;
private TouchLayer layer; private TouchLayer layer;


public void LoadLevel(string name) public void LoadLevel(string name)
{ {
#if UNITY_5_3_OR_NEWER #if UNITY_5_3_OR_NEWER
SceneManager.LoadScene(name); SceneManager.LoadScene(name);
#else #else
Application.LoadLevel(name); Application.LoadLevel(name);
#endif #endif
} }


public void LoadNextLevel() public void LoadNextLevel()
{ {
Expand All @@ -43,47 +42,48 @@ public void LoadNextLevel()
#endif #endif
} }


public void LoadPreviousLevel() public void LoadPreviousLevel()
{ {
#if UNITY_5_3_OR_NEWER #if UNITY_5_3_OR_NEWER
var newLevel = SceneManager.GetActiveScene().buildIndex - 1; var newLevel = SceneManager.GetActiveScene().buildIndex - 1;
if (newLevel == 0) newLevel = SceneManager.sceneCountInBuildSettings - 1; if (newLevel == 0) newLevel = SceneManager.sceneCountInBuildSettings - 1;
SceneManager.LoadScene(newLevel); SceneManager.LoadScene(newLevel);
#else #else
var newLevel = Application.loadedLevel - 1; var newLevel = Application.loadedLevel - 1;
if (newLevel == 0) newLevel = Application.levelCount - 1; if (newLevel == 0) newLevel = Application.levelCount - 1;
Application.LoadLevel(newLevel); Application.LoadLevel(newLevel);
#endif #endif
} }


private void Start() private void Start()
{ {
if (instance == null) if (instance == null)
{ {
instance = this; instance = this;
DontDestroyOnLoad(gameObject); DontDestroyOnLoad(gameObject);
} }


layer = GetComponent<TouchLayer>(); layer = GetComponent<TouchLayer>();


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


#if UNITY_5_4_OR_NEWER #if UNITY_5_4_OR_NEWER
Expand All @@ -103,14 +103,15 @@ private void Start()
private void OnDestroy() private void OnDestroy()
{ {
#if UNITY_5_4_OR_NEWER #if UNITY_5_4_OR_NEWER
SceneManager.sceneLoaded -= sceneLoadedHandler; SceneManager.sceneLoaded -= sceneLoadedHandler;
#endif #endif
} }


private void Update() private void Update()
{ {
if (Input.GetKeyDown(KeyCode.Escape)) Application.Quit(); if (Input.GetKeyDown(KeyCode.Escape)) Application.Quit();
} }

#if UNITY_5_4_OR_NEWER #if UNITY_5_4_OR_NEWER
private void sceneLoadedHandler(Scene scene, LoadSceneMode mode) private void sceneLoadedHandler(Scene scene, LoadSceneMode mode)
{ {
Expand All @@ -124,9 +125,9 @@ private void OnLevelWasLoaded(int num)
#endif #endif


private IEnumerator resetUILayer() private IEnumerator resetUILayer()
{ {
yield return new WaitForEndOfFrame(); yield return new WaitForEndOfFrame();
TouchManager.Instance.AddLayer(layer, 0); LayerManager.Instance.AddLayer(layer, 0);
} }
} }
} }
Expand Up @@ -56,9 +56,6 @@ protected override void OnEnable()
updateNativeResulotion(); updateNativeResulotion();
updateNativeDPI(); updateNativeDPI();
UpdateDPI(); UpdateDPI();

Debug.LogFormat("{0}x{1} {2}x{3}", Screen.width, Screen.height, Screen.currentResolution.width, Screen.currentResolution.height);
Debug.LogFormat("Device Model: {0}, Device Name: {1}, GPU: {2}", SystemInfo.deviceModel, SystemInfo.deviceName, SystemInfo.graphicsDeviceName);
} }


private void updateNativeResulotion() private void updateNativeResulotion()
Expand Down
2 changes: 1 addition & 1 deletion Source/Assets/TouchScript/Scripts/GestureManager.cs
Expand Up @@ -12,7 +12,7 @@ namespace TouchScript
/// <remarks> /// <remarks>
/// <para>Why IList instead of Pointer in pointer events?</para> /// <para>Why IList instead of Pointer in pointer events?</para>
/// <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> /// <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>
/// <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 /// <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
/// </para> /// </para>
/// </remarks> /// </remarks>
public sealed class GestureManager : MonoBehaviour public sealed class GestureManager : MonoBehaviour
Expand Down
2 changes: 1 addition & 1 deletion Source/Assets/TouchScript/Scripts/Gestures/Gesture.cs
Expand Up @@ -647,7 +647,7 @@ public virtual HitData GetScreenPositionHitData()
{ {
HitData hit; HitData hit;
fakePointer.Position = ScreenPosition; fakePointer.Position = ScreenPosition;
touchManager.INTERNAL_GetHitTarget(fakePointer, out hit); LayerManager.Instance.GetHitTarget(fakePointer, out hit);
return hit; return hit;
} }


Expand Down
53 changes: 53 additions & 0 deletions Source/Assets/TouchScript/Scripts/ILayerManager.cs
@@ -0,0 +1,53 @@
/*
* @author Valentin Simonov / http://va.lent.in/
*/

using System;
using System.Collections.Generic;
using TouchScript.Hit;
using TouchScript.Layers;
using TouchScript.Pointers;

namespace TouchScript
{
public interface ILayerManager
{
/// <summary>
/// Gets the list of <see cref="TouchLayer"/>.
/// </summary>
/// <value>A sorted list of currently active layers.</value>
IList<TouchLayer> Layers { get; }

int LayerCount { get; }

/// <summary>
/// Adds a layer in a specific position.
/// </summary>
/// <param name="layer">The layer to add.</param>
/// <param name="index">Layer index to add the layer to or <c>-1</c> to add to the end of the list.</param>
/// <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>
/// <returns>
/// True if the layer was added.
/// </returns>
bool AddLayer(TouchLayer layer, int index = -1, bool addIfExists = true);

/// <summary>
/// Removes a layer.
/// </summary>
/// <param name="layer">The layer to remove.</param>
/// <returns>True if the layer was removed.</returns>
bool RemoveLayer(TouchLayer layer);

/// <summary>
/// Swaps layers.
/// </summary>
/// <param name="at">Layer index 1.</param>
/// <param name="to">Layer index 2.</param>
void ChangeLayerIndex(int at, int to);

void ForEach(Func<TouchLayer, bool> action);

bool GetHitTarget(IPointer pointer, out HitData hit);

}
}
12 changes: 12 additions & 0 deletions Source/Assets/TouchScript/Scripts/ILayerManager.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 0 additions & 32 deletions Source/Assets/TouchScript/Scripts/ITouchManager.cs
Expand Up @@ -6,7 +6,6 @@
using System.Collections.Generic; using System.Collections.Generic;
using TouchScript.Devices.Display; using TouchScript.Devices.Display;
using TouchScript.InputSources; using TouchScript.InputSources;
using TouchScript.Layers;
using TouchScript.Pointers; using TouchScript.Pointers;


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


/// <summary>
/// Gets the list of <see cref="TouchLayer"/>.
/// </summary>
/// <value>A sorted list of currently active layers.</value>
IList<TouchLayer> Layers { get; }

/// <summary> /// <summary>
/// Gets the list of <see cref="IInputSource"/> /// Gets the list of <see cref="IInputSource"/>
/// </summary> /// </summary>
Expand Down Expand Up @@ -146,31 +139,6 @@ public interface ITouchManager
/// <value>An unsorted list of all pointers which were pressed but not released yet.</value> /// <value>An unsorted list of all pointers which were pressed but not released yet.</value>
IList<Pointer> PressedPointers { get; } IList<Pointer> PressedPointers { get; }


/// <summary>
/// Adds a layer in a specific position.
/// </summary>
/// <param name="layer">The layer to add.</param>
/// <param name="index">Layer index to add the layer to or <c>-1</c> to add to the end of the list.</param>
/// <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>
/// <returns>
/// True if the layer was added.
/// </returns>
bool AddLayer(TouchLayer layer, int index = -1, bool addIfExists = true);

/// <summary>
/// Removes a layer.
/// </summary>
/// <param name="layer">The layer to remove.</param>
/// <returns>True if the layer was removed.</returns>
bool RemoveLayer(TouchLayer layer);

/// <summary>
/// Swaps layers.
/// </summary>
/// <param name="at">Layer index 1.</param>
/// <param name="to">Layer index 2.</param>
void ChangeLayerIndex(int at, int to);

/// <summary> /// <summary>
/// Adds an input source. /// Adds an input source.
/// </summary> /// </summary>
Expand Down
16 changes: 16 additions & 0 deletions Source/Assets/TouchScript/Scripts/LayerManager.cs
@@ -0,0 +1,16 @@
/*
* @author Valentin Simonov / http://va.lent.in/
*/

using UnityEngine;

namespace TouchScript
{
public sealed class LayerManager : MonoBehaviour
{
public static ILayerManager Instance
{
get { return LayerManagerInstance.Instance; }
}
}
}
12 changes: 12 additions & 0 deletions Source/Assets/TouchScript/Scripts/LayerManager.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 07031dd

Please sign in to comment.