Browse Source

物体同步逻辑

DGJ 1 year ago
parent
commit
adff7bc624

+ 2 - 1
Assets/Scripts/MultiPlayer/MultiPlayerManager.cs

@@ -76,5 +76,6 @@ public class SyncVideo
 public enum SyncObjectType
 {
     Object,
-    Video
+    Video,
+    Player
 }

+ 32 - 1
Assets/Scripts/MultiPlayer/SynchronizationObject.cs

@@ -4,14 +4,45 @@ using UnityEngine;
 
 public class SynchronizationObject : MonoBehaviour
 {
+    public SyncObjectType type;
+
+    public bool isSync;
+
+    private SyncObject data;
+    private float Speed = 3;
+    private float framSpeed;
+    private float dis;
+    private float pross;
 
     private void Start()
     {
         MultiPlayerManager.Instance.OnSynObject += OnSyncObject;
     }
 
-    private void OnSyncObject(SyncObject obj)
+    private void OnSyncObject(SyncObject data)
     {
 
+
+
+    }
+
+    private void Update()
+    {
+        if(type == SyncObjectType.Player)
+        if (data != null && transform.position != data.pos)
+        {
+            framSpeed = Time.deltaTime * Speed;
+            dis = Vector3.Distance(transform.position, data.pos);
+            pross = 0;
+            if (framSpeed > dis)
+            {
+                transform.position = data.pos;
+            }
+            else
+            {
+                pross = framSpeed / dis;
+                transform.position = Vector3.Lerp(transform.position, data.pos, pross);
+            }
+        }
     }
 }

+ 0 - 1
Assets/Scripts/MultiPlayer/SynchronizationVideo.cs

@@ -24,7 +24,6 @@ public class SynchronizationVideo : MonoBehaviour
         if (syncVideo.times != -1)
             AvideoPlayer.SetSeek(syncVideo.times);
 
-
     }
 
     public void SendSyncVideo()

+ 2 - 2
ProjectSettings/ProjectSettings.asset

@@ -935,8 +935,8 @@ PlayerSettings:
       PrivateNetworkClientServer: False
       InternetClientServer: False
       VideosLibrary: False
+      BackgroundMediaPlayback: False
       Objects3D: False
-      InternetClient: True
       RemoteSystem: False
       BlockedChatMessages: False
       PhoneCall: False
@@ -957,9 +957,9 @@ PlayerSettings:
       PointOfService: False
       RecordedCallsFolder: False
       Contacts: False
+      InternetClient: True
       Proximity: False
       CodeGeneration: False
-      BackgroundMediaPlayback: False
       EnterpriseAuthentication: False
   metroTargetDeviceFamilies:
     Desktop: False