Exemple #1
0
    public void Awake()
    {
        instance = this;
        Game.Scene.GetComponent <ResourcesComponent>().LoadBundle(abName);
        skillCollection = Game.Scene.GetComponent <ResourcesComponent>().GetAsset(abName, "SkillCollection") as SkillCollection;
#if UNITY_EDITOR
        TestDeserialize();
#else
        activeDatas = skillCollection.activeSkillDataDic;
#endif
    }
        public static Unit Create(long id, int typeId, UnitData unitData)
        {
            UnitComponent unitComponent = Game.Scene.GetComponent <UnitComponent>();
            Unit          unit          = ComponentFactory.CreateWithId <Unit>(id);
            UnitConfig    unitConfig    = Game.Scene.GetComponent <ConfigComponent>().Get(typeof(UnitConfig), typeId) as UnitConfig;

            unit.AddComponent <NumericComponent, int>(typeId);
            unit.AddComponent <UnitStateComponent>();
            unit.AddComponent <UnitPathComponent>();
            unit.AddComponent <BuffMgrComponent>();
            var activeSkillCom  = unit.AddComponent <ActiveSkillComponent>();
            var passiveSkillCom = unit.AddComponent <PassiveSkillComponent>();

            unit.AddComponent <SkillEffectComponent>();

            //添加碰撞体
            AddCollider(unit, unitData, true, unitConfig.AssetName);
            unit.AddComponent <CharacterStateComponent>();
            unit.AddComponent <CharacterMoveComponent>();
            unit.AddComponent <CalNumericComponent>();


            if (unitConfig.Skills != null && unitConfig.Skills.Length > 0)
            {
                SkillConfigComponent skillConfigComponent = Game.Scene.GetComponent <SkillConfigComponent>();
                foreach (var v in unitConfig.Skills)
                {
                    if (string.IsNullOrEmpty(v))
                    {
                        continue;
                    }
                    var activeSkill = skillConfigComponent.GetActiveSkill(v);
                    if (activeSkill != null)
                    {
                        Log.Debug(string.Format("{0} 添加主动技能 {1} ({2})成功!", typeId, v, activeSkill.skillName));
                        activeSkillCom.AddSkill(v);
                        continue;
                    }
                    var passiveSkill = skillConfigComponent.GetPassiveSkill(v);
                    if (passiveSkill != null)
                    {
                        Log.Debug(string.Format("{0} 添加被动技能 {1} ({2})成功!", typeId, v, passiveSkill.skillName));
                        passiveSkillCom.AddSkill(v);
                        continue;
                    }
                    Log.Error(v + "  这样的技能不存在!");
                }
            }

            //unit.AddComponent<TurnComponent>();

            unitComponent.Add(unit);
            return(unit);
        }
        public static Unit Create(long id, int typeId, UnitData unitData)
        {
            ResourcesComponent resourcesComponent = Game.Scene.GetComponent <ResourcesComponent>();

            UnitConfig unitConfig = Game.Scene.GetComponent <ConfigComponent>().Get(typeof(UnitConfig), typeId) as UnitConfig;

            resourcesComponent.LoadBundle(unitConfig.ABPacketName.ToLower().StringToAB());

            GameObject    bundleGameObject = (GameObject)resourcesComponent.GetAsset(unitConfig.ABPacketName.ToLower().StringToAB(), unitConfig.ABPacketName);
            UnitComponent unitComponent    = Game.Scene.GetComponent <UnitComponent>();

            GameObject go   = UnityEngine.Object.Instantiate(bundleGameObject);
            Unit       unit = ComponentFactory.CreateWithId <Unit, GameObject>(id, go);

            unit.AddComponent <NumericComponent, int>(typeId);
            unit.AddComponent <AnimatorComponent>();
            unit.AddComponent <UnitStateComponent>();
            unit.AddComponent <UnitPathComponent>();
            unit.AddComponent <AudioComponent>();
            unit.AddComponent <BuffMgrComponent>();
            var activeSkillCom  = unit.AddComponent <ActiveSkillComponent>();
            var passiveSkillCom = unit.AddComponent <PassiveSkillComponent>();

            unit.AddComponent <SkillEffectComponent>();
            if (!GlobalConfigComponent.Instance.networkPlayMode)
            {
                //添加碰撞体
                AddCollider(unit, unitData, true);
            }
            unit.AddComponent <CharacterStateComponent>();
            unit.AddComponent <CharacterMoveComponent>();

            if (!Game.Scene.GetComponent <GlobalConfigComponent>().networkPlayMode)
            {
                unit.AddComponent <CalNumericComponent>();
            }


            if (unitConfig.Skills != null && unitConfig.Skills.Length > 0)
            {
                SkillConfigComponent skillConfigComponent = Game.Scene.GetComponent <SkillConfigComponent>();
                foreach (var v in unitConfig.Skills)
                {
                    if (string.IsNullOrEmpty(v))
                    {
                        continue;
                    }
                    var activeSkill = skillConfigComponent.GetActiveSkill(v);
                    if (activeSkill != null)
                    {
                        Log.Debug(string.Format("{0} 添加主动技能 {1} ({2})成功!", typeId, v, activeSkill.skillName));
                        activeSkillCom.AddSkill(v);
                        continue;
                    }
                    var passiveSkill = skillConfigComponent.GetPassiveSkill(v);
                    if (passiveSkill != null)
                    {
                        Log.Debug(string.Format("{0} 添加被动技能 {1} ({2})成功!", typeId, v, passiveSkill.skillName));
                        passiveSkillCom.AddSkill(v);
                        continue;
                    }
                    Log.Error(v + "  这样的技能不存在!");
                }
            }

            //unit.AddComponent<TurnComponent>();

            unitComponent.Add(unit);
            return(unit);
        }
Exemple #4
0
 public void Awake()
 {
     instance = this;
     TestDeserialize();
 }