コード例 #1
0
ファイル: Player.cs プロジェクト: Master109/Turn-Based-Chaos
        // void HandeSafeZoneIcons ()
        // {
        //  foreach (IconForSafeZone iconForSafeZone in IconForSafeZone.instances)
        //  {
        //      if (inSafeZone)
        //          iconForSafeZone.rectTrs.localPosition = cameraCanvasRectTrs.sizeDelta.Multiply(GameManager.GetSingleton<GameCamera>().camera.WorldToViewportPoint(iconForSafeZone.trs.position)) - cameraCanvasRectTrs.sizeDelta / 2;
        //      iconForSafeZone.image.enabled = inSafeZone;
        //  }
        // }

        bool CheckForSafeZone()
        {
            Collider2D hitCollider = Physics2D.OverlapPoint(trs.position, whatIsSafeZone);

            if (hitCollider != null)
            {
                foreach (Enemy enemy in Enemy.enemiesInArea)
                {
                    if (enemy != null)
                    {
                        enemy.Reset();
                        enemy.enabled = false;
                    }
                }
                Enemy.enemiesInArea = new Enemy[0];
                foreach (Trap trap in Trap.trapsInArea)
                {
                    trap.Reset();
                    trap.enabled = false;
                }
                Trap.trapsInArea = new Trap[0];
                for (int i = 0; i < Bullet.activeBullets.Count; i++)
                {
                    Bullet bullet = Bullet.activeBullets[i];
                    GameManager.GetSingleton <ObjectPool>().Despawn(bullet.prefabIndex, bullet.gameObject, bullet.trs);
                    i--;
                }
                RedDoor.redDoorsInArea = new RedDoor[0];
                SafeArea safeArea = hitCollider.GetComponent <SafeZone>().safeArea;
                foreach (ConveyorBelt conveyorBelt in ConveyorBelt.conveyorBeltsInArea)
                {
                    conveyorBelt.enabled = false;
                }
                foreach (ConveyorBelt conveyorBelt in safeArea.conveyorBelts)
                {
                    conveyorBelt.enabled = true;
                }
                ConveyorBelt.conveyorBeltsInArea = safeArea.conveyorBelts;
                GameManager.GetSingleton <GameCamera>().trs.position = safeArea.cameraRect.center.SetZ(GameManager.GetSingleton <GameCamera>().trs.position.z);
                GameManager.GetSingleton <GameCamera>().viewSize     = safeArea.cameraRect.size;
                GameManager.GetSingleton <GameCamera>().HandleViewSize();
                return(true);
            }
            return(false);
        }
コード例 #2
0
        public virtual void OnDefeated()
        {
            foreach (Enemy enemy in enemies)
            {
                Destroy(enemy.gameObject);
            }
            if (GameManager.GetSingleton <Survival>() != null)
            {
                return;
            }
            foreach (DangerZone dangerZone in dangerZones)
            {
                dangerZone.correspondingSafeZone.trs.gameObject.SetActive(true);
                dangerZone.correspondingSafeZone.trs.SetParent(null);
                Destroy(dangerZone.gameObject);
            }
            foreach (RedDoor redDoor in redDoors)
            {
                Destroy(redDoor.gameObject);
            }
            List <SafeArea> remainingSafeAreas = new List <SafeArea>();
            List <SafeArea> updatedSafeAreas   = new List <SafeArea>();

            remainingSafeAreas.Add(correspondingSafeArea);
            do
            {
                SafeArea safeArea    = remainingSafeAreas[0];
                Rect[]   cameraRects = new Rect[safeArea.surroundingSafeAreas.Count + 1];
                for (int i = 0; i < cameraRects.Length - 1; i++)
                {
                    SafeArea surroundingSafeArea = safeArea.surroundingSafeAreas[i];
                    cameraRects[i] = surroundingSafeArea.cameraRect;
                    if (!updatedSafeAreas.Contains(surroundingSafeArea))
                    {
                        remainingSafeAreas.Add(surroundingSafeArea);
                    }
                }
                cameraRects[cameraRects.Length - 1] = safeArea.cameraRect;
                // safeArea.cameraRect = RectExtensions.Combine(cameraRects);
                updatedSafeAreas.Add(safeArea);
                remainingSafeAreas.RemoveAt(0);
            } while (remainingSafeAreas.Count > 0);
            Enemy.enemiesInArea = new Enemy[0];
            foreach (Trap trap in Trap.trapsInArea)
            {
                if (trap != null)
                {
                    trap.enabled = false;
                }
            }
            Trap.trapsInArea       = new Trap[0];
            RedDoor.redDoorsInArea = new RedDoor[0];
            // GameManager.GetSingleton<Player>().OnMove ();
            foreach (SafeArea surroundingSafeArea in correspondingSafeArea.surroundingSafeAreas)
            {
                foreach (Vector3Int cellPosition in surroundingSafeArea.unexploredCellPositions)
                {
                    GameManager.GetSingleton <GameManager>().unexploredTilemap.SetTile(cellPosition, null);
                }
            }
            Destroy(gameObject);
        }