Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 39a36d3

Browse files
committedJan 6, 2025
🚀 Draginput sample
1 parent 582e2c8 commit 39a36d3

14 files changed

+55
-29
lines changed
 

‎Assets/Samples/03. DragObject/Script/DragInput.cs

Lines changed: 0 additions & 23 deletions
This file was deleted.
File renamed without changes.

‎Assets/Samples/03. DragObject/DragObjectScene.unity renamed to ‎Assets/Samples/DragObject/DragObjectScene.unity

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ RenderSettings:
3838
m_ReflectionIntensity: 1
3939
m_CustomReflection: {fileID: 0}
4040
m_Sun: {fileID: 0}
41-
m_IndirectSpecularColor: {r: 0, g: 0, b: 0, a: 1}
41+
m_IndirectSpecularColor: {r: 0.44657815, g: 0.49641192, b: 0.5748165, a: 1}
4242
m_UseRadianceAmbientProbe: 0
4343
--- !u!157 &3
4444
LightmapSettings:
@@ -156,7 +156,7 @@ MonoBehaviour:
156156
m_Script: {fileID: 11500000, guid: 3774a79397e790b408c746ceb43b2ebe, type: 3}
157157
m_Name:
158158
m_EditorClassIdentifier:
159-
rotationSpeed: 500
159+
rotationSpeed: 5000
160160
--- !u!23 &695629108
161161
MeshRenderer:
162162
m_ObjectHideFlags: 0
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
using System;
2+
using R3;
3+
using R3.Triggers;
4+
using UnityEngine;
5+
using System.Threading;
6+
using System.Threading.Tasks;
7+
8+
namespace Samples.DragObject.Script
9+
{
10+
public class DragInput : MonoBehaviour
11+
{
12+
13+
public float rotationSpeed = 8000.0f;
14+
private readonly CancellationTokenSource _cancellationTokenSource = new ();
15+
16+
private async void Start()
17+
{
18+
try
19+
{
20+
while (!this._cancellationTokenSource.IsCancellationRequested)
21+
{
22+
await this.OnMouseDownAsObservable().FirstAsync(cancellationToken: this._cancellationTokenSource.Token);
23+
24+
await Observable.EveryUpdate()
25+
.Select(_ => new Vector2(Input.GetAxis("Mouse X"), Input.GetAxis("Mouse Y")))
26+
.TakeUntil(this.OnMouseUpAsObservable())
27+
.ForEachAsync(
28+
action: (move) =>
29+
{
30+
this.transform.rotation =
31+
Quaternion.AngleAxis(move.y * this.rotationSpeed * Time.deltaTime, Vector3.right)
32+
* Quaternion.AngleAxis(-move.x * this.rotationSpeed * Time.deltaTime, Vector3.up)
33+
* this.transform.rotation;
34+
},
35+
cancellationToken: this._cancellationTokenSource.Token);
36+
}
37+
}
38+
catch (TaskCanceledException e)
39+
{
40+
Debug.Log("Task cancellation was Success!!: " + e.Message);
41+
}
42+
}
43+
44+
private void OnDestroy()
45+
{
46+
this._cancellationTokenSource.Cancel();
47+
}
48+
}
49+
}

‎UserSettings/EditorUserSettings.asset

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,16 @@ EditorUserSettings:
1212
value: 530503525c075d5a09595e2615740f4415151c7b287920667d2f4431b7e16139
1313
flags: 0
1414
RecentlyUsedSceneGuid-2:
15-
value: 55060155060d0b085f59552746730c4413164f2f7e2d7e352b7e1861e6b9616c
15+
value: 000605075c020a5a0b5b0a73137a0c444215407e742e77687c2b4a31b5e5656d
1616
flags: 0
1717
RecentlyUsedSceneGuid-3:
18-
value: 000605075c020a5a0b5b0a73137a0c444215407e742e77687c2b4a31b5e5656d
18+
value: 520805525c01080c0f5d5924122006444e4f4872292924607f704965e0e26c3e
1919
flags: 0
2020
RecentlyUsedSceneGuid-4:
21-
value: 520805525c01080c0f5d5924122006444e4f4872292924607f704965e0e26c3e
21+
value: 07520d5550505d0f0c585d2314775c44454f417f2e7b75342e2c4b30bae66d3d
2222
flags: 0
2323
RecentlyUsedSceneGuid-5:
24-
value: 07520d5550505d0f0c585d2314775c44454f417f2e7b75342e2c4b30bae66d3d
24+
value: 55060155060d0b085f59552746730c4413164f2f7e2d7e352b7e1861e6b9616c
2525
flags: 0
2626
vcSharedLogLevel:
2727
value: 0d5e400f0650

0 commit comments

Comments
 (0)
Please sign in to comment.