/// <summary> /// Initialise when enabled /// </summary> protected override void OnEnable() { base.OnEnable(); m_Logo = (Texture2D)Resources.Load("itemManagerIcon", typeof(Texture2D)); manager = (MagicAIItemManager)target; itemReferenceList = serializedObject.FindProperty("startItems"); skin = Resources.Load("skin") as GUISkin; //animator = manager.GetComponent<Animator>(); }
/// <summary> /// Initialise listeners and component references. /// </summary> protected virtual void Start() { // initialise invector AI handling player = GlobalFuncs.FindPlayerInstance(); agent = GetComponent <NavMeshAgent>(); animator = GetComponent <Animator>(); inventory = GetComponent <MagicAIItemManager>(); #if !VANILLA ai = GetComponent <v_AIController>(); if (ai) { // don't start if invector AI and all components are not present // invector ai event handlers ai.onReceiveDamage.AddListener(OnReceiveDamage_Chase); // listen for damage to enable chase when out of FOV ai.onChase.AddListener(delegate { OnChase(); }); // listen for start of chase mode ai.onIdle.AddListener(delegate { OnIdle(); }); // listen for start of idle mode //ai.onPatrol.AddListener(delegate { OnPatrol(); }); // listen for start of idle mode ai.onDead.AddListener(delegate { OnDead(); }); // listen for sudden death // store original FOV fOriginal_maxDetectDistance = ai.maxDetectDistance; fOriginal_distanceToLostTarget = ai.distanceToLostTarget; fOriginal_fieldOfView = ai.fieldOfView; } #else // handle non invector events #endif // add a listener to the leveling component if available CharacterBase levelingSystem = GetComponentInParent <CharacterBase>(); if (levelingSystem) { useMana = new SetIntValue(levelingSystem.UseMana); levelingSystem.NotifyUpdateHUD += new CharacterBase.UpdateHUDHandler(UpdateHUDListener); levelingSystem.ForceUpdateHUD(); } #if !VANILLA // make short list of spells in inventory if (inventory && AnimatorTrigger.Length > 0 && HasMagicAbilities) { SpellsShortList = new List <MagicAIAvailableSpell>(); // init the list foreach (ItemReference ir in inventory.startItems) { // process all start items vItem item = inventory.itemListData.items.Find(t => t.id.Equals(ir.id)); // find the vItem by id if (item.type == vItemType.Spell) { // only after spells SpellsShortList.Add(new MagicAIAvailableSpell() { MagicID = item.attributes.Find(ia => ia.name.ToString() == "MagicID").value, ManaCost = item.attributes.Find(ia => ia.name.ToString() == "ManaCost").value }); // add to the short list } } if (SpellsShortList.Count == 0) { // none found SpellsShortList = null; // reset back to null for fast checking if (GlobalFuncs.DEBUGGING_MESSAGES) { Debug.Log("Warning spells NOT found in magic AI inventory"); } } } #endif // birth animation & magic spawning if (BirthStartTrigger != "") { // birth animation specified animator.SetTrigger(BirthStartTrigger); // trigger the random magic state selector } CoDelayedSpawn = StartCoroutine(GlobalFuncs.SpawnAllDelayed(SpawnOnBirth, BirthSpawnDelay, NoneSequentialSpawns, transform, null, 0, false, (gameObject.tag == "Enemy" ? SpawnTarget.Friend : SpawnTarget.Enemy))); // trigger all birth spawns the the array }
/// <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."); } }