Unity 3D(二) 附件 - LeanTouch的ReadMe的翻译

本文主要是用微软翻译工具翻译的, 我修改了部分句子.

Thank you for downloading! 

If you like this asset then please leave a review/rating on the Asset Store, it really helps me out. 

If you have any questions, feel free to e​mail me at: ​carlos.wilkes@gmail.com I’m also available for freelance work if you need help with your projects. 

 感谢下载.

如果你喜欢这个这个资源请在Asset Store留下评论或打分, 这对我很有帮助.

如果你有什么疑问, 请随时给我发邮件. 如果您需要有关项目的帮助, 我也可以作为自由职业者为你工作。

What is Lean Touch? 

When you create mobile games you often want to make use of multi touch gestures, like pinch and twist. However, Unity makes this difficult to do, because they only provide the Input.touches array, requiring you to do all the calculations yourself. 
With LeanTouch you no longer have to worry about these issues, because all the touch gesture calculations are done for you in a very simple and elegant way. LeanTouch also allows you to simulate multi touch gestures on desktop, so you don’t have to waste lots of time deploying to your mobile devices while you setup your input. 

 Lean Touch是什么?

当你开发手机游戏时, 你经常想利用多点触摸手势, 比如双指捏合和旋转。但是, Unity 使这一操作变得困难, 因为它们只提供Input.touches数组, 要求你自己做所有的计算。
使用 LeanTouch, 您不必再担心这些问题, 因为所有的触摸手势计算都是以非常简单和优雅的方式完成的。LeanTouch 还允许您在PC上模拟多点触摸手势, 因此在设置输入时不必浪费大量时间部署到移动设备。

How do I add Lean Touch to my game? 

Click GameObject / Lean / Touch, or right click your Hierarchy window and go to Lean / Touch. 

You should now see a new GameObject called ‘LeanTouch’ with the LeanTouch component selected. 
When you enter play mode, this component will automatically convert all mouse and touch input into an easy to use format. 
Remember that scripts using Lean Touch only work when there is a LeanTouch component active in your scene, so make sure to add one to every scene (or carry it over with DontDestroyOnLoad). 

 如何将Lean Touch添加到游戏中?

点击GameObject→Lean→Touch, 或者在Hierarchy窗口中右击, 选择Lean→Touch.

现在, 您应该看到一个新的游戏对象叫做 "LeanTouch" , 并且 LeanTouch 处于选中状态。
当您进入播放模式时, 此组件将自动将所有鼠标和触摸输入转换为易于使用的格式。
请记住, 使用Lean Touch的脚本只有在场景中有一个 LeanTouch 组件处于活动状态时才起作用, 因此请确保向每个场景添加一个 (或将其设置成 加载时禁止销毁)。(参考链接: DontDestroyOnLoad使用方法)

How do I use Lean Touch without code? 

Lean Touch comes with many example components to do common tasks. 
For example, if you want to spawn a prefab when a finger touches the screen, you can begin by making a new GameObject, and adding the LeanSpawnAt component. Inside this component, you’ll see it has the ‘Prefab’ setting. You can browse or drag and drop your desired prefab here. Next, you can add the LeanFingerTap component. Inside this component, you’ll see it has the ‘OnTap’ event. To link this event to the prefab spawning, you need to click the plus ‘+’ button below where it says ‘List is Empty’, and in the bottom left box that says ‘None (Object)’, you need to drag and drop the LeanSpawn component you added earlier. Next, you need to click the ‘No Function’ dropdown, and select the ‘LeanSpawnAt -> Dynamic LeanFinger -> Spawn’ function. You can now hit play, and tapping a finger (or clicking) on the screen will spawn your prefab. 
There are many other components that work in similar ways that can be connected together using only the editor. To find out how these work I recommend you browse through the demo scenes and look at the GameObjects to see what’s going on. 

如何在不写代码的情况下使用Lean Touch?

Lean Touch附带许多示例组件来执行常见任务。
例如, 如果您想在手指触摸屏幕时生成预制件(Prefab), 需要首先创建一个GameObject, 然后在上面添加 LeanSpawnAt 组件。在此组件中, 您将看到它有Prefab参数。您可以在这里设置您想要的Prefab。然后添加 LeanFingerTap 组件。在此组件中, 您将看到它具有 "OnTap" 事件。要将此事件链接到生成Prefab的方法, 您需要单击 "List is empty" 下面的"+"按钮, 在 "None (Object)" 的左下角框中, 您需要拖放刚才添加的GameObject。接下来, 您需要单击 "No Function" 下拉列表, 然后选择 LeanSpawnAt → Dynamic LeanFinger → Spawn" 函数。现在, 您可以运行游戏, 触摸 (或点击) 屏幕将生成您的Prefab。
其他组件的工作方式也是类似的, 只使用编辑器就可以连接在一起。要了解这些是如何工作的, 我建议您看看示例场景, 观察GameObject上有什么。

How do I use Lean Touch with C#? 

You can access all finger data from the Lean.Touch.LeanTouch class. 
The easiest way to begin is by hooking into the static events it exposes. 
For example, if you want to perform an action when a finger touches the screen, you can hook into the Lean.Touch.LeanTouch.OnFingerDown event. This event gets called every time a finger begins touching the screen, and gets passed a Lean.Touch.LeanFinger instance as a parameter. It’s recommended you hook into these events from OnEnable, and unhook from OnDisable. 

如何在C#中使用Lean Touch 

您可以从 Lean.Touch.LeanTouch 类访问所有触摸数据。
开始的最简单的方法是将LeanTouch的事件绑定与GameObject的生命周期联系在一起。
例如, 如果要在触摸屏幕时执行操作, 则可以处理 Lean.Touch.LeanTouch.OnFingerDown 事件。每次手指开始触摸屏幕时, 都会调用此事件, 并将一个 Lean.Touch.LeanFinger 对象作为参数传递。建议您在 OnEnable 函数添加事件监听器, 并从 OnDisable 删除。

To see what other events are available, I recommend you read the LeanTouch.cs, script and its comments. 
Another way to access finger data is to poll it directly from the Lean.Touch.LeanTouch.Fingers static list. This list stores all fingers that are currently touching the screen, and you can use this data at any time (e.g. Update) to quickly handle input. 

若要什么事件时可以使用的, 我建议您阅读 LeanTouch.cs 的代码及其注释。
访问触摸数据的另一种方法是直接从 Lean.Touch.LeanTouch.Fingers 静态列表轮询它。此列表存储当前触摸屏幕的所有手指, 您可以随时使用此数据 (例如在Update()中) 来快速处理输入。

If you need to modify or exclude certain fingers then I highly recommend you use the Lean.Touch.LeanTouch.GetFingers(...) method, which wich has common filter options, and will return a temporary list that you can further filter without breaking LeanTouch. 

 如果您需要修改或排除某些手指, 那么我强烈建议您使用 Lean.Touch.LeanTouch.GetFingers (...) 方法, 它具有常见的筛选器选项, 并将返回一个临时列表, 您可以进一步筛选而不中断 LeanTouch。

How do I handle multi-finger gestures (e.g. Pinch, Twist) from C#? 

The Lean.Touch.LeanGesture class makes this very easy. 
For example, if you want to find how many degrees the fingers were twisted in the last frame, you can call the 
Lean.Touch.LeanGesture.GetTwistDegrees() method, which will automatically calculate it from all fingers. This method also has an overload that allows you to pass a specific list of fingers if you don’t want to use them all. 
To see what other gestures are available, I recommend you read the LeanGesture.cs script and its comments. 

如何在C#中处理多指手势?

Lean.Touch.LeanGesture 类使这非常容易实现。
例如, 如果要查找最后一帧中手指扭曲的度数, 可以调用Lean.Touch.LeanGesture.GetTwistDegrees() 方法, 它将自动从所有手指计算它。此方法还具有重载. 如果您不想使用全部手指, 该方法允许您传递特定的手指列表, 。
若要查看其他可用的手势, 我建议您阅读 LeanGesture.cs 代码及其注释。 

Why are my inputs delayed by one frame? 

By default, all components in Unity have an execution order value of 0 (Default Time). This means messages like Update (where inputs are handled) can potentially be executed in any order between your scripts. This can be an issue if the main LeanTouch script executes after your gameplay scripts, as your gameplay scripts will be working on one-frame old data, which can be noticeable if your game is running at low FPS, or requires precision inputs. To fix this: 
1 - go to Edit → Project Settings → Script Execution Order. 
2 - Below the ‘Default Time’ box, click the ‘+’ button, and select the ‘Lean.Touch.LeanTouch’ script. 
3 - Change the execution order value (default 100) to something below 0 (e.g. -100), or drag it above ‘Default Time’ and any other scripts. 
4 - Click Apply, and enjoy! 

为什么我的输入延迟了一帧?

默认情况下, Unity 中的所有组件都有一个执行顺序,值为 0 (默认值)。这意味着像Update (在其中处理输入) 的生命周期函数的执行时刻不确定,可能处于任何其它脚本之间。如果 LeanTouch 脚本在您的游戏脚本后执行, 就会出现问题, 因为您的游戏脚本将处理一帧旧数据, 如果您的游戏运行时 FPS 比较低, 或者要求精确的输入, 这可能会很明显。若要修复此问题:
1-转到Edit→Project Settings→Script Execution Order。
2-在 "Default time" 框下, 单击 "+" 按钮, 然后选择 "Lean.Touch.LeanTouch" 脚本。
3-将执行顺序值 (默认为 100) 更改为低于 0 (例如-100), 或将其拖动到 "Default Time" 和任何其他脚本之上。
4-点击应用, 完成!

How do I stop my touch controls from going through my UI from C#? 

If you hook into any of the Lean.Touch.LeanTouch.OnFinger… events, you will get a Lean.Touch.LeanFinger instance. This class has the IsOverGui and StartedOverGui values you can check. 

如何在C#中禁止触摸UI组件? 

如果你添加过任何 Lean.Touch.LeanTouch.OnFinger 事件监听器, 你将得到一个 Lean.Touch.LeanFinger 实例。此类行具有两个属性 IsOverGui(是否在GUI之上) 和 StartedOverGui(在GUI之上开始) 值。

If you’re polling from Lean.Touch.LeanTouch.Fingers and want to quickly remove fingers that are touching the GUI, you can instead get the fingers from the Lean.Touch.LeanTouch.GetFingers method, which has a setting to quickly exclude these, as well as restrict it to a certain amount of fingers. 

如果您正在从 Lean.Touch.LeanTouch.Fingers 中遍历, 并且想要快速移除触摸 GUI 的手指, 则可以从 Lean.Touch.LeanTouch.GetFingers 方法获取手指, 它有一个选项来快速把这些手指快速排出, 也可以限制手指数量。

Why do I have to keep typing ‘Lean.Touch.’ before everything? 

To improve organization, all Lean Touch classes are inside the Lean.Touch namespace. If you don’t like typing Lean.Touch. each time, then you can add the following code to the top of your script: using Lean.Touch;  You can now just call LeanTouch.PointOverGui(...) etc 

为什么每次敲代码都要在前面加Lean.Touch?

为了便于组织, 所有LeanTouch类都在Lean.Touch命名空间中。如果你不喜欢每次都打Lean.Touch, 然后您可以将以下代码添加到您的脚本的顶部: using Lean.Touch; 你现在可以直接调用 LeanTouch. PointOverGui (...) 等方法了。

What is Lean Touch+? 

Lean Touch+ is the paid version of Lean Touch. It has the same features as Lean Touch, but comes with MANY more example scripts that show you how to implement features found in many modern games and applications. 
You can find more information about it here: ​https://www.assetstore.unity3d.com/#!/content/72356 

Lean Touch+是什么?

Lean Touch+ 是Lean Touch的付费版本。它具有与Lean Touch相同的功能, 但附带了许多示例脚本, 向您展示了如何实现许多现代游戏和应用程序中的功能。
您可以在这里找到有关它的更多信息: https://www.assetstore.unity3d.com/#!/content/72356

Can I request a new demo scene? 

Yes, if you have an idea for a demo scene that doesn’t come with LeanTouch or LeanTouch+ then please request it via e-mail above. Just make sure your demo scene idea doesn’t require another asset or library, because I can’t include those in this package! 
If I like your demo scene idea then I’ll even send you a free copy of Lean Touch+ 

我可以提交一个新的Demo场景吗?

可以, 如果你有一个Demo场景的想法(没有包含在LeanTouch 或 LeanTouch +中), 请通过电子邮件发送给我。只是确保你的演示场景的想法不需要其他的Asset或Library, 因为我不能在我的包里面添加那些Assets.
如果我喜欢你的Demo场景, 那么我会免费给你一个Lean Touch +。

How does the Screen Depth inspector setting work? 

Fingers touching the screen only have a 2D XY coordinate, but many touch interactions require calculating a 3D XYZ point (e.g. LeanSpawnAt to spawn a prefab in 3D). This inspector setting/class handles this conversion, and is flexible enough to support 2D games, 3D games, perspective 2D games, and much more. 
Understanding exactly how this works and can be used in your games can be difficult, so I recommend you examine the demo scenes to see how they are set up. 
The way it can work with all these different scene types is via the dropdown box, and associated settings. 
Camera Distance​ - This setting calculates a position in front of the current camera at the finger position, where the Distance setting is the distance from the camera in world space the point is pushed away. This setting is suitable for normal 3D games. 
Depth Intercept​ - This setting calculates a ray in front of the current camera at the finger position, and finds the point where this ray intercepts a plane lying on the XY plane with the specified Z position. This setting is suitable for normal 2D games. If you’re using standard 2D settings then a Z value of 0 should be used, but this can be adjusted for specific situations, because 2D sprites in Unity can be placed at any Z position and still work. 
Physics Raycast​ - This setting calculates a ray in front of the current camera at the finger position, and finds the point where this ray hits the physics scene. This setting is suitable for 3D games where you need to spawn something on an object or similar. 
Plane Intercept​ - This setting works similar to Depth Intercept, but allows you to specify a custom plane that can point in any direction, and optionally allows you to constrain or snap the final values. 

屏幕深度检查器如何工作?

手指触摸屏幕只有 2D XY 坐标, 但许多触摸交互需要计算一个 3D XYZ 点 (例如 LeanSpawnAt 在三维中生成一个Prefab)。此检查器设置/类处理此转换, 并且足够灵活, 以支持2D 游戏、3D 游戏、透视2D 游戏等。
准确理解这是如何工作以及如何在你的游戏中使用可能是困难的, 所以我建议你看看Demo场景, 看看它们是如何设置的。
可以在不同类型的场景中工作的方法通过下拉框和关联设置。
相机距离(Camera Distance) - 此设置计算手指位置在当前摄像机前方的位置, 其中距离设置为某点与世界坐标系中的Camera的距离。此设置适用于普通的3D 游戏。
深度截距(Depth Intercept) - 此设置生成一个当前摄像机到手指位置的射线, 并查找此射线在Z=确定值的 XY 平面上截取平面的点。此设置适用于普通的2D 游戏。如果您使用的是标准2D 设置, 则应使用 Z 值 0, 但这可以根据特定情况进行调整, 因为在 Unity 中的2D Sprite可以放置在任何 Z 位置上, 并且仍然工作。
物理学光线投射(Physics Raycast) - 此设置生成一个当前摄像机到手指位置的射线, 并找到此射线击中物理场景的点。此设置适用于需要在(3D)对象上生成东西的3D游戏。
平面截距(Plane Intercept) - 此设置与深度截距类似, 但允许您指定可指向任意方向的自定义平面, 并可选择允许约束或捕捉最终值。 

Why do I have to link up so many components? 

In earlier versions of Lean Touch, most components were self-contained, and calculated their own fingers. This made setup very simple, as you only had to add one component to instantly get its full functionality, but this simplicity came at a cost of making the code more complex and rigid. For example, there used to be a component that allowed you to rotate a GameObject when you swiped a finger, but if you wanted this to work with the just finger dragging, then this component would have to be duplicated and modified for each type of custom input you wanted. Doing this for swiping or dragging isn’t too difficult, but for more complex behaviours like multi tapping, or swipe no-release, it required a lot of complex code to be added to each unique behaviour. 
To solve this problem, Lean Touch 1.5.0 separated most of these features, so now there is a simple component that only handles rotation, and then you have separate finger handling components like LeanFingerSet, LeanFingerSwipe, LeanFingerSwipeNoRelease, and these use events that can be hooked to the rotation component. You can then use these same finger handling components to feed input to other components, and compose the exact type of touch behaviour you want without modifying any code. 

为什么我需要把这么多组件连接起来?

在早期版本的Lean Touch中, 大多数组件都是自包含的, 并计算了自己的手指。这使得安装非常简单, 因为您只需添加一个组件即可立即获得其完整功能, 但这种简单性的代价是使代码变得更加复杂和僵化。例如, 以前有一个组件, 允许您在轻扫手指时旋转游戏对象, 但如果您希望这能只需手指拖动就能使用, 则必须为所需的每种类型的自定义输入复制和修改此组件。这样做对于轻扫或拖动不是太难, 但对于更复杂的行为, 如多点触摸, 或轻扫但不释放, 它需要大量复杂的代码添加到每个独特的行为。
为了解决这个问题, Lean Touch1.5.0 分离了大部分这些功能, 所以现在的组件就比较简单了. 比如有一个组件只处理旋转, 还有分离的手指处理组件, 如 LeanFingerSet, LeanFingerSwipe, LeanFingerSwipeNoRelease, 这些使用可与旋转组件挂钩的事件。然后, 您可以使用这些相同的手指处理组件输入到其他组件, 并在不修改任何代码的情况下编写所需的触摸行为的确切类型。

 

  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值