Esempio n. 1
0
        //private vMeleeManager MeleeManager;

        /// <summary>
        /// Initialise component references
        /// </summary>
        public virtual void Start()
        {
            Settings = GetComponent <MagicSettings>();
#if !VANILLA
            //MeleeManager = GetComponent<vMeleeManager>();
            ItemManager = GetComponent <vItemManager>();
#endif
        }
Esempio n. 2
0
 /// <summary>
 /// Find the character database component.
 /// </summary>
 /// <returns>Active magic settings class instance.</returns>
 public static MagicSettings TheMagicalSettings()
 {
     if (!mSet)
     {
         GameObject player = FindPlayerInstance();
         if (player)
         {
             mSet = player.GetComponent <MagicSettings>();
         }
     }
     return(mSet);
 }
Esempio n. 3
0
        /// <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.");
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Add a check UI links validator to the default inspector window.
        /// </summary>
        public override void OnInspectorGUI()
        {
            defaultSkin = GUI.skin;
            if (skin)
            {
                GUI.skin = skin;
            }
            GUILayout.BeginVertical("MAGIC SETTINGS", "window");
            GUILayout.Space(30);

            // validate the interface to player links
            if (GUILayout.Button("Check UI->Player Links", GUILayout.ExpandWidth(true)))
            {
                // setup
                GameObject    player         = Selection.activeGameObject;
                MagicSettings settings       = player.GetComponent <MagicSettings>();
                CharacterBase levelingSystem = player.GetComponent <CharacterBase>();
                lastUICheckResults = "";
                int changeCount = 0;

                // check magic spawn point
                if (!settings.MagicSpawnPoint)
                {
                    Transform tMagicSpawn = player.transform.Find("Magic Spawn");
                    if (!tMagicSpawn)
                    {
                        GameObject goMagicSpawn = new GameObject("Magic Spawn");
                        goMagicSpawn.transform.SetParent(player.transform);
                        goMagicSpawn.transform.position = new Vector3(0f, 1.5f, 0.9f);
                        settings.MagicSpawnPoint        = goMagicSpawn.transform;
                    }
                    else
                    {
                        settings.MagicSpawnPoint = tMagicSpawn;
                    }

                    changeCount        += 1;
                    lastUICheckResults += "Added Magic Spawn Point\r\n";
                }

                // leveling system on use mana connection
                if (levelingSystem)
                {
                    settings.onUseMana = new UnityIntEvent();
                    UnityEventTools.AddPersistentListener(settings.onUseMana, levelingSystem.UseMana);
                    changeCount        += 1;
                    lastUICheckResults += "Re-Linked leveling system to onUseMana\r\n";
                }
                else
                {
                    lastUICheckResults += "Optional Leveling system is missing, onUseMana not handled\r\n";
                }

                // check links between inventory ui and the player
                vItemManager itemManager = player.GetComponent <vItemManager>();
                if (!itemManager)
                {
                    lastUICheckResults += "vItemManager is MISSING\r\n";
                }
                else  // found, checking slot links
                {
                    GameObject goInventoryWindow    = itemManager.inventoryPrefab.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 = itemManager.inventoryPrefab.transform.GetComponentsInChildren <vEquipSlot>();
                    settings.SpellsTriggers.Clear();
                    foreach (vEquipSlot slot in allSlots)
                    {
                        if (slot.transform.parent.parent.name == "EquipMentArea_Spells")  // is a spell inventory area
                        {
                            slot.onAddItem    = new OnHandleItemEvent();
                            slot.onRemoveItem = new OnHandleItemEvent();
                            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 = itemManager.inventoryPrefab.transform.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, settings.SpellEquiped);                                  // listen for spells equiped
                                    UnityEventTools.AddPersistentListener(slot.onRemoveItem, settings.SpellUnEquiped);                             // and unequiped
                                    break;                                                                                                         // drop out
                                }
                            }
                            settings.SpellsTriggers.Add(trigger); // add the trigger
                            iNext += 1;                           // next please
                        }
                    }
                    goEquipmentInventory.SetActive(false);  // deactivate the inventory display

                    changeCount        += 1;
                    lastUICheckResults += "Re-Linked inventory/UI display slots to the player\r\n";

                    // check use potion links
                    itemManager.onUseItem = new OnHandleItemEvent();
                    UnityEventTools.AddPersistentListener(itemManager.onUseItem, settings.UsePotion);

                    changeCount        += 1;
                    lastUICheckResults += "Re-Linked item manager use potion to the player\r\n";
                }

                // finish up
                lastUICheckResults += "All done " + changeCount.ToString() + " changes applied\r\n\r\n";
            }
            GUILayout.Label(lastUICheckResults, GUILayout.ExpandWidth(true));

            // output the base inspector window
            GUI.skin = defaultSkin;
            base.OnInspectorGUI();
            GUI.skin = skin;
            GUILayout.EndVertical();
            GUI.skin = defaultSkin;
        }
Esempio n. 5
0
 public static void ResetSettings()
 {
     sSettings = null;
 }