public override void ComponentAwake()
        {
            actor      = GetRequiredComponent <ActorComponent>();
            despawner  = GetRequiredComponent <DespawnComponent>();
            collider2d = GetRequiredComponent <Collider2D>();
            rigidBody  = GetRequiredComponent <Rigidbody2D>();


            if (!UnityUtils.Exists(player))
            {
                throw new UnityException($"{gameObject.name} needs a player object dragged onto its NPCBrain");
            }

            playerActor = GetRequiredComponent <ActorComponent>(player);


            if (!UnityUtils.Exists(onIdleStateBehavior))
            {
                throw new UnityException("Idle State Behavior is null.  Please drag one onto the inspector.");
            }

            if (!UnityUtils.Exists(onActiveStateBehavior))
            {
                throw new UnityException("Active State Behavior is null.  Please drag one onto the inspector.");
            }


            base.ComponentAwake();
        }
Ejemplo n.º 2
0
        public static Particle Create(EParticles particleType, Vector3 location, Vector3 force)
        {
            Particle particle = EntityFactory.Create <Particle>(string.Format("{0}Particle", particleType.ToString()));

            particle.AddComponent <TransformComponent>().Init(location);

            PhysicsComponent physics = particle.AddComponent <PhysicsComponent>();

            physics.Init(BodyType.Dynamic, 0.94f, 0.5f);
            physics.ApplyForce(force, true);

            SpriteComponent   sprite  = particle.AddComponent <SpriteComponent>();
            LightingComponent light   = particle.AddComponent <LightingComponent>();
            DespawnComponent  despawn = particle.AddComponent <DespawnComponent>();

            switch (particleType)
            {
            case EParticles.Spark:
                float lifeTime = SeedManager.Get().NextRandF(2.0f, 5.0f);

                sprite.Init(CollisionManager.Get().PointTexture);
                sprite.Scale = new Vector2(SeedManager.Get().NextRandF(5, 15), SeedManager.Get().NextRandF(5, 15));
                sprite.AddColorFunction(x => { return(Color.Lerp(new Color(0.99f, 1.0f, 0.78f), new Color(1.0f, 0.0f, 0.0f), x)); });
                sprite.AddOpacityFunction(x => { return(1.0f - x / lifeTime); });

                light.Init(AssetManager.Get().Find <Texture2D>(ELightAssets.CircleLight), Vector2.Zero, new Vector2(0.4f, 0.4f));
                light.AddColorFunction(x => { return(Color.Lerp(new Color(0.99f, 1.0f, 0.78f), new Color(1.0f, 0.0f, 0.0f), x)); });
                light.AddBrightnessFunction(x => { return(1.0f - x / lifeTime); });

                despawn.AddTimeTrigger(x => x > lifeTime);
                break;
            }

            return(particle);
        }
Ejemplo n.º 3
0
        //---------------------------------------------------------------------------

        protected virtual void OnHit(IEntity source, IEntity target)
        {
            if (target is Enemy)
            {
            }
            DespawnComponent despawn = GetComponent <DespawnComponent>();

            if (despawn != null)
            {
                despawn.Trigger();
            }
        }