/// <summary> /// Occurs per frame for the unity inspector GUI /// </summary> void OnGUI() { // header if (!skin) { skin = Resources.Load("skin") as GUISkin; } GUI.skin = skin; this.minSize = rect; this.titleContent = new GUIContent("Shadex", null, "Create Magic Controller"); m_Logo = Resources.Load("icon_v2") as Texture2D; GUILayout.BeginVertical("Create Magic Controller", "window"); GUILayout.Label(m_Logo, GUILayout.MaxHeight(25)); GUILayout.Space(5); GUILayout.BeginVertical("box"); if (!bLoaded) { // fill conditions list Conditions = new List <BaseCondition>(); BaseDamage[] AllConditions = (BaseDamage[])Enum.GetValues(typeof(BaseDamage)); for (int i = 0; i < AllConditions.Length; i++) { if (AllConditions[i] != BaseDamage.Physical) { Conditions.Add(new BaseCondition() { Type = AllConditions[i], Display = AssetDatabase.LoadAssetAtPath("Assets/Invector-3rdPersonController/Add-ons/ShadesSpellSystem/Prefabs/Conditions/" + AllConditions[i].ToString() + ".prefab", typeof(GameObject)) as GameObject }); } } // standard invector components, grab prefabs if (File.Exists(Application.dataPath + "/Invector-3rdPersonController/Basic Locomotion/3D Models/Particles/DamageEffect/prefabs/bloodSplash.prefab")) { HitDamageParticle = AssetDatabase.LoadAssetAtPath("Assets/Invector-3rdPersonController/Basic Locomotion/3D Models/Particles/DamageEffect/prefabs/bloodSplash.prefab", typeof(GameObject)) as GameObject; } if (File.Exists(Application.dataPath + "/Invector-3rdPersonController/ItemManager/Prefabs/ItemCollectionDisplay.prefab")) { ItemCollectionDisplay = AssetDatabase.LoadAssetAtPath("Assets/Invector-3rdPersonController/ItemManager/Prefabs/ItemCollectionDisplay.prefab", typeof(GameObject)) as GameObject; } // spell system components, grab prefabs if (File.Exists(Application.dataPath + "/Invector-3rdPersonController/Add-ons/ShadesSpellSystem/Inventory/Inventory_MeleeMagic_Auto.prefab")) { InventoryPrefab = AssetDatabase.LoadAssetAtPath("Assets/Invector-3rdPersonController/Add-ons/ShadesSpellSystem/Inventory/Inventory_MeleeMagic_Auto.prefab", typeof(vInventory)) as vInventory; } if (File.Exists(Application.dataPath + "/Invector-3rdPersonController/Add-ons/ShadesSpellSystem/Inventory/vMeleeMagic_ItemListDataV2.asset")) { ItemListData = AssetDatabase.LoadAssetAtPath("Assets/Invector-3rdPersonController/Add-ons/ShadesSpellSystem/Inventory/vMeleeMagic_ItemListDataV2.asset", typeof(vItemListData)) as vItemListData; } // find the vUI root hierarchy object GameObject[] goRoots = UnityEngine.SceneManagement.SceneManager.GetActiveScene().GetRootGameObjects(); foreach (GameObject go in goRoots) { if (go.name == "vUI") { UIBase = go; break; } } // only run once bLoaded = true; } // rescan for skinned mesh renderers on active selection change if (Selection.activeGameObject != null) { if (LastScanned != Selection.activeGameObject) { LastScanned = Selection.activeGameObject; iWhichMesh = -1; LOD1BodyMeshNames = new List <string>(); LOD1BodyMesh = null; LOD1BodyMesh = Selection.activeGameObject.GetComponentsInChildren <SkinnedMeshRenderer>(); if (LOD1BodyMesh != null) { for (int i = 0; i < LOD1BodyMesh.Length; i++) { LOD1BodyMeshNames.Add(LOD1BodyMesh[i].name); } } } } else { iWhichMesh = -1; LOD1BodyMeshNames = new List <string>(); } // allow user to change the default component parts InventoryPrefab = EditorGUILayout.ObjectField("Inventory Prefab: ", InventoryPrefab, typeof(vInventory), false) as vInventory; ItemListData = EditorGUILayout.ObjectField("Item List Data: ", ItemListData, typeof(vItemListData), false) as vItemListData; ItemCollectionDisplay = EditorGUILayout.ObjectField("Item Collection Display: ", ItemCollectionDisplay, typeof(GameObject), false) as GameObject; HitDamageParticle = EditorGUILayout.ObjectField("Hit Damage Particle: ", HitDamageParticle, typeof(GameObject), false) as GameObject; UIBase = EditorGUILayout.ObjectField("UI Parent: ", UIBase, typeof(GameObject), false) as GameObject; for (int i = 0; i < Conditions.Count; i++) { Conditions[i].Display = EditorGUILayout.ObjectField(Conditions[i].Type.ToString() + " Condition", Conditions[i].Display, typeof(GameObject), false) as GameObject; } //LOD1BodyMesh = EditorGUILayout.ObjectField("LOD1 Body Mesh: ", LOD1BodyMesh, typeof(SkinnedMeshRenderer), false) as SkinnedMeshRenderer; iWhichMesh = EditorGUILayout.Popup("LOD1 Body :", iWhichMesh, LOD1BodyMeshNames.ToArray()); // fail safe if (InventoryPrefab != null && InventoryPrefab.GetComponent <vInventory>() == null) { EditorGUILayout.HelpBox("Please select a Inventory Prefab that contains the vInventory script", MessageType.Warning); } GUILayout.EndVertical(); // create button if valid GUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); if (InventoryPrefab != null && ItemListData != null) { if (Selection.activeGameObject != null && Selection.activeGameObject.GetComponent <vThirdPersonController>() != null) { if (iWhichMesh > -1) { if (GUILayout.Button("Create")) { Create(); } } else { EditorGUILayout.HelpBox("Please select which skinned mesh renderer is the LOD1 body", MessageType.Warning); } } else { EditorGUILayout.HelpBox("Please select the Player to add this component", MessageType.Warning); } } else { EditorGUILayout.HelpBox("Please select the inventory prefab and item list data", MessageType.Warning); } GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); GUILayout.EndVertical(); }
/// <summary> /// Occurs per frame for the unity inspector GUI /// </summary> void OnGUI() { // header if (!skin) { skin = Resources.Load("skin") as GUISkin; } GUI.skin = skin; this.minSize = rect; this.titleContent = new GUIContent("Shadex", null, "Create Magic NPC Controller"); m_Logo = Resources.Load("icon_v2") as Texture2D; GUILayout.BeginVertical("Create Magic NPC Controller", "window"); GUILayout.Label(m_Logo, GUILayout.MaxHeight(25)); GUILayout.Space(5); // attempt grab the headbone on selected gameobject if (LastSelection != Selection.activeGameObject) { Animator animator = Selection.activeGameObject.GetComponent <Animator>(); if (animator) { HeadBone = animator.GetBoneTransform(HumanBodyBones.Head); } LastSelection = Selection.activeGameObject; } GUILayout.BeginVertical("box"); if (!bLoaded) { // fill conditions list Conditions = new List <BaseCondition>(); BaseDamage[] AllConditions = (BaseDamage[])Enum.GetValues(typeof(BaseDamage)); for (int i = 0; i < AllConditions.Length; i++) { if (AllConditions[i] != BaseDamage.Physical) { Conditions.Add(new BaseCondition() { Type = AllConditions[i], Display = AssetDatabase.LoadAssetAtPath("Assets/Invector-3rdPersonController/Add-ons/ShadesSpellSystem/Prefabs/Conditions/" + AllConditions[i].ToString() + ".prefab", typeof(GameObject)) as GameObject }); } } // standard invector components, grab prefabs if (File.Exists(Application.dataPath + "/Invector-3rdPersonController/Basic Locomotion/3D Models/Particles/DamageEffect/prefabs/bloodSplash.prefab")) { HitDamageParticle = AssetDatabase.LoadAssetAtPath("Assets/Invector-3rdPersonController/Basic Locomotion/3D Models/Particles/DamageEffect/prefabs/bloodSplash.prefab", typeof(GameObject)) as GameObject; } // spell system components, grab prefabs if (File.Exists(Application.dataPath + "/Invector-3rdPersonController/Add-ons/ShadesSpellSystem/Inventory/vMeleeMagic_ItemListDataV2.asset")) { ItemListData = AssetDatabase.LoadAssetAtPath("Assets/Invector-3rdPersonController/Add-ons/ShadesSpellSystem/Inventory/vMeleeMagic_ItemListDataV2.asset", typeof(vItemListData)) as vItemListData; } if (File.Exists(Application.dataPath + "/Invector-3rdPersonController/Add-ons/ShadesSpellSystem/UI/enemyHealthUI.prefab")) { HealthUI = AssetDatabase.LoadAssetAtPath("Assets/Invector-3rdPersonController/Add-ons/ShadesSpellSystem/UI/enemyHealthUI.prefab", typeof(GameObject)) as GameObject; } // only run once bLoaded = true; } // rescan for skinned mesh renderers on active selection change if (Selection.activeGameObject != null) { if (LastScanned != Selection.activeGameObject) { LastScanned = Selection.activeGameObject; iWhichMesh = -1; LOD1BodyMeshNames = new List <string>(); LOD1BodyMesh = null; LOD1BodyMesh = Selection.activeGameObject.GetComponentsInChildren <SkinnedMeshRenderer>(); if (LOD1BodyMesh != null) { for (int i = 0; i < LOD1BodyMesh.Length; i++) { LOD1BodyMeshNames.Add(LOD1BodyMesh[i].name); } } } } else { iWhichMesh = -1; LOD1BodyMeshNames = new List <string>(); } // allow user to change the default component parts ItemListData = EditorGUILayout.ObjectField("Item List Data: ", ItemListData, typeof(vItemListData), false) as vItemListData; HitDamageParticle = EditorGUILayout.ObjectField("Hit Damage Particle: ", HitDamageParticle, typeof(GameObject), false) as GameObject; HeadBone = EditorGUILayout.ObjectField("Head Bone: ", HeadBone, typeof(Transform), false) as Transform; for (int i = 0; i < Conditions.Count; i++) { Conditions[i].Display = EditorGUILayout.ObjectField(Conditions[i].Type.ToString() + " Condition", Conditions[i].Display, typeof(GameObject), false) as GameObject; } iWhichMesh = EditorGUILayout.Popup("LOD1 Body :", iWhichMesh, LOD1BodyMeshNames.ToArray()); GUILayout.EndVertical(); // create button if valid GUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); if (ItemListData != null && HeadBone != null && LOD1BodyMesh != null) { if (Selection.activeGameObject != null && Selection.activeGameObject.GetComponent <v_AIController>() != null) { if (iWhichMesh > -1) { if (GUILayout.Button("Create")) { Create(); } } else { EditorGUILayout.HelpBox("Please select which skinned mesh renderer is the LOD1 body", MessageType.Warning); } } else { EditorGUILayout.HelpBox("Please select the vAI to add this component", MessageType.Warning); } } else { EditorGUILayout.HelpBox("Please select the inventory prefab and item list data", MessageType.Warning); } GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); GUILayout.EndVertical(); }