Exemplo n.º 1
0
    public static PetCreature Create(Creature parent, PetInfo info, Vector3_ pos, Vector3 rot, bool player = false, string name = "", string uiName = "", bool combat = true, bool useSpringBone = true)
    {
        if (info == null)
        {
            Logger.LogError("PetCreature::Create: Create pet failed, invalid config info");
            return(null);
        }

        var petInfo = info.BuildCreatureInfo();

        if (petInfo == null)
        {
            Logger.LogError("PetCreature::Create Create pet [{0}] failed, invalid config info", info.ID);
            return(null);
        }

        var rootNode = new GameObject().transform;

        if (!CreateMorphNodes(petInfo, rootNode))
        {
            Logger.LogError("PetCreature::Create: Create pet [{0}:{1}] failed, main model [{2}] not loaded", info.ID, petInfo.name, CreatureInfo.GetMorphModelName(petInfo.models, 0));
            return(null);
        }

        rootNode.position    = pos;
        rootNode.eulerAngles = rot;

        var c = Create <PetCreature>(string.IsNullOrEmpty(name) ? petInfo.name : name, rootNode.gameObject);

        c.InitPosition(pos);
        c.petInfo        = info;
        c.ParentCreature = parent;
        c.isPlayer       = player;
        c.isMonster      = false;
        c.isCombat       = combat;
        c.isRobot        = false;
        c.creatureCamp   = parent ? parent.creatureCamp : CreatureCamp.PlayerCamp;
        c.uiName         = string.IsNullOrEmpty(uiName) ? c.name : uiName;
        c.isDead         = false;
        c.realDead       = false;
        c.useSpringBone  = useSpringBone;

        c.UpdateConfig(petInfo);

        c.behaviour.UpdateAllColliderState(false);
        c.behaviour.attackCollider.enabled = true;
        c.teamIndex = MonsterCreature.GetMonsterRoomIndex();

        c.Buffs = info.GetBuff(info.AdditiveLevel);
        c.OnCreate(info.GetInitBuff());


        c.avatar = info.UpGradeInfo.icon;
        c.skills.Clear();
        var skill = info.GetSkill();

        if (skill != null)
        {
            c.skills.Add(skill.state, PetSkillData.Create(skill));
        }
        return(c);
    }