public override void OnInspectorGUI() { EditorGUILayout.EnumPopup("ItemType", fe); DrawDefaultInspector(); ShieldItem invItem = (ShieldItem)target; bool loadDefaults = GUILayout.Button("Load Default Shield Clips & Sounds"); if (loadDefaults) { Utils.LoadDefaultShieldSoundsAndClips(invItem); } if (GUI.changed) { EditorUtility.SetDirty(invItem); } }
/// <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); } } }