_EagleOwle_

NetTransform

Aug 24th, 2020
1,401
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using GalaxyCoreLib.Api;
  2. using GalaxyCoreLib.NetEntity;
  3. using System;
  4. using System.Collections;
  5. using System.Threading;
  6. using UnityEngine;
  7. using GalaxyCoreLib;
  8.  
  9. public class NetTransform : MonoBehaviour
  10. {
  11.     /// <summary>
  12.     ///  Ссылка на сетевую сущность в ядре
  13.     /// </summary>
  14.     ClientNetEntity netEntity;
  15.     public bool sendMyPosition;
  16.     public bool sendMyRotation;
  17.  
  18.     private void Awake()
  19.     {
  20.         netEntity = GetComponent<NetEntity>().netEntity;
  21.     }
  22.  
  23.     private void OnEnable()
  24.     {
  25.         GalaxyEvents.OnFrameUpdate += OnFrameUpdate;
  26.  
  27.     }
  28.     private void OnDisable()
  29.     {
  30.         GalaxyEvents.OnFrameUpdate -= OnFrameUpdate;
  31.     }
  32.     private void OnFrameUpdate()
  33.     {
  34.         if (!netEntity.isMy) return;
  35.         if (sendMyPosition) netEntity.transform.SendPosition(transform.position.NetworkVector3());
  36.         if (sendMyRotation) netEntity.transform.SendRotation(transform.rotation.NetworkQuaternion());
  37.     }
  38.  
  39.     public void Update()
  40.     {
  41.         if (!netEntity.isMy)
  42.         {
  43.             transform.position = Vector3.Lerp(transform.position, netEntity.transform.position.Vector3(), GalaxyApi.lerpDelta);
  44.             if (!netEntity.transform.rotation.isZero()) transform.rotation = Quaternion.Lerp(transform.rotation, netEntity.transform.rotation.Quaternion(), GalaxyApi.lerpDelta);
  45.         }
  46.     }
  47.  
  48. }
  49.  
RAW Paste Data