Exemplo n.º 1
0
    void AttachHitboxes(Transform t, ParagonAI.HealthScript hs)
    {
        if (t.gameObject.GetComponent <Collider>())
        {
            ParagonAI.HitBox hitboxNow = t.gameObject.AddComponent <ParagonAI.HitBox>() as ParagonAI.HitBox;

            if (t.gameObject.GetComponent <SphereCollider>())
            {
                hitboxNow.damageMultiplyer = headHitMultiplier;
            }
            else
            {
                hitboxNow.damageMultiplyer = defaultHitMultiplier;
            }
            hitboxNow.myScript = hs;

            t.transform.tag = hitBoxTag;
        }

        for (int c = 0; c < t.childCount; c++)
        {
            AttachHitboxes(t.GetChild(c), hs);
        }
    }
Exemplo n.º 2
0
    void AttachAIComponents(GameObject modelBase, Transform spineBoneTransform, Transform targetParentTrans, AnimatorController animController, Transform bulletSpawnTransform, Avatar ava, Transform eye)
    {
        //Create parent object and move it to the position of the model base
        GameObject parentObj = new GameObject();

        parentObj.name = agentName;
        parentObj.transform.position = modelBase.transform.position;

        //parent model base to parent object
        modelBase.transform.parent = parentObj.transform;

        parentObj.AddComponent(typeof(UnityEngine.AI.NavMeshAgent));
        parentObj.AddComponent(typeof(AudioSource));
        if (bulletSpawnerTransform)
        {
            bulletSpawnerTransform.gameObject.AddComponent(typeof(AudioSource));
        }

        parentObj.GetComponent <UnityEngine.AI.NavMeshAgent>().acceleration     = 30;
        parentObj.GetComponent <UnityEngine.AI.NavMeshAgent>().angularSpeed     = 100000;
        parentObj.GetComponent <UnityEngine.AI.NavMeshAgent>().stoppingDistance = 2;

        ParagonAI.BaseScript           newBaseScript           = (ParagonAI.BaseScript)parentObj.AddComponent(typeof(ParagonAI.BaseScript));
        ParagonAI.RotateToAimGunScript newRotateToAimGunScript = (ParagonAI.RotateToAimGunScript)parentObj.AddComponent(typeof(ParagonAI.RotateToAimGunScript));
        ParagonAI.HealthScript         newHealthScript         = (ParagonAI.HealthScript)parentObj.AddComponent(typeof(ParagonAI.HealthScript));
        ParagonAI.SoundScript          newSoundScript          = (ParagonAI.SoundScript)parentObj.AddComponent(typeof(ParagonAI.SoundScript));
        ParagonAI.CoverFinderScript    newCoverFinderScript    = (ParagonAI.CoverFinderScript)parentObj.AddComponent(typeof(ParagonAI.CoverFinderScript));
        ParagonAI.GunScript            newGunScript            = (ParagonAI.GunScript)parentObj.AddComponent(typeof(ParagonAI.GunScript));
        ParagonAI.AnimationScript      newAnimationScript      = (ParagonAI.AnimationScript)parentObj.AddComponent(typeof(ParagonAI.AnimationScript));


        //Attach Animator to to modelBase if one doesn't exist
        if (!modelBase.GetComponent <Animator>())
        {
            modelBase.AddComponent(typeof(Animator));
        }

        //Assign controller to animator
        modelBase.GetComponent <Animator>().runtimeAnimatorController = animController;
        modelBase.GetComponent <Animator>().avatar = ava;

        //Recursively Attach hitboxes to all colliders
        AttachHitboxes(modelBase.transform, newHealthScript);

        //Create target object
        //ParagonAI.TargetScript currTarScript = (ParagonAI.TargetScript) targetObjParentTransform.gameObject.AddComponent(typeof(ParagonAI.TargetScript));
        ParagonAI.TargetScript currTarScript = (ParagonAI.TargetScript)parentObj.AddComponent(typeof(ParagonAI.TargetScript));
        currTarScript.targetObjectTransform = targetObjParentTransform;
        currTarScript.myTeamID          = teamNumber;
        currTarScript.alliedTeamsIDs    = new int[1];
        currTarScript.alliedTeamsIDs[0] = teamNumber;
        currTarScript.enemyTeamsIDs     = new int[1];
        currTarScript.enemyTeamsIDs[0]  = enemyTeamNumber;
        currTarScript.myAIBaseScript    = newBaseScript;
        currTarScript.eyeTransform      = eye;

        //Set connections
        newBaseScript.gunScript         = newGunScript;
        newBaseScript.audioScript       = newSoundScript;
        newBaseScript.headLookScript    = newRotateToAimGunScript;
        newBaseScript.animationScript   = newAnimationScript;
        newBaseScript.coverFinderScript = newCoverFinderScript;

        newRotateToAimGunScript.spineBone            = spineBoneToRotate;
        newRotateToAimGunScript.bulletSpawnTransform = bulletSpawnTransform;
        //newRotateToAimGunScript.myBodyTransform = modelBase.transform;

        newHealthScript.rigidbodies = modelBase.GetComponentsInChildren <Rigidbody>();

        for (var r = 0; r < newHealthScript.rigidbodies.Length; r++)
        {
            newHealthScript.rigidbodies[r].isKinematic = true;
        }


        newHealthScript.collidersToEnable    = modelBase.GetComponentsInChildren <Collider>();
        newHealthScript.gunScript            = newGunScript;
        newHealthScript.rotateToAimGunScript = newRotateToAimGunScript;
        newHealthScript.animator             = modelBase.GetComponent <Animator>();
        newHealthScript.myTargetScript       = currTarScript;
        newHealthScript.myAIBaseScript       = newBaseScript;
        newHealthScript.soundScript          = newSoundScript;

        newGunScript.myAIBaseScript  = newBaseScript;
        newGunScript.animationScript = newAnimationScript;
        newGunScript.bulletSpawn     = bulletSpawnerTransform;
        newGunScript.bulletObject    = bulletObject;
        newGunScript.bulletSound     = bulletSound;

        newAnimationScript.myBaseScript      = newBaseScript;
        newAnimationScript.rotateGunScript   = newRotateToAimGunScript;
        newAnimationScript.myAIBodyTransform = modelBase.transform;
        newAnimationScript.animator          = modelBase.GetComponent <Animator>();
        newAnimationScript.gunScript         = newGunScript;
        newAnimationScript.turnSpeed         = 7.0f;
    }