|
@@ -21,6 +21,8 @@ public class SoundGameController : MonoBehaviour
|
|
|
float GameEndTime;
|
|
|
// 游戏得分统计
|
|
|
int score, combo, maxCombo, NGCombo, perfectCount, goodCount, poorCount, missCount, totalCount;
|
|
|
+ // 游戏数据
|
|
|
+ string currentDogState = "walking"; // 是否有狗在跑
|
|
|
|
|
|
// TapOrSwipe 触控检测
|
|
|
Vector2 pressDownPosition = new Vector2(0, 0);
|
|
@@ -42,12 +44,58 @@ public class SoundGameController : MonoBehaviour
|
|
|
notePrefabTap = Resources.Load<GameObject>("WalkDogs/Note/NoteTap");
|
|
|
|
|
|
StartCoroutine(PlaySoundGame());
|
|
|
+ StartCoroutine(DogComponentInstaller());
|
|
|
}
|
|
|
|
|
|
// Update is called once per frame
|
|
|
void Update()
|
|
|
{
|
|
|
+ DogStatusUpdate();
|
|
|
+ }
|
|
|
+
|
|
|
+ IEnumerator DogComponentInstaller()
|
|
|
+ {
|
|
|
+ yield return null;
|
|
|
+ // 找到所有标签为 "dog" 的 GameObject
|
|
|
+ GameObject[] dogObjects = GameObject.FindGameObjectsWithTag("dog");
|
|
|
+
|
|
|
+ foreach (GameObject dog in dogObjects)
|
|
|
+ {
|
|
|
+ // 加载指定的Animator controller
|
|
|
+ Animator animator = dog.GetComponent<Animator>();
|
|
|
+ DogProperty dogProperty = new DogProperty();
|
|
|
+ foreach (var dogProp in UserProperty.dogs)
|
|
|
+ {
|
|
|
+ if (dogProp.dog_name == dog.name)
|
|
|
+ {
|
|
|
+ dogProperty = dogProp;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ RuntimeAnimatorController animatorController = Resources.Load<RuntimeAnimatorController>("WalkDogs/Animation/shibaInu");
|
|
|
+ if (dogProperty.breed == "shibaInu")
|
|
|
+ {
|
|
|
+ animatorController = Resources.Load<RuntimeAnimatorController>("WalkDogs/Animation/shibaInu");
|
|
|
+ }
|
|
|
+ animator.runtimeAnimatorController = animatorController;
|
|
|
|
|
|
+ // 加载Rigidbody
|
|
|
+ Rigidbody rigidbody = dog.AddComponent<Rigidbody>();
|
|
|
+ //rigidbody.isKinematic = true;
|
|
|
+ rigidbody.mass = 10;
|
|
|
+ rigidbody.linearDamping = 10;
|
|
|
+ rigidbody.angularDamping = 10;
|
|
|
+ //rigidbody.freezeRotation = true;
|
|
|
+ rigidbody.constraints = RigidbodyConstraints.FreezePositionY | RigidbodyConstraints.FreezeRotation;
|
|
|
+ rigidbody.interpolation = RigidbodyInterpolation.Interpolate;
|
|
|
+ rigidbody.collisionDetectionMode = CollisionDetectionMode.ContinuousSpeculative;
|
|
|
+
|
|
|
+ // 加载box collider
|
|
|
+ BoxCollider boxCollider = dog.AddComponent<BoxCollider>();
|
|
|
+ boxCollider.isTrigger = false;
|
|
|
+ boxCollider.center = new Vector3(0, 0.25f, 0);
|
|
|
+ boxCollider.size = new Vector3(0.2f, 0.5f, 0.6f);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
IEnumerator PlaySoundGame()
|
|
@@ -87,7 +135,7 @@ public class SoundGameController : MonoBehaviour
|
|
|
if (myMaterial != null)
|
|
|
{
|
|
|
backgroundMeshRenderer.material = myMaterial;
|
|
|
- Debug.Log("Background changed to: " + backgroundPath);
|
|
|
+ // Debug.Log("Background changed to: " + backgroundPath);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
@@ -115,8 +163,9 @@ public class SoundGameController : MonoBehaviour
|
|
|
note.isTapped = true;
|
|
|
missCount++;
|
|
|
NGCombo++;
|
|
|
- Debug.Log("Miss!" + Time.time + " Tap time deadline: " + TapTimeDeadline + " total miss:" + missCount);
|
|
|
- Debug.Log("index of note:" + soundTrackManager.soundAction.IndexOf(note));
|
|
|
+ combo = 0; // 重置连击
|
|
|
+ // Debug.Log("Miss!" + Time.time + " Tap time deadline: " + TapTimeDeadline + " total miss:" + missCount);
|
|
|
+ // Debug.Log("index of note:" + soundTrackManager.soundAction.IndexOf(note));
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
@@ -154,16 +203,16 @@ public class SoundGameController : MonoBehaviour
|
|
|
if (action == "tap")
|
|
|
{
|
|
|
note = Instantiate(notePrefabTap);
|
|
|
- Debug.Log("Create Tap Note: " + noteName);
|
|
|
- Debug.Log("Hit Time: " + hitTime + ", Action: " + action);
|
|
|
- Debug.Log("Create Time: " + Time.time);
|
|
|
+ // Debug.Log("Create Tap Note: " + noteName);
|
|
|
+ // Debug.Log("Hit Time: " + hitTime + ", Action: " + action);
|
|
|
+ // Debug.Log("Create Time: " + Time.time);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
note = Instantiate(notePrefabSwipe);
|
|
|
- Debug.Log("Create Tap Note: " + noteName);
|
|
|
- Debug.Log("Hit Time: " + hitTime + ", Action: " + action);
|
|
|
- Debug.Log("Create Time: " + Time.time);
|
|
|
+ // Debug.Log("Create Tap Note: " + noteName);
|
|
|
+ // Debug.Log("Hit Time: " + hitTime + ", Action: " + action);
|
|
|
+ // Debug.Log("Create Time: " + Time.time);
|
|
|
}
|
|
|
note.gameObject.name = "note_" + noteName;
|
|
|
NoteController noteController = note.GetComponent<NoteController>();
|
|
@@ -258,7 +307,7 @@ public class SoundGameController : MonoBehaviour
|
|
|
}
|
|
|
perfectCount++;
|
|
|
NGCombo = 0;
|
|
|
- Debug.Log("Perfect!" + Time.time + " total perfect:" + perfectCount);
|
|
|
+ // Debug.Log("Perfect!" + Time.time + " total perfect:" + perfectCount);
|
|
|
string noteName = soundTrackManager.soundAction.IndexOf(note).ToString();
|
|
|
DestroyNote(noteName);
|
|
|
}
|
|
@@ -268,7 +317,7 @@ public class SoundGameController : MonoBehaviour
|
|
|
combo = 0;
|
|
|
goodCount++;
|
|
|
NGCombo = 0;
|
|
|
- Debug.Log("Good!" + Time.time + " total good:" + goodCount);
|
|
|
+ // Debug.Log("Good!" + Time.time + " total good:" + goodCount);
|
|
|
string noteName = soundTrackManager.soundAction.IndexOf(note).ToString();
|
|
|
DestroyNote(noteName);
|
|
|
}
|
|
@@ -278,7 +327,7 @@ public class SoundGameController : MonoBehaviour
|
|
|
combo = 0;
|
|
|
poorCount++;
|
|
|
NGCombo++;
|
|
|
- Debug.Log("Poor!" + Time.time + " total poor:" + poorCount);
|
|
|
+ // Debug.Log("Poor!" + Time.time + " total poor:" + poorCount);
|
|
|
}
|
|
|
}
|
|
|
else
|
|
@@ -286,9 +335,9 @@ public class SoundGameController : MonoBehaviour
|
|
|
combo = 0;
|
|
|
missCount++;
|
|
|
NGCombo++;
|
|
|
- Debug.Log("Wrong!" + Time.time + " total miss:" + missCount);
|
|
|
+ // Debug.Log("Wrong!" + Time.time + " total miss:" + missCount);
|
|
|
}
|
|
|
- Debug.Log("index of note:" + soundTrackManager.soundAction.IndexOf(note));
|
|
|
+ // Debug.Log("index of note:" + soundTrackManager.soundAction.IndexOf(note));
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
@@ -307,8 +356,59 @@ public class SoundGameController : MonoBehaviour
|
|
|
Debug.Log("Note not found: " + noteName);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ // 设置狗的状态
|
|
|
+ private void DogStatusUpdate()
|
|
|
+ {
|
|
|
+ GameObject[] dogObjects = GameObject.FindGameObjectsWithTag("dog");
|
|
|
+ Debug.Log("combo:"+ combo);
|
|
|
+ // combo = 6; // 这里是为了测试用,实际应该从游戏逻辑中获取当前连击数
|
|
|
+ if (combo >= 5 && combo < 10)
|
|
|
+ {
|
|
|
+ currentDogState = "running";
|
|
|
+ foreach (GameObject dog in dogObjects)
|
|
|
+ {
|
|
|
+ Animator animator = dog.GetComponent<Animator>();
|
|
|
+ if (animator != null)
|
|
|
+ {
|
|
|
+ animator.SetTrigger("run");
|
|
|
+ // animator.Play("Run");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if (combo >= 10)
|
|
|
+ {
|
|
|
+ currentDogState = "fastRunning";
|
|
|
+ foreach (GameObject dog in dogObjects)
|
|
|
+ {
|
|
|
+ Animator animator = dog.GetComponent<Animator>();
|
|
|
+ if (animator != null)
|
|
|
+ {
|
|
|
+ animator.SetTrigger("fastRun");
|
|
|
+ // animator.Play("Fast Run");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if(combo == 0)
|
|
|
+ {
|
|
|
+ if (currentDogState == "running" || currentDogState == "fastRunning")
|
|
|
+ {
|
|
|
+ currentDogState = "walking";
|
|
|
+ foreach (GameObject dog in dogObjects)
|
|
|
+ {
|
|
|
+ Animator animator = dog.GetComponent<Animator>();
|
|
|
+ if (animator != null)
|
|
|
+ {
|
|
|
+ // animator.Play("Walk");
|
|
|
+ animator.SetTrigger("walk");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
+
|
|
|
public class TouchResponse
|
|
|
{
|
|
|
public string action = ""; // 触控动作 up, down, left, right, tap, none(表示无效)
|