protected override void OnUpdate()
    {
        if (Time.time - lastSynchTime < 0.2 || !GameVariable.IsNeedSynchSceneInfo)
        {
            return;
        }
        lastSynchTime = Time.time;
        var  positions       = group.GetComponentDataArray <Position>();
        var  targetPositions = group.GetComponentDataArray <TargetPosition>();
        long synchTime       = System.DateTime.Now.Millisecond;

        for (int i = 0; i < targetPositions.Length; i++)
        {
            var targetPos = targetPositions[i].Value;
            var pos       = positions[i].Value;

            scene_walk.request walk = new scene_walk.request();
            // Debug.Log("upload pos"+pos.ToString());
            walk.start_x = (int)(pos.x * GameConst.RealToLogic);
            walk.start_y = (int)(pos.y * GameConst.RealToLogic);
            walk.start_z = (int)(pos.z * GameConst.RealToLogic);
            walk.end_x   = (int)(targetPos.x * GameConst.RealToLogic);
            walk.end_y   = (int)(targetPos.y * GameConst.RealToLogic);
            walk.end_z   = (int)(targetPos.z * GameConst.RealToLogic);
            walk.time    = synchTime;
            NetMsgDispatcher.GetInstance().SendMessage <Protocol.scene_walk>(walk);
        }
    }
Exemple #2
0
    protected override void OnUpdate()
    {
        if (Time.time - lastSynchTime < 0.05 || !GameVariable.IsNeedSynchSceneInfo)
        {
            return;
        }
        var  positions       = group.ToComponentArray <Transform>();
        var  targetPositions = group.ToComponentDataArray <TargetPosition>(Allocator.TempJob);
        var  synchInfos      = group.ToComponentDataArray <PosSynchInfo>(Allocator.TempJob);
        var  entities        = group.ToEntityArray(Allocator.TempJob);
        long synchTime       = System.DateTime.Now.Millisecond;

        for (int i = 0; i < targetPositions.Length; i++)
        {
            var targetPos          = targetPositions[i].Value;
            var pos                = positions[i].localPosition;
            var synchInfo          = synchInfos[i];
            var distance           = Vector3.Distance(targetPos, pos);
            var distance_with_last = Vector3.Distance(synchInfo.LastUploadPos, targetPos);
            // Debug.Log("distance:"+distance+" distance_with_last:"+distance_with_last+" upload pos"+pos.x+" "+pos.y+" "+pos.z);
            if (distance <= 0.5 && distance_with_last <= 0.5)
            {
                continue;
            }
            synchInfo.LastUploadPos = targetPos;
            // synchInfos[i] = synchInfo;
            EntityManager.SetComponentData <PosSynchInfo>(entities[i], synchInfo);
            scene_walk.request walk = new scene_walk.request();
            walk.start_x = (long)(pos.x * GameConst.RealToLogic);
            walk.start_y = (long)(pos.y * GameConst.RealToLogic);
            walk.start_z = (long)(pos.z * GameConst.RealToLogic);
            walk.end_x   = (long)(targetPos.x * GameConst.RealToLogic);
            // walk.end_y = (long)(targetPos.y*GameConst.RealToLogic);
            walk.end_z      = (long)(targetPos.z * GameConst.RealToLogic);
            walk.time       = synchTime;
            walk.jump_state = 0;
            NetMsgDispatcher.GetInstance().SendMessage <Protocol.scene_walk>(walk);
            lastSynchTime = Time.time;
        }
        entities.Dispose();
        targetPositions.Dispose();
        synchInfos.Dispose();
    }
Exemple #3
0
        // protected override void OnCreateManager(int capacity)
        // {
        //     Debug.Log("synch system OnCreateManager");
        //     base.OnCreateManager(capacity);

        // }

        protected override void OnUpdate()
        {
            //upload per second
            // Debug.Log("synch system"+Time.time.ToString()+" lasttime:"+lastSynchTime.ToString());
            if (Time.time - lastSynchTime < 0.1 || !GameVariable.IsNeedSynchSceneInfo)
            {
                return;
            }
            lastSynchTime = Time.time;
            long synchTime = System.DateTime.Now.Millisecond;

            for (int index = 0; index < m_Data.Length; ++index)
            {
                // Debug.Log("synch system");
                scene_walk.request walk    = new scene_walk.request();
                float3             cur_pos = m_Data.Position[index].Value;
                walk.pos_x = (int)(cur_pos.x * GameConst.RealToLogic);
                walk.pos_y = (int)(cur_pos.y * GameConst.RealToLogic);
                walk.pos_z = (int)(cur_pos.z * GameConst.RealToLogic);
                walk.time  = synchTime;
                NetMsgDispatcher.GetInstance().SendMessage <Protocol.scene_walk>(walk);
            }
        }
Exemple #4
0
 protected override void OnUpdate()
 {
     //upload per second
     // Debug.Log("synch system"+Time.time.ToString()+" lasttime:"+lastSynchTime.ToString());
     if (Time.time - lastSynchTime < 4)
     {
         return;
     }
     lastSynchTime = Time.time + 500;
     for (int index = 0; index < m_Data.Length; ++index)
     {
         Debug.Log("synch system");
         scene_walk.request walk    = new scene_walk.request();
         float3             cur_pos = m_Data.Position[index].Value;
         walk.pos_x = (int)(cur_pos.x * GameConst.RealToLogic);
         walk.pos_y = (int)(cur_pos.y * GameConst.RealToLogic);
         walk.pos_z = (int)(cur_pos.z * GameConst.RealToLogic);
         walk.dir_x = 3;
         walk.dir_y = 4;
         walk.dir_z = 5;
         walk.time  = 6;
         NetMsgDispatcher.GetInstance().SendMessage <Protocol.scene_walk>(walk);
     }
 }