Beispiel #1
0
    public void SetCharacter(GameObject obj)
    {
        CharacterController cc = obj.GetComponent <CharacterController>();

        cc_slopeLimit      = cc.slopeLimit;
        cc_stepOffset      = cc.stepOffset;
        cc_skinWidth       = cc.skinWidth;
        cc_minMoveDistance = cc.minMoveDistance;
        cc_center          = cc.center;
        cc_radius          = cc.radius;
        cc_height          = cc.height;

        Player_Movement player = obj.GetComponent <Player_Movement>();

        p_smooth = player.smooth;
        //p_isDead = player.isDead;
        p_onGravityField = player.onGravityField;
        //p_isSwap = player.isSwap;
        p_rollDistance    = player.rollDistance;
        p_rollReduction   = player.rollReduction;
        p_jumpPower       = player.JumpPower;
        p_swapDelay       = player.SwapDelay;
        p_walkSpeed       = player.walkSpeed;
        p_jogSpeed        = player.jogSpeed;
        p_runSpeed        = player.runSpeed;
        p_meleeDistance   = player.MeleeDistance;
        p_rotateTurnSpeed = player.RotateturnSpeed;

        Player_IK handIK = obj.GetComponent <Player_IK>();

        ik_smoothDamp = handIK.smoothDamp;

        CharacterAttributes attribute = obj.GetComponent <CharacterAttributes>();

        c_name                  = attribute.name;
        c_maxHealth             = attribute.maxHealth;
        c_health                = attribute.health;
        c_maxShield             = attribute.maxShield;
        c_shield                = attribute.shield;
        c_shieldRecoverValue    = attribute.shieldRecoverValue;
        c_shieldRecoverStart    = attribute.shieldRecoverStartTime;
        c_shieldRecoverInterval = attribute.shieldRecoverIntervalTime;
        c_faceSprite            = attribute.faceSprite.name;

        WeaponManager weapon = obj.GetComponent <WeaponManager>();

        w_mainWeapon    = weapon.m_MainWeapon;
        w_subWeapon     = weapon.m_SubWeapon;
        w_specialWeapon = new string[weapon.m_SpecialWeapon.Count];

        for (int i = 0; i < weapon.m_SpecialWeapon.Count; i++)
        {
            w_specialWeapon[i] = weapon.m_SpecialWeapon[i];
        }
    }
    GameObject CreateCharacter(Vector3 Spawnpos)
    {
        GameObject obj = Instantiate(Resources.Load("Models/Character/Character") as GameObject);

        switch (SettingManager.instance.stageName)
        {
        case "Varba":
            obj.transform.position = new Vector3(80f, -13.4f, 243f);
            //obj.transform.rotation = Quaternion.Euler(new Vector3(0f, 155f, 0f));
            break;

        case "Dungeon":
            obj.transform.position = new Vector3(-1.5f, 1f, 2.3f);
            //obj.transform.rotation = Quaternion.Euler(new Vector3(0f, -180f, 0f));
            break;
        }

        // 1번 오디오 소스
        AudioSource objAudio = obj.AddComponent <AudioSource>();

        objAudio.playOnAwake  = false;
        objAudio.spatialBlend = 1f;
        objAudio.dopplerLevel = 1f;
        objAudio.rolloffMode  = AudioRolloffMode.Linear;
        objAudio.minDistance  = 3f;
        objAudio.maxDistance  = 40f;

        // 2번 애니메이터
        Avatar objAvatar = Resources.Load("Character/CharactersAvatar") as Avatar;
        RuntimeAnimatorController objController = Resources.Load("Character/PlayerAnimator_Male") as RuntimeAnimatorController;
        Animator objAnim = obj.AddComponent <Animator>();

        objAnim.avatar = objAvatar;
        obj.GetComponent <Animator>().runtimeAnimatorController = objController;
        objAnim.updateMode      = AnimatorUpdateMode.UnscaledTime;
        objAnim.applyRootMotion = true;
        objAnim.cullingMode     = AnimatorCullingMode.CullUpdateTransforms;

        // 3번 캐릭터 컨트롤러
        CharacterController objcon = obj.AddComponent <CharacterController>();

        objcon.slopeLimit      = JsonManager.instance.characterInfo.cc_slopeLimit;
        objcon.stepOffset      = JsonManager.instance.characterInfo.cc_stepOffset;
        objcon.skinWidth       = JsonManager.instance.characterInfo.cc_skinWidth;
        objcon.minMoveDistance = JsonManager.instance.characterInfo.cc_minMoveDistance;
        objcon.center          = JsonManager.instance.characterInfo.cc_center;
        objcon.radius          = JsonManager.instance.characterInfo.cc_radius;
        objcon.height          = JsonManager.instance.characterInfo.cc_height;

        // 4번 스크립트 Player_Movement
        Player_Movement objMove = obj.AddComponent <Player_Movement>();

        objMove.smooth          = JsonManager.instance.characterInfo.p_smooth;
        objMove.onGravityField  = JsonManager.instance.characterInfo.p_onGravityField;
        objMove.rollDistance    = JsonManager.instance.characterInfo.p_rollDistance;
        objMove.rollReduction   = JsonManager.instance.characterInfo.p_rollReduction;
        objMove.JumpPower       = JsonManager.instance.characterInfo.p_jumpPower;
        objMove.SwapDelay       = JsonManager.instance.characterInfo.p_swapDelay;
        objMove.walkSpeed       = JsonManager.instance.characterInfo.p_walkSpeed;
        objMove.jogSpeed        = JsonManager.instance.characterInfo.p_jogSpeed;
        objMove.runSpeed        = JsonManager.instance.characterInfo.p_runSpeed;
        objMove.MeleeDistance   = JsonManager.instance.characterInfo.p_meleeDistance;
        objMove.RotateturnSpeed = JsonManager.instance.characterInfo.p_rotateTurnSpeed;
        objMove.SpineBody       = obj.transform.GetChild(0).GetChild(0).gameObject;
        playerMovement          = objMove;

        GameObject objManager = new GameObject("PlayerManager");

        objManager.transform.SetParent(obj.transform);
        objManager.transform.localPosition = Vector3.zero;

        objMove.fallDirection = objManager.transform;
        objMove.headPivot     = obj.GetComponent <BodyInfomation>().Head.transform;
        objMove.LeftHand      = obj.GetComponent <BodyInfomation>().Hand1.transform.GetChild(0).gameObject;
        objMove.RightHand     = obj.GetComponent <BodyInfomation>().Hand2.transform.GetChild(4).gameObject;

        GameObject CameraPivot = new GameObject("CameraPivot");

        CameraPivot.transform.SetParent(obj.transform);
        CameraPivot.transform.localPosition = JsonManager.instance.characterInfo.p_pivot;

        GameObject CameraTarget = new GameObject("CameraTarget");

        CameraTarget.transform.SetParent(CameraPivot.transform);
        CameraTarget.transform.localPosition = JsonManager.instance.characterInfo.p_target;

        GameObject Grenade = new GameObject("Grenade");

        Grenade.transform.SetParent(obj.transform);
        Grenade.transform.localPosition = Vector3.zero;

        GameObject fixedGrenade = new GameObject("FixedAngle");

        fixedGrenade.transform.SetParent(Grenade.transform);
        fixedGrenade.transform.localPosition = Vector3.zero;

        //Player_Manager objPlayerManager = objManager.AddComponent<Player_Manager>();
        //objPlayerManager.Character = obj;

        // 6번 스크립트 WeaponManager
        WeaponManager objWeapon = obj.AddComponent <WeaponManager>();

        objWeapon.m_MainWeapon = JsonManager.instance.characterInfo.w_mainWeapon;
        objWeapon.m_SubWeapon  = JsonManager.instance.characterInfo.w_subWeapon;

        objWeapon.m_WeaponObject = obj.GetComponent <BodyInfomation>().Hand2.transform.GetChild(0).gameObject;
        objWeapon.m_AudioSource  = objAudio;
        objWeapon.playerMovement = objMove;
        objWeapon.anim           = obj.GetComponent <Animator>();
        objWeapon.m_Attacker     = obj;
        objWeapon.species        = JWeaponOffset.SPECIES.HUMAN;

        // 7번 스크립트 Weapon_Animation
        Player_WeaponAnimation objWanim = obj.AddComponent <Player_WeaponAnimation>();

        objWanim.Pose_MainWeapon = obj.GetComponent <BodyInfomation>().Body.transform.GetChild(0).gameObject;
        objWanim.Pose_SubWeapon  = obj.transform.GetChild(0).GetChild(0).GetChild(2).GetChild(0).gameObject;
        objWanim.type1           = obj.GetComponent <BodyInfomation>().Hand2.transform.GetChild(0).GetChild(0).gameObject;
        objWanim.type2           = obj.GetComponent <BodyInfomation>().Hand2.transform.GetChild(0).GetChild(1).gameObject;

        // 8번 스크립트 player_IK
        Player_IK objHand = obj.AddComponent <Player_IK>();

        objHand.smoothDamp    = JsonManager.instance.characterInfo.ik_smoothDamp;
        objHand.weaponManager = objWeapon;
        objHand.First_Weapon  = objWanim.type1;
        objHand.Second_Weapon = objWanim.type2;
        objHand.Third_Weapon  = obj.GetComponent <BodyInfomation>().Hand2.transform.GetChild(0).GetChild(2).gameObject;

        obj.GetComponent <HumanoidVerticalLegPlacement>().CameraPivot = CameraPivot.transform;
        obj.GetComponent <HumanoidVerticalLegPlacement>().LayerMask   = LayerMask.GetMask("Map");

        // 10번 스크립트 Granade
        Grenade objG = Grenade.AddComponent <Grenade>();

        objG.m_CurrentClip        = JsonManager.instance.characterInfo.g_currentClip;
        objG.m_ThrowPower         = JsonManager.instance.characterInfo.g_throwPower;
        objG.m_Explosion_Time     = JsonManager.instance.characterInfo.g_explosionTime;
        objG.m_Explosion_Distance = JsonManager.instance.characterInfo.g_explosionDistance;
        objG.m_ThrowRate          = JsonManager.instance.characterInfo.g_throwRate;
        objG.m_Damage             = JsonManager.instance.characterInfo.g_damage;
        objG.m_Bounce_Count       = JsonManager.instance.characterInfo.g_bounceCount;
        objG.isThrow      = JsonManager.instance.characterInfo.g_isThrow;
        objG.isSticky     = JsonManager.instance.characterInfo.g_isSticky;
        objG.isAir        = JsonManager.instance.characterInfo.g_isAir;
        objG.isPenetrate  = JsonManager.instance.characterInfo.g_isPenetrate;
        objG.isStun       = JsonManager.instance.characterInfo.g_isStun;
        objG.isRadiation  = JsonManager.instance.characterInfo.g_isRadiation;
        objG.isSlow       = JsonManager.instance.characterInfo.g_isSlow;
        objG.isDouble     = JsonManager.instance.characterInfo.g_isDouble;
        objG.isAttraction = JsonManager.instance.characterInfo.g_isAttraction;
        objG.isWeakness   = JsonManager.instance.characterInfo.g_isWeakness;
        objG.isAi         = JsonManager.instance.characterInfo.g_isAI;
        objG.FixedAngle   = fixedGrenade;
        objG.m_Muzzle     = obj.GetComponent <BodyInfomation>().Hand1;

        // 11번 GrenadeManager
        GrenadeManager objGM = Grenade.AddComponent <GrenadeManager>();

        objGM.grenade  = objG;
        objGM.isEnemy  = JsonManager.instance.characterInfo.gm_isEnemy;
        objGM.isFriend = JsonManager.instance.characterInfo.gm_isFriend;

        // 12번 스크립트 CharacterAttribute
        CharacterAttributes objAtt = obj.AddComponent <CharacterAttributes>();

        objAtt.name                      = JsonManager.instance.characterInfo.c_name;
        objAtt.maxHealth                 = JsonManager.instance.characterInfo.c_maxHealth;
        objAtt.health                    = JsonManager.instance.characterInfo.c_health;
        objAtt.maxShield                 = JsonManager.instance.characterInfo.c_maxShield;
        objAtt.shield                    = JsonManager.instance.characterInfo.c_shield;
        objAtt.shieldRecoverValue        = JsonManager.instance.characterInfo.c_shieldRecoverValue;
        objAtt.shieldRecoverStartTime    = JsonManager.instance.characterInfo.c_shieldRecoverStart;
        objAtt.shieldRecoverIntervalTime = JsonManager.instance.characterInfo.c_shieldRecoverInterval;
        objAtt.faceSprite                = Resources.Load("Images/CharacterFace/" + JsonManager.instance.characterInfo.c_faceSprite, typeof(Sprite)) as Sprite;
        objAtt.animator                  = obj.GetComponent <Animator>();
        objAtt.weaponManager             = objWeapon;
        objAtt.playerMovement            = objMove;
        objAtt.grenade                   = objG;
        objAtt.characterIK               = objHand;

        // 13번 CameraFollow
        GameObject   CameraParent = new GameObject("cameraParent");
        CameraFollow camfol       = CameraParent.AddComponent <CameraFollow>();

        camfol.Sensitivity = JsonManager.instance.characterInfo.cf_Sensitivity;
        camfol.clampAngle  = JsonManager.instance.characterInfo.cf_ClampAngle;
        camfol.CameraPivot = CameraPivot.transform;
        camfol.Character   = obj.transform;
        camfol.anim        = objAnim;

        GameObject camera = new GameObject("Main Camera");

        camera.transform.SetParent(CameraParent.transform);
        camera.transform.localPosition = Vector3.zero;
        camera.tag = "MainCamera";
        var cameraComponent = camera.AddComponent <Camera>();

        cameraComponent.cullingMask = ~(1 << HidePos);
        camera.AddComponent <AudioListener>();
        camera.AddComponent <VolumetricFogAndMist.VolumetricFog>().density = 0;

        GameObject targetLook = new GameObject("targetLook");

        targetLook.transform.SetParent(camera.transform);
        targetLook.transform.localPosition = new Vector3(0, 0, 30);

        CameraCollision camcol = camera.AddComponent <CameraCollision>();

        camcol.Target = CameraTarget.transform;

        GameObject dummy = new GameObject("Dummy");

        dummy.transform.SetParent(CameraParent.transform);
        dummy.transform.localPosition = Vector3.zero;

        camcol.CameraTransform = dummy.transform;
        camcol.Character       = obj;
        camcol.smooth          = JsonManager.instance.characterInfo.cc_smooth;
        camcol.offset          = new CameraCollision.Offset();
        camcol.offset.idle     = JsonManager.instance.characterInfo.cc_idle;
        camcol.offset.Zoom     = JsonManager.instance.characterInfo.cc_zoom;
        camcol.offset.Aiming   = JsonManager.instance.characterInfo.cc_aiming;

        // 15번 스크립트 Player_Manager
        Player_Manager objM = objManager.AddComponent <Player_Manager>();

        objM.Character       = obj;
        objM.camerafollow    = camfol;
        objM.collisionCamera = camcol;

        // 카메라 생기고
        objHand.targetLook = camera.transform.GetChild(0);

        GameObject SubPos = new GameObject("SubCameraPosition");

        SubPos.transform.SetParent(obj.transform);
        SubPos.transform.localPosition = JsonManager.instance.characterInfo.sc_pos;

        // 매니저에 넣는작업
        player = obj;
        cameraTopView.TpsCamera         = camera;
        cameraTopView.SubCameraposition = SubPos;
        cameraTopView.Character         = obj;

        cameraManager.arrCam[0] = camera.GetComponent <Camera>();

        keyManager.weaponManager       = objWeapon;
        keyManager.grenadeManager      = objGM;
        keyManager.playerMovement      = objMove;
        keyManager.characterAttributes = objAtt;

        uiManager.player_Attributes = objAtt;
        uiManager.playerWeapon      = obj;

        // 파티클 생성
        GameObject particleObj = new GameObject("Particle");

        particleObj.transform.SetParent(obj.transform);
        particleObj.transform.localPosition = Vector3.zero;

        GameObject bleedingObj = Instantiate(Resources.Load("Prefabs/Particle/" + JsonManager.instance.characterInfo.bleeding) as GameObject, particleObj.transform);

        bleedingObj.transform.localPosition = JsonManager.instance.characterInfo.bleeding_pos;
        objAtt.bleeding = bleedingObj.GetComponent <ParticleSystem>();

        GameObject stunObj = Instantiate(Resources.Load("Prefabs/Particle/" + JsonManager.instance.characterInfo.stun) as GameObject, particleObj.transform);

        stunObj.transform.localPosition = JsonManager.instance.characterInfo.stun_pos;
        objAtt.stun = stunObj.GetComponent <ParticleSystem>();

        GameObject radiationObj = Instantiate(Resources.Load("Prefabs/Particle/" + JsonManager.instance.characterInfo.radiation) as GameObject, particleObj.transform);

        radiationObj.transform.localPosition = JsonManager.instance.characterInfo.radiation_pos;
        objAtt.radiation = radiationObj.GetComponent <ParticleSystem>();

        GameObject burnObj = Instantiate(Resources.Load("Prefabs/Particle/" + JsonManager.instance.characterInfo.burn) as GameObject, particleObj.transform);

        burnObj.transform.localPosition = JsonManager.instance.characterInfo.burn_pos;
        objAtt.burn = burnObj.GetComponent <ParticleSystem>();

        GameObject strenuousObj = Instantiate(Resources.Load("Prefabs/Particle/FX_Strenuous") as GameObject, particleObj.transform);

        strenuousObj.transform.localPosition = new Vector3(0f, 1f, 0f);
        objAtt.strenuous = strenuousObj.GetComponent <ParticleSystem>();

        GameObject drainHealthObj = Instantiate(Resources.Load("Prefabs/Particle/FX_DrainHealth") as GameObject, particleObj.transform);

        drainHealthObj.transform.localPosition = new Vector3(0f, 1f, 0f);
        objAtt.drainHealth = drainHealthObj.GetComponent <ParticleSystem>();

        GameObject healObj = Instantiate(Resources.Load("Prefabs/Particle/FX_Heal_02") as GameObject, particleObj.transform);

        healObj.transform.localPosition = Vector3.zero;
        objAtt.heal = healObj.GetComponent <ParticleSystem>();

        GameObject electricObj = Instantiate(Resources.Load("Prefabs/Particle/FX_Electricity_gun") as GameObject, particleObj.transform);

        electricObj.transform.localPosition = new Vector3(0f, 1f, 0f);
        objAtt.electric = electricObj.GetComponent <ParticleSystem>();

        GameObject poisonObj = Instantiate(Resources.Load("Prefabs/Particle/FX_Poison_Purple") as GameObject, particleObj.transform);

        poisonObj.transform.localPosition = JsonManager.instance.characterInfo.radiation_pos;
        objAtt.poison = poisonObj.GetComponent <ParticleSystem>();

        // Character Addforce
        obj.AddComponent <CharacterAddforce>();

        // WeaponManager 생성 후 생성.
        GameObject a = new GameObject("MagazinePool");

        a.transform.SetParent(this.transform.parent);
        a.AddComponent <MagazinePool>();
        a.transform.localPosition = Vector3.zero;

        return(obj);
    }