コード例 #1
0
        private void HandleBomb(InteractivePacket <InteractiveBombMessage> message)
        {
            var        location = [email protected];
            RaycastHit hit;
            var        ray = Camera.main.ViewportPointToRay(new Vector3(
                                                                Util.ScaleValue(location.x, 0, 1, Util.MinimapMinBoundary.x, Util.MinimapMaxBoundary.x),
                                                                Util.ScaleValue(1 - location.y, 0, 1, Util.MinimapMinBoundary.y, Util.MinimapMaxBoundary.y),
                                                                0));

            if (!Physics.Raycast(ray, out hit))
            {
                Debug.LogError("Bomb missed world");
                return;
            }

            switch ([email protected])
            {
            case "blast":
                new BlastBomb(BlastBombRadius, BlastBombDamage)
                .Drop(hit.point);
                break;

            case "sonic":
                new SonicBomb(SonicBombRadius, SonicBombAffector)
                .Drop(hit.point);
                break;

            default:
                Debug.LogError("I'm not dropping it like it's hot: " + [email protected]);
                break;
            }
        }
コード例 #2
0
        private IEnumerator HandleTakeControl(InteractivePacket <InteractiveBombMessage> message)
        {
            var participant = [email protected];

            if (Controller.ContainsKey(participant))
            {
                yield break;
            }

            var enemies = GameObject.FindObjectsOfType <EnemyMovement>()
                          .Where(e => !e.GetIsBeingControlled())
                          .ToArray();
            var enemyIndex = UnityEngine.Random.Range(0, enemies.Length);
            var session    = new InteractiveControlSession
            {
                ControlDurationSeconds = 30f,
                ControlledObject       = enemies[enemyIndex].gameObject,
                ParticipantSessionId   = participant,
            };

            // Take Control
            Debug.Log("Take Control");
            Controller.Add(participant, session);
            yield return(session.TakeControl());

            // Control ended
            Debug.Log("Yield control");
            Controller.Remove(participant);
        }