Example #1
0
        public static void ApplyNetworkerConstraints(Networker networker)
        {
            if (networker.ObservedComponents == null)
            {
                networker.ObservedComponents = new List <Component>();
            }

            var hash = NetworkertHash(networker);

            var observables = networker.GetComponents <INetworkObserved>();

            networker.ObservedComponents.Clear();
            networker.ObservedComponents.AddRange(observables.Select(x => x as Component));

            if (networker.SyncTransforms && networker.GetComponent <INetworkStatic>() != null)
            {
                networker.SyncTransforms = false;
            }

            if (!networker.SyncTransforms)
            {
                networker.ObservedComponents.Remove(networker);
            }

            if (networker.GetComponent <INetworkTakeover>() != null)
            {
                networker.ownershipTransfer = OwnershipOption.Takeover;
            }

            if (networker.GetComponent <INetworkTakeover>() == null)
            {
                networker.ownershipTransfer = OwnershipOption.Fixed;
            }

            if (networker.ObservedComponents.Count > 0)
            {
                networker.synchronization = ViewSynchronization.UnreliableOnChange;
            }

            if (networker.ObservedComponents.Count == 0)
            {
                networker.synchronization = ViewSynchronization.Off;
            }

            if (hash != NetworkertHash(networker))
            {
                // Debug.Log( $"Updating Networker {networker.gameObject.name} - {hash}" );
                UnityEditor.EditorUtility.SetDirty(networker.gameObject);
            }
        }
Example #2
0
 static string NetworkertHash(Networker networker)
 {
     return($"{string.Join( ";", networker.ObservedComponents.Select( x => x?.ToString() ) )}-{networker.ownershipTransfer}-{networker.synchronization}-{networker.SyncTransforms}");
 }