-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit df6e038
Showing
4 changed files
with
304 additions
and
0 deletions.
There are no files selected for viewing
106 changes: 106 additions & 0 deletions
106
Assets/MRTK/Extensions/HandPhysicsService/JointKinematicBody.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
using Microsoft.MixedReality.Toolkit.Utilities; | ||
using System; | ||
using Unity.Profiling; | ||
using UnityEngine; | ||
|
||
namespace Microsoft.MixedReality.Toolkit.Extensions.HandPhysics | ||
{ | ||
/// <summary> | ||
/// Updates a rigidbody transform against another transform. | ||
/// </summary> | ||
public class JointKinematicBody : MonoBehaviour | ||
{ | ||
/// <summary> | ||
/// The joint this component tracks. | ||
/// </summary> | ||
public Transform Joint { get; set; } | ||
|
||
/// <summary> | ||
/// What hand this component lives on. | ||
/// </summary> | ||
public Handedness HandednessType { get; set; } | ||
|
||
/// <summary> | ||
/// What joint this component lives on. | ||
/// </summary> | ||
public TrackedHandJoint JointType { get; set; } | ||
|
||
/// <summary> | ||
/// An event to subscribe to when the component get's enabled. Useful for tacking when the joint loses tracking. | ||
/// </summary> | ||
public Action<JointKinematicBody> OnEnableAction { get; set; } | ||
|
||
/// <summary> | ||
/// An event to subscribe to when the component get's disabled. Useful for tacking when the joint loses tracking. | ||
/// </summary> | ||
public Action<JointKinematicBody> OnDisableAction { get; set; } | ||
|
||
/// <summary> | ||
/// self body | ||
/// </summary> | ||
public GameObject _player; | ||
public GameObject _effect; | ||
private GameObject mEffect; | ||
|
||
private static readonly ProfilerMarker UpdateStatePerfMarker = new ProfilerMarker("[MRTK] JointKinematicBody.UpdateState"); | ||
|
||
/// <summary> | ||
/// 手とオブジェクトが当たった時にサウンドを再生する | ||
/// </summary> | ||
/// <param name="other"></param> | ||
void OnTriggerEnter(Collider other) | ||
{ | ||
if (_player && _player == other.gameObject) | ||
{ | ||
return; | ||
} | ||
|
||
if (other.gameObject.tag.Contains("Cube")) | ||
{ | ||
GetComponent<AudioSource>().Play(); | ||
mEffect = Instantiate(_effect, this.transform.position, Quaternion.identity); | ||
mEffect.transform.localScale = Vector3.one; | ||
Invoke(nameof(DestroyEffect), 3.0f); // 3秒後に破棄 | ||
} | ||
} | ||
|
||
void DestroyEffect() | ||
{ | ||
Destroy(mEffect); | ||
} | ||
|
||
|
||
/// <summary> | ||
/// Updates the position of the <see cref="JointKinematicBody"/> based on <see cref="JointType"/>. | ||
/// </summary> | ||
public void UpdateState(bool active) | ||
{ | ||
using (UpdateStatePerfMarker.Auto()) | ||
{ | ||
bool previousActiveState = gameObject.activeSelf; | ||
gameObject.SetActive(active); | ||
|
||
if (active) | ||
{ | ||
transform.position = Joint.position; | ||
transform.rotation = Joint.rotation; | ||
} | ||
|
||
if (previousActiveState != active) | ||
{ | ||
if (active) | ||
{ | ||
OnEnableAction?.Invoke(this); | ||
} | ||
else | ||
{ | ||
OnDisableAction?.Invoke(this); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
using Microsoft.MixedReality.Toolkit; | ||
using UnityEngine; | ||
|
||
public class Cube : MonoBehaviour | ||
{ | ||
public Vector3 playerpos; | ||
public GameObject effectExplosion; // オブジェクトに触れた時のパーティクル | ||
public GameObject touchEffect; // 一定以上ポイントがたまったら生成する背景のパーティクル | ||
private float tmpTarget; | ||
private bool isTrigger = false; | ||
private Vector3 targetPoint; | ||
private int counter = 0; | ||
private GameObject effect; | ||
|
||
// Start is called before the first frame update | ||
void Start() | ||
{ | ||
playerpos = CoreServices.InputSystem.GazeProvider.GazeOrigin; | ||
tmpTarget = UnityEngine.Random.Range(-2, 2); | ||
|
||
var diff = -3.0f; | ||
if((tmpTarget+2)%2==1) | ||
{ | ||
diff = -4.0f; | ||
} | ||
this.targetPoint = new Vector3(tmpTarget*3, diff, 0); | ||
} | ||
|
||
// Update is called once per frame | ||
void Update() | ||
{ | ||
// targetに向かう | ||
this.transform.position = Vector3.MoveTowards( | ||
this.transform.position, | ||
this.targetPoint, | ||
1.1f); | ||
|
||
// 一定の位置に達したらGameObjectを破棄する | ||
if (this.transform.position.z == 0) | ||
{ | ||
Destroy(this.gameObject); | ||
} | ||
} | ||
|
||
// 手との衝突判定 | ||
void OnTriggerEnter(Collider other) | ||
{ | ||
if (isTrigger) | ||
{ | ||
return; | ||
} | ||
|
||
isTrigger = true; | ||
if (other.gameObject.tag.Contains("Player")) | ||
{ | ||
PointCounter.AddPoint(50); // ポイント加算 | ||
|
||
if (counter%1000==0) // 1000ポイントごとに背景のパーティクルを増やす | ||
{ | ||
Instantiate(touchEffect, this.transform.position, Quaternion.identity); | ||
} | ||
|
||
counter++; | ||
} | ||
isTrigger = false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
using DG.Tweening; | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using UnityEngine; | ||
|
||
public class LaneAnimation : MonoBehaviour | ||
{ | ||
public Renderer rendererComponent; | ||
// Start is called before the first frame update | ||
void Start() | ||
{ | ||
// Minute=60/BPM=105*2 | ||
this.rendererComponent.material.DOColor(Color.red, 0.2857f).SetLoops(-1, LoopType.Yoyo); | ||
} | ||
|
||
// Update is called once per frame | ||
void Update() | ||
{ | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
using Microsoft.MixedReality.Toolkit; | ||
using System.Linq; | ||
using UnityEngine; | ||
|
||
public class Spawner : MonoBehaviour | ||
{ | ||
public GameObject[] cubes; | ||
public Transform[] points; | ||
private float beat = 1; | ||
public GameObject[] lanes; // レーン | ||
public GameObject resultText; // リザルトの表示 | ||
public GameObject calorieText; // 消費カロリーの表示 | ||
public GameObject clearEffect; // クリア時の花火エフェクト | ||
public GameObject retryButton; // リトライボタン | ||
private float timer; | ||
private System.Timers.Timer aTimer; | ||
private bool terminated; | ||
|
||
// Start is called before the first frame update | ||
void Start() | ||
{ | ||
terminated = false; | ||
|
||
var playerpos = CoreServices.InputSystem.GazeProvider.GazeOrigin; | ||
var cnt = 0; | ||
|
||
// 約4分後(曲の終わりごろ)に画面遷移、オブジェクト生成をやめる | ||
Invoke(nameof(StopCreateCube), 60.0f*3.8f); | ||
|
||
// レーンを作る | ||
foreach (int i in Enumerable.Range(-2, 5)) | ||
{ | ||
// レーンの形状を変えたいときはlane[]にお好みのGameObjectを入れてください | ||
GameObject lane = Instantiate( | ||
lanes[cnt], points[0]); | ||
|
||
lane.transform.localPosition = new Vector3(0, 15, 100); | ||
|
||
// 2点間の距離を算出してサイズを調整 | ||
float yPointDiff = -3.0f; | ||
if((i+2)%2==1) | ||
{ | ||
// 1,3,5番目のレーンだけ到達する位置の高さを変更 | ||
yPointDiff = -4.0f; | ||
} | ||
|
||
float distance = Vector3.Distance(lane.transform.localPosition, new Vector3(i*3,yPointDiff, -1)); | ||
|
||
// Rotationの制御 | ||
lane.transform.localScale = new Vector3(0.1f, 0.1f, distance * 3); | ||
var rotate = Quaternion.LookRotation( | ||
lane.transform.localPosition - new Vector3(i * 3, yPointDiff, 0), Vector3.forward); | ||
lane.transform.rotation = rotate; | ||
|
||
cnt++; | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Cubeの生成をやめる | ||
/// </summary> | ||
public void StopCreateCube() | ||
{ | ||
terminated = true; | ||
Invoke(nameof(MoveToResult), 10.0f); | ||
} | ||
|
||
/// <summary> | ||
/// 結果を表示する | ||
/// </summary> | ||
public void MoveToResult() | ||
{ | ||
|
||
var text = "FAILED"; | ||
if (PointCounter.currentPoints > 20000) | ||
{ | ||
text = "CLEAR!"; | ||
Instantiate(clearEffect, new Vector3(0, 0, 5), Quaternion.identity); | ||
} | ||
|
||
resultText.GetComponent<TextMesh>().text = text; | ||
resultText.transform.localScale = new Vector3(1, 1, 1); | ||
calorieText.GetComponent<TextMesh>().text = "13.2kcal"; // 今は固定表示 | ||
calorieText.transform.localScale = new Vector3(1, 1, 1); | ||
retryButton.transform.localScale = new Vector3(40, 40, 1); | ||
} | ||
|
||
// Update is called once per frame | ||
void Update() | ||
{ | ||
if (terminated) | ||
{ | ||
return; | ||
} | ||
|
||
if (timer > beat) | ||
{ | ||
GameObject cube = Instantiate( | ||
cubes[UnityEngine.Random.Range(0, 3)]); | ||
cube.transform.localPosition = new Vector3(0, 22.5f, 150); | ||
cube.transform.Rotate(new Vector3(0, 180, 0)); | ||
|
||
timer -= beat; | ||
} | ||
|
||
timer += Time.deltaTime; | ||
} | ||
|
||
|
||
} |