Exemplo n.º 1
0
 void ReceivedMessage(ParticleEvent receivedEvent)
 {
     if (OnMessage != null)
     {
         OnMessage(this, new ParticleEventArgs(receivedEvent));
     }
 }
Exemplo n.º 2
0
        public async Task StartHandlingEvents()
        {
            if (SourceEvent.State == EventState.Open)
            {
                return;
            }

            SourceEvent.State = EventState.Connecting;
            var    url       = EventUrl + "?access_token=" + AccessToken;
            string eventName = "";

            isSubscribed = true;
            try
            {
                using (var client = new HttpClient())
                {
                    client.Timeout = TimeSpan.FromSeconds(ClientTimeOut);

                    var request = new HttpRequestMessage(HttpMethod.Get, url);

                    using (var response = await client.SendAsync(
                               request,
                               HttpCompletionOption.ResponseHeadersRead))
                    {
                        SourceEvent.State = EventState.Open;

                        using (var body = await response.Content.ReadAsStreamAsync())
                            using (var reader = new StreamReader(body))
                            {
                                if (OnOpen != null)
                                {
                                    OnOpen(this, new ParticleEventArgs());
                                }

                                while (!reader.EndOfStream && isSubscribed)
                                {
                                    var outputString = reader.ReadLine();
                                    if (outputString.Contains("event"))
                                    {
                                        eventName = outputString.Substring(6);
                                    }
                                    else if (outputString.Contains("data"))
                                    {
                                        var values    = DeserializeObject <Dictionary <string, string> >(outputString.Substring(5));
                                        var lastevent = new ParticleEvent(values, eventName);
                                        ReceivedMessage(lastevent);
                                    }
                                }
                            }
                    }
                }
            }
            catch (HttpRequestException e)
            {
                ErrorReceived(e.Message);
            }
        }
Exemplo n.º 3
0
    protected override void OnEvent(TakeDamageEvent eventType)
    {
        SoundEvent soundEvent = new SoundEvent(eventType.entity.transform, eventType.sound);

        soundEvent.FireEvent();
        ParticleEvent particleEvent = new ParticleEvent(eventType.entity.transform, eventType.particle);

        particleEvent.FireEvent();
    }
    protected override void OnEvent(DeathEvent eventType)
    {
        SoundEvent soundEvent = new SoundEvent(eventType.entity.transform, eventType.deathSound);

        soundEvent.FireEvent();
        ParticleEvent particleEvent = new ParticleEvent(eventType.entity.transform, eventType.deathParticle);

        particleEvent.FireEvent();
        //Destroy(eventType.entity);

        eventType.entity.SetActive(false);
        EnemyManager.EnemyManagerRef.AddDeadEnemiesToDictionary(eventType.entity);
    }
Exemplo n.º 5
0
 // Update is called once per frame
 void Update()
 {
     if (timer <= 0)
     {
         Destroy(gameObject);
     }
     if (Physics2D.OverlapCircle(gameObject.transform.position, 0.5f, LayerMask.GetMask("Player")))
     {
         ParticleEvent part = new ParticleEvent(gameObject.transform, particle);
         part.FireEvent();
         SoundEvent sound = new SoundEvent(gameObject.transform, audio);
         sound.FireEvent();
         GameManager.Instance.UpdateScore(10);
         Destroy(gameObject);
     }
     timer -= Time.deltaTime;
 }
Exemplo n.º 6
0
        // Creates an Event with the same properties as the given event
        public Event(Event other)
        {
            type                 = other.type;
            actionToPerform      = other.actionToPerform;
            basicActionToPerform = other.basicActionToPerform;
            soundEffect          = other.soundEffect;

            cameraMovement = new CameraMovement(other.cameraMovement);
            slowMotion     = other.slowMotion;
            particleEvent  = other.particleEvent;
            forceEvent     = new Force(other.forceEvent, false);
            colorFlash     = other.colorFlash;
            ghostEffect    = other.ghostEffect;
            screenShake    = other.screenShake;
            tweenEvent     = other.tweenEvent;

            startTime = other.startTime;
            duration  = other.duration;
        }
        private ParticleEventSequence ProcessEventSequenceBlock(ref List <ParticleEmitterToken> .Enumerator tokenIter)
        {
            bool startedProcessingEvents = false;
            ParticleEventSequence seq    = new ParticleEventSequence();

            seq.Reset();

            // move past the event sequence keyword...
            ParticleEmitterTokenizer.NextToken(ref tokenIter);

            // next token should be the name of the sequence...
            if (tokenIter.Current.Type != TokenType.Quote)
            {
                throw new Exception("Must name particle sequence block!");
            }

            seq.Name = tokenIter.Current.StringValue;

            ParticleEmitterTokenizer.NextToken(ref tokenIter);

            // next token should be opening brace...
            if (tokenIter.Current.Type != TokenType.OpenBrace)
            {
                throw new Exception("Expected opening brace for particle sequence block!");
            }

            ParticleEmitterTokenizer.NextToken(ref tokenIter);

            while (tokenIter.Current.Type != TokenType.CloseBrace)
            {
                ParticleEmitterToken savedtoken;
                savedtoken = tokenIter.Current;

                // the first token here can be a SysNumberProperty, SysAlphaBlendModeProperty, SysVectorProperty,
                // or an EventSequence.
                switch (tokenIter.Current.Type)
                {
                case TokenType.SeqNumericProp:
                {
                    if (startedProcessingEvents)
                    {
                        throw new Exception("Cannot specify any sequence properties after specifying events.");
                    }

                    MinMax <float> number;

                    // the next 2 tokens should be an equals, and a number.
                    ParticleEmitterTokenizer.NextToken(ref tokenIter);

                    if (tokenIter.Current.Type != TokenType.Equals)
                    {
                        throw new Exception("Expected equals sign!");
                    }

                    ParticleEmitterTokenizer.NextToken(ref tokenIter);

                    number = ParticleEmitterTokenizer.ProcessNumber(ref tokenIter);

                    if (savedtoken.IsEmitRate())
                    {
                        seq.EmitRate = number;
                    }
                    else if (savedtoken.IsLifeTime())
                    {
                        seq.Lifetime = number;
                    }
                    else if (savedtoken.IsNumParticles())
                    {
                        seq.NumParticles = (int)number.Max;
                    }
                    else if (savedtoken.IsLoops())
                    {
                        seq.Loops = (int)number.Max;
                    }
                    else
                    {
                        throw new Exception("Unknown sequence numeric property!");
                    }
                }

                break;

                case TokenType.SeqVectorProp:
                {
                    if (startedProcessingEvents)
                    {
                        throw new Exception("Cannot specify any sequence properties after specifying events.");
                    }

                    MinMax <Vector3> v;

                    ParticleEmitterTokenizer.NextToken(ref tokenIter);

                    if (tokenIter.Current.Type != TokenType.Equals)
                    {
                        throw new Exception("Expected equals sign!");
                    }

                    ParticleEmitterTokenizer.NextToken(ref tokenIter);

                    v = ParticleEmitterTokenizer.ProcessVector(ref tokenIter);

                    if (savedtoken.IsSpawnDir())
                    {
                        seq.SpawnDir = v;
                    }
                    else if (savedtoken.IsEmitRadius())
                    {
                        seq.EmitRadius = v;
                    }
                    else if (savedtoken.IsGravity())
                    {
                        seq.Gravity = v;
                    }
                    else
                    {
                        throw new Exception("Unknown sequence vector property!");
                    }
                }

                break;

                case TokenType.SeqAlphaBlendModeProp:
                {
                    if (startedProcessingEvents)
                    {
                        throw new Exception("Cannot specify any sequence properties after specifying events.");
                    }

                    LocalBlendState alphablendmode;
                    ParticleEmitterTokenizer.NextToken(ref tokenIter);

                    if (tokenIter.Current.Type != TokenType.Equals)
                    {
                        throw new Exception("Expected equals sign!");
                    }

                    ParticleEmitterTokenizer.NextToken(ref tokenIter);

                    alphablendmode = ParticleEmitterTokenizer.ProcessAlphaBlendMode(ref tokenIter);

                    if (savedtoken.IsSrcBlendMode())
                    {
                        seq.SrcBlendMode = (Blend)alphablendmode;
                    }
                    else if (savedtoken.IsDestBlendMode())
                    {
                        seq.DestBlendMode = (Blend)alphablendmode;
                    }
                    else
                    {
                        throw new Exception("Unknown sequence alpha blending mode property!");
                    }
                }

                break;

                case TokenType.KeywordTexture:
                {
                    // TODO
                    if (startedProcessingEvents)
                    {
                        throw new Exception("Cannot specify any sequence properties after specifying events.");
                    }

                    ParticleEmitterTokenizer.NextToken(ref tokenIter);

                    if (tokenIter.Current.Type != TokenType.Equals)
                    {
                        throw new Exception("Expected equals sign!");
                    }

                    ParticleEmitterTokenizer.NextToken(ref tokenIter);

                    if (tokenIter.Current.Type != TokenType.Quote)
                    {
                        throw new Exception("Expected filename after texture sequence property.");
                    }

                    seq.TextureFilename = tokenIter.Current.StringValue.RemoveQuotes();
                    ParticleEmitterTokenizer.NextToken(ref tokenIter);
                }

                break;

                case TokenType.KeywordFade:
                case TokenType.KeywordAt:
                case TokenType.KeywordInitial:
                case TokenType.KeywordFinal:
                {
                    startedProcessingEvents = true;

                    bool           isFade    = false;
                    MinMax <float> timeRange = new MinMax <float>();

                    // parse the time range section of the event line
                    ParticleEmitterTokenizer.ProcessTime(ref timeRange, ref isFade, 0, seq.Lifetime.Max, ref tokenIter);

                    if (tokenIter.Current.Type != TokenType.ParticleNumericProp && tokenIter.Current.Type != TokenType.ParticleVectorProp &&
                        tokenIter.Current.Type != TokenType.ParticleColorProp)
                    {
                        throw new Exception("Expecting particle property after time specifier!");
                    }

                    ParticleEvent newEvent = null;

                    try
                    {
                        // create the appropriate event
                        newEvent = EventFactory(tokenIter.Current.StringValue);

                        if (newEvent == null)
                        {
                            throw new Exception("Unknown event type, or there was an error creating this event.");
                        }

                        // let the event parse the rest of its properties from the token stream.
                        if (isFade && !newEvent.FadeAllowed())
                        {
                            throw new Exception("Fading is not supported on this event.");
                        }

                        newEvent.ProcessTokenStream(ref tokenIter);
                        newEvent.TimeRange = timeRange;
                        newEvent.SetFade(isFade);
                        seq.Events.Add(newEvent);
                    }
                    catch (Exception ex)
                    {
                        throw ex;
                    }
                }

                break;

                default:
                {
                    throw new Exception("Unexpected " + tokenIter.Current.StringValue + " in Sequence Block!");
                }
                }
            }

            seq.NailDownRandomTimes();
            seq.SortEvents();
            seq.CreateFadeLists();
            ParticleEmitterTokenizer.NextToken(ref tokenIter);

            return(seq);
        }
Exemplo n.º 8
0
 public ParticleEventArgs(ParticleEvent eventData)
 {
     EventData = eventData;
 }