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/MoveSequence.cs | 99 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 GameCode/MoveSequence.cs (limited to 'GameCode/MoveSequence.cs') diff --git a/GameCode/MoveSequence.cs b/GameCode/MoveSequence.cs new file mode 100644 index 0000000..1437614 --- /dev/null +++ b/GameCode/MoveSequence.cs @@ -0,0 +1,99 @@ +using Photon.Pun; +using UnityEngine; + +public class MoveSequence : MonoBehaviour +{ + private int targetID; + + public Vector2[] positions; + + public float drag = 1f; + + public float spring = 1f; + + public float cap = 1f; + + public float threshold = 1f; + + public float timeAtPos; + + private float counter; + + private Vector2 startPos; + + private Vector2 velocity; + + private Rigidbody2D rig; + + private Map map; + + private string myKey; + + private void Start() + { + base.gameObject.layer = 17; + startPos = base.transform.localPosition; + rig = GetComponent(); + map = GetComponentInParent(); + myKey = "MapObect " + GetComponentInParent().levelID + " " + base.transform.GetSiblingIndex(); + MapManager.instance.GetComponent().childRPCsInt.Add(myKey, RPCA_SetTargetID); + } + + private void OnDestroy() + { + if ((bool)MapManager.instance) + { + MapManager.instance.GetComponent().childRPCsInt.Remove(myKey); + } + } + + private void OnDrawGizmos() + { + for (int i = 0; i < positions.Length; i++) + { + Gizmos.DrawSphere((Vector2)base.transform.position + positions[i], 0.25f + (float)i * 0.15f); + } + } + + private void Update() + { + if (MapTransition.isTransitioning || !map.hasEntered) + { + return; + } + Vector2 vector = positions[targetID] + startPos; + Vector2 vector2 = vector - (Vector2)base.transform.position; + vector2 = Vector3.ClampMagnitude(vector2, cap); + if ((bool)rig) + { + rig.gravityScale = 0f; + rig.AddForce(vector2 * spring * CappedDeltaTime.time * rig.mass); + } + else + { + velocity += vector2 * spring * CappedDeltaTime.time; + velocity -= velocity * drag * CappedDeltaTime.time; + base.transform.position += (Vector3)velocity * TimeHandler.deltaTime; + } + if (!PhotonNetwork.IsMasterClient || !(Vector2.Distance(base.transform.position, vector) < threshold)) + { + return; + } + counter += TimeHandler.deltaTime; + if (counter > timeAtPos) + { + targetID++; + if (targetID >= positions.Length) + { + targetID = 0; + } + MapManager.instance.GetComponent().CallFunction(myKey, targetID); + counter = 0f; + } + } + + private void RPCA_SetTargetID(int setValue) + { + targetID = setValue; + } +} -- cgit v1.1-26-g67d0