public void init(EnergyStream energy, string spriteName, float damageRatio, int bounces, float lifespan, float speed, Dictionary<string, List<ProjectileBehavior>> behaviors) { _energy = energy; _damageRatio = damageRatio; _lifespan = lifespan; _speed = speed; _behaviors = new Dictionary<string, List<ProjectileBehavior>>(); foreach (string key in behaviors.Keys) { foreach (ProjectileBehavior behavior in behaviors[key]) { addBehavior(key, behavior); } } setSprite(spriteName); if(gameObject != null) { if(gameObject.GetComponent<SpriteRenderer>() != null) { setSpriteRenderer(gameObject.GetComponent<SpriteRenderer>()); } else { setSpriteRenderer(gameObject.AddComponent<SpriteRenderer>()); } if (gameObject.GetComponent<CircleCollider2D>() != null) { setCollider(gameObject.GetComponent<CircleCollider2D>()); } else { setCollider(gameObject.AddComponent<CircleCollider2D>()); } if(gameObject.GetComponent<Rigidbody2D>() != null) { setRigidbody(gameObject.GetComponent<Rigidbody2D>()); } else { setRigidbody(gameObject.AddComponent<Rigidbody2D>()); } } //Woo hard coding for now. if(_collider != null) { PhysicsMaterial2D projectilePhysicsMaterial = new PhysicsMaterial2D("Projectile"); projectilePhysicsMaterial.bounciness = 1; projectilePhysicsMaterial.friction = 0; _collider.sharedMaterial = projectilePhysicsMaterial; //Separate physics will need to be written to handle this. //_collider.isTrigger = true; //It is a trigger because it passes through other Projectiles. _collider.enabled = false; _collider.enabled = true; } if(_rigidbody != null) { _rigidbody.angularDrag = 0; _rigidbody.gravityScale = 0; _rigidbody.collisionDetectionMode = CollisionDetectionMode2D.Continuous; _rigidbody.interpolation = RigidbodyInterpolation2D.Interpolate; } }
public EnergyStream process(EnergyStream inStream) { return inStream; }
/// <summary> /// Attaches the component to an object, given an energy stream. /// </summary> /// <param name="obj">The object to attach the projectile component stream.</param> /// <param name="energy">The energy the projectile contains, typically the stream will come from the weapon firing it.</param> /// <returns></returns> public GameObject attachComponent(GameObject obj, EnergyStream energy) { componentProjectile compProjectile = obj.AddComponent<componentProjectile>(); compProjectile.init(energy, _spriteName, _damageRatio.getValue(), _bounces.getValue(), _lifespan.getValue(), _speed.getValue(), _behaviors); return obj; }