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/PhotonMapObject.cs | 98 +++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 98 insertions(+)
 create mode 100644 GameCode/PhotonMapObject.cs

(limited to 'GameCode/PhotonMapObject.cs')

diff --git a/GameCode/PhotonMapObject.cs b/GameCode/PhotonMapObject.cs
new file mode 100644
index 0000000..8bfe674
--- /dev/null
+++ b/GameCode/PhotonMapObject.cs
@@ -0,0 +1,98 @@
+using System;
+using System.Collections;
+using Photon.Pun;
+using UnityEngine;
+
+public class PhotonMapObject : MonoBehaviour
+{
+	private Map map;
+
+	private bool photonSpawned;
+
+	private float counter;
+
+	private bool waitingToBeRemoved;
+
+	private void Awake()
+	{
+		if (base.transform.parent != null)
+		{
+			UnityEngine.Object.DestroyImmediate(GetComponent<PhotonView>());
+		}
+	}
+
+	private void Start()
+	{
+		Rigidbody2D component = GetComponent<Rigidbody2D>();
+		component.isKinematic = true;
+		component.simulated = false;
+		if (base.transform.parent == null)
+		{
+			photonSpawned = true;
+			base.transform.SetParent(MapManager.instance.currentMap.Map.transform, worldPositionStays: true);
+			map = GetComponentInParent<Map>();
+			map.missingObjects--;
+			Map obj = map;
+			obj.mapIsReadyAction = (Action)Delegate.Combine(obj.mapIsReadyAction, new Action(Go));
+			if (map.hasRope && !GetComponent<PhotonView>().IsMine)
+			{
+				component.gravityScale = 0f;
+			}
+		}
+		else
+		{
+			map = GetComponentInParent<Map>();
+			Map obj2 = map;
+			obj2.mapIsReadyEarlyAction = (Action)Delegate.Combine(obj2.mapIsReadyEarlyAction, new Action(GoEarly));
+		}
+	}
+
+	private void GoEarly()
+	{
+		if (waitingToBeRemoved)
+		{
+			UnityEngine.Object.DestroyImmediate(base.gameObject);
+		}
+	}
+
+	private void Go()
+	{
+		StartCoroutine(IGo());
+	}
+
+	private IEnumerator IGo()
+	{
+		Rigidbody2D rig = GetComponent<Rigidbody2D>();
+		yield return new WaitForSeconds(0f);
+		yield return new WaitForSeconds(0f);
+		yield return new WaitForSeconds(0f);
+		rig.isKinematic = false;
+		rig.simulated = true;
+		if ((bool)rig)
+		{
+			for (float i = 0f; i < 1f; i += Time.deltaTime * 1f)
+			{
+				rig.velocity -= rig.velocity * i * 0.05f;
+				yield return null;
+			}
+		}
+	}
+
+	private void Update()
+	{
+		if (waitingToBeRemoved || photonSpawned)
+		{
+			return;
+		}
+		counter += Mathf.Clamp(Time.deltaTime, 0f, 0.1f);
+		if ((PhotonNetwork.OfflineMode && counter > 1f && map.hasEntered) || ((bool)map && map.hasEntered && map.LoadedForAll()))
+		{
+			if (PhotonNetwork.IsMasterClient)
+			{
+				PhotonNetwork.Instantiate("4 Map Objects/" + base.gameObject.name.Split(char.Parse(" "))[0], base.transform.position, base.transform.rotation, 0);
+			}
+			map.missingObjects++;
+			waitingToBeRemoved = true;
+		}
+	}
+}
-- 
cgit v1.1-26-g67d0