protected override void OnUpdate() { dt = Time.deltaTime; Entities.WithAll <Transform, Actor, ActorInput, ActorCharacter>().ForEach((Entity entity, Transform transform, ref ActorInput actorInput) => { // Data var actor = EntityManager.GetSharedComponentData <Actor>(entity); var actorCharacter = EntityManager.GetSharedComponentData <ActorCharacter>(entity); //MonoBehaviours var animationEventManager = transform.GetComponentInChildren <AnimationEventManager>(); var animator = transform.GetComponentInChildren <Animator>(); var rigidbody = transform.GetComponent <Rigidbody>(); //Get Grounded state | Head State isGrounded = ActorUtilities.IsGrounded(actor, transform); isHeadFree = ActorUtilities.IsHeadFree(actor, transform); //Update Movement GetMovement(ref actorInput); OnFallMovement(transform, animationEventManager, animator, rigidbody, entity, actor, ref actorInput, actorCharacter); OnJumpMovement(transform, animationEventManager, animator, rigidbody, entity, actor, ref actorInput, actorCharacter); OnGroundMovement(transform, animationEventManager, animator, rigidbody, entity, actor, ref actorInput, actorCharacter); actorInput.crouchPreviousFrame = actorInput.crouch; }); }
private void OnJumpMovement(Transform transform, AnimationEventManager animationEventManager, Animator animator, Rigidbody rigidbody, Entity entity, Actor actor, ref ActorInput actorInput, ActorCharacter actorCharacter) { //Save Jump Data if (!jumpIntervals.ContainsKey(entity.Index)) { jumpIntervals.Add(entity.Index, jumpInterval); } //Decrease jump interval if goruned if (isGrounded && rigidbody.velocity.y <= 0) { jumpIntervals[entity.Index] -= 1 * dt; actorInput.isJumping = 0; } //If were not grounded reset jump interval else { jumpIntervals[entity.Index] = jumpInterval; } //Do Jump if (actorInput.action == 0 && actorInput.actionToDo == 2 && isGrounded && actorCharacter.jumpForce != 0 && isHeadFree && jumpIntervals[entity.Index] <= 0) { var velocity = rigidbody.velocity; velocity.y = actorCharacter.jumpForce; rigidbody.velocity = velocity; animator.SetTrigger("jump"); actorInput.isJumping = 1; if (actorInput.crouch == 1) { ActorUtilities.UpdateCollider(actor, transform, "standing"); } if (actorInput.movement.magnitude != 0) { transform.forward = actorInput.movement; } } //Sound { if (animationEventManager.RequestEvent("jumpGrunt") && actorCharacter.jumpGruntAudioEvent != null) { actorCharacter.jumpGruntAudioEvent.Play(transform.position); } else if (animationEventManager.RequestEvent("jumpStart") && actorCharacter.jumpStartAudioEvent != null) { actorCharacter.jumpStartAudioEvent.Play(transform.position); } else if (animationEventManager.RequestEvent("jumpLand") && actorCharacter.jumpLandAudioEvent != null) { actorCharacter.jumpLandAudioEvent.Play(transform.position); } } }
protected override void OnUpdate() { Entities.WithAll <Transform, Actor>().WithNone <Frozen>().ForEach((Entity entity, Transform transform) => { var actor = EntityManager.GetSharedComponentData <Actor>(entity); PostUpdateCommands.AddComponent(entity, new Frozen()); PostUpdateCommands.AddComponent(entity, new ActorInput()); ActorUtilities.UpdateModel(actor, transform); ActorUtilities.UpdateAnimator(actor, transform); ActorUtilities.UpdateCollider(actor, transform, 0); ActorUtilities.UpdatePhysics(actor, transform); }); }
protected override void OnUpdate() { Entities.WithAll <Transform, ActorInventory, ActorInput>().ForEach((Entity inventoryEntity, Transform inventoryTransform, ref ActorInventory actorInventory, ref ActorInput actorInput) => { newActorInventory = actorInventory; newInventoryActorInput = actorInput; attemptToPickUp = false; if (actorInput.actionToDo == 1 && actorInput.action == 0) { Entities.WithAll <Transform, ActorItem>().ForEach((Entity itemEntity, Transform itemTransform) => { //Get Item shared component var actorItem = EntityManager.GetSharedComponentData <ActorItem>(itemEntity); //Check if were in distance and not already picked up if (!attemptToPickUp && Vector3.Distance(inventoryTransform.position, itemTransform.position) <= 1f && !EntityManager.HasComponent(itemEntity, typeof(Parent))) { //Set that we attempted to pick a item up attemptToPickUp = true; //Get Target Socket var targetSocket = ActorUtilities.GetFirstEmptyTransform(inventoryTransform, actorItem.sockets); //Do Pickup | Set action to 0 if (targetSocket != null) { ActorUtilities.PickupItem(PostUpdateCommands, EntityManager, targetSocket, itemTransform, itemEntity, actorItem, inventoryTransform, inventoryEntity, ref newActorInventory); newInventoryActorInput.action = 0; } } }); } //Drop | Set Action to 0 if (actorInput.actionToDo == 1 && actorInput.action == 0 && attemptToPickUp == false && newActorInventory.isEquipped == 1) { ActorUtilities.DropItem(PostUpdateCommands, EntityManager, newActorInventory.equippedEntiy, inventoryTransform, inventoryEntity, ref newActorInventory); newInventoryActorInput.action = 0; } actorInventory = newActorInventory; actorInput = newInventoryActorInput; }); }
public void SelectOptionActorSubmenu() { switch (Option) { case "1": ActorUtilities.addActor(); break; case "2": ActorUtilities.editActor(); break; case "3": ActorUtilities.removeActor(); break; case "4": MovieUtilities.assignMovie(); break; case "5": ActorUtilities.performMovie(); break; case "6": ActorUtilities.quitMovie(); break; case "7": ActorUtilities.showActorList(); break; case "8": ActorUtilities.showActorById(); break; case "9": ActorUtilities.showActorMovies(); break; case "10": Finished = true; break; } }
protected override void OnUpdate() { //Que spawns Entities.WithAll <Transform, ActorSpawnPoint>().WithNone <Frozen>().ForEach((Entity entity, Transform transform) => { var spawnPoint = EntityManager.GetSharedComponentData <ActorSpawnPoint>(entity); PostUpdateCommands.AddComponent(entity, new Frozen()); spawnPontsToUse.Add(spawnPoint); spawnPontsToUsePositions.Add(transform.position); }); //Spawn outside of entity loop { for (int i = 0; i < spawnPontsToUse.Count; i++) { ActorUtilities.Spawn(EntityManager, spawnPontsToUsePositions[i], spawnPontsToUse[i].sourceGameObject, spawnPontsToUse[i].spawnAsPlayer); } spawnPontsToUse.Clear(); spawnPontsToUsePositions.Clear(); } }
public void SelectOptionMovieSubmenu() { switch (Option) { case "1": MovieUtilities.addMovie(); break; case "2": MovieUtilities.editMovie(); break; case "3": MovieUtilities.assignMovie(); break; case "4": MovieUtilities.removeMovie(); break; case "5": MovieUtilities.showMoviesList(); break; case "6": MovieUtilities.showMovieById(); break; case "7": ActorUtilities.showActorMovies(); break; case "8": Finished = true; break; } }
private void OnFallMovement(Transform transform, AnimationEventManager animationEventManager, Animator animator, Rigidbody rigidbody, Entity entity, Actor actor, ref ActorInput actorInput, ActorCharacter actorCharacter) { //set Animators in air previoius animator.SetBool("inAirPrevious", animator.GetBool("inAir")); if (!isGrounded) { var newMovement = rigidbody.velocity; newMovement.y -= actorCharacter.fallForce * dt; rigidbody.velocity = newMovement; if (actorInput.crouch == 1) { ActorUtilities.UpdateCollider(actor, transform, "Standing"); actorInput.crouch = 0; } animator.SetBool("inAir", true); } else { animator.SetBool("inAir", false); } }
private void OnGroundMovement(Transform transform, AnimationEventManager animationEventManager, Animator animator, Rigidbody rigidbody, Entity entity, Actor actor, ref ActorInput actorInput, ActorCharacter actorCharacter) { //Return if doing diffrent action | Not Grounded if (actorInput.action != 0 || !isGrounded || actorInput.isJumping == 1) { return; } //Get movement type { if (!isHeadFree && actorInput.crouchPreviousFrame == 1) { actorInput.crouch = 1; } if (actorInput.movement.magnitude == 0 || actorInput.crouch == 1 && !isHeadFree) { actorInput.sprint = 0; } if (actorInput.sprint == 1) { actorInput.crouch = 0; } if (actorInput.walk == 1 && actorInput.sprint == 0 && actorInput.crouch == 0) { actorInput.movement *= deadPoint; } } //Move { //Set Velocity var velocity = actorInput.movement; velocity *= actorInput.sprint == 1 ? actorCharacter.sprintSpeed : actorInput.crouch == 1 ? actorCharacter.crouchSpeed : actorCharacter.runSpeed; velocity.y = -1; rigidbody.velocity = velocity; } //Collider { //Set Collider if (actorInput.crouch == 1 && actorInput.crouchPreviousFrame == 0) { ActorUtilities.UpdateCollider(actor, transform, "Crouching"); } else if (actorInput.crouch == 0 && actorInput.crouchPreviousFrame == 1) { ActorUtilities.UpdateCollider(actor, transform, "Standing"); } } //Rotate { if (actorInput.movement.magnitude != 0 && actorInput.strafe == 0 || actorInput.movement.magnitude != 0 && actorInput.sprint == 1) { var lookRotation = Quaternion.LookRotation(actorInput.movement); transform.rotation = Quaternion.Slerp(transform.rotation, lookRotation, dt * actorCharacter.rotationSpeed); } } //Animate { //Is Sprinting if (actorInput.sprint == 1) { actorInput.movement = new float3(0, 0, 2f); } //Strafing else if (actorInput.strafe == 1) { actorInput.movement = transform.InverseTransformDirection(actorInput.movement); } //Not Strafing else { actorInput.movement = new float3(0, 0, Mathf.Abs(actorInput.movement.magnitude)); } //Set Animator Properties animator.SetBool("crouch", actorInput.crouch == 1 && actorInput.sprint == 0); animator.SetFloat("movementX", actorInput.movement.x, animationTransitionRate, dt); animator.SetFloat("movementY", actorInput.movement.z, animationTransitionRate, dt); animator.SetFloat("movementAmount", actorInput.movement.magnitude, animationTransitionRate, dt); } //Sound if (animationEventManager.RequestEvent("footStep") && actorCharacter.footStepAudioEvent != null && actorInput.movement.magnitude != 0) { actorCharacter.footStepAudioEvent.Play(transform.position); } }