/// <summary> /// initialize component /// </summary> /// <returns>success</returns> public override bool initialize() { weaponAudio = GetComponent <WeaponAudio>(); if (!weaponAudio) { Debug.LogWarning("Cannot find 'WeaponAudio' on " + this.gameObject.name); } return(base.initialize()); }
void _createAudioManager() { AudioManager am = character.GetComponent <AudioManager>(); if (!am) { am = Undo.AddComponent <AudioManager>(character); } WeaponAudio ms = character.GetComponent <WeaponAudio>(); if (!ms) { ms = Undo.AddComponent <WeaponAudio>(character); } // load default clips AudioClip grunt1 = Resources.Load <AudioClip>("Audio/grunt1"); AudioClip grunt2 = Resources.Load <AudioClip>("Audio/grunt2"); AudioClip grunt4 = Resources.Load <AudioClip>("Audio/grunt4"); AudioClip grunt5 = Resources.Load <AudioClip>("Audio/grunt5"); AudioClip punch1 = Resources.Load <AudioClip>("Audio/punch1"); AudioClip smack1 = Resources.Load <AudioClip>("Audio/smack1"); AudioClip smack2 = Resources.Load <AudioClip>("Audio/smack2"); AudioClip smack3 = Resources.Load <AudioClip>("Audio/smack3"); AudioClip block1 = Resources.Load <AudioClip>("Audio/block1"); if (!grunt1) { Debug.LogWarning("Unable to load clip: 'Audio/grunt1'"); } if (!grunt2) { Debug.LogWarning("Unable to load clip: 'Audio/grunt2'"); } if (!grunt4) { Debug.LogWarning("Unable to load clip: 'Audio/grunt4'"); } if (!grunt5) { Debug.LogWarning("Unable to load clip: 'Audio/grunt5'"); } if (!punch1) { Debug.LogWarning("Unable to load clip: 'Audio/punch1'"); } if (!smack1) { Debug.LogWarning("Unable to load clip: 'Audio/smack1'"); } if (!smack2) { Debug.LogWarning("Unable to load clip: 'Audio/smack2'"); } if (!smack3) { Debug.LogWarning("Unable to load clip: 'Audio/smack3'"); } if (!block1) { Debug.LogWarning("Unable to load clip: 'Audio/block1'"); } am.jumpSounds = new AudioClip[] { grunt1, grunt5 }; am.diveRollSounds = new AudioClip[] { grunt2 }; ms.attackSwingSounds = new AudioClip[] { grunt4, grunt5 }; ms.attackHitSounds = new AudioClip[] { punch1, smack1, smack2, smack3 }; ms.blockSounds = new AudioClip[] { block1 }; }
void _createAudio() { AudioManager am = character.GetComponent <AudioManager>(); if (!am) { am = Undo.AddComponent <AudioManager>(character); } // load default clips AudioClip jumpClip1 = Resources.Load <AudioClip>("Audio/grunt5"); AudioClip jumpClip2 = Resources.Load <AudioClip>("Audio/grunt1"); AudioClip diveRoll = Resources.Load <AudioClip>("Audio/grunt2"); if (!jumpClip1) { Debug.LogWarning("Unable to load clip: 'Audio/grunt5'"); } if (!jumpClip2) { Debug.LogWarning("Unable to load clip: 'Audio/grunt1'"); } if (!diveRoll) { Debug.LogWarning("Unable to load clip: 'Audio/grunt2'"); } am.jumpSounds = new AudioClip[] { jumpClip1, jumpClip2 }; am.diveRollSounds = new AudioClip[] { diveRoll }; if (CharacterType == CharacterTypes.ThirdPerson || CharacterType == CharacterTypes.TopDown) { WeaponAudio ms = character.GetComponent <WeaponAudio>(); if (!ms) { ms = Undo.AddComponent <WeaponAudio>(character); } // load default clips AudioClip punch1 = Resources.Load <AudioClip>("Audio/punch1"); AudioClip smack1 = Resources.Load <AudioClip>("Audio/smack1"); AudioClip smack2 = Resources.Load <AudioClip>("Audio/smack2"); AudioClip smack3 = Resources.Load <AudioClip>("Audio/smack3"); AudioClip block1 = Resources.Load <AudioClip>("Audio/block1"); AudioClip swoosh1 = Resources.Load <AudioClip>("Audio/swoosh1"); AudioClip swoosh2 = Resources.Load <AudioClip>("Audio/swoosh2"); if (!punch1) { Debug.LogWarning("Unable to load clip: 'Audio/punch1'"); } if (!smack1) { Debug.LogWarning("Unable to load clip: 'Audio/smack1'"); } if (!smack2) { Debug.LogWarning("Unable to load clip: 'Audio/smack2'"); } if (!smack3) { Debug.LogWarning("Unable to load clip: 'Audio/smack3'"); } if (!block1) { Debug.LogWarning("Unable to load clip: 'Audio/block1'"); } if (!swoosh1) { Debug.LogWarning("Unable to load clip: 'Audio/swoosh1'"); } if (!swoosh2) { Debug.LogWarning("Unable to load clip: 'Audio/swoosh2'"); } ms.attackSwingSounds = new AudioClip[] { swoosh1, swoosh2 }; ms.attackHitSounds = new AudioClip[] { punch1, smack1, smack2, smack3 }; ms.blockSounds = new AudioClip[] { block1 }; } }
/// <summary> /// initialize component /// </summary> public void initialize() { if (m_Initialized) { return; } m_Animator = GetComponent <Animator>(); if (!m_Animator) { Debug.LogError("Cannot find component 'Animator'" + " < " + this.ToString() + ">"); return; } m_Audio = GetComponent <AudioManager>(); if (!m_Audio) { Debug.LogError("Cannot find component 'AudioManager'" + " < " + this.ToString() + ">"); return; } m_Character = GetComponent <TPCharacter>(); if (!m_Character) { Debug.LogError("Cannot find component 'TPCharacter'" + " < " + this.ToString() + ">"); return; } m_Character.initialize(); m_Character.setIKMode(TPCharacter.IKMode.None); AudioManager amg = m_Character.audioManager as AudioManager; if (!amg) { Debug.LogError("Cannot find component 'AudioManager'" + " < " + this.ToString() + ">"); return; } m_Audio = amg; m_DefaultWeaponSounds = GetComponent <WeaponAudio>(); if (!m_DefaultWeaponSounds) { Debug.LogError("Cannot find 'WeaponAudio' component <" + this.ToString() + " >"); return; } m_Stats = GetComponent <Stats>(); if (!m_Stats) { Debug.LogError("Cannot find 'Stats' component: " + " < " + this.ToString() + ">"); return; } m_HealthUI = GetComponent <HealthUI>(); m_Ragdoll = GetComponent <RagdollManager>(); if (!m_Ragdoll) { Debug.LogError("Cannot find component 'RagdollManager'" + " < " + this.ToString() + ">"); return; } m_Ragdoll.initialize(); m_Ragdoll.OnHit = () => { m_Character.simulateRootMotion = false; m_Character.disableMove = true; m_Character.rigidBody.velocity = Vector3.zero; m_Character.rigidBody.detectCollisions = false; m_Character.rigidBody.isKinematic = true; m_Character.capsule.enabled = false; }; // allow movement when transitioning to animated m_Ragdoll.OnStartTransition = () => { /* * Enable simulating root motion on transition if * character is not in full ragdoll to * make character not freeze on place when hit. * Otherwise root motion will interfere with getting up animation. */ if (!m_Ragdoll.isFullRagdoll && !m_Ragdoll.isGettingUp) { m_Character.simulateRootMotion = true; m_Character.rigidBody.detectCollisions = true; m_Character.rigidBody.isKinematic = false; m_Character.capsule.enabled = true; } }; // event that will be last fired ( when full ragdoll - on get up, when hit reaction - on blend end m_Ragdoll.LastEvent = () => { m_Character.simulateRootMotion = true; m_Character.disableMove = false; m_Character.rigidBody.detectCollisions = true; m_Character.rigidBody.isKinematic = false; m_Character.capsule.enabled = true; }; m_Ragdoll.ragdollEventTime = 4.0f; //m_Ragdoll.OnTimeEnd = () => //{ // if (m_Stats.health > 0) // { // m_Ragdoll.blendToMecanim(); // } // //m_Ragdoll.OnTimeEnd = null; //}; GameObject playerGO = GameObject.FindGameObjectWithTag("Player"); if (!playerGO) { Debug.LogError("Cannot find object with tag 'Player' " + " < " + this.ToString() + ">"); return; } m_Player = playerGO.GetComponent <Player>(); if (!m_Player) { Debug.LogError("Cannot find 'Player' script on " + playerGO.name + " < " + this.ToString() + ">"); return; } m_path = new UnityEngine.AI.NavMeshPath(); m_NpcState = NPCState.Idle; m_NPCManager = GameObject.FindObjectOfType <NPCManager>(); m_StartPosition = transform.position; m_StartLookAt = transform.forward; #if SMOOTH_MOVEMENT for (int i = 0; i < avgMove.Length; i++) { avgMove[i] = Vector3.zero; } #endif if (!attackSweepBody) { Debug.LogError("Cannot find attack sweep body used for finding obstructions." + " < " + this.ToString() + ">"); return; } m_DamageUI = GetComponent <DebugUI>(); m_Initialized = true; }
/// <summary> /// load default shield animation clips /// </summary> /// <param name="weaponItem">shield item to assign clips to</param> public static void LoadDefaultShieldSoundsAndClips(ShieldItem shieldItem) { WeaponAudio wa = shieldItem.GetComponent <WeaponAudio>(); if (!wa) { wa = Undo.AddComponent <WeaponAudio>(shieldItem.gameObject); } AudioClip swoosh1 = Resources.Load <AudioClip>("Audio/swoosh1"); AudioClip swoosh2 = Resources.Load <AudioClip>("Audio/swoosh2"); AudioClip metal_clang = Resources.Load <AudioClip>("Audio/metal_clang"); AudioClip smack1 = Resources.Load <AudioClip>("Audio/smack1"); AudioClip smack2 = Resources.Load <AudioClip>("Audio/smack2"); AudioClip smack3 = Resources.Load <AudioClip>("Audio/smack3"); if (!swoosh1) { Debug.LogWarning("Unable to load clip: 'Audio/swoosh1'"); } if (!swoosh2) { Debug.LogWarning("Unable to load clip: 'Audio/swoosh2'"); } if (!metal_clang) { Debug.LogWarning("Unable to load clip: 'Audio/metal_clang'"); } if (!smack1) { Debug.LogWarning("Unable to load clip: 'Audio/smack1'"); } if (!smack2) { Debug.LogWarning("Unable to load clip: 'Audio/smack2'"); } if (!smack3) { Debug.LogWarning("Unable to load clip: 'Audio/smack3'"); } wa.attackSwingSounds = new AudioClip[] { swoosh1, swoosh2 }; wa.attackHitSounds = new AudioClip[] { smack1, smack2, smack3 }; wa.blockSounds = new AudioClip[] { metal_clang }; AnimationClip defaultAttack = null; AnimationClip defaultBlock = null; System.Collections.Generic.List <AnimationClip> blockHitClips = new System.Collections.Generic.List <AnimationClip>(); AnimationClip[] onehandedclips = Resources.LoadAll <AnimationClip>("Animations/c_sword&shield_03"); if (onehandedclips.Length == 0) { Debug.LogWarning("Cannot find animations from 'Resources/Animations/c_sword&shield_03"); } foreach (AnimationClip clip in onehandedclips) { if (clip.name == "ShieldAttack") { defaultAttack = clip; } if (clip.name == "ShieldBlock1") { defaultBlock = clip; } if (clip.name.StartsWith("ShieldBlockHit")) { blockHitClips.Add(clip); } } if (defaultAttack) { shieldItem.attackClip.original_name = "default_attack_walk_fast"; shieldItem.attackClip.clip = defaultAttack; } if (defaultBlock) { shieldItem.blockClip.original_name = "default_block_stance"; shieldItem.blockClip.clip = defaultBlock; } shieldItem.blockHitClips = new System.Collections.Generic.List <AnimationClipReplacementInfo>(5); for (int i = 0; i < blockHitClips.Count; i++) { AnimationClipReplacementInfo info = new AnimationClipReplacementInfo(); info.original_name = "default_block_hit" + i; info.clip = blockHitClips[i]; shieldItem.blockHitClips.Add(info); } Debug.LogWarning("NEED TO CREATE SECONDARY HAND LOCOMOTION ANIMATIONS !!!"); AnimationClip[] locomotionClips = Resources.LoadAll <AnimationClip>("Animations/DefaultLocomotions/c_SecondaryItemLocomotion"); if (locomotionClips.Length == 0) { Debug.LogWarning("Cannot find animations from 'Resources/Animations/DefaultLocomotions/c_SecondaryItemLocomotion"); } shieldItem.locomotionClips = new System.Collections.Generic.List <AnimationClipReplacementInfo>(15); for (int i = 0; i < locomotionClips.Length; i++) { AnimationClip clip = locomotionClips[i]; if (!clip) { continue; } if (clip.name == "c_SecItem_Idle") { AnimationClipReplacementInfo info = new AnimationClipReplacementInfo(); info.original_name = "Default_Idle"; info.clip = clip; shieldItem.locomotionClips.Add(info); } else if (clip.name == "c_SecItem_Run") { AnimationClipReplacementInfo info = new AnimationClipReplacementInfo(); info.original_name = "Default_Run"; info.clip = clip; shieldItem.locomotionClips.Add(info); } else if (clip.name == "c_SecItem_Walk") { AnimationClipReplacementInfo info = new AnimationClipReplacementInfo(); info.original_name = "Default_Walk"; info.clip = clip; shieldItem.locomotionClips.Add(info); } else if (clip.name == "c_SecItem_TurnRightQuarter") { AnimationClipReplacementInfo info = new AnimationClipReplacementInfo(); info.original_name = "Default_TurnRightQuarter"; info.clip = clip; shieldItem.locomotionClips.Add(info); } else if (clip.name == "c_SecItem_TurnRightHalf") { AnimationClipReplacementInfo info = new AnimationClipReplacementInfo(); info.original_name = "Default_TurnRightHalf"; info.clip = clip; shieldItem.locomotionClips.Add(info); } else if (clip.name == "c_SecItem_TurnLeftQuarter") { AnimationClipReplacementInfo info = new AnimationClipReplacementInfo(); info.original_name = "Default_TurnLeftQuarter"; info.clip = clip; shieldItem.locomotionClips.Add(info); } else if (clip.name == "c_SecItem_TurnLeftHalf") { AnimationClipReplacementInfo info = new AnimationClipReplacementInfo(); info.original_name = "Default_TurnLeftHalf"; info.clip = clip; shieldItem.locomotionClips.Add(info); } else if (clip.name == "c_SecItem_WalkRightSharp") { AnimationClipReplacementInfo info = new AnimationClipReplacementInfo(); info.original_name = "Default_WalkRightSharp"; info.clip = clip; shieldItem.locomotionClips.Add(info); } else if (clip.name == "c_SecItem_WalkLeftSharp") { AnimationClipReplacementInfo info = new AnimationClipReplacementInfo(); info.original_name = "Default_WalkLeftSharp"; info.clip = clip; shieldItem.locomotionClips.Add(info); } else if (clip.name == "c_SecItem_WalkRightWide") { AnimationClipReplacementInfo info = new AnimationClipReplacementInfo(); info.original_name = "Default_WalkRightWide"; info.clip = clip; shieldItem.locomotionClips.Add(info); } else if (clip.name == "c_SecItem_WalkLeftWide") { AnimationClipReplacementInfo info = new AnimationClipReplacementInfo(); info.original_name = "Default_WalkLeftWide"; info.clip = clip; shieldItem.locomotionClips.Add(info); } else if (clip.name == "c_SecItem_RunRightSharp") { AnimationClipReplacementInfo info = new AnimationClipReplacementInfo(); info.original_name = "Default_RunRightSharp"; info.clip = clip; shieldItem.locomotionClips.Add(info); } else if (clip.name == "c_SecItem_RunLeftSharp") { AnimationClipReplacementInfo info = new AnimationClipReplacementInfo(); info.original_name = "Default_RunLeftSharp"; info.clip = clip; shieldItem.locomotionClips.Add(info); } else if (clip.name == "c_SecItem_RunRightWide") { AnimationClipReplacementInfo info = new AnimationClipReplacementInfo(); info.original_name = "Default_RunRightWide"; info.clip = clip; shieldItem.locomotionClips.Add(info); } else if (clip.name == "c_SecItem_RunLeftWide") { AnimationClipReplacementInfo info = new AnimationClipReplacementInfo(); info.original_name = "Default_RunLeftWide"; info.clip = clip; shieldItem.locomotionClips.Add(info); } } }
/// <summary> /// load default two handed weapon animation clips /// </summary> /// <param name="weaponItem">weapon item to assign clips to</param> public static void LoadDefaultWeapon2HSoundsAndClips(MeleeWeaponItem weaponItem) { WeaponAudio wa = weaponItem.GetComponent <WeaponAudio>(); if (!wa) { wa = Undo.AddComponent <WeaponAudio>(weaponItem.gameObject); } AudioClip swoosh1 = Resources.Load <AudioClip>("Audio/swoosh1"); AudioClip swoosh2 = Resources.Load <AudioClip>("Audio/swoosh2"); AudioClip metal_clang = Resources.Load <AudioClip>("Audio/metal_clang"); AudioClip sword_hit = Resources.Load <AudioClip>("Audio/blade_slash_hit"); if (!swoosh1) { Debug.LogWarning("Unable to load clip: 'Audio/swoosh1'"); } if (!swoosh2) { Debug.LogWarning("Unable to load clip: 'Audio/swoosh2'"); } if (!metal_clang) { Debug.LogWarning("Unable to load clip: 'Audio/metal_clang'"); } if (!sword_hit) { Debug.LogWarning("Unable to load clip: 'Audio/blade_slash_hit'"); } wa.attackSwingSounds = new AudioClip[] { swoosh1, swoosh2 }; wa.attackHitSounds = new AudioClip[] { sword_hit }; wa.blockSounds = new AudioClip[] { metal_clang }; AnimationClip defaultAttack = null; AnimationClip defaultBlock = null; System.Collections.Generic.List <AnimationClip> blockHitClips = new System.Collections.Generic.List <AnimationClip>(); AnimationClip[] twohandedclips = Resources.LoadAll <AnimationClip>("Animations/c_Weapon2H"); if (twohandedclips.Length == 0) { Debug.LogWarning("Cannot find animations from 'Resources/Animations/c_Weapon2H"); } foreach (AnimationClip clip in twohandedclips) { if (clip.name == "c_Weapon2HCombo01") { defaultAttack = clip; } if (clip.name == "c_Weapon2HBlockStance01") { defaultBlock = clip; } if (clip.name.StartsWith("c_W2HBlockHit")) { blockHitClips.Add(clip); } } if (defaultAttack) { weaponItem.attackClip.original_name = "default_attack_walk_fast"; weaponItem.attackClip.clip = defaultAttack; } if (defaultBlock) { weaponItem.blockClip.original_name = "default_block_stance"; weaponItem.blockClip.clip = defaultBlock; } weaponItem.blockHitClips = new System.Collections.Generic.List <AnimationClipReplacementInfo>(5); for (int i = 0; i < blockHitClips.Count; i++) { AnimationClipReplacementInfo info = new AnimationClipReplacementInfo(); info.original_name = "default_block_hit" + i; info.clip = blockHitClips[i]; weaponItem.blockHitClips.Add(info); } AnimationClip[] locomotionClips = Resources.LoadAll <AnimationClip>("Animations/DefaultLocomotions/c_TwoHanded_Locomotion"); if (locomotionClips.Length == 0) { Debug.LogWarning("Cannot find animations from 'Resources/Animations/DefaultLocomotions/c_Locomotion2HMain"); } weaponItem.locomotionClips = new System.Collections.Generic.List <AnimationClipReplacementInfo>(15); for (int i = 0; i < locomotionClips.Length; i++) { AnimationClip clip = locomotionClips[i]; if (!clip) { continue; } if (clip.name == "c_Item2H_Idle") { AnimationClipReplacementInfo info = new AnimationClipReplacementInfo(); info.original_name = "Default_Idle"; info.clip = clip; weaponItem.locomotionClips.Add(info); } else if (clip.name == "c_Item2H_Walk") { AnimationClipReplacementInfo info = new AnimationClipReplacementInfo(); info.original_name = "Default_Walk"; info.clip = clip; weaponItem.locomotionClips.Add(info); } else if (clip.name == "c_Item2H_Run") { AnimationClipReplacementInfo info = new AnimationClipReplacementInfo(); info.original_name = "Default_Run"; info.clip = clip; weaponItem.locomotionClips.Add(info); } else if (clip.name == "c_Item2H_TurnRightQuarter") { AnimationClipReplacementInfo info = new AnimationClipReplacementInfo(); info.original_name = "Default_TurnRightQuarter"; info.clip = clip; weaponItem.locomotionClips.Add(info); } else if (clip.name == "c_Item2H_TurnRightHalf") { AnimationClipReplacementInfo info = new AnimationClipReplacementInfo(); info.original_name = "Default_TurnRightHalf"; info.clip = clip; weaponItem.locomotionClips.Add(info); } else if (clip.name == "c_Item2H_TurnLeftQuarter") { AnimationClipReplacementInfo info = new AnimationClipReplacementInfo(); info.original_name = "Default_TurnLeftQuarter"; info.clip = clip; weaponItem.locomotionClips.Add(info); } else if (clip.name == "c_Item2H_TurnLeftHalf") { AnimationClipReplacementInfo info = new AnimationClipReplacementInfo(); info.original_name = "Default_TurnLeftHalf"; info.clip = clip; weaponItem.locomotionClips.Add(info); } else if (clip.name == "c_Item2H_WalkRightSharp") { AnimationClipReplacementInfo info = new AnimationClipReplacementInfo(); info.original_name = "Default_WalkRightSharp"; info.clip = clip; weaponItem.locomotionClips.Add(info); } else if (clip.name == "c_Item2H_WalkLeftSharp") { AnimationClipReplacementInfo info = new AnimationClipReplacementInfo(); info.original_name = "Default_WalkLeftSharp"; info.clip = clip; weaponItem.locomotionClips.Add(info); } else if (clip.name == "c_Item2H_WalkRightWide") { AnimationClipReplacementInfo info = new AnimationClipReplacementInfo(); info.original_name = "Default_WalkRightWide"; info.clip = clip; weaponItem.locomotionClips.Add(info); } else if (clip.name == "c_Item2H_WalkLeftWide") { AnimationClipReplacementInfo info = new AnimationClipReplacementInfo(); info.original_name = "Default_WalkLeftWide"; info.clip = clip; weaponItem.locomotionClips.Add(info); } else if (clip.name == "c_Item2H_RunRightSharp") { AnimationClipReplacementInfo info = new AnimationClipReplacementInfo(); info.original_name = "Default_RunRightSharp"; info.clip = clip; weaponItem.locomotionClips.Add(info); } else if (clip.name == "c_Item2H_RunLeftSharp") { AnimationClipReplacementInfo info = new AnimationClipReplacementInfo(); info.original_name = "Default_RunLeftSharp"; info.clip = clip; weaponItem.locomotionClips.Add(info); } else if (clip.name == "c_Item2H_RunRightWide") { AnimationClipReplacementInfo info = new AnimationClipReplacementInfo(); info.original_name = "Default_RunRightWide"; info.clip = clip; weaponItem.locomotionClips.Add(info); } else if (clip.name == "c_Item2H_RunLeftWide") { AnimationClipReplacementInfo info = new AnimationClipReplacementInfo(); info.original_name = "Default_RunLeftWide"; info.clip = clip; weaponItem.locomotionClips.Add(info); } } }