Пример #1
0
        private IEnumerator TeleportPlayer()
        {
            if (TeleporterType == TeleporterType.Map)
            {
                TeleportPoints = GameObject.Find("SpawnPointContainer")?.GetComponentsInChildren <Transform>().Where(e => e != null && e.gameObject.name != "SpawnPointContainer").ToList();
            }

            if (TeleportPoints == null || !TeleportPoints.HasAtLeast(0))
            {
                if (TeleporterType == TeleporterType.Map)
                {
                    TeleportPoints = new List <Transform>()
                    {
                        GameObject.Find("TreeHomeTargetObject").transform
                    }
                }
                ;
                else
                {
                    yield break;
                }
            }

            var destination = TeleportPoints.Count > 1
                ? TeleportPoints[Random.Range(0, TeleportPoints.Count)]
                : TeleportPoints[0];

            if (TagOnTeleport)
            {
                TagZone.TagLocalPlayer();
            }
            if (JoinGameOnTeleport)
            {
                MapLoader.JoinGame();
            }
            if (TeleporterType == TeleporterType.Treehouse)
            {
                MapLoader.ResetMapProperties();
            }

            PlayerTeleportPatch.TeleportPlayer(destination);

            _isTeleporting = false;
        }
Пример #2
0
        private IEnumerator TeleportPlayer()
        {
            if (_isTeleporting || TeleportPoints == null || !TeleportPoints.HasAtLeast(0))
            {
                if (TeleporterType == TeleporterType.Map)
                {
                    TeleportPoints = GameObject.Find("SpawnPointContainer")?.GetComponentsInChildren <Transform>().Where(e => e != null && e.gameObject.name != "SpawnPointContainer").ToList();
                }
            }

            if (TeleportPoints == null || !TeleportPoints.HasAtLeast(0))
            {
                if (TeleporterType == TeleporterType.Map)
                {
                    TeleportPoints = new List <Transform>()
                    {
                        GameObject.Find("TreeHomeTargetObject").transform
                    }
                }
                ;
                else
                {
                    yield break;
                }
            }

            var destination = TeleportPoints.Count > 1
                ? TeleportPoints[Random.Range(0, TeleportPoints.Count)]
                : TeleportPoints[0];

            if (TagOnTeleport)
            {
                TagZone.TagLocalPlayer();
            }
            if (JoinGameOnTeleport)
            {
                MapLoader.JoinGame();
            }
            if (TeleporterType == TeleporterType.Treehouse)
            {
                MapLoader.ResetMapProperties();
            }

            PlayerTeleportPatch.TeleportPlayer(destination);

            _isTeleporting = false;

            if (JoinGameOnTeleport && Events.OnMapEnter != null && destination != MapLoader._globalData.BigTreePoint.transform)
            {
                try
                {
                    Events.OnMapEnter(true);
                }
                catch (Exception e)
                {
                    Debug.LogError(e);
                }
            }
            else if (TeleporterType == TeleporterType.Treehouse && Events.OnMapEnter != null)
            {
                try
                {
                    Events.OnMapEnter(false);
                }
                catch (Exception e)
                {
                    Debug.LogError(e);
                }
            }
        }