示例#1
0
        public static Unit Create(long id)
        {
            ResourcesComponent resourcesComponent = Game.Scene.GetComponent <ResourcesComponent>();
            GameObject         bundleGameObject   = (GameObject)resourcesComponent.GetAsset("Unit.unity3d", "Unit");
            GameObject         prefab             = bundleGameObject.Get <GameObject>("Skeleton");

            UnitComponent unitComponent = Game.Scene.GetComponent <UnitComponent>();

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

            unit.AddComponent <AnimatorComponent>();

            SyncType type = Game.Scene.GetComponent <NetSyncComponent>().type;

            if (type == SyncType.Frame)
            {
                unit.AddComponent <FrameMoveComponent>();
            }
            else if (type == SyncType.State)
            {
                unit.AddComponent <MoveComponent>();
                unit.AddComponent <TurnComponent>();
                unit.AddComponent <UnitPathComponent>();
            }


            unitComponent.Add(unit);
            return(unit);
        }
示例#2
0
        /// <summary>
        /// 创建木桩
        /// </summary>
        /// <param name="selfId">自己的id</param>
        /// <param name="parentId">父实体id</param>
        /// <returns></returns>
        public static Unit CreateSpiling(long selfId, long parentId)
        {
            PrepareHeroRes("NuoKe");

            UnitComponent unitComponent = Game.Scene.GetComponent <UnitComponent>();
            Unit          unit          = Game.Scene.GetComponent <GameObjectPool>().FetchEntityWithId(selfId, "NuoKe");

            //Log.Info($"此英雄的Model层ID为{unit.Id}");

            //增加子实体组件,用于管理子实体
            unit.AddComponent <ChildrenUnitComponent>();
            //增加栈式状态机,辅助动画切换
            unit.AddComponent <StackFsmComponent>();
            unit.AddComponent <AnimationComponent>();
            unit.AddComponent <TurnComponent>();
            unit.AddComponent <EffectComponent>();
            unit.AddComponent <B2S_RoleCastComponent, RoleCast>(RoleCast.Adverse);
            unit.AddComponent <HeroTransformComponent>();

            //增加Buff管理组件
            unit.AddComponent <BuffManagerComponent>();
            unit.GameObject.GetComponent <MonoBridge>().BelongToUnit = unit;
            unitComponent.Get(parentId).GetComponent <ChildrenUnitComponent>().AddUnit(unit);
            return(unit);
        }
示例#3
0
        // public static async ETVoid LoadAsyncTest_1()
        // {
        //     Log.Error("异步加载测试1开始");
        //     ResourcesComponent resourcesComponent = Game.Scene.GetComponent<ResourcesComponent>();
        //     await resourcesComponent.LoadAssetAsync<GameObject>(ABPathUtilities.GetUnitPath("Unit"));
        //     Log.Error("异步加载测试1完成");
        // }
        //
        // public static async ETVoid LoadAsyncTest_2()
        // {
        //     Log.Error("异步加载测试2开始");
        //     ResourcesComponent resourcesComponent = Game.Scene.GetComponent<ResourcesComponent>();
        //     await resourcesComponent.LoadAssetAsync<GameObject>(ABPathUtilities.GetUnitPath("Unit"));
        //     Log.Error("异步加载测试2完成");
        // }

        /// <summary>
        /// 用于NPBehave测试
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public static void NPBehaveTestCreate()
        {
            Unit unit = ComponentFactory.Create <Unit>();

            unit.AddComponent <NP_RuntimeTreeManager>();
            UnitComponent.Instance.Add(unit);
            //NP_RuntimeTreeFactory.CreateNpRuntimeTree(unit, NP_Client_TreeIds.Darius_Q_Client).Start();
        }
示例#4
0
        public static Unit Create(Entity domain, long id)
        {
            ResourcesComponent resourcesComponent = Game.Scene.GetComponent <ResourcesComponent>();
            GameObject         bundleGameObject   = (GameObject)resourcesComponent.GetAsset("Unit.unity3d", "Unit");
            GameObject         prefab             = bundleGameObject.Get <GameObject>("Skeleton");

            UnitComponent unitComponent = Game.Scene.GetComponent <UnitComponent>();

            GameObject go   = UnityEngine.Object.Instantiate(prefab);
            Unit       unit = EntityFactory.CreateWithId <Unit, GameObject>(domain, id, go);

            unit.AddComponent <AnimatorComponent>();
            unit.AddComponent <MoveComponent>();
            unit.AddComponent <TurnComponent>();
            unit.AddComponent <UnitPathComponent>();

            unitComponent.Add(unit);
            return(unit);
        }
示例#5
0
文件: BBox.cs 项目: yzx4036/BodyET
        // public BBoxMeshSettings meshSettings = new BBoxMeshSettings();

        public static Unit CreateNew(Vector3 position, Quaternion rotation)
        {
            Unit go   = new Unit();
            BBox bBox = go.AddComponent <BBox>();

            //            CreateNewBase(go, position, rotation);
            bBox.BuildMesh();
            // go.name = "BBox";
            return(go);
        }
示例#6
0
        public static Unit Create(long id)
        {
            ResourcesComponent resourcesComponent = Game.Scene.GetComponent <ResourcesComponent>();
            GameObject         bundleGameObject   = (GameObject)resourcesComponent.GetAsset("Unit.unity3d", "Unit");
            GameObject         prefab             = bundleGameObject.Get <GameObject>("Skeleton");

            UnitComponent unitComponent = Game.Scene.GetComponent <UnitComponent>();

            Unit unit = ComponentFactory.CreateWithId <Unit>(id);

            unit.GameObject = UnityEngine.Object.Instantiate(prefab);
            GameObject parent = GameObject.Find($"/Global/Unit");

            unit.GameObject.transform.SetParent(parent.transform, false);
            unit.AddComponent <AnimatorComponent>();
            unit.AddComponent <MoveComponent>();
            Debug.Log("create Skeleton");
            unitComponent.Add(unit);
            return(unit);
        }
示例#7
0
        public static Unit CreateEmitObj(long id, GameObject go, UnitData unitData)
        {
            EmitObjUnitComponent unitComponent = Game.Scene.GetComponent <EmitObjUnitComponent>();
            Unit unit = ComponentFactory.CreateWithId <Unit, GameObject>(id, go);

            if (!GlobalConfigComponent.Instance.networkPlayMode)
            {
                AddCollider(unit, unitData, true);
            }
            unit.AddComponent <EmitObjMoveComponent>();
            unitComponent.Add(unit);
            return(unit);
        }
示例#8
0
        public static void AddCollider(Unit unit, UnitData unitData, bool isSensor)
        {
            PBaseColliderHelper pBaseColliderHelper = unit.GameObject.GetComponentInChildren <PBaseColliderHelper>();
            PBaseShape          pBaseShape          = null;


            switch (pBaseColliderHelper)
            {
            case PBoxColliderHelper pBoxCollider:
                PBoxShape pBoxShape = new PBoxShape()
                {
                    eulerAnglesY = pBoxCollider.transform.eulerAngles.y,
                    offset       = pBoxCollider.offset,
                    size         = pBoxCollider.size,
                    bodyType     = pBoxCollider.bodyType,
                    unitData     = unitData,
                    isSensor     = isSensor
                };

                pBaseShape = pBoxShape;
                break;

            case PCircleColliderHelper pCircleCollider:
                PCircleShape pCircleShape = new PCircleShape()
                {
                    eulerAnglesY = pCircleCollider.transform.eulerAngles.y,
                    offset       = pCircleCollider.offset,
                    radius       = pCircleCollider.radius,
                    halfHeight   = pCircleCollider.height,
                    bodyType     = pCircleCollider.bodyType,
                    unitData     = unitData,
                    isSensor     = isSensor
                };
                pBaseShape = pCircleShape;
                break;
            }
            var bodyCom = unit.AddComponent <P2DBodyComponent, PBaseShape>(pBaseShape);

            pBaseColliderHelper.bodyComponent = bodyCom;
        }
示例#9
0
        public void Awake()
        {
            otherPlayers = new List <Unit>();
            Game.Scene.GetComponent <GlobalConfigComponent>().networkPlayMode = false;
            Game.EventSystem.Run(EventIdType.LoadAssets);
            {
                UnitData playerData = new UnitData();
                playerData.groupIndex = GroupIndex.Player;
                playerData.layerMask  = UnitLayerMask.ALL;
                playerData.unitLayer  = UnitLayer.Character;
                playerData.unitTag    = UnitTag.Player;
                //创建主角
                Unit v = UnitFactory.Create(IdGenerater.GenerateId(), 1001, playerData);
                v.Position = new UnityEngine.Vector3(-10, 0, -10);
                UnitComponent.Instance.MyUnit = v;
                v.AddComponent <CameraComponent>();
                v.AddComponent <CommandComponent>();
                var input = v.AddComponent <InputComponent>();
                var list  = v.GetComponent <ActiveSkillComponent>().skillList.Keys.ToArray();
                input.AddSkillToHotKey("Q", list[0]);
                input.AddSkillToHotKey("W", list[1]);
                input.AddSkillToHotKey("E", list[2]);
                BattleEventHandler.LoadAssets(v);
            }
            UnitData monsterData = new UnitData();

            monsterData.groupIndex = GroupIndex.Monster;
            monsterData.layerMask  = UnitLayerMask.ALL;
            monsterData.unitLayer  = UnitLayer.Character;
            monsterData.unitTag    = UnitTag.Monster;
            {
                //创建怪物
                Unit v = UnitFactory.Create(IdGenerater.GenerateId(), 1001, monsterData);
                v.Position = new UnityEngine.Vector3(4.2f, 4, -15);
                v.Rotation = UnityEngine.Quaternion.LookRotation(v.Position - UnitComponent.Instance.MyUnit.Position, Vector3.up);
                //v.AddComponent<PDynamicBodyComponent, Shape>(new CircleShape() { Radius = 0.5f });

                BattleEventHandler.LoadAssets(v);
                otherPlayers.Add(v);
            }
            {
                //创建怪物
                Unit v = UnitFactory.Create(IdGenerater.GenerateId(), 1001, monsterData);
                v.Position = new UnityEngine.Vector3(-10, 0, 11);
                v.Rotation = UnityEngine.Quaternion.LookRotation(v.Position - UnitComponent.Instance.MyUnit.Position, Vector3.up);
                //v.AddComponent<PDynamicBodyComponent, Shape>(new CircleShape() { Radius = 0.5f });

                BattleEventHandler.LoadAssets(v);
                otherPlayers.Add(v);
            }
            {
                //创建怪物
                Unit v = UnitFactory.Create(IdGenerater.GenerateId(), 1001, monsterData);
                v.Position = new UnityEngine.Vector3(-10, 0, 15);
                v.Rotation = UnityEngine.Quaternion.LookRotation(v.Position - UnitComponent.Instance.MyUnit.Position, Vector3.up);
                //v.AddComponent<PDynamicBodyComponent, Shape>(new CircleShape() { Radius = 0.5f });

                BattleEventHandler.LoadAssets(v);
                otherPlayers.Add(v);
            }

            //这里准备其他角色施放技能的参数
        }
示例#10
0
        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);
        }
示例#11
0
        public static Unit CreateHero(long id, string unitType, RoleCamp roleCamp)
        {
            PrepareHeroRes(unitType);
            Unit unit = Game.Scene.GetComponent <GameObjectPool>().FetchEntityWithId(id, unitType);

            //Log.Info($"此英雄的Model层ID为{unit.Id}");
            unit.AddComponent <DataModifierComponent>();
            unit.AddComponent <NumericComponent>();
            unit.AddComponent <HeroTransformComponent>();
            //增加子实体组件,用于管理子实体
            unit.AddComponent <ChildrenUnitComponent>();
            //增加栈式状态机,辅助动画切换
            unit.AddComponent <StackFsmComponent>();
            unit.AddComponent <AnimationComponent>();
            unit.AddComponent <MoveComponent>();
            unit.AddComponent <TurnComponent>();
            unit.AddComponent <UnitPathComponent>();
            unit.AddComponent <EffectComponent>();
            //增加Buff管理组件
            unit.AddComponent <BuffManagerComponent>();
            unit.AddComponent <SkillCanvasManagerComponent>();
            unit.AddComponent <B2S_RoleCastComponent, RoleCamp>(roleCamp);
            unit.AddComponent <CommonAttackComponent>();

            unit.GameObject.GetComponent <MonoBridge>().BelongToUnit = unit;
            UnitComponent.Instance.Add(unit);
            return(unit);
        }