手势插件引入暂存

This commit is contained in:
Caiyanpeng committed 2021-10-08 16:03:55 +08:00
1 parent 6d1bc8e2c8
commit fd8f419f09
70 files changed
+5062 -126

No files matched your search

@@ -0,0 +1,56 @@
using UnityEngine;
using System.Collections;
/// <summary>
/// this demo will create a virtual d-pad and two buttons. the virtual d-pad will have a left, right and up button. the up
/// button will overlap the left and right buttons. the reason for this is to show one way to handle 5 directional d-pad
/// (left, up-left, up, up-right, right) letting the player slide their finger around. It alsow demonstrates how the TKAnyTouchRecognizer
/// does not "eat" touches and allows them to bleed down through to recognizers below them.
///
/// note that we are working with a 16:9 design time resolution since that is the most popular on mobile and a good base. Note also
/// that we have set shouldAutoUpdateTouches to false and we are manually calling updateTouches. This lets us process the touches
/// exactly when we want: right before we use them.
/// </summary>
public class DemoTwo : MonoBehaviour
{
private VirtualControls _controls;
void Start()
{
_controls = new VirtualControls();
_controls.createDebugQuads();
}
void Update()
{
_controls.update();
}
void OnGUI()
{
showLabelAndValue( "Left: ", _controls.leftDown.ToString() );
showLabelAndValue( "Right: ", _controls.rightDown.ToString() );
showLabelAndValue( "Up: ", _controls.upDown.ToString() );
GUILayout.Space( 4 );
showLabelAndValue( "Attack: ", _controls.attackDown.ToString() );
showLabelAndValue( "Jump: ", _controls.jumpDown.ToString() );
}
void showLabelAndValue( string label, string value )
{
GUILayout.BeginHorizontal();
{
GUILayout.Label( label, GUILayout.Width( 50 ) );
GUILayout.Label( value );
}
GUILayout.EndHorizontal();
}
}
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 14e83b1078b824cc5957fa7a77be02d7
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
@@ -0,0 +1,308 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!29 &1
OcclusionCullingSettings:
m_ObjectHideFlags: 0
serializedVersion: 2
m_OcclusionBakeSettings:
smallestOccluder: 5
smallestHole: 0.25
backfaceThreshold: 100
m_SceneGUID: 00000000000000000000000000000000
m_OcclusionCullingData: {fileID: 0}
--- !u!104 &2
RenderSettings:
m_ObjectHideFlags: 0
serializedVersion: 9
m_Fog: 0
m_FogColor: {r: 0.5, g: 0.5, b: 0.5, a: 1}
m_FogMode: 3
m_FogDensity: 0.01
m_LinearFogStart: 0
m_LinearFogEnd: 300
m_AmbientSkyColor: {r: 0.2, g: 0.2, b: 0.2, a: 1}
m_AmbientEquatorColor: {r: 0.2, g: 0.2, b: 0.2, a: 1}
m_AmbientGroundColor: {r: 0.2, g: 0.2, b: 0.2, a: 1}
m_AmbientIntensity: 1
m_AmbientMode: 3
m_SubtractiveShadowColor: {r: 0.42, g: 0.478, b: 0.627, a: 1}
m_SkyboxMaterial: {fileID: 0}
m_HaloStrength: 0.5
m_FlareStrength: 1
m_FlareFadeSpeed: 3
m_HaloTexture: {fileID: 0}
m_SpotCookie: {fileID: 10001, guid: 0000000000000000e000000000000000, type: 0}
m_DefaultReflectionMode: 0
m_DefaultReflectionResolution: 128
m_ReflectionBounces: 1
m_ReflectionIntensity: 1
m_CustomReflection: {fileID: 0}
m_Sun: {fileID: 0}
m_IndirectSpecularColor: {r: 0, g: 0, b: 0, a: 1}
m_UseRadianceAmbientProbe: 0
--- !u!157 &4
LightmapSettings:
m_ObjectHideFlags: 0
serializedVersion: 11
m_GIWorkflowMode: 1
m_GISettings:
serializedVersion: 2
m_BounceScale: 1
m_IndirectOutputScale: 1
m_AlbedoBoost: 1
m_EnvironmentLightingMode: 0
m_EnableBakedLightmaps: 1
m_EnableRealtimeLightmaps: 0
m_LightmapEditorSettings:
serializedVersion: 12
m_Resolution: 1
m_BakeResolution: 50
m_AtlasSize: 1024
m_AO: 1
m_AOMaxDistance: 1
m_CompAOExponent: 1
m_CompAOExponentDirect: 0
m_ExtractAmbientOcclusion: 0
m_Padding: 2
m_LightmapParameters: {fileID: 0}
m_LightmapsBakeMode: 1
m_TextureCompression: 0
m_FinalGather: 0
m_FinalGatherFiltering: 1
m_FinalGatherRayCount: 256
m_ReflectionCompression: 2
m_MixedBakeMode: 1
m_BakeBackend: 0
m_PVRSampling: 1
m_PVRDirectSampleCount: 32
m_PVRSampleCount: 512
m_PVRBounces: 2
m_PVREnvironmentSampleCount: 512
m_PVREnvironmentReferencePointCount: 2048
m_PVRFilteringMode: 0
m_PVRDenoiserTypeDirect: 0
m_PVRDenoiserTypeIndirect: 0
m_PVRDenoiserTypeAO: 0
m_PVRFilterTypeDirect: 0
m_PVRFilterTypeIndirect: 0
m_PVRFilterTypeAO: 0
m_PVREnvironmentMIS: 0
m_PVRCulling: 1
m_PVRFilteringGaussRadiusDirect: 1
m_PVRFilteringGaussRadiusIndirect: 5
m_PVRFilteringGaussRadiusAO: 2
m_PVRFilteringAtrousPositionSigmaDirect: 0.5
m_PVRFilteringAtrousPositionSigmaIndirect: 2
m_PVRFilteringAtrousPositionSigmaAO: 1
m_ExportTrainingData: 0
m_TrainingDataDestination: TrainingData
m_LightProbeSampleCountMultiplier: 4
m_LightingDataAsset: {fileID: 0}
m_UseShadowmask: 0
--- !u!196 &5
NavMeshSettings:
serializedVersion: 2
m_ObjectHideFlags: 0
m_BuildSettings:
serializedVersion: 2
agentTypeID: 0
agentRadius: 0.5
agentHeight: 2
agentSlope: 45
agentClimb: 0.4
ledgeDropHeight: 0
maxJumpAcrossDistance: 0
minRegionArea: 2
manualCellSize: 0
cellSize: 0.16666666
manualTileSize: 0
tileSize: 256
accuratePlacement: 0
debug:
m_Flags: 0
m_NavMeshData: {fileID: 0}
--- !u!1 &59454456
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 59454461}
- component: {fileID: 59454460}
- component: {fileID: 59454458}
- component: {fileID: 59454457}
m_Layer: 0
m_Name: Main Camera
m_TagString: MainCamera
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!81 &59454457
AudioListener:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 59454456}
m_Enabled: 1
--- !u!124 &59454458
Behaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 59454456}
m_Enabled: 1
--- !u!20 &59454460
Camera:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 59454456}
m_Enabled: 1
serializedVersion: 2
m_ClearFlags: 1
m_BackGroundColor: {r: 0.19215687, g: 0.3019608, b: 0.4745098, a: 0.019607844}
m_projectionMatrixMode: 1
m_GateFitMode: 2
m_FOVAxisMode: 0
m_SensorSize: {x: 36, y: 24}
m_LensShift: {x: 0, y: 0}
m_FocalLength: 50
m_NormalizedViewPortRect:
serializedVersion: 2
x: 0
y: 0
width: 1
height: 1
near clip plane: 0.3
far clip plane: 1000
field of view: 60
orthographic: 1
orthographic size: 5
m_Depth: -1
m_CullingMask:
serializedVersion: 2
m_Bits: 4294967295
m_RenderingPath: -1
m_TargetTexture: {fileID: 0}
m_TargetDisplay: 0
m_TargetEye: 3
m_HDR: 0
m_AllowMSAA: 1
m_AllowDynamicResolution: 0
m_ForceIntoRT: 0
m_OcclusionCulling: 1
m_StereoConvergence: 10
m_StereoSeparation: 0.022
--- !u!4 &59454461
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 59454456}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 1, z: -10}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &494578000
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 494578002}
- component: {fileID: 494578001}
m_Layer: 0
m_Name: DemoTwo
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!114 &494578001
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 494578000}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 14e83b1078b824cc5957fa7a77be02d7, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!4 &494578002
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 494578000}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &1995668659
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1995668661}
- component: {fileID: 1995668660}
m_Layer: 0
m_Name: TouchKit
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!114 &1995668660
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1995668659}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: e065ffc7dbca743ee9cef1b5106b0d26, type: 3}
m_Name:
m_EditorClassIdentifier:
simulateTouches: 1
simulateMultitouch: 1
drawTouches: 1
drawDebugBoundaryFrames: 1
autoScaleRectsAndDistances: 1
shouldAutoUpdateTouches: 0
maxTouchesToProcess: 5
--- !u!4 &1995668661
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1995668659}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 2
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
@@ -0,0 +1,4 @@
fileFormatVersion: 2
guid: 62c8bf4ea5f784fed9707bbb086970ae
DefaultImporter:
userData:
@@ -0,0 +1,126 @@
using UnityEngine;
using System.Collections;
/// <summary>
/// this class shows one way to setup a virtual control setup (d-pad and two buttons). It illustrates a bunch of concepts
/// including recognizer layering (overlapping "up" button to get diagonals) and also how to detect only in this frame
/// if a button is down (attack button).
/// </summary>
public class VirtualControls
{
public bool leftDown, upDown, rightDown, attackDown, jumpDown;
private float buttonWidth = 24f;
private float buttonHeight = 30f;
private TKAnyTouchRecognizer _leftRecognizer;
private TKAnyTouchRecognizer _rightRecognizer;
private TKAnyTouchRecognizer _upRecognizer;
private TKButtonRecognizer _attackRecognizer;
private TKButtonRecognizer _jumpRecognizer;
public TKRect leftRect { get { return _leftRecognizer.boundaryFrame.Value; } }
public TKRect rightRect { get { return _rightRecognizer.boundaryFrame.Value; } }
public TKRect upRect { get { return _upRecognizer.boundaryFrame.Value; } }
public TKRect attackRect { get { return _attackRecognizer.boundaryFrame.Value; } }
public TKRect jumpRect { get { return _jumpRecognizer.boundaryFrame.Value; } }
public VirtualControls()
{
// if we have something like the iPad with a squarish aspect ratio adjust the button height to be a bit smaller
if( Camera.main.aspect < 1.7f )
{
buttonHeight *= Camera.main.aspect / 1.7f;
buttonWidth *= Camera.main.aspect / 1.7f;
}
setupRecognizers();
}
public void update()
{
// reset our state
leftDown = upDown = rightDown = attackDown = jumpDown = false;
// first update our touches then use our recognizers to set our state
TouchKit.updateTouches();
leftDown = _leftRecognizer.state == TKGestureRecognizerState.RecognizedAndStillRecognizing;
rightDown = _rightRecognizer.state == TKGestureRecognizerState.RecognizedAndStillRecognizing;
upDown = _upRecognizer.state == TKGestureRecognizerState.RecognizedAndStillRecognizing;
jumpDown = _jumpRecognizer.state == TKGestureRecognizerState.RecognizedAndStillRecognizing;
}
public void createDebugQuads()
{
createQuadButton( leftRect, Color.green );
createQuadButton( rightRect, Color.green );
createQuadButton( upRect, Color.white );
createQuadButton( attackRect, Color.cyan );
createQuadButton( jumpRect, Color.magenta );
}
void createQuadButton( TKRect rect, Color color )
{
color.a = 0.2f;
// find the center point in Unity units
var center = Camera.main.ScreenToWorldPoint( rect.center );
center.z = 0;
// create the quad button
var button = GameObject.CreatePrimitive( PrimitiveType.Quad );
button.transform.position = center;
button.GetComponent<Renderer>().material.shader = Shader.Find( "Sprites/Default" );
button.GetComponent<Renderer>().material.color = color;
// scale the quad button accordingly
button.transform.localScale = new Vector3
(
TouchKit.instance.pixelsToUnityUnitsMultiplier.x * rect.width,
TouchKit.instance.pixelsToUnityUnitsMultiplier.y * rect.height
);
}
void setupRecognizers()
{
// left button
_leftRecognizer = new TKAnyTouchRecognizer( new TKRect( 0f, 0f, buttonWidth, buttonHeight ) );
TouchKit.addGestureRecognizer( _leftRecognizer );
// right button
_rightRecognizer = new TKAnyTouchRecognizer( new TKRect( buttonWidth + 1f, 0f, buttonWidth, buttonHeight ) );
TouchKit.addGestureRecognizer( _rightRecognizer );
// up button. we place it 70% of the way up the other two buttons allowing some overlap
_upRecognizer = new TKAnyTouchRecognizer( new TKRect( 0f, buttonHeight * 0.7f, buttonWidth * 2f + 1f, 20f ) );
TouchKit.addGestureRecognizer( _upRecognizer );
// attack button. we use the onSelectedEvent here because we only want to know the exact frame it was pressed
_attackRecognizer = new TKButtonRecognizer( new TKRect( TouchKit.instance.designTimeResolution.x - buttonWidth * 2f, 0, buttonWidth, buttonHeight ), 0f );
_attackRecognizer.onSelectedEvent += ( r ) =>
{
attackDown = true;
};
TouchKit.addGestureRecognizer( _attackRecognizer );
// jump button
_jumpRecognizer = new TKButtonRecognizer( new TKRect( TouchKit.instance.designTimeResolution.x - buttonWidth, 0, buttonWidth, buttonHeight ), 0f );
TouchKit.addGestureRecognizer( _jumpRecognizer );
}
}
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 9dbccd6fa8ec6447aaa2b359982e10a0
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData: