public static int AddView(KNetView view)
        {
            if (IsServer == false)
            {
                KNetLogger.LogError("KlivenNet.AddView() is only available on Server. On clients Views are synchronized automatically.");
                return(-1);
            }
            int id = Views.Count;

            view.Init(id);
            Views.Add(view);
            return(id);
        }
Exemple #2
0
        internal static void RecieveBufferedObject(KNetSerializedField serializedField)
        {
            KNetView view = KlivenNet.FindView(serializedField.viewId);

            if (view == null)
            {
                KNetLogger.LogError($"KNetClient: could not Recieve buffered object: KNetView of id {serializedField.viewId}: view does not exist.");
                return;
            }
            var field = serializedField.fieldId < view.BufferedFields.Length ? view.BufferedFields[serializedField.fieldId] : null;

            if (field == null)
            {
                KNetLogger.LogError($"KNetClient: could not Recieve buffered object: KNetView of id {serializedField.viewId}: field id {serializedField.fieldId} is not defined.");
                return;
            }
            field.SetValue(view, KNetUtils.Deserialize(serializedField.data, serializedField.count
                                                       , KNetUtils.IsSerializable(field.FieldType), field.FieldType));
        }
        public static KNetRpcInfo CreateRpcInfo(short id, KNetView view, MethodInfo methodInfo)
        {
            KNetRpcInfo info = new KNetRpcInfo();
            var         args = methodInfo.GetParameters().OrderBy(e => e.Position);

            if (args.Where(e => KNetUtils.IsSerializable(e.ParameterType) == SerializableType.nonSerializable).Any())
            {
                return(null);
            }
            info.methodInfo            = methodInfo;
            info.Name                  = methodInfo.Name;
            info.ArgumentsInfo         = args.ToArray();
            info.ArgumentsTypes        = new Type[info.ArgumentsInfo.Length];
            info.ArgSerializationTypes = new SerializableType[info.ArgumentsInfo.Length];
            for (int i = 0; i < info.ArgumentsInfo.Length; i++)
            {
                info.ArgumentsTypes[i]        = info.ArgumentsInfo[i].ParameterType;
                info.ArgSerializationTypes[i] = KNetUtils.IsSerializable(info.ArgumentsTypes[i]);
            }
            info.Id       = id;
            info.kNetView = view;
            return(info);
        }
 internal static void AddView(KNetView view, int id)
 {
     view.Init(id);
     Views.Add(view);
 }