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/RemoteControl.cs | 128 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 128 insertions(+) create mode 100644 GameCode/RemoteControl.cs (limited to 'GameCode/RemoteControl.cs') diff --git a/GameCode/RemoteControl.cs b/GameCode/RemoteControl.cs new file mode 100644 index 0000000..c0049bb --- /dev/null +++ b/GameCode/RemoteControl.cs @@ -0,0 +1,128 @@ +using Photon.Pun; +using Sonigon; +using SoundImplementation; +using UnityEngine; + +public class RemoteControl : MonoBehaviour +{ + [Header("Sound")] + public SoundEvent soundRemoteSteeringLoop; + + private bool soundIsPlaying; + + [Header("Settings")] + public bool snap; + + public float rotateSpeed = 1f; + + private SpawnedAttack spawned; + + private MoveTransform move; + + private float startVelocity; + + private bool isOn; + + private ProjectileHit hit; + + private ParticleSystem part; + + public ParticleSystem boopPart; + + private float c; + + private PhotonView view; + + private ChildRPC childRPC; + + private void OnDestroy() + { + if (soundRemoteSteeringLoop != null && spawned != null && spawned.spawner != null && soundIsPlaying) + { + soundIsPlaying = false; + SoundStaticRemoteControl.remoteControl.AddNumberOf(spawned.spawner.transform, -1); + if (SoundStaticRemoteControl.remoteControl.GetNumberOf(spawned.spawner.transform) <= 0) + { + SoundManager.Instance.Stop(soundRemoteSteeringLoop, spawned.spawner.transform); + } + } + } + + private void Start() + { + childRPC = GetComponentInParent(); + view = GetComponentInParent(); + hit = GetComponentInParent(); + move = GetComponentInParent(); + spawned = GetComponentInParent(); + startVelocity = move.velocity.magnitude; + part = GetComponentInChildren(); + GetComponentInParent().active = true; + if (soundRemoteSteeringLoop != null && spawned != null && spawned.spawner != null && !soundIsPlaying) + { + soundIsPlaying = true; + if (SoundStaticRemoteControl.remoteControl.GetNumberOf(spawned.spawner.transform) <= 0) + { + SoundManager.Instance.Play(soundRemoteSteeringLoop, spawned.spawner.transform); + } + SoundStaticRemoteControl.remoteControl.AddNumberOf(spawned.spawner.transform, 1); + } + } + + public void ToggleOn(bool isOn) + { + } + + private void Update() + { + if (!view.IsMine) + { + return; + } + Vector3 zero = Vector3.zero; + if (spawned.spawner.data.playerActions.Device != null) + { + zero = spawned.spawner.data.input.aimDirection; + } + else + { + zero = MainCam.instance.cam.ScreenToWorldPoint(Input.mousePosition) - base.transform.position; + zero.z = 0f; + zero.Normalize(); + } + zero += Vector3.Cross(Vector3.forward, zero) * move.selectedSpread; + c += TimeHandler.deltaTime; + if (snap) + { + if (spawned.spawner.data.block.blockedThisFrame) + { + part.Play(); + move.velocity *= -1f; + base.enabled = false; + } + } + else if (zero.magnitude > 0.2f && hit.sinceReflect > 2f) + { + move.velocity = Vector3.RotateTowards(move.velocity, zero.normalized * startVelocity, rotateSpeed * TimeHandler.deltaTime, rotateSpeed * TimeHandler.deltaTime * 10f); + if (c > 0.1f) + { + boopPart.transform.parent.rotation = Quaternion.LookRotation(zero); + boopPart?.Emit(1); + c = 0f; + } + if (!isOn) + { + move.simulateGravity++; + } + isOn = true; + } + else + { + if (isOn) + { + move.simulateGravity--; + } + isOn = false; + } + } +} -- cgit v1.1-26-g67d0