GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — Examples Examples
Valentin Simonov edited this page
TouchScript comes with many example scenes, each of them demonstrates how to use various framework features.
/Scene GameObject has the main logic and 3 TouchScript components:
private void OnEnable() { TwoFingerMoveGesture.Transformed += twoFingerTransformHandler; ManipulationGesture.Transformed += manipulationTransformedHandler; } private void OnDisable() { TwoFingerMoveGesture.Transformed -= twoFingerTransformHandler; ManipulationGesture.Transformed -= manipulationTransformedHandler; } private void manipulationTransformedHandler(object sender, System.EventArgs e) { var rotation = Quaternion.Euler(ManipulationGesture.DeltaPosition.y/Screen.height*RotationSpeed, -ManipulationGesture.DeltaPosition.x/Screen.width*RotationSpeed, ManipulationGesture.DeltaRotation); pivot.localRotation *= rotation; cam.transform.localPosition += Vector3.forward*(ManipulationGesture.DeltaScale - 1f)*ZoomSpeed; } private void twoFingerTransformHandler(object sender, System.EventArgs e) { pivot.localPosition += pivot.rotation*TwoFingerMoveGesture.DeltaPosition*PanSpeed; }
/Scene/Camera GameObject has a StandardLayer with all options disabled but /Scenes/Board GameObject has two components attached:
private void OnEnable() { gesture = GetComponent<PinnedTransformGesture>(); gesture.Transformed += transformedHandler; } private void OnDisable() { gesture.Transformed -= transformedHandler; } private void transformedHandler(object sender, System.EventArgs e) { transform.localRotation *= Quaternion.AngleAxis(gesture.DeltaRotation, gesture.RotationAxis); } /Scene/Board/Container/CheckerDark GameObjects have the following components attached:
/scene GameObject has Exclusive component attached to it which implements public bool ShouldBegin(Gesture gesture) { if (exclusive) return gesture == Target; return true; } public bool ShouldReceivePointer(Gesture gesture, Pointer pointer) { if (exclusive) return gesture == Target; return true; }
/Scene/Camera GameObject has a StandardLayer with all options disabled but Circle prefab has the following components attached:
GetComponent<TransformGesture>().Cancel(true, true); (true, true) means that the pointers should be returned to the system, like they were just pressed. At this point cancelled pointers are caught by the new (bigger) circle and its TransformGesture so the user can continue moving and resizing the new circle.
This example shows how extensible TouchScript is. There's a cube in the scene which has a /Scene/Scene Camera/Image GameObject has TransformGesture and Transformer components to move it around. This is the image you see on the Cube. /Scene/Cube GameObject has the following components attached:
private void pointerPressedHandler(object sender, MetaGestureEventArgs metaGestureEventArgs) { var pointer = metaGestureEventArgs.Pointer; if (pointer.InputSource == (IInputSource)this) return; If this pointer is generated by this script, stop processing it. var newPointer = PointerFactory.Create(pointer.Type, this); newPointer.CopyFrom(pointer); newPointer.Position = processCoords(pointer.GetPressData().RaycastHit.textureCoord); newPointer.Flags = pointer.Flags | Pointer.FLAG_ARTIFICIAL | Pointer.FLAG_INTERNAL; addPointer(newPointer); pressPointer(newPointer); map.Add(pointer.Id, newPointer); } Next, the code creates a copy pointer, adds /Scene GameObject has the following components attached:
This is the code inside LayerDelegate: public RedirectInput Source; public TouchLayer RenderTextureLayer; public bool ShouldReceivePointer(TouchLayer layer, IPointer pointer) { if (layer == RenderTextureLayer) return pointer.InputSource == (IInputSource)Source; return pointer.InputSource != (IInputSource)Source; } Which basically says: "The layer on RenderTexture Camera should receive fake pointers, while others don't".
The scene contains 5 layers. Check TouchManager GameObject with /Scene/2D/Unity_Logo GameObjects have TapGesture on them which are used by Logo component to change color on tap. /Scene/Left/Board and /Scene/Right/Board are the same as in
/Scene/World Space Plane/World Space Canvas/Field/Image # GameObjects have the following components attached:
/Scene/World Space Plane/World Space Canvas/Field/Image #/Close is just a UI Button which TouchScript sends pointer input. /Scene/ScreenSpace Canvas/Panel/Button is just a set of UI Buttons which interact with TouchScript. No special components or code is required.
This example demonstrates how to do the following:
/Game Canvas/Spawner# GameObjects have the following components attached:
var target = Instantiate(Prefab, Position.parent); target.position = Position.position; LayerManager.Instance.SetExclusive(target); press.Cancel(true, true); LayerManager.Instance.ClearExclusive(); This code creates an instance of /Scene/Camera/Stuff/Vortex has a script attached which calls var gesture = GetComponent<TransformGesture>(); if (gesture != null) gesture.Cancel(); It cancels the gesture but doesn't cancel its pointers, so the planes just fall into the vortex if the user doesn't catch them quickly.
This example shows how to use raw pointer input with no gesture logic. /Scene/Camera has Spawner script attached which spawns prefab instances using this code: private void OnEnable() { if (TouchManager.Instance != null) TouchManager.Instance.PointersPressed += pointersPressedHandler; } private void OnDisable() { if (TouchManager.Instance != null) TouchManager.Instance.PointersPressed -= pointersPressedHandler; } private void pointersPressedHandler(object sender, PointerEventArgs e) { foreach (var pointer in e.Pointers) spawnPrefabAt(pointer.Position); }
/Scene/Container/Cube GameObjects have the following components attached:
longPressGesture.StateChanged += longPressedHandler; private void longPressedHandler(object sender, GestureStateChangeEventArgs e) { if (e.State == Gesture.GestureState.Recognized) { ... } else if (e.State == Gesture.GestureState.Failed) { stopGrowing(); } } We use /Scene/table_and_chair GameObject has a TapGesture component attached with Number of Taps Required set to This example shows how to write and use custom gestures. Clone this wiki locally |
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |