コード例 #1
0
    void Awake()
    {
        template        = GetComponent <v_AIController>();
        navMeshAgent    = GetComponent <NavMeshAgent>();
        animator        = GetComponent <Animator>();
        selectionCircle = transform.Find("SelectionCircle").GetComponent <SpriteRenderer>();

        //Randomization of NavMeshAgent speed. More fun!
        float rndmFactor = navMeshAgent.speed * .15f;

        navMeshAgent.speed += Random.Range(-rndmFactor, rndmFactor);
    }
コード例 #2
0
        /// <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
        }
コード例 #3
0
        /// <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.");
            }
        }
コード例 #4
0
    IEnumerator Start()
    {
        itemCollection = GetComponentInChildren <vItemCollection>(true);
        ai             = GetComponent <v_AIController>();
        manager        = GetComponent <vMeleeManager>();
        yield return(new WaitForEndOfFrame());

        if (itemCollection && ai && manager)
        {
            ai.onSetAgressive.AddListener(OnSetAgressive);
            leftArm  = ai.animator.GetBoneTransform(HumanBodyBones.LeftLowerArm);
            rightArm = ai.animator.GetBoneTransform(HumanBodyBones.RightLowerArm);

            for (int i = 0; i < itemCollection.items.Count; i++)
            {
                if (itemCollection.items[i].amount > 0)
                {
                    var item = itemCollection.itemListData.items.Find(_item => _item.id == itemCollection.items[i].id && _item.type == vItemType.MeleeWeapon);
                    if (item != null)
                    {
                        AddItem(itemCollection.items[i].id, itemCollection.items[i].amount);
                    }
                }
            }

            if (useRightWeapon)
            {
                if (randomRightWeapon)
                {
                    GetRandomWeapon(ref rightWeaponItem, vMeleeType.OnlyAttack);
                }
                else
                {
                    GetItemWeapon(rightWeaponID, ref rightWeaponItem, vMeleeType.OnlyAttack);
                }
            }

            if (useLeftWeapon)
            {
                if (randomLeftWeapon)
                {
                    GetRandomWeapon(ref leftWeaponItem, vMeleeType.OnlyDefense);
                }
                else
                {
                    GetItemWeapon(leftWeaponID, ref leftWeaponItem, vMeleeType.OnlyDefense);
                }
            }

            if (rightArm && rightWeaponItem)
            {
                Transform equipPoint = null;
                if (customEquipPointR.Count > 0)
                {
                    equipPoint = customEquipPointR.Find(t => t.name == rightWeaponItem.customEquipPoint);
                }

                if (equipPoint == null)
                {
                    equipPoint = defaultEquipPointR;
                }

                if (equipPoint)
                {
                    rightWeapon = Instantiate(rightWeaponItem.originalObject) as GameObject;
                    rightWeapon.transform.parent           = equipPoint;
                    rightWeapon.transform.localPosition    = Vector3.zero;
                    rightWeapon.transform.localEulerAngles = Vector3.zero;
                    manager.SetRightWeapon(rightWeapon);
                    rightWeapon.SetActive(false);
                    if (ai.agressiveAtFirstSight)
                    {
                        StartCoroutine(EquipItemRoutine(false, rightWeaponItem, rightWeapon));
                    }
                }
            }

            if (leftArm && leftWeaponItem)
            {
                Transform equipPoint = null;
                if (customEquipPointL.Count > 0)
                {
                    equipPoint = customEquipPointL.Find(t => t.name == leftWeaponItem.customEquipPoint);
                }

                if (equipPoint == null)
                {
                    equipPoint = defaultEquipPointL;
                }

                if (equipPoint)
                {
                    leftWeapon = Instantiate(leftWeaponItem.originalObject) as GameObject;
                    leftWeapon.transform.parent           = equipPoint;
                    leftWeapon.transform.localPosition    = Vector3.zero;
                    leftWeapon.transform.localEulerAngles = Vector3.zero;
                    var scale = leftWeapon.transform.localScale;
                    scale.x *= -1;
                    leftWeapon.transform.localScale = scale;
                    manager.SetLeftWeapon(leftWeapon);
                    leftWeapon.SetActive(false);
                    if (ai.agressiveAtFirstSight)
                    {
                        StartCoroutine(EquipItemRoutine(true, leftWeaponItem, leftWeapon));
                    }
                }
            }
        }
    }