Exemplo n.º 1
0
    public TeleporterTileLogic FindNearest()
    {
        var thisPosition    = m_Transform.position;
        var leastSqDistance = float.PositiveInfinity;
        var matches         = m_Master.m_Teleporters[(int)m_ColorCode.m_TileColor];
        TeleporterTileLogic nearestTeleporter = null;

        foreach (var other in matches)
        {
            if (other == this)
            {
                continue;
            }

            var otherPosition = other.m_Transform.position;
            var difference    = otherPosition - thisPosition;
            var sqDistance    = difference.sqrMagnitude;

            if (sqDistance < leastSqDistance)
            {
                leastSqDistance   = sqDistance;
                nearestTeleporter = other;
            }
        }

        return(nearestTeleporter);
    }
Exemplo n.º 2
0
    void CollisionEnded(GameObject obj)
    {
        var teleporter = obj.GetComponent <TeleporterTileLogic>();

        if (teleporter == null)
        {
            return;
        }

        if (teleporter == m_LastTeleportDestination)
        {
            m_LastTeleportDestination = null;
        }
    }
Exemplo n.º 3
0
    void AttemptTeleport(TeleporterTileLogic fromTeleporter)
    {
        if (fromTeleporter == m_LastTeleportDestination)
        {
            return;
        }

        var toTeleporter = fromTeleporter.FindNearest();

        if (toTeleporter == null)
        {
            // feedback re: no destination

            return;
        }

        Teleport(fromTeleporter, toTeleporter);
    }
Exemplo n.º 4
0
    void Teleport(TeleporterTileLogic fromTeleporter, TeleporterTileLogic toTeleporter)
    {
        var fromPosition = m_Transform.position;
        var toPosition   = toTeleporter.m_Transform.position;

        var eventData = new TeleportEventData()
        {
            m_FromTeleporter = fromTeleporter,
            m_ToTeleporter   = toTeleporter,
            m_FromPosition   = fromPosition,
            m_ToPosition     = toPosition,
        };

        m_LastTeleportDestination = eventData.m_ToTeleporter;
        m_Transform.position      = eventData.m_ToPosition;

        eventData.m_FromTeleporter.m_Events.TeleportedFrom.Invoke(eventData);
        m_Events.UsedTeleporter.Invoke(eventData);
        eventData.m_ToTeleporter.m_Events.TeleportedTo.Invoke(eventData);

        var teleporterColor = fromTeleporter.m_ColorCode.GetCurrentColor();

        CreateStreak(fromPosition, toPosition, teleporterColor);
    }
Exemplo n.º 5
0
 public void Add(TeleporterTileLogic teleporter, TileColor color)
 {
     m_Teleporters[(int)color].Add(teleporter);
 }