public void RegisterVar(SyncableVariable var, SyncFrequency frequency, Action <SyncableVariable, NetworkWriter> registerMethod, Action <SyncableVariable, NetworkReader> syncMethod, Func <NetworkWriter, int> byteSizeMethod, bool ignoreAuthority)
        {
            if (_varIgnoresAuthority.ContainsKey(var))
            {
                _varIgnoresAuthority.Remove(var);
            }
            if (_methods.ContainsKey(var))
            {
                _methods.Remove(var);
            }
            if (_varSizesMethods.ContainsKey(var))
            {
                _varSizesMethods.Remove(var);
            }

            _varIgnoresAuthority[var] = ignoreAuthority;
            _methods.Add(var, new NetworkSyncableVarMethods(var, registerMethod, syncMethod));

            _frequenciesMasks[(int)frequency] |= var;

            if (byteSizeMethod == null)
            {
                BakeVarSize(var, registerMethod);
            }
            else
            {
                _varSizesMethods.Add(var, byteSizeMethod);
            }
        }
            private void SyncEntityEquip(SyncableVariable var, NetworkReader reader)
            {
                int count = reader.ReadInt32();

                for (int i = 0; i < count; i++)
                {
                    bool            method = reader.ReadBoolean();
                    EntityEquipable eq     = reader.ReadEntityEquipable();

                    UnsubscribeToEquipEvents();
                    if (method)
                    {
                        Equip(eq);
                    }
                    else
                    {
                        Unequip(eq);
                    }
                    SubscribeToEquipEvents();

                    if (References.NetworkIdentity.isServer == true && References.NetworkIdentity.hasAuthority == false)
                    {
                        _equipableSyncMethod.Add(method);
                        _equipablesToSync.Add(eq);
                        PinouNetworkManager.MainBehaviour.SetDirty(master.gameObject, SyncableVariable.EntityEquip);
                    }
                }
            }
예제 #3
0
        private void SyncAbilityHit(SyncableVariable var, NetworkReader reader)
        {
            if (References.NetworkIdentity.isServer)
            {
                _nextSyncResults = new List <AbilityCastResult>();
            }
            int resultsCount = reader.ReadInt32();

            for (int i = 0; i < resultsCount; i++)
            {
                AbilityCastResult result = reader.ReadAbilityCastResult();

                if (References.NetworkIdentity.isServer)
                {
                    OnReceiveAbilityHit.Invoke(this, result);
                    result.CastData.FillResult(result);
                    _nextSyncResults.Add(result);
                    PinouNetworkManager.MainBehaviour.SetDirty(gameObject, SyncableVariable.EntityAbilityHit);
                }
                else if (References.NetworkIdentity.hasAuthority)
                {
                    OnReceiveAbilityHit.Invoke(this, result);
                    result.CastData.FillResult(result);
                }

                if (result.CastData.Caster == this)
                {
                    return;
                }

                OnAbilityHitResult.Invoke(this, result);
            }
        }
        private void BakeVarSize(SyncableVariable var, Action <SyncableVariable, NetworkWriter> registerMethod)
        {
            dummyWriter.Reset();
            registerMethod.Invoke(var, dummyWriter);

            _varSizes[var.GetIndex()] = dummyWriter.Length;
        }
 private void SyncVelocity(SyncableVariable var, NetworkReader reader)
 {
     if (_rigidbodyTarget == null)
     {
         return;
     }
     _targetVel = reader.ReadVector3();
 }
 private void RegisterRotation(SyncableVariable var, NetworkWriter writer)
 {
     if (_rotationTarget == null)
     {
         return;
     }
     writer.WriteQuaternion(_rotationTarget.rotation);
 }
 private void RegisterPosition(SyncableVariable var, NetworkWriter writer)
 {
     if (_positionTarget == null)
     {
         return;
     }
     writer.WriteVector3(_positionTarget.position);
 }
 public bool IgnoreAuthority(SyncableVariable var)
 {
     if (_varIgnoresAuthority.ContainsKey(var) == false)
     {
         return(false);
     }
     return(_varIgnoresAuthority[var]);
 }
 private void RegisterVelocity(SyncableVariable var, NetworkWriter writer)
 {
     if (_rigidbodyTarget == null)
     {
         return;
     }
     writer.WriteVector3(_rigidbodyTarget.velocity);
 }
예제 #10
0
 private void RegisterAbilityHit(SyncableVariable var, NetworkWriter writer)
 {
     writer.WriteInt32(_nextSyncResults.Count);
     for (int i = 0; i < _nextSyncResults.Count; i++)
     {
         writer.WriteAbilityCastResult(_nextSyncResults[i]);
     }
     _nextSyncResults.Clear();
 }
 public NetworkSyncableGameobjectInfos(GameObject go)
 {
     _gameObject          = go;
     _frequenciesMasks    = new SyncableVariable[Enum.GetValues(typeof(SyncFrequency)).Length];
     _varIgnoresAuthority = new Dictionary <SyncableVariable, bool>();
     _varSizes            = new int[Enum.GetValues(typeof(SyncableVariable)).Length];
     _methods             = new Dictionary <SyncableVariable, NetworkSyncableVarMethods>();
     _varSizesMethods     = new Dictionary <SyncableVariable, Func <NetworkWriter, int> >();
 }
예제 #12
0
            private void RegisterCastAbility(SyncableVariable var, NetworkWriter writer)
            {
                writer.WriteInt32(_nextAbilitiesCast.Count);
                for (int i = 0; i < _nextAbilitiesCast.Count; i++)
                {
                    writer.WriteAbilityCastData(_nextAbilitiesCast[i]);
                }

                _nextAbilitiesCast.Clear();
            }
예제 #13
0
            private void RegisterDestroyAbilityHitbox(SyncableVariable var, NetworkWriter writer)
            {
                writer.WriteInt32(_nextHitboxDestroyed.Count);
                for (int i = 0; i < _nextHitboxDestroyed.Count; i++)
                {
                    writer.WriteAbilityCastData(_nextHitboxDestroyed[i]);
                }

                _nextHitboxDestroyed.Clear();
            }
예제 #14
0
 public void InvokeRegisterMethods(GameObject go, SyncableVariable varFlags, NetworkWriter writer)
 {
     for (int i = 0; i < _syncableVariablesEnumValues.Length; i++)
     {
         SyncableVariable curVar = (SyncableVariable)_syncableVariablesEnumValues.GetValue(i);
         if ((curVar & varFlags) > 0)
         {
             _gameObjectSyncInfos[go].InvokeRegisterMethod(curVar, writer);
         }
     }
 }
예제 #15
0
        private void ComputeChannelMasks()
        {
            Array values = Enum.GetValues(typeof(SyncableVariable));

            _channelMasks = new SyncableVariable[CHANNEL_COUNT];
            for (int i = 0; i < values.Length; i++)
            {
                SyncableVariable var = (SyncableVariable)values.GetValue(i);
                _channelMasks[var.GetChannel()] |= var;
            }
        }
        private void SyncPosition(SyncableVariable var, NetworkReader reader)
        {
            if (_positionTarget == null)
            {
                return;
            }
            Vector3 oldPos = _targetPos;

            _targetPos = reader.ReadVector3();
            _posSpeed  = (_targetPos - oldPos).magnitude;
        }
        private void SyncRotation(SyncableVariable var, NetworkReader reader)
        {
            if (_rotationTarget == null)
            {
                return;
            }
            Quaternion oldRot = _targetRot;

            _targetRot = reader.ReadQuaternion();
            _rotSpeed  = Quaternion.Angle(oldRot, _targetRot);
        }
            private void RegisterEntityEquip(SyncableVariable var, NetworkWriter writer)
            {
                writer.WriteInt32(_equipableSyncMethod.Count);
                for (int i = 0; i < _equipablesToSync.Count; i++)
                {
                    writer.WriteBoolean(_equipableSyncMethod[i]);
                    writer.WriteEntityEquipable(_equipablesToSync[i]);
                }

                _equipableSyncMethod.Clear();
                _equipablesToSync.Clear();
            }
예제 #19
0
        public static int GetIndex(this SyncableVariable var)
        {
            for (int i = 0; i < s_SyncableVariableValues.Length; i++)
            {
                if (var == (SyncableVariable)s_SyncableVariableValues.GetValue(i))
                {
                    return(i);
                }
            }

            return(-1);
        }
 public int GetSyncVarByteSize(SyncableVariable var)
 {
     if (_varSizesMethods.ContainsKey(var))
     {
         dummyWriter.Reset();
         return(_varSizesMethods[var].Invoke(dummyWriter));
     }
     else
     {
         return(_varSizes[var.GetIndex()]);
     }
 }
예제 #21
0
        public static NetworkSyncableVarsDirtyData ReadNetworkSyncableVarsDirtyData(this NetworkReader reader)
        {
            GameObject       gameObject = reader.ReadGameObject();
            SyncableVariable dirtyVars  = (SyncableVariable)reader.ReadInt64();

            if (gameObject != null)
            {
                PinouNetworkManager.MainBehaviour.InvokeSyncMethods(gameObject, dirtyVars, reader);
            }

            return(new NetworkSyncableVarsDirtyData(gameObject));
        }
예제 #22
0
            private void SyncDestroyAbilityHitbox(SyncableVariable var, NetworkReader reader)
            {
                int hitboxCount = reader.ReadInt32();

                for (int i = 0; i < hitboxCount; i++)
                {
                    AbilityCastData castData = reader.ReadAbilityCastData();
                    AbilityHitbox.DestroyFromCastData(castData);
                    if (References.NetworkIdentity.isServer && References.NetworkIdentity.hasAuthority == false)
                    {
                        _nextHitboxDestroyed.Add(castData);
                        PinouNetworkManager.MainBehaviour.SetDirty(master.gameObject, SyncableVariable.EntityAbilityHitboxDestroyed);
                    }
                }
            }
예제 #23
0
        private int ComputeExpectedSize(NetworkSyncableVarsDirtyData dirtyData)
        {
            NetworkSyncableGameobjectInfos infos = _gameObjectSyncInfos[dirtyData.GameObject];
            int totalSize = 9;

            for (int i = 0; i < _syncableVariablesEnumValues.Length; i++)
            {
                SyncableVariable var = (SyncableVariable)_syncableVariablesEnumValues.GetValue(i);
                if (dirtyData.IsDirty(var))
                {
                    totalSize += infos.GetSyncVarByteSize(var);
                }
            }

            return(totalSize);
        }
예제 #24
0
        public void RegisterGameObjectSyncVar(GameObject go, SyncableVariable var, SyncFrequency frequency, Action <SyncableVariable, NetworkWriter> registerMethod, Action <SyncableVariable, NetworkReader> syncMethod, Func <NetworkWriter, int> byteSizeMethod, bool ignoreAuthority)
        {
            IDestroyableNetworkSyncableGameObject destroyableGameObject = go.GetComponent <IDestroyableNetworkSyncableGameObject>();

            if (destroyableGameObject == null)
            {
                Debug.LogError("GameObject must have a IDestroyableNetworkSyncableGameObject component."); return;
            }

            if (_gameObjectSyncInfos.ContainsKey(go) == false)
            {
                _gameObjectSyncInfos.Add(go, new NetworkSyncableGameobjectInfos(go));
            }

            _gameObjectSyncInfos[go].RegisterVar(var, frequency, registerMethod, syncMethod, byteSizeMethod, ignoreAuthority);
            destroyableGameObject.OnGameObjectDestroyed.SafeSubscribe(OnSyncableGameObjectDestroyed);
        }
예제 #25
0
 public void InvokeSyncMethods(GameObject go, SyncableVariable varFlags, NetworkReader reader)
 {
     for (int i = 0; i < _syncableVariablesEnumValues.Length; i++)
     {
         SyncableVariable curVar = (SyncableVariable)_syncableVariablesEnumValues.GetValue(i);
         if ((curVar & varFlags) > 0)
         {
             try
             {
                 _gameObjectSyncInfos[go].InvokeSyncMethod(curVar, reader);
             }
             catch
             {
                 Debug.LogWarning(go + " | " + curVar + " | not present.");
             }
         }
     }
 }
예제 #26
0
            private void SyncCastAbility(SyncableVariable var, NetworkReader reader)
            {
                int hitboxCount = reader.ReadInt32();

                for (int i = 0; i < hitboxCount; i++)
                {
                    AbilityCastData castData = reader.ReadAbilityCastData();
                    if (castData.AbilityCast.Hitbox.UnlimitedLifeSpan == true || castData.AbilityCast.Hitbox.LifeSpan > 0)
                    {
                        AbilityHitbox hitBox = AbilityPerformer.HandleSpawnAbilityHitbox(castData);
                        hitBox.ActivateVisualMode();
                    }

                    OnPerformAbility.Invoke(master, castData);
                    if (References.NetworkIdentity.isServer && References.NetworkIdentity.hasAuthority == false)
                    {
                        _nextAbilitiesCast.Add(castData);
                        PinouNetworkManager.MainBehaviour.SetDirty(master.gameObject, SyncableVariable.EntityAbilityCast);
                    }
                }
            }
예제 #27
0
        public static int GetChannel(this SyncableVariable var)
        {
            switch (var)
            {
            case SyncableVariable.Position:
                return(2);

            case SyncableVariable.Rotation:
                return(2);

            case SyncableVariable.Velocity:
                return(1);

            case SyncableVariable.MovementsParticlesEmission:
                return(2);

            case SyncableVariable.MovementsParticlesAngle:
                return(2);

            case SyncableVariable.EntityAbilityCast:
                return(1);

            case SyncableVariable.EntityAbilityHit:
                return(1);

            case SyncableVariable.EntityAbilityHitboxDestroyed:
                return(1);

            case SyncableVariable.EntityDeath:
                return(1);

            case SyncableVariable.EntityHealth:
                return(1);

            case SyncableVariable.EntityEquip:
                return(0);
            }

            return(0);
        }
예제 #28
0
 private void SyncDeath(SyncableVariable var, NetworkReader reader)
 {
     OnDeath.Invoke(master, reader.ReadAbilityCastResult());
 }
예제 #29
0
 private void RegisterDeath(SyncableVariable var, NetworkWriter writer)
 {
     writer.WriteAbilityCastResult(deathResult);
     deathResult = null;
 }
예제 #30
0
 private void SyncHealth(SyncableVariable var, NetworkReader reader)
 {
     currentHealth = (float)reader.ReadDouble();
 }