/// <summary> /// Update the behavior /// </summary> public void UpdateBehavior() { if (model.currentBehavior == null) { return; } accumilatedTime += Time.deltaTime; while (accumilatedTime > fps) { // if the current frame reach to the current behavior's end frame int scaledFrameLength = (int)(model.currentBehavior.frameLength / model.objectTimeScale); if (model.currentFrame >= scaledFrameLength) { // if this behavior is toggled loop if (model.currentBehavior.loopBehavior) { model.LoopBehavior(); } else { model.EndBehavior(); } } model.currentFrame += 1; CombatDebugger.Log(scaledFrameLength.ToString(), LogDomain.FrameInfo); UpdateBehaviorActions(); UpdateBehaviorAttack(); // set the previouse frame to current frame at the end model.previousFrame = model.currentFrame; accumilatedTime -= fps; } }
public override void Enter(ActorModel model) { if (vfxPrefab == null) { return; } if ((int)model.currentFrame == model.previousFrame) { return; } Vector3 forward = model.character.transform.forward * posOffset.z; Vector3 right = model.character.transform.right * posOffset.x; Vector3 up = model.character.transform.up * posOffset.y; Vector3 spawnPos = model.character.transform.position + forward + right + up; Transform parent = CheckForAttachment(model); // todo Use FX Manager to control the particle pool, so that no need to get component all the time GameObject particleGo = GameObject.Instantiate(vfxPrefab, spawnPos, model.character.transform.rotation, parent); particles = particleGo.GetComponentsInChildren <ParticleSystem>(); GameObject.Destroy(particleGo, 5); CombatDebugger.Log("Play vfx", LogDomain.BehaviorAcrion); foreach (var particle in particles) { var main = particle.main; main.simulationSpeed = model.objectTimeScale * speedMultiplier; particle.Play(); } }
void DetectPressedKeys(ref List <KeyCode> keys, float keyLifetime) { // todo switch to all necessary to optimize foreach (KeyCode kcode in System.Enum.GetValues(typeof(KeyCode))) { if (Input.GetKeyDown(kcode)) { if (kcode != KeyCode.None) { CombatDebugger.Log(kcode.ToString(), LogDomain.Input); keys.Add(kcode); StartCoroutine(RemoveKeyFromBuffer(kcode, keyLifetime)); } } } }
public override void Execute(ActorModel model) { if (sfx == null) { Debug.Log("Can't find sfx audio clip!"); return; } if ((int)model.currentFrame == model.previousFrame) { Debug.Log("Is previous frame"); return; } model.audioSource.pitch = model.objectTimeScale; model.audioSource.outputAudioMixerGroup.audioMixer.SetFloat("pitchBend", 1f / model.objectTimeScale); model.audioSource.PlayOneShot(sfx); CombatDebugger.Log("Play Audio", LogDomain.BehaviorAcrion); }
/// <summary> /// The Condition Requirement to execute this behavior /// </summary> /// <param name="model"> ActorMode object </param> /// <returns></returns> public bool MetRequirements(ActorModel model) { if (!isActivated) { return(false); } // if character has recovered from an attack? //if (model.HitRecoverFrames > 0) //{ // return false; //} // if this behavior require character to be grounded? if (requireGrounded) { if (!model.cc.isGrounded) { CombatDebugger.Log("Grounded requirement failed", LogDomain.BehaviorRequirement); return(false); } } if (requireRunning) { if (model.moveInputDir.magnitude <= 0.75f) { CombatDebugger.Log("Running requirement failed", LogDomain.BehaviorRequirement); return(false); } } // if this behavior require character to be in the air? if (requireAerial) { if (!model.isAerial) { CombatDebugger.Log("In Air requirement failed", LogDomain.BehaviorRequirement); return(false); } } // if this behavior require to have a target? if (requireTarget) { if (model.target == null) { return(false); } } // if this behavior can force cancel other behaviors? if (canForceExecute && !model.currentBehavior.canForceExecute && !model.currentBehavior.isHurtBehavior) { // Disable Hitbox when force execute Behavior model.CanCancel = true; if (model.hitBox != null) { model.hitBox.SetActive(false); model.hitBox.SetLocalScale(Vector3.zero); } } if (requireUnderAttack) { if (model.currentBehavior.isHurtBehavior) { model.CanCancel = true; } else { return(false); } } // if this behavior can be canncel? if (model.CanCancel == false) { CombatDebugger.Log("CanCancel requirement failed", LogDomain.BehaviorRequirement); return(false); } else { model.CanCancel = false; } // if the behavior have CoolDown if (cooldown > 0) { if (!cdTimer.IsTimeUp) { CombatDebugger.Log("Cooldown requirement failed", LogDomain.BehaviorRequirement); return(false); // if count down haven't finish, return } ResetTimer(cooldown); cdTimer.Start(); // Start count down again } // if the character have enough energy to execute this behavior if (model.actorStats.currentEnergy < energyPointCost) { CombatDebugger.Log("PowerMeter requirement failed", LogDomain.BehaviorRequirement); return(false); } // if the character have enough air jump points to execute this behavior if (model.actorStats.currentAirJumpPoint < airJumpPointCost) { CombatDebugger.Log("AirJumpPoints requirement failed", LogDomain.BehaviorRequirement); return(false); } // if passing all the conditions, then return true return(true); }