예제 #1
0
    protected override void OnUpdate()
    {
        //TODO:控制刷新或请求频率
        var requestArray = RequestGroup.ToComponentDataArray <RoleLooksNetRequest>(Allocator.TempJob);

        if (requestArray.Length == 0)
        {
            requestArray.Dispose();
            return;
        }

        var requestEntityArray = RequestGroup.ToEntityArray(Allocator.TempJob);

        // Copy requests as spawning will invalidate Group
        var requests = new RoleLooksNetRequest[requestArray.Length];

        for (var i = 0; i < requestArray.Length; i++)
        {
            requests[i] = requestArray[i];
            PostUpdateCommands.DestroyEntity(requestEntityArray[i]);
        }

        for (var i = 0; i < requests.Length; i++)
        {
            SprotoType.scene_get_role_look_info.request req = new SprotoType.scene_get_role_look_info.request();
            req.uid = requests[i].roleUid;
            Entity owner = requests[i].owner;
            if (!EntityManager.Exists(owner))
            {
                continue;
            }
            UnityMMO.NetMsgDispatcher.GetInstance().SendMessage <Protocol.scene_get_role_look_info>(req, (_) =>
            {
                SprotoType.scene_get_role_look_info.response rsp = _ as SprotoType.scene_get_role_look_info.response;
                // Debug.Log("rsp.result : "+rsp.result.ToString()+" owner:"+owner.ToString());
                if (rsp.result == UnityMMO.GameConst.NetResultOk)
                {
                    RoleMgr.GetInstance().SetName(req.uid, rsp.role_looks_info.name);
                    if (m_world.GetEntityManager().HasComponent <HealthStateData>(owner))
                    {
                        var hpData   = m_world.GetEntityManager().GetComponentData <HealthStateData>(owner);
                        hpData.CurHp = rsp.role_looks_info.hp;
                        hpData.MaxHp = rsp.role_looks_info.max_hp;
                        m_world.GetEntityManager().SetComponentData <HealthStateData>(owner, hpData);
                    }
                    bool hasTrans = m_world.GetEntityManager().HasComponent <Transform>(owner);
                    if (hasTrans)
                    {
                        var transform = m_world.GetEntityManager().GetComponentObject <Transform>(owner);
                        //因为是异步操作,等后端发送信息过来时PostUpdateCommands已经失效了,所以不能这么用
                        RoleLooksSpawnRequest.Create(m_world.GetEntityManager(), (int)rsp.role_looks_info.career, transform.localPosition, transform.localRotation, owner, (int)rsp.role_looks_info.body, (int)rsp.role_looks_info.hair);
                    }
                }
            });
        }
        requestEntityArray.Dispose();
        requestArray.Dispose();
    }
예제 #2
0
    public static void Create(EntityCommandBuffer commandBuffer, long roleUid, Entity owner)
    {
        var data = new RoleLooksNetRequest();

        data.roleUid = roleUid;
        data.owner   = owner;
        commandBuffer.CreateEntity();
        commandBuffer.AddComponent(data);
    }
예제 #3
0
    protected override void OnUpdate()
    {
        EntityArray entities       = RoleGroup.GetEntityArray();
        var         roleStateArray = RoleGroup.GetComponentArray <RoleState>();
        var         mainRoleGOE    = RoleMgr.GetInstance().GetMainRole();
        float3      mainRolePos    = float3.zero;

        if (mainRoleGOE != null)
        {
            mainRolePos = m_world.GetEntityManager().GetComponentData <Position>(mainRoleGOE.Entity).Value;
        }
        for (int i = 0; i < roleStateArray.Length; i++)
        {
            var  roleState          = roleStateArray[i];
            var  entity             = entities[i];
            bool isNeedReqLooksInfo = false;
            bool isNeedHideLooks    = false;

            //其它玩家离主角近时就要请求该玩家的角色外观信息
            var   curPos   = m_world.GetEntityManager().GetComponentData <Position>(entity).Value;
            float distance = Vector3.Distance(curPos, mainRolePos);
            Debug.Log("distance : " + distance);
            if (!roleState.hasLooks)
            {
                isNeedReqLooksInfo = distance <= 400;
                // bool isMainRole = m_world.GetEntityManager().HasComponent(entity, typeof(UnityMMO.MainRoleTag));
                // if (isMainRole)
                // {
                //     isNeedReqLooksInfo = true;
                // }
                // else
                // {
                // //其它玩家离主角近时就要请求该玩家的角色外观信息
                // var curPos = m_world.GetEntityManager().GetComponentData<Position>(entity).Value;
                // float distance = Vector3.Distance(curPos, mainRolePos);
                // Debug.Log("distance : "+distance);
                // isNeedReqLooksInfo = distance <= 200;
                // }
            }
            else
            {
                isNeedHideLooks = distance >= 300;
            }
            if (isNeedReqLooksInfo)
            {
                roleState.hasLooks = true;
                RoleLooksNetRequest.Create(PostUpdateCommands, roleState.roleUid, entity);
            }
        }
    }
예제 #4
0
    protected override void OnUpdate()
    {
        //TODO:控制刷新或请求频率
        var requestArray = RequestGroup.GetComponentDataArray <RoleLooksNetRequest>();

        if (requestArray.Length == 0)
        {
            return;
        }

        var requestEntityArray = RequestGroup.GetEntityArray();

        // Copy requests as spawning will invalidate Group
        var requests = new RoleLooksNetRequest[requestArray.Length];

        for (var i = 0; i < requestArray.Length; i++)
        {
            requests[i] = requestArray[i];
            PostUpdateCommands.DestroyEntity(requestEntityArray[i]);
        }

        for (var i = 0; i < requests.Length; i++)
        {
            SprotoType.scene_get_role_look_info.request req = new SprotoType.scene_get_role_look_info.request();
            req.uid = requests[i].roleUid;
            Entity owner = requests[i].owner;
            UnityMMO.NetMsgDispatcher.GetInstance().SendMessage <Protocol.scene_get_role_look_info>(req, (_) =>
            {
                SprotoType.scene_get_role_look_info.response rsp = _ as SprotoType.scene_get_role_look_info.response;
                Debug.Log("rsp.result : " + rsp.result.ToString() + " owner:" + owner.ToString());
                if (rsp.result == UnityMMO.GameConst.NetResultOk)
                {
                    bool hasRoleState = m_world.GetEntityManager().HasComponent <RoleState>(owner);
                    if (hasRoleState)
                    {
                        RoleState roleState = m_world.GetEntityManager().GetComponentObject <RoleState>(owner);
                        Debug.Log("roleState.position : " + roleState.transform.localPosition.ToString());
                        //因为是异步操作,等后端发送信息过来时PostUpdateCommands已经失效了,所以不能这么用
                        // RoleLooksSpawnRequest.Create(PostUpdateCommands, (int)rsp.role_looks_info.career, roleState.transform.localPosition, roleState.transform.localRotation, owner, (int)rsp.role_looks_info.body, (int)rsp.role_looks_info.hair);
                        RoleLooksSpawnRequest.Create(m_world.GetEntityManager(), (int)rsp.role_looks_info.career, roleState.transform.localPosition, roleState.transform.localRotation, owner, (int)rsp.role_looks_info.body, (int)rsp.role_looks_info.hair);
                    }
                }
            });
        }
    }
예제 #5
0
    protected override void OnUpdate()
    {
        var    entities       = RoleGroup.ToEntityArray(Allocator.TempJob);
        var    uidArray       = RoleGroup.ToComponentDataArray <UID>(Allocator.TempJob);
        var    looksInfoArray = RoleGroup.ToComponentDataArray <LooksInfo>(Allocator.TempJob);
        var    mainRoleGOE    = RoleMgr.GetInstance().GetMainRole();
        float3 mainRolePos    = float3.zero;

        if (mainRoleGOE != null)
        {
            mainRolePos = m_world.GetEntityManager().GetComponentObject <Transform>(mainRoleGOE.Entity).localPosition;
        }
        for (int i = 0; i < looksInfoArray.Length; i++)
        {
            var  uid                = uidArray[i];
            var  looksInfo          = looksInfoArray[i];
            var  entity             = entities[i];
            bool isNeedReqLooksInfo = false;
            bool isNeedHideLooks    = false;

            //其它玩家离主角近时就要请求该玩家的角色外观信息
            var   curPos   = m_world.GetEntityManager().GetComponentObject <Transform>(entity).localPosition;
            float distance = Vector3.Distance(curPos, mainRolePos);
            if (looksInfo.CurState == LooksInfo.State.None)
            {
                isNeedReqLooksInfo = distance <= 400;
            }
            else
            {
                isNeedHideLooks = distance >= 300;
            }
            // Debug.Log("isNeedReqLooksInfo : "+isNeedReqLooksInfo.ToString()+" looksInfo.CurState:"+looksInfo.CurState.ToString());
            if (isNeedReqLooksInfo)
            {
                looksInfo.CurState = LooksInfo.State.Loading;
                // looksInfoArray[i] = looksInfo;
                EntityManager.SetComponentData <LooksInfo>(entities[i], looksInfo);
                RoleLooksNetRequest.Create(PostUpdateCommands, uid.Value, entity);
            }
        }
        entities.Dispose();
        looksInfoArray.Dispose();
        uidArray.Dispose();
    }
예제 #6
0
    protected override void OnUpdate()
    {
        EntityArray entities       = RoleGroup.GetEntityArray();
        var         roleStateArray = RoleGroup.GetComponentArray <RoleState>();
        var         looksInfoArray = RoleGroup.GetComponentDataArray <LooksInfo>();
        var         mainRoleGOE    = RoleMgr.GetInstance().GetMainRole();
        float3      mainRolePos    = float3.zero;

        if (mainRoleGOE != null)
        {
            mainRolePos = m_world.GetEntityManager().GetComponentObject <Transform>(mainRoleGOE.Entity).localPosition;
        }
        for (int i = 0; i < looksInfoArray.Length; i++)
        {
            var  roleState          = roleStateArray[i];
            var  looksInfo          = looksInfoArray[i];
            var  entity             = entities[i];
            bool isNeedReqLooksInfo = false;
            bool isNeedHideLooks    = false;

            //其它玩家离主角近时就要请求该玩家的角色外观信息
            var   curPos   = m_world.GetEntityManager().GetComponentObject <Transform>(entity).localPosition;
            float distance = Vector3.Distance(curPos, mainRolePos);
            if (looksInfo.CurState == LooksInfo.State.None)
            {
                isNeedReqLooksInfo = distance <= 400;
            }
            else
            {
                isNeedHideLooks = distance >= 300;
            }
            // Debug.Log("isNeedReqLooksInfo : "+isNeedReqLooksInfo.ToString()+" looksInfo.CurState:"+looksInfo.CurState.ToString());
            if (isNeedReqLooksInfo)
            {
                roleState.hasLooks = true;
                looksInfo.CurState = LooksInfo.State.Loading;
                looksInfoArray[i]  = looksInfo;
                RoleLooksNetRequest.Create(PostUpdateCommands, roleState.roleUid, entity);
            }
        }
    }