Exemplo n.º 1
0
        protected override async ETTask Run(Scene scene, M2M_UnitTransferRequest request, M2M_UnitTransferResponse response, Action reply)
        {
            await ETTask.CompletedTask;
            UnitComponent unitComponent = scene.GetComponent <UnitComponent>();
            Unit          unit          = request.Unit;

            unitComponent.AddChild(unit);
            unitComponent.Add(unit);

            foreach (Entity entity in request.Entitys)
            {
                unit.AddComponent(entity);
            }

            unit.AddComponent <MoveComponent>();
            unit.AddComponent <PathfindingComponent, string>(scene.Name);
            unit.Position = new Vector3(-10, 0, -10);

            unit.AddComponent <MailBoxComponent>();

            // 通知客户端创建My Unit
            M2C_CreateMyUnit m2CCreateUnits = new M2C_CreateMyUnit();

            m2CCreateUnits.Unit = UnitHelper.CreateUnitInfo(unit);
            MessageHelper.SendToClient(unit, m2CCreateUnits);

            // 加入aoi
            unit.AddComponent <AOIEntity, int, Vector3>(9 * 1000, unit.Position);

            response.NewInstanceId = unit.InstanceId;

            reply();
        }
        protected override async ETTask Run(Scene scene, M2M_UnitTransferRequest request, M2M_UnitTransferResponse response, Action reply)
        {
            await ETTask.CompletedTask;
            UnitComponent unitComponent = scene.GetComponent <UnitComponent>();
            Unit          unit          = request.Unit;

            unitComponent.AddChild(unit);
            unitComponent.Add(unit);

            foreach (var item in request.Map)
            {
                var    entity = request.Entitys[item.ChildIndex];
                Entity parent;
                if (item.ParentIndex == -1)                //父组件为自己
                {
                    parent = unit;
                }
                else
                {
                    parent = request.Entitys[item.ParentIndex];
                }

                if (item.IsChild == 0)
                {
                    parent.AddComponent(entity);
                }
                else
                {
                    parent.AddChild(entity);
                }
            }
            unit.AddComponent <MoveComponent>();
            unit.AddComponent <PathfindingComponent, string>(scene.Name);
            unit.Position = new Vector3(-10, 0, -10);

            unit.AddComponent <MailBoxComponent>();

            // 通知客户端创建My Unit
            M2C_CreateMyUnit m2CCreateUnits = new M2C_CreateMyUnit();

            m2CCreateUnits.Unit = UnitHelper.CreateUnitInfo(unit);

            MessageHelper.SendToClient(unit, m2CCreateUnits);

            var numericComponent = unit.GetComponent <NumericComponent>();

            // 加入aoi
            var aoiu = unit.AddComponent <AOIUnitComponent, Vector3, Quaternion, UnitType, int>
                           (unit.Position, unit.Rotation, UnitType.Player, numericComponent.GetAsInt(NumericType.AOI));

            aoiu.AddSphereTrigger(0.5f, AOITriggerType.None, null, true);
            response.NewInstanceId = unit.InstanceId;

            reply();
        }
Exemplo n.º 3
0
        /// <summary>
        /// 创建技能触发体(单机用)
        /// </summary>
        /// <param name="currentScene"></param>
        /// <param name="configId"></param>
        /// <param name="pos"></param>
        /// <param name="rota"></param>
        /// <param name="para"></param>
        /// <returns></returns>
        public static Unit CreateSkillCollider(Scene currentScene, int configId, Vector3 pos, Quaternion rota, SkillPara para)
        {
            UnitComponent unitComponent = currentScene.GetComponent <UnitComponent>();
            Unit          unit          = unitComponent.AddChild <Unit, int>(configId);

            unit.Position = pos;
            unit.Rotation = rota;
            unit.AddComponent <SkillColliderComponent, SkillPara>(para);
            unit.AddComponent <AOIUnitComponent, Vector3, Quaternion, UnitType>(pos, rota, UnitType.Skill);
            return(unit);
        }
Exemplo n.º 4
0
        public static Unit CreateSkillCollider(Scene currentScene, int configId, Vector3 pos, Quaternion rota, SkillPara para)
        {
            UnitComponent unitComponent = currentScene.GetComponent <UnitComponent>();
            Unit          unit          = unitComponent.AddChild <Unit, int>(configId);

            unit.Position = pos;
            unit.Rotation = rota;
            var collider = SkillJudgeConfigCategory.Instance.Get(configId);

            if (collider.ColliderType == SkillJudgeType.Target)//朝指定位置方向飞行碰撞体
            {
                var numc = unit.AddComponent <NumericComponent>();

                numc.Set(NumericType.SpeedBase, collider.Speed);
                var moveComp = unit.AddComponent <MoveComponent>();
                Log.Info(pos + " " + pos + (para.Position - pos).normalized * collider.Speed * collider.Time / 1000f);
                List <Vector3> target = new List <Vector3>();
                target.Add(pos);
                target.Add(pos + (para.Position - pos).normalized * collider.Speed * collider.Time / 1000f);
                moveComp.MoveToAsync(target, collider.Speed).Coroutine();
            }
            else if (collider.ColliderType == SkillJudgeType.Aim) //锁定目标飞行
            {
                var numc = unit.AddComponent <NumericComponent>();
                numc.Set(NumericType.SpeedBase, collider.Speed);
                unit.AddComponent <MoveComponent>();
                unit.AddComponent <ZhuiZhuAimComponent, Unit, Action>(para.To.unit, () =>
                {
                    unit.Dispose();
                });
                unit.AddComponent <AIComponent, int, int>(2, 50);
            }
            unit.AddComponent <SkillColliderComponent, SkillPara>(para);
            unit.AddComponent <AOIUnitComponent, Vector3, Quaternion, UnitType>(pos, rota, unit.Type);
            return(unit);
        }