public void Execute() { //Debug.Log ("VelocitySystem.Execute(), _group.count : " + _group.count); foreach (var entity in _group.GetEntities()) { Vector3 velocity = new Vector3 ( entity.velocity.velocity.x, entity.velocity.velocity.y, entity.velocity.velocity.z ); Vector3 position = new Vector3 ( entity.position.position.x, entity.position.position.y, entity.position.position.z ); entity.ReplacePosition(new RMC.Common.UnityEngineReplacement.Vector3 ( (position.x + velocity.x * entity.tick.deltaTime) * (1- entity.friction.friction.x), (position.y + velocity.y * entity.tick.deltaTime) * (1- entity.friction.friction.y), (position.z + velocity.z * entity.tick.deltaTime) * (1- entity.friction.friction.z) )); } }
public void Execute() { foreach (var entity in _aiGroup.GetEntities()) { Vector3 nextVelocity = Vector3.zero; //THe ball is destroyed after each goal, so we do some checks to NOT follow it at that moment - srivello Entity targetEntity = entity.aI.targetEntity; if (targetEntity != null) { if (targetEntity.hasPosition) { Vector3 targetPosition = targetEntity.position.position; if (targetPosition.y > entity.position.position.y + entity.aI.deadZoneY) { nextVelocity = new Vector3(0, entity.aI.velocityY, 0); } else if (targetPosition.y < entity.position.position.y - entity.aI.deadZoneY) { nextVelocity = new Vector3(0, -entity.aI.velocityY, 0); } entity.ReplaceVelocity(nextVelocity); } } } }
public void ExecuteSystemTest([NUnit.Framework.Range (1, 10, 1)] int totalSystemExecutions) { // Setup Vector3 velocity = new Vector3(10, 20, 30); Vector3 position = new Vector3(1, 2, 3); Vector3 expectedPosition = position; _testEnity = Pools.pool.CreateEntity() .AddPosition(position) .AddVelocity(velocity); //Desired. Strong typing when CreateSystem<T> is called. VelocitySystem velocitySystem = Pools.pool.CreateSystem<VelocitySystem>() as VelocitySystem; // This will run the system exacly once. for (var ex = 0; ex < totalSystemExecutions; ex++) { //for every execution velocitySystem.Execute(); //we expect it to move by one velocity unit expectedPosition += velocity; } // Assert Assert.AreEqual(expectedPosition, _testEnity.position.position, "The entity position will the original position plus one velocity."); }
// ------------------ Constants and statics // ------------------ Events // ------------------ Serialized fields and properties // ------------------ Non-serialized fields // ------------------ Methods public static Entity CreateEffect(this Pool pool, Vector3 position, string resourcePath ) { Entity entity = pool.CreateEntity(); entity.AddPosition (position, false); entity.AddResource (resourcePath); //keep short until I can figure out how to shorten the particle lifetime //(looks like looping now, but looping bool is not true) entity.AddDestroyMe (1); //Most effects won't rotate by rotating the game object. Must manually edit prefab entity.AddRotation (RMC.Common.UnityEngineReplacement.Vector3.zero, false); return entity; }
private static Entity CreateBullet(this Pool pool, string resourcePath, Vector3 fromPosition, Vector3 toPosition, float speed) { Entity entity = pool.CreateEntity (); entity.AddPosition (fromPosition, false); // Vector3 newVelocity = (toPosition - fromPosition).Normalize() * speed; entity.AddFriction (RMC.Common.UnityEngineReplacement.Vector3.zero); entity.AddResource (resourcePath); entity.AddVelocity (newVelocity); entity.AddTick (0); entity.AddDestroyMe (4); entity.AddRotation (RMC.Common.UnityEngineReplacement.Vector3.zero, false); return entity; }
public void Execute() { foreach (var inputEntity in _inputGroup.GetEntities()) { //We choose to listen to axis, not buttons. But either is possible - srivello if (inputEntity.input.inputType == InputComponent.InputType.Axis) { foreach (var acceptInputEntity in _acceptInputGroup.GetEntities()) { //Debug.Log ("inputEntity.input.inputAxis.y : " + inputEntity.input.inputAxis.y); Vector3 nextVelocity = new Vector3(0, inputEntity.input.inputAxis.y * 50, 0); acceptInputEntity.ReplaceVelocity(nextVelocity); } } // The Entity holding the AcceptInputComponent has been processed, so destroy the related Entity inputEntity.WillDestroy(true); } }
public void Execute() { foreach (var inputEntity in _inputGroup.GetEntities()) { if (inputEntity.input.inputKeyCode == KeyCode.Space) { if (inputEntity.input.inputType == InputComponent.InputType.KeyDown) { Vector3 position; foreach (var acceptInputEntity in _acceptInputGroup.GetEntities()) { position = new Vector3( acceptInputEntity.position.position.x, 0, acceptInputEntity.position.position.z); acceptInputEntity.ReplacePosition(position, acceptInputEntity.position.useTween); } } else if (inputEntity.input.inputType == InputComponent.InputType.KeyUp) { Vector3 position; foreach (var acceptInputEntity in _acceptInputGroup.GetEntities()) { position = new Vector3( acceptInputEntity.position.position.x, - 1, acceptInputEntity.position.position.z); acceptInputEntity.ReplacePosition(position, acceptInputEntity.position.useTween); } } } else if (inputEntity.input.inputType == InputComponent.InputType.PointerDown) { if (inputEntity.input.inputPointerPosition.y > CanvasController.Instance.StandButtonTopY) { //TODO: add a gun model and shoot from the barrel position Entity playerEntity = _pool.GetGroup(Matcher.AllOf(Matcher.Player, Matcher.Position)).GetSingleEntity() ; Entity enemyEntity = _pool.GetGroup(Matcher.AllOf(Matcher.Enemy, Matcher.Position)).GetSingleEntity(); Vector3 fromPosition = playerEntity.position.position + GameConstants.PositionOffsetBulletY; Vector3 toPosition = enemyEntity.position.position + GameConstants.PositionOffsetBulletY; UnityEngine.Vector3 v3 = UnityEngine.Camera.main.ScreenToWorldPoint(new UnityEngine.Vector3( inputEntity.input.inputPointerPosition.x, inputEntity.input.inputPointerPosition.y, 10)); toPosition = UnityEngineReplacementUtility.Convert(v3); //KEEP //UnityEngine.Debug.Log ("Shoot from : " + fromPosition + " + to " + toPosition); _pool.CreatePlayerBullet ( fromPosition, toPosition, GameConstants.BulletSpeed); } } // The Entity holding the AcceptInputComponent has been processed, so destroy the related Entity inputEntity.AddDestroyMe(0); } }
public static Entity CreatePlayerBullet(this Pool pool, Vector3 fromPosition, Vector3 toPosition, float speed) { return pool.CreateBullet("Prefabs/BulletPlayer", fromPosition, toPosition, speed); }