Exemplo n.º 1
0
    public void ProcessQueues()
    {
        lock (QueuedMovements)
        {
            foreach (KeyValuePair <WebsocketMinionControl, float[]> item in QueuedMovements)
            {
                if (item.Key.AssociatedMinion == null)
                {
                    Debug.LogWarning("[WEB] User sent movement without registering.");
                }

                NavMeshHit hit;
                NavMesh.SamplePosition(
                    new Vector3(
                        item.Value[0] * 50,
                        0,
                        item.Value[1] * 25
                        ),
                    out hit,
                    2.0f,
                    NavMesh.AllAreas
                    );

                Debug.Log(string.Format("[WEB] Moving '{0}' to [{1}, {2}] ([])", item.Key.AssociatedMinion.name, item.Value[0] * 50, item.Value[1] * 25, item.Value[0], item.Value[1]));

                item.Key.AssociatedMinion.GetComponent <NavMeshAgent>().SetDestination(
                    hit.position
                    );
            }
            QueuedMovements.Clear();
        }

        lock (QueuedAssociations)
        {
            foreach (WebsocketMinionControl item in QueuedAssociations)
            {
                Debug.Log("[WEB] Registration: " + item.Context.Host);

                GameObject minion = Minions.GetControllableMinion();
                if (minion != null)
                {
                    Debug.Log(string.Format("[WEB] {0} now controls minion {1}", item.Context.Host, minion.name), minion);
                    item.AssociatedMinion      = minion;
                    item.AssociatedMinion.name = "[C]" + item.AssociatedMinion.name;
                    item.AssociatedMinion.GetComponent <MeshRenderer>().material.color = new Color(0.27f, 0.61f, 0.1333f, 1.0f);
                }
                else
                {
                    Debug.Log(string.Format("[WEB] {0} couldn't get a minion: No minions left", item.Context.Host));
                }
            }
            QueuedAssociations.Clear();
        }
    }