// CONSTRUCTOR: --------------------------------------------------------------------------- public Combo() { this.combo = new CharacterMelee.ActionKey[] { CharacterMelee.ActionKey.A }; this.condition = ComboSystem.Condition.None; this.meleeClip = null; this.isEnabled = true; }
public void OnReceiveAttack(CharacterMelee attacker, MeleeClip attack, CharacterMelee.HitResult hitResult) { // TODO: Filter attack by type, such as hit result, by attack, by player attack, ... this.ExecuteTrigger(attacker.gameObject); }
// UPDATE: -------------------------------------------------------------------------------- private void Update() { this.UpdatePoise(); this.UpdateDefense(); if (this.comboSystem != null) { this.comboSystem.Update(); if (this.CanAttack() && this.inputBuffer.HasInput()) { ActionKey key = this.inputBuffer.GetInput(); MeleeClip meleeClip = this.comboSystem.Select(key); if (meleeClip) { this.inputBuffer.ConsumeInput(); this.currentMeleeClip = meleeClip; this.targetsEvaluated = new HashSet <int>(); this.currentMeleeClip.Play(this); if (this.EventAttack != null) { this.EventAttack.Invoke(meleeClip); } } } } }
public void OnReceiveAttack(CharacterMelee attacker, MeleeClip attack, CharacterMelee.HitResult hitResult) { if (this.type == hitResult) { this.storeAttacker.Set(attacker.gameObject, gameObject); this.ExecuteTrigger(attacker.gameObject); } }
private void OnAttack(MeleeClip attack) { Character _character = this.character.GetCharacter(gameObject); if (_character == null) { return; } this.ExecuteTrigger(_character.gameObject); }
private void DuplicateMeleeClip() { string path = AssetDatabase.GetAssetPath(this.target); string newPath = AssetDatabase.GenerateUniqueAssetPath(path); MeleeClip newInstance = Instantiate(this.target) as MeleeClip; AssetDatabase.CreateAsset(newInstance, newPath); SerializedObject soNewInstance = new SerializedObject( AssetDatabase.LoadAssetAtPath <MeleeClip>(newPath) ); SerializedProperty newActionsOnHit = soNewInstance.FindProperty("actionsOnHit"); SerializedProperty newActionsOnExec = soNewInstance.FindProperty("actionsOnExecute"); IActionsList a1 = newActionsOnHit.objectReferenceValue as IActionsList; IActionsList a2 = newActionsOnExec.objectReferenceValue as IActionsList; GameObject a1Src = PrefabUtility.InstantiatePrefab(a1.gameObject) as GameObject; GameObject a2Src = PrefabUtility.InstantiatePrefab(a2.gameObject) as GameObject; PrefabUtility.UnpackPrefabInstance(a1Src, PrefabUnpackMode.OutermostRoot, InteractionMode.AutomatedAction); PrefabUtility.UnpackPrefabInstance(a2Src, PrefabUnpackMode.OutermostRoot, InteractionMode.AutomatedAction); string a1Path = AssetDatabase.GetAssetPath(a1.gameObject); string a2Path = AssetDatabase.GetAssetPath(a2.gameObject); string a1NewPath = AssetDatabase.GenerateUniqueAssetPath(a1Path); string a2NewPath = AssetDatabase.GenerateUniqueAssetPath(a2Path); GameObject p1Src = PrefabUtility.SaveAsPrefabAsset(a1Src, a1NewPath); GameObject p2Src = PrefabUtility.SaveAsPrefabAsset(a2Src, a2NewPath); newActionsOnHit.objectReferenceValue = p1Src.GetComponent <IActionsList>(); newActionsOnExec.objectReferenceValue = p2Src.GetComponent <IActionsList>(); soNewInstance.ApplyModifiedPropertiesWithoutUndo(); soNewInstance.Update(); DestroyImmediate(a1Src); DestroyImmediate(a2Src); }
// CALLBACK METHODS: ---------------------------------------------------------------------- public HitResult OnReceiveAttack(CharacterMelee attacker, MeleeClip attack) { if (this.currentWeapon == null) { return(HitResult.ReceiveDamage); } if (this.IsInvincible) { return(HitResult.Ignore); } float attackAngle = Vector3.Angle( attacker.transform.TransformDirection(Vector3.forward), this.transform.TransformDirection(Vector3.forward) ); float defenseAngle = this.currentShield != null ? this.currentShield.defenseAngle.GetValue(gameObject) : 0f; if (this.currentShield != null && attack.isBlockable && this.IsBlocking && 180f - attackAngle < defenseAngle / 2f) { this.AddDefense(-attack.defenseDamage); if (this.Defense > 0) { if (Time.time < this.startBlockingTime + this.currentShield.perfectBlockWindow) { if (attacker != null) { MeleeClip attackerReaction = this.Character.IsGrounded() ? this.currentShield.groundPerfectBlockReaction : this.currentShield.airbornPerfectBlockReaction; attackerReaction.Play(attacker); } if (this.currentShield.perfectBlockClip != null) { this.currentShield.perfectBlockClip.Play(this); } this.ExecuteEffects( this.blade.GetImpactPosition(), this.currentShield.audioPerfectBlock, this.currentShield.prefabImpactPerfectBlock ); this.comboSystem.OnPerfectBlock(); return(HitResult.PerfectBlock); } MeleeClip blockReaction = this.currentShield.GetBlockReaction(); if (blockReaction != null) { blockReaction.Play(this); } this.ExecuteEffects( this.blade.GetImpactPosition(), this.currentShield.audioBlock, this.currentShield.prefabImpactBlock ); this.comboSystem.OnBlock(); return(HitResult.AttackBlock); } else { this.Defense = 0f; this.StopBlocking(); if (this.EventBreakDefense != null) { this.EventBreakDefense.Invoke(); } } } this.AddPoise(-attack.poiseDamage); bool isFrontalAttack = attackAngle >= 90f; bool isKnockback = this.Poise <= float.Epsilon; MeleeClip hitReaction = this.currentWeapon.GetHitReaction( this.Character.IsGrounded(), isFrontalAttack, isKnockback ); this.ExecuteEffects( attacker.blade.GetImpactPosition(), isKnockback ? this.currentWeapon.audioImpactKnockback : this.currentWeapon.audioImpactNormal, isKnockback ? this.currentWeapon.prefabImpactKnockback : this.currentWeapon.prefabImpactNormal ); attack.ExecuteHitPause(); if (!this.IsUninterruptable) { hitReaction.Play(this); } return(HitResult.ReceiveDamage); }
private void LateUpdate() { this.IsAttacking = false; if (this.comboSystem != null) { int phase = this.comboSystem.GetCurrentPhase(); this.IsAttacking = phase >= 0f; if (this.blade != null && phase == 1) { GameObject[] hits = this.blade.CaptureHits(); for (int i = 0; i < hits.Length; ++i) { int hitInstanceID = hits[i].GetInstanceID(); if (this.targetsEvaluated.Contains(hitInstanceID)) { continue; } if (hits[i].transform.IsChildOf(this.transform)) { continue; } HitResult hitResult = HitResult.ReceiveDamage; CharacterMelee targetMelee = hits[i].GetComponent <CharacterMelee>(); MeleeClip attack = this.comboSystem.GetCurrentClip(); if (targetMelee != null) { hitResult = targetMelee.OnReceiveAttack(this, attack); } IgniterMeleeOnReceiveAttack[] triggers = ( hits[i].GetComponentsInChildren <IgniterMeleeOnReceiveAttack>() ); bool hitSuccess = triggers.Length > 0; if (hitSuccess) { for (int j = 0; j < triggers.Length; ++j) { triggers[j].OnReceiveAttack(this, attack, hitResult); } } if (hitSuccess || targetMelee != null) { Vector3 position = this.blade.GetImpactPosition(); attack.ExecuteActionsOnHit(position, hits[i].gameObject); } if (attack.pushForce > float.Epsilon) { Rigidbody[] rigidbodies = hits[i].GetComponents <Rigidbody>(); for (int j = 0; j < rigidbodies.Length; ++j) { Vector3 direction = rigidbodies[j].transform.position - transform.position; rigidbodies[j].AddForce(direction.normalized * attack.pushForce, ForceMode.Impulse); } } this.targetsEvaluated.Add(hitInstanceID); } } } }
public MeleeClip GetHitReaction(bool isGrounded, bool frontalAttack, bool isKnockback) { int index; MeleeClip meleeClip = null; if (isKnockback) { index = UnityEngine.Random.Range(0, this.knockbackReaction.Count - 1); if (this.knockbackReaction.Count != 1 && index == this.prevRandomHit) { index++; } this.prevRandomHit = index; return(this.knockbackReaction[index]); } switch (isGrounded) { case true: switch (frontalAttack) { case true: index = UnityEngine.Random.Range(0, this.groundHitReactionsFront.Count - 1); if (this.groundHitReactionsFront.Count != 1 && index == this.prevRandomHit) { index++; } this.prevRandomHit = index; meleeClip = this.groundHitReactionsFront[index]; break; case false: index = UnityEngine.Random.Range(0, this.groundHitReactionsBehind.Count); if (this.groundHitReactionsBehind.Count != 1 && index == this.prevRandomHit) { index++; } this.prevRandomHit = index; meleeClip = this.groundHitReactionsBehind[index]; break; } break; case false: switch (frontalAttack) { case true: index = UnityEngine.Random.Range(0, this.airborneHitReactionsFront.Count); if (this.airborneHitReactionsFront.Count != 1 && index == this.prevRandomHit) { index++; } this.prevRandomHit = index; meleeClip = this.airborneHitReactionsFront[index]; break; case false: index = UnityEngine.Random.Range(0, this.airborneHitReactionsBehind.Count); if (this.airborneHitReactionsBehind.Count != 1 && index == this.prevRandomHit) { index++; } this.prevRandomHit = index; meleeClip = this.airborneHitReactionsBehind[index]; break; } break; } return(meleeClip); }
// INITIALIZER: --------------------------------------------------------------------------- private void OnEnable() { this.instance = this.target as MeleeClip; this.sectionAnimation = new Section("Animation", this.LoadIcon("Animation"), this.Repaint); this.sectionMotion = new Section("Motion", this.LoadIcon("Animation"), this.Repaint); this.sectionEffects = new Section("Effects", this.LoadIcon("Effects"), this.Repaint); this.sectionCombat = new Section("Combat", this.LoadIcon("Animation"), this.Repaint); this.spAnimationClip = this.serializedObject.FindProperty("animationClip"); this.spAvatarMask = this.serializedObject.FindProperty("avatarMask"); this.spTransitionIn = this.serializedObject.FindProperty("transitionIn"); this.spTransitionOut = this.serializedObject.FindProperty("transitionOut"); this.spMovementForward = this.serializedObject.FindProperty("movementForward"); this.spMovementSides = this.serializedObject.FindProperty("movementSides"); this.spMovementVertical = this.serializedObject.FindProperty("movementVertical"); this.spGravityInfluence = this.serializedObject.FindProperty("gravityInfluence"); this.spMovementMultiplier = this.serializedObject.FindProperty("movementMultiplier"); this.spSoundEffect = this.serializedObject.FindProperty("soundEffect"); this.spPushForce = this.serializedObject.FindProperty("pushForce"); this.spHitPause = this.serializedObject.FindProperty("hitPause"); this.spHitPauseAmount = this.serializedObject.FindProperty("hitPauseAmount"); this.spHitPauseDuration = this.serializedObject.FindProperty("hitPauseDuration"); this.spIsAttack = this.serializedObject.FindProperty("isAttack"); this.spIsBlockable = this.serializedObject.FindProperty("isBlockable"); this.spPoiseDamage = this.serializedObject.FindProperty("poiseDamage"); this.spDefenseDamage = this.serializedObject.FindProperty("defenseDamage"); this.spInterruptible = this.serializedObject.FindProperty("interruptible"); this.spVulnerability = this.serializedObject.FindProperty("vulnerability"); this.spPosture = this.serializedObject.FindProperty("posture"); this.spAttackPhase = serializedObject.FindProperty("attackPhase"); if (!TEX_PREVIEW_ACCEPT) { TEX_PREVIEW_ACCEPT = MakeTexture(Color.green, 0.25f); } if (!TEX_PREVIEW_REJECT) { TEX_PREVIEW_REJECT = MakeTexture(Color.red, 0.25f); } if (!TEX_DARKER) { TEX_DARKER = MakeTexture(Color.black, 0.5f); } if (!TEX_ATK_PHASE1) { TEX_ATK_PHASE1 = MakeTexture(COLOR_PHASE1); } if (!TEX_ATK_PHASE2) { TEX_ATK_PHASE2 = MakeTexture(COLOR_PHASE2); } if (!TEX_ATK_PHASE3) { TEX_ATK_PHASE3 = MakeTexture(COLOR_PHASE3); } this.spActionsOnHit = this.serializedObject.FindProperty("actionsOnHit"); if (this.spActionsOnHit.objectReferenceValue == null) { string actionsName = Guid.NewGuid().ToString("N"); GameCreatorUtilities.CreateFolderStructure(PATH_ONHIT); string path = Path.Combine(PATH_ONHIT, string.Format(PREFAB_NAME, actionsName)); path = AssetDatabase.GenerateUniqueAssetPath(path); GameObject sceneInstance = new GameObject(actionsName); sceneInstance.AddComponent <Actions>(); GameObject prefabInstance = PrefabUtility.SaveAsPrefabAsset(sceneInstance, path); DestroyImmediate(sceneInstance); Actions prefabActions = prefabInstance.GetComponent <Actions>(); prefabActions.destroyAfterFinishing = true; this.spActionsOnHit.objectReferenceValue = prefabActions.actionsList; this.serializedObject.ApplyModifiedPropertiesWithoutUndo(); this.serializedObject.Update(); } this.spActionsOnExecute = this.serializedObject.FindProperty("actionsOnExecute"); if (this.spActionsOnExecute.objectReferenceValue == null) { string actionsName = Guid.NewGuid().ToString("N"); GameCreatorUtilities.CreateFolderStructure(PATH_ONHIT); string path = Path.Combine(PATH_ONHIT, string.Format(PREFAB_NAME, actionsName)); path = AssetDatabase.GenerateUniqueAssetPath(path); GameObject sceneInstance = new GameObject(actionsName); sceneInstance.AddComponent <Actions>(); GameObject prefabInstance = PrefabUtility.SaveAsPrefabAsset(sceneInstance, path); DestroyImmediate(sceneInstance); Actions prefabActions = prefabInstance.GetComponent <Actions>(); prefabActions.destroyAfterFinishing = true; this.spActionsOnExecute.objectReferenceValue = prefabActions.actionsList; this.serializedObject.ApplyModifiedPropertiesWithoutUndo(); this.serializedObject.Update(); } }