public static UnityObjectHandle ToObjectHandle(Object obj)
        {
            var handle = new UnityObjectHandle();

            if (!obj || null == obj)
            {
                return(handle);
            }

#if UNITY_EDITOR
            var json = UnityEditor.EditorJsonUtility.ToJson(new Container {
                o = obj
            });
            json = json.Substring(5, json.Length - 6);

            var reader = new JsonObjectReader(json);
            reader.ReadBeginObject();
            reader.ReadPropertyNameSegment(); // fileID
            handle.FileId = reader.ReadInt64();
            reader.ReadValueSeparator();
            reader.ReadPropertyNameSegment(); // guid
            handle.Guid = reader.ReadString();
            reader.ReadValueSeparator();
            reader.ReadPropertyNameSegment(); // type
            handle.Type = reader.ReadInt32();
            reader.ReadValueSeparator();
#endif
            return(handle);
        }
Exemple #2
0
            public Ready(JObject data)
            {
                JsonObjectReader r = data.GetReader();

                ProtocolVersion  = r.ReadInt32("v");
                ClientServerUser = User.CreateFromJson(r.ReadObject("user").ToObject <UserJson>(), null);
                // ReSharper disable once CoVariantArrayConversion (read-only)
                DmChannels      = r.ReadArray("private_channels").AllObject <ChannelJson>().Select(x => DirectMessageTextChannel.CreateFromJson(x, null)).ToArray();
                ServersToCreate = r.ReadObjectArray <UaServerJson>("guilds").Where(x => x.unavailable).Select(x => x.id).ToList();
                SessionId       = r.ReadString("session_id");
                Trace           = r.ReadStringArray("_trace");
            }
Exemple #3
0
        internal virtual void UpdateInstance(JsonObjectReader r)
        {
            ulong cid = r.ReadSnowflake("channel_id");

            if (cid != ChannelId)
            {
                ChannelId = cid;
                Channel   = new CachedPromise <TextChannel>(new AliasCache <IChannel, TextChannel>(ChannelUtils._globalCache), ChannelId, TextChannel.GetAsync);
            }
            // author and webhook_id should be dealt with in this method's overloads
            if (r.Contains("content"))
            {
                Content = r.ReadString("content");
            }
            if (r.Contains("timestamp"))
            {
                CreationTime = DateTime.Parse(r.ReadString("timestamp"));
            }
            if (r.Contains("edited_timestamp"))
            {
                string letStr = r.ReadNullableString("edited_timestamp"); if (letStr != null)
                {
                    LastEditTime = (DateTime?)DateTime.Parse(letStr);
                }
            }
            if (r.Contains("tts"))
            {
                IsTextToSpeech = r.ReadBoolean("tts");
            }
            if (r.Contains("mention_everyone"))
            {
                MentionedEveryone = r.ReadBoolean("mention_everyone");
            }
            if (r.Contains("mentions"))
            {
                MentionedUsers = r.ReadObjectArray <UserJson>("mentions").Select(x => User.CreateFromJson(x, null)).ToIdDic();
            }
            if (r.Contains("mention_roles"))
            {
                MentionedRoles = r.ReadObjectArray <RoleJson>("mention_roles").Select(x => Role.CreateFromJson(((IServerChannel)Channel.GetCachedValue()).ServerId, x, null)).ToIdDic();
            }
            if (r.Contains("pinned"))
            {
                IsPinned = r.ReadBoolean("pinned");
            }
            if (r.Contains("type"))
            {
                MsgType = (InternalMessageType)r.ReadInt32("type");
            }
        }
Exemple #4
0
        // TODO: Make channel concrete instead of a promise, and thus fix the cast error
        protected Message(JsonObjectReader r)
        {
            Id           = r.ReadSnowflake("id");
            ChannelId    = r.ReadSnowflake("channel_id");
            Channel      = new CachedPromise <TextChannel>(new AliasCache <IChannel, TextChannel>(ChannelUtils._globalCache), ChannelId, TextChannel.GetAsync);
            Content      = r.ReadString("content");
            CreationTime = DateTime.Parse(r.ReadString("timestamp"));
            string letStr = r.ReadNullableString("edited_timestamp"); if (letStr != null)

            {
                LastEditTime = (DateTime?)DateTime.Parse(letStr);
            }

            IsTextToSpeech    = r.ReadBoolean("tts");
            MentionedEveryone = r.ReadBoolean("mention_everyone");
            MentionedUsers    = r.ReadObjectArray <UserJson>("mentions").Select(x => User.CreateFromJson(x, null)).ToIdDic();
            MentionedRoles    = r.ReadObjectArray <RoleJson>("mention_roles").Select(x => Role.CreateFromJson(((IServerChannel)Channel.GetCachedValue()).ServerId, x, null)).ToIdDic();
            IsPinned          = r.ReadBoolean("pinned");
            MsgType           = (InternalMessageType)r.ReadInt32("type");
            _cache.Add(this);
        }