From 766cdff5ffa72b65d7f106658d1603f47739b2ba Mon Sep 17 00:00:00 2001 From: chai <215380520@qq.com> Date: Fri, 27 Oct 2023 11:05:14 +0800 Subject: + init --- GameCode/BounceEffectRetarget.cs | 103 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100644 GameCode/BounceEffectRetarget.cs (limited to 'GameCode/BounceEffectRetarget.cs') diff --git a/GameCode/BounceEffectRetarget.cs b/GameCode/BounceEffectRetarget.cs new file mode 100644 index 0000000..8e1ef79 --- /dev/null +++ b/GameCode/BounceEffectRetarget.cs @@ -0,0 +1,103 @@ +using System.Collections; +using Photon.Pun; +using Sonigon; +using UnityEngine; + +public class BounceEffectRetarget : BounceEffect +{ + [Header("Sound")] + public SoundEvent soundTargetBounceTargetPlayer; + + private MoveTransform move; + + private PhotonView view; + + private void Start() + { + view = GetComponentInParent(); + move = GetComponentInParent(); + GetComponentInParent().childRPCsVector2.Add("TargetBounce", SetNewVel); + GetComponentInParent().childRPCsInt.Add("TargetBounceLine", DrawLineTo); + } + + public override void DoBounce(HitInfo hit) + { + StartCoroutine(DelayMove(hit)); + } + + private void ActuallyDoBounce(int playerId) + { + Player playerWithID = PlayerManager.instance.GetPlayerWithID(playerId); + if ((bool)playerWithID) + { + GetComponentInParent().CallFunction("TargetBounce", (playerWithID.data.playerVel.position + Vector2.up * move.GetUpwardsCompensation(base.transform.position, playerWithID.data.playerVel.position) - (Vector2)base.transform.position).normalized * move.velocity.magnitude); + SoundManager.Instance.PlayAtPosition(soundTargetBounceTargetPlayer, SoundManager.Instance.GetTransform(), base.transform); + } + else + { + GetComponentInParent().CallFunction("TargetBounce", move.velocity); + } + } + + private void SetNewVel(Vector2 newVel) + { + move.enabled = true; + move.velocity = newVel; + } + + private Player FindTarget(HitInfo hit) + { + Player closestPlayer = PlayerManager.instance.GetClosestPlayer(base.transform.position + (Vector3)hit.normal * 0.1f); + if (PlayerManager.instance.CanSeePlayer(base.transform.position, closestPlayer).canSee) + { + return closestPlayer; + } + return null; + } + + private IEnumerator DelayMove(HitInfo hit) + { + Player p = FindTarget(hit); + if ((bool)p && view.IsMine) + { + GetComponentInParent().CallFunction("TargetBounceLine", p.playerID); + } + move.enabled = false; + if ((bool)hit.rigidbody) + { + move.GetComponent().IgnoreRigFor(hit.rigidbody, 0.5f); + } + yield return new WaitForSeconds(0.1f); + if (view.IsMine) + { + if ((bool)p) + { + ActuallyDoBounce(p.playerID); + } + else + { + ActuallyDoBounce(-1); + } + } + } + + private void DrawLineTo(int playerID) + { + Player playerWithID = PlayerManager.instance.GetPlayerWithID(playerID); + if ((bool)playerWithID) + { + StartCoroutine(DrawLine(playerWithID.transform)); + } + } + + private IEnumerator DrawLine(Transform target) + { + LineEffect line = GetComponentInChildren(includeInactive: true); + line.StartDraw(); + while ((bool)line) + { + line.DrawLine(base.transform.position, target.position); + yield return null; + } + } +} -- cgit v1.1-26-g67d0