示例#1
0
        public void LocalFieldSet <T>(T newValue, bool invokeOnChange = true)
        {
            //InitializeSpecialFields(true); //Cause when data gets sent over the network it may miss doing this, then there wont be able special UnityEvents added.

            if (ENSUtils.IsSimple(newValue.GetType()))
            {
                jsonData = "" + newValue;
            }
            else
            {
                jsonData = JsonUtility.ToJson(newValue); //This is used in UnityPacketHandler when setting it after packet being recieved. Don't use.
            }
            jsonDataTypeName = newValue.GetType().ToString();

            FieldArgs constructedArgs = new FieldArgs();

            constructedArgs.fieldName  = fieldName;
            constructedArgs.networkID  = netID;
            constructedArgs.fieldValue = newValue;

            initialized = true;
            if (invokeOnChange && !disableChangeEvents)
            {
                onValueChange.Invoke(constructedArgs);

                //You can also input the method names as strings, not as efficient but sometimes necessary.
                InvokeOnValueChangeMethods(constructedArgs);
            }
        }
 public void OnNetworkFieldFlipY(FieldArgs args)
 {
     if (net.IsOwner())
     {
         return;
     }
     sR.flipX = args.GetValue <bool>();
 }
 public void OnNetworkFieldBoolUpdate(FieldArgs args)
 {
     if (net.IsOwner())
     {
         return;
     }
     anim.SetBool(args.fieldName, args.GetValue <bool>());
     //Debug.Log("Field Updated... " + args.fieldName + " "+args.GetValue<bool>());
 }
        public void UpdateIPosition(FieldArgs args)
        {
            Vector3 newPos = args.GetValue <SerializableVector>().ToVec3();

            if (Vector3.Distance(transform.position, newPos) >= 5f)
            {
                transform.position = newPos;
                return;
            }

            targetPosition         = newPos;
            currentlyInterpolating = true;
        }
 public void OnNetworkUpdate(FieldArgs args)
 {
     try
     {
         char[] keyData = args.GetValue <KeyNetworkData>().keyData.ToCharArray();
         keyDown    = keyData[0] == '1';
         keyPressed = keyData[1] == '1';
         keyUp      = keyData[2] == '1';
     }
     catch
     {
         //Can error when a client is first joining the game.
     }
 }
示例#6
0
    /// <summary>Called when data(JSON formatted string) arrives</summary>
    public void onNotification(string data)
    {
        Notification notification = JsonUtility.FromJson <Notification>(data);

                #pragma warning disable CS0162
        if (isLogging)
        {
            Debug.Log(TAG + "onNotification, data: " + data);
            Debug.Log(TAG + "onNotification, notification.Uri:" + notification.Uri);
            Debug.Log(TAG + "onNotification, serial: " + serial);
            Debug.Log(TAG + "onNotification, subscriptionPath: " + subscriptionPath);
        }
                #pragma warning restore CS0162

        EventArgs eventArgs;

        if (subscriptionPath == SubscriptionPath.LinearAcceleration)
        {
            eventArgs = new FieldArgs(serial, subscriptionPath, data, notification.Body.ArrayAcc);
        }
        else if (subscriptionPath == SubscriptionPath.AngularVelocity)
        {
            eventArgs = new FieldArgs(serial, subscriptionPath, data, notification.Body.ArrayGyro);
        }
        else if (subscriptionPath == SubscriptionPath.MagneticField)
        {
            eventArgs = new FieldArgs(serial, subscriptionPath, data, notification.Body.ArrayMagn);
        }
        else if (subscriptionPath == SubscriptionPath.HeartRate)
        {
            double pulse = notification.Body.average;
            eventArgs = new HeartRateArgs(serial, data, pulse, notification.Body.rrData);
        }
        else if (subscriptionPath == SubscriptionPath.Temperature)
        {
            double temperature = notification.Body.Measurement;
            eventArgs = new TemperatureArgs(serial, data, temperature);
        }
        else
        {
            // for custom paths
            eventArgs = new EventArgs(serial, subscriptionPath, data);
        }

        if (Event != null)
        {
            Event(null, eventArgs);
        }
    }
 private void CountAll()
 {
     while (refsToProcess.Count > 0 || fieldsToProcess.Count > 0)
     {
         while (fieldsToProcess.Count > 0)
         {
             FieldArgs fieldArgs = fieldsToProcess[fieldsToProcess.Count - 1];
             fieldsToProcess.RemoveAt(fieldsToProcess.Count - 1);
             CountField(fieldArgs);
         }
         while (refsToProcess.Count > 0)
         {
             ReferenceArgs refArgs = refsToProcess[refsToProcess.Count - 1];
             refsToProcess.RemoveAt(refsToProcess.Count - 1);
             CountReference(refArgs);
         }
     }
 }
 private void CountField(FieldArgs fieldArgs)
 {
     if (!ShouldExclude(fieldArgs.field.FieldType))
     {
         object obj = null;
         try
         {
             if (!fieldArgs.field.FieldType.Name.Contains("*"))
             {
                 obj = fieldArgs.field.GetValue(fieldArgs.lineage.obj);
             }
         }
         catch
         {
             obj = null;
         }
         string field_name = fieldArgs.field.DeclaringType.ToString() + "." + fieldArgs.field.Name;
         refsToProcess.Add(new ReferenceArgs(fieldArgs.field.FieldType, field_name, new Lineage(obj, fieldArgs.lineage.parent3, fieldArgs.lineage.parent2, fieldArgs.lineage.parent1, fieldArgs.lineage.parent0, fieldArgs.field.DeclaringType)));
     }
 }
 public void OnValueChangeTestExample(FieldArgs args)
 {
     Debug.Log("Player Position Changed: " + args.GetValue <SerializableVector>().ToVec3());
 }