/// <summary> /// Create button event, adds all components. /// </summary> void Create() { if (Selection.activeGameObject != null) { // fail safe // add melee manager for when shooter if (!Selection.activeGameObject.GetComponent <vMeleeManager>()) { Selection.activeGameObject.AddComponent <vMeleeManager>(); } // inventory vItemManager itemManager = Selection.activeGameObject.GetComponent <vItemManager>(); if (!itemManager) { itemManager = Selection.activeGameObject.AddComponent <vItemManager>(); vItemManagerUtilities.CreateDefaultEquipPoints(itemManager, itemManager.GetComponent <vMeleeManager>()); } itemManager.inventoryPrefab = InventoryPrefab; itemManager.itemListData = ItemListData; itemManager.itemsFilter.Add(vItemType.MeleeWeapon); itemManager.itemsFilter.Add(vItemType.Spell); // hit damage particle vHitDamageParticle hitDamageParticle = Selection.activeGameObject.GetComponent <vHitDamageParticle>(); if (!hitDamageParticle) { hitDamageParticle = Selection.activeGameObject.AddComponent <vHitDamageParticle>(); } hitDamageParticle.defaultDamageEffect = HitDamageParticle; // UI GameObject goItemCollectionDisplay = PrefabUtility.InstantiatePrefab(ItemCollectionDisplay) as GameObject; goItemCollectionDisplay.transform.SetParent(UIBase.transform); GameObject goInventoryPrefab = PrefabUtility.InstantiatePrefab(InventoryPrefab.gameObject) as GameObject; goInventoryPrefab.name = "Inventory_MeleeMagic_Auto"; // leveling system CharacterInstance levelingsystem = Selection.activeGameObject.GetComponent <CharacterInstance>(); if (!levelingsystem) { levelingsystem = Selection.activeGameObject.AddComponent <CharacterInstance>(); } // link the invector character damage event to the leveling system vThirdPersonController thirdp = Selection.activeGameObject.GetComponent <vThirdPersonController>(); UnityEventTools.AddPersistentListener(thirdp.onReceiveDamage, levelingsystem.OnRecieveDamage); // link the melee manager hits to the leveling system vMeleeManager meleeM = Selection.activeGameObject.GetComponent <vMeleeManager>(); if (meleeM) { if (meleeM.onDamageHit == null) { meleeM.onDamageHit = new vOnHitEvent(); } UnityEventTools.AddPersistentListener(meleeM.onDamageHit, levelingsystem.OnSendHit); } // add conditions and update particles to use the LOD 1 mesh levelingsystem.Conditions = new List <BaseCondition>(); levelingsystem.Conditions.Add(new BaseCondition() { Type = BaseDamage.Physical }); GameObject goConditionsRoot = new GameObject("Conditions"); goConditionsRoot.transform.SetParent(Selection.activeGameObject.transform); goConditionsRoot.transform.position = new Vector3(0f, 0f, 0f); foreach (BaseCondition bc in Conditions) { GameObject goCondition = null; if (bc.Display) { // load the prefab goCondition = PrefabUtility.InstantiatePrefab(bc.Display) as GameObject; goCondition.transform.SetParent(goConditionsRoot.transform); goCondition.transform.position = new Vector3(0f, 0f, 0f); // update all particles to use the mesh renderer from LOD1 goCondition.SetActive(true); ParticleSystem[] ConditionParticles = goCondition.GetComponentsInChildren <ParticleSystem>(); foreach (ParticleSystem p in ConditionParticles) { if (p.shape.enabled) { if (p.shape.shapeType == ParticleSystemShapeType.SkinnedMeshRenderer) { ParticleSystem.ShapeModule editableShape = p.shape; editableShape.skinnedMeshRenderer = LOD1BodyMesh[iWhichMesh]; } } } goCondition.SetActive(false); } // add to the levelling system levelingsystem.Conditions.Add(new BaseCondition() { Type = bc.Type, Length = 0, Display = goCondition }); } // add the magic spawn point GameObject goMagicSpawn = new GameObject("Magic Spawn"); goMagicSpawn.transform.SetParent(Selection.activeGameObject.transform); goMagicSpawn.transform.position = new Vector3(0f, 1.5f, 0.9f); // magic input MagicSettings magicIO = Selection.activeGameObject.GetComponent <MagicSettings>(); if (!magicIO) { magicIO = Selection.activeGameObject.AddComponent <MagicSettings>(); } magicIO.PooledMagic = true; magicIO.MagicSpawnPoint = goMagicSpawn.transform; magicIO.onUseMana = new UnityIntEvent(); UnityEventTools.AddPersistentListener(magicIO.onUseMana, levelingsystem.UseMana); #if !VANILLA // set spell triggers F1-F5 GameObject goInventoryWindow = goInventoryPrefab.transform.Find("InventoryWindow").gameObject; // grab inventory window GameObject goEquipmentInventory = goInventoryWindow.transform.Find("EquipmentInventory").gameObject; // and the equip slot parent goEquipmentInventory.SetActive(true); // enable for component search int iNext = 1; vEquipSlot[] allSlots = goInventoryPrefab.GetComponentsInChildren <vEquipSlot>(); foreach (vEquipSlot slot in allSlots) { if (slot.transform.parent.parent.name == "EquipMentArea_Spells") { // is a spell inventory area MagicSpellTrigger trigger = new MagicSpellTrigger(); // create the trigger trigger.EquipSlots = new vEquipSlot[] { slot }; // set the inventory slot trigger.Input = new GenericInput("F" + iNext.ToString(), null, null); // set the input key trigger.Input.useInput = true; // enable vEquipmentDisplay[] allDisplays = goInventoryPrefab.GetComponentsInChildren <vEquipmentDisplay>(); // find all displays foreach (vEquipmentDisplay disp in allDisplays) { // check all if (disp.gameObject.name == slot.gameObject.name.Replace("EquipSlot ", "EquipDisplay_Spell ")) { // found matching name? trigger.EquipDisplay = disp; // success, apply UnityEventTools.AddPersistentListener(slot.onAddItem, magicIO.SpellEquiped); // listen for spells equiped UnityEventTools.AddPersistentListener(slot.onRemoveItem, magicIO.SpellUnEquiped); // and unequiped break; // drop out } } magicIO.SpellsTriggers.Add(trigger); // add the trigger iNext += 1; // next please } } goEquipmentInventory.SetActive(false); // deactivate the inventory display #endif // link the UI further Transform tHUD = UIBase.transform.Find("HUD"); magicIO.XPText = tHUD.Find("XP").GetComponent <UnityEngine.UI.Text>(); magicIO.LevelText = tHUD.Find("Level").GetComponent <UnityEngine.UI.Text>(); magicIO.LevelUpText = tHUD.Find("Level up").GetComponent <UnityEngine.UI.Text>(); magicIO.ManaSlider = tHUD.Find("mana").GetComponent <UnityEngine.UI.Slider>(); #if !VANILLA itemManager.onUseItem = new OnHandleItemEvent(); UnityEventTools.AddPersistentListener(itemManager.onUseItem, magicIO.UsePotion); // also lock input when inventory open itemManager.onOpenCloseInventory = new OnOpenCloseInventory(); vMeleeCombatInput MeleeInput = Selection.activeGameObject.GetComponent <vMeleeCombatInput>(); if (MeleeInput) { UnityEventTools.AddPersistentListener(itemManager.onOpenCloseInventory, MeleeInput.SetLockMeleeInput); } #endif // work complete this.Close(); } else { Debug.Log("Please select the Player to add these components."); } }
/// <summary> /// Create button event, adds all components. /// </summary> void Create() { if (Selection.activeGameObject != null) { // fail safe // hit damage particle vHitDamageParticle hitDamageParticle = Selection.activeGameObject.GetComponent <vHitDamageParticle>(); if (!hitDamageParticle) { hitDamageParticle = Selection.activeGameObject.AddComponent <vHitDamageParticle>(); } hitDamageParticle.defaultDamageEffect = HitDamageParticle; // melee manager vMeleeManager meleeManager = Selection.activeGameObject.GetComponent <vMeleeManager>(); if (!meleeManager) { meleeManager = Selection.activeGameObject.AddComponent <vMeleeManager>(); } meleeManager.hitProperties = new HitProperties(); meleeManager.hitProperties.hitDamageTags[0] = "Player"; // leveling system CharacterInstance levelingsystem = Selection.activeGameObject.GetComponent <CharacterInstance>(); if (!levelingsystem) { levelingsystem = Selection.activeGameObject.AddComponent <CharacterInstance>(); } // add conditions and update particles to use the LOD 1 mesh levelingsystem.Conditions = new List <BaseCondition>(); levelingsystem.Conditions.Add(new BaseCondition() { Type = BaseDamage.Physical }); GameObject goConditionsRoot = new GameObject("Conditions"); goConditionsRoot.transform.SetParent(Selection.activeGameObject.transform); goConditionsRoot.transform.position = new Vector3(0f, 0f, 0f); foreach (BaseCondition bc in Conditions) { GameObject goCondition = null; if (bc.Display) { // load the prefab goCondition = PrefabUtility.InstantiatePrefab(bc.Display) as GameObject; goCondition.transform.SetParent(goConditionsRoot.transform); goCondition.transform.position = new Vector3(0f, 0f, 0f); // update all particles to use the mesh renderer from LOD1 goCondition.SetActive(true); ParticleSystem[] ConditionParticles = goCondition.GetComponentsInChildren <ParticleSystem>(); foreach (ParticleSystem p in ConditionParticles) { if (p.shape.enabled) { if (p.shape.shapeType == ParticleSystemShapeType.SkinnedMeshRenderer) { ParticleSystem.ShapeModule editableShape = p.shape; editableShape.skinnedMeshRenderer = LOD1BodyMesh[iWhichMesh]; } } } goCondition.SetActive(false); } // add to the levelling system levelingsystem.Conditions.Add(new BaseCondition() { Type = bc.Type, Length = 0, Display = goCondition }); } // link the ai damage to the leveling system v_AIController vai = Selection.activeGameObject.GetComponent <v_AIController>(); vai.onReceiveDamage = new Invector.OnReceiveDamage(); UnityEventTools.AddPersistentListener(vai.onReceiveDamage, levelingsystem.OnRecieveDamage); // link the melee manager hits to the leveling system meleeManager.onDamageHit = new vOnHitEvent(); UnityEventTools.AddPersistentListener(meleeManager.onDamageHit, levelingsystem.OnSendHit); // add the magic spawn point GameObject goMagicSpawn = new GameObject("Magic Spawn"); goMagicSpawn.transform.SetParent(Selection.activeGameObject.transform); goMagicSpawn.transform.position = new Vector3(0f, 1.5f, 0.9f); // AI inventory MagicAIItemManager itemManager = Selection.activeGameObject.GetComponent <MagicAIItemManager>(); if (!itemManager) { itemManager = Selection.activeGameObject.AddComponent <MagicAIItemManager>(); } itemManager.itemListData = ItemListData; itemManager.itemsFilter.Add(vItemType.Spell); // Magic AI MagicAI mai = Selection.activeGameObject.GetComponent <MagicAI>(); if (!mai) { mai = Selection.activeGameObject.AddComponent <MagicAI>(); } mai.MagicSpawnPoint = goMagicSpawn.transform; // health/mana bars GameObject HealthUIinstance = (GameObject)Instantiate(HealthUI); HealthUIinstance.transform.SetParent(HeadBone); HealthUIinstance.transform.localPosition = HealthUI.transform.localPosition; HealthUIinstance.transform.localRotation = HealthUI.transform.localRotation; HealthUIinstance.transform.localScale = HealthUI.transform.localScale; // work complete this.Close(); } else { Debug.Log("Please select the Player to add these components."); } }