Skip to content
Permalink
Browse files

Moved layer manager functionality into LayerManager class.

  • Loading branch information...
valyard committed Jul 22, 2017
1 parent 67e867e commit 07031dd970f9842d95ca3ff1c7daf2f71b1bbfcd
@@ -200,13 +200,13 @@ private void refresh()
{
if (Application.isPlaying)
{
var l = TouchManager.Instance.Layers;
layers.arraySize = 0;
for (var i = 0; i < l.Count; i++)
LayerManager.Instance.ForEach((l) =>
{
layers.arraySize++;
layers.GetArrayElementAtIndex(layers.arraySize - 1).objectReferenceValue = l[i];
}
layers.GetArrayElementAtIndex(layers.arraySize - 1).objectReferenceValue = l;
return true;
});
}
else
{
@@ -5,14 +5,13 @@
using UnityEngine;
using TouchScript.Layers;
using System.Collections;

#if UNITY_EDITOR
using UnityEditor;
using System;
#endif

#if UNITY_5_3_OR_NEWER
using UnityEngine.SceneManagement;

#endif

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

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

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

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

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

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

#if UNITY_EDITOR
var guids = AssetDatabase.FindAssets("t:Scene", new string[]{"Assets/TouchScript/Examples"});
if (EditorBuildSettings.scenes.Length != guids.Length)
{
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"))
{
var importers = Array.ConvertAll(guids, (string guid) => AssetImporter.GetAtPath(AssetDatabase.GUIDToAssetPath(guid)));
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);
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");
}
}
var guids = AssetDatabase.FindAssets("t:Scene", new string[] {"Assets/TouchScript/Examples"});
if (EditorBuildSettings.scenes.Length != guids.Length)
{
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"))
{
var importers = Array.ConvertAll(guids, (string guid) => AssetImporter.GetAtPath(AssetDatabase.GUIDToAssetPath(guid)));
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);
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");
}
}
#endif

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

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

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

private IEnumerator resetUILayer()
{
yield return new WaitForEndOfFrame();
TouchManager.Instance.AddLayer(layer, 0);
}
{
yield return new WaitForEndOfFrame();
LayerManager.Instance.AddLayer(layer, 0);
}
}
}
@@ -56,9 +56,6 @@ protected override void OnEnable()
updateNativeResulotion();
updateNativeDPI();
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()
@@ -12,7 +12,7 @@ namespace TouchScript
/// <remarks>
/// <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>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>
/// </remarks>
public sealed class GestureManager : MonoBehaviour
@@ -647,7 +647,7 @@ public virtual HitData GetScreenPositionHitData()
{
HitData hit;
fakePointer.Position = ScreenPosition;
touchManager.INTERNAL_GetHitTarget(fakePointer, out hit);
LayerManager.Instance.GetHitTarget(fakePointer, out hit);
return hit;
}

@@ -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);

}
}

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
@@ -6,7 +6,6 @@
using System.Collections.Generic;
using TouchScript.Devices.Display;
using TouchScript.InputSources;
using TouchScript.Layers;
using TouchScript.Pointers;

namespace TouchScript
@@ -107,12 +106,6 @@ public interface ITouchManager
/// <remarks>This is usually a desired behavior but sometimes you would want to turn this off.</remarks>
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>
/// Gets the list of <see cref="IInputSource"/>
/// </summary>
@@ -146,31 +139,6 @@ public interface ITouchManager
/// <value>An unsorted list of all pointers which were pressed but not released yet.</value>
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>
/// Adds an input source.
/// </summary>
@@ -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; }
}
}
}

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
Oops, something went wrong.

0 comments on commit 07031dd

Please sign in to comment.
You can’t perform that action at this time.