示例#1
0
        /// <summary>
        /// Unregister the network object.
        /// </summary>

        internal void Unregister()
        {
            if (mIsRegistered)
            {
                if (mDictionary != null)
                {
                    Dictionary <uint, TNObject> dict = mDictionary[channelID];

                    if (dict != null)
                    {
                        dict.Remove(uid);
                        if (dict.Count == 0)
                        {
                            mDictionary.Remove(channelID);
                        }
                    }
                }

                if (mList != null)
                {
                    TNet.List <TNObject> list = mList[channelID];

                    if (list != null)
                    {
                        list.Remove(this);
                        if (list.size == 0)
                        {
                            mList.Remove(channelID);
                        }
                    }
                }

                mIsRegistered = false;
            }
        }
示例#2
0
        /// <summary>
        /// Register the network object with the lists.
        /// </summary>

        public void Register()
        {
            if (!mIsRegistered && uid != 0 && mParent == null)
            {
#if UNITY_EDITOR
                UniqueCheck();
#endif
                Dictionary <uint, TNObject> dict;

                if (!mDictionary.TryGetValue(channelID, out dict) || dict == null)
                {
                    dict = new Dictionary <uint, TNObject>();
                    mDictionary[channelID] = dict;
                }

                dict[uid] = this;

                TNet.List <TNObject> list;

                if (!mList.TryGetValue(channelID, out list) || list == null)
                {
                    list             = new TNet.List <TNObject>();
                    mList[channelID] = list;
                }

                list.Add(this);
                mIsRegistered = true;
            }
        }
        void _CallOnChannelList(TNet.List <Channel.Info> chList)
        {
            for (int x = 0; x < chList.size; x++)
            {
                int Players   = chList[x].players;
                int ChannelID = chList[x].id;

                string value = (ChannelID.ToString() + "," + Players.ToString());
                valuestring = value;

                storeValue.Resize(storeValue.Length + 1);
                storeValue.Set(storeValue.Length - 1, valuestring.Value);

                Finish();
            }
        }
示例#4
0
        /// <summary>
        /// Get a new unique object identifier.
        /// </summary>

        static internal uint GetUniqueID()
        {
            foreach (KeyValuePair <int, TNet.List <TNObject> > pair in mList)
            {
                TNet.List <TNObject> list = pair.Value;

                for (int i = 0; i < list.size; ++i)
                {
                    TNObject ts = list[i];
                    if (ts != null && ts.uid > mLastID && ts.uid < 32768)
                    {
                        mLastID = ts.uid;
                    }
                }
            }
            return(++mLastID);
        }
示例#5
0
        /// <summary>
        /// Retrieve the Tasharen Network Object by ID.
        /// </summary>

        static public TNObject Find(int channelID, uint tnID)
        {
            if (mDictionary == null)
            {
                return(null);
            }
            TNObject tno = null;

            if (channelID == 0)
            {
                // Broadcasts are sent with the channel ID of '0'
                foreach (KeyValuePair <int, TNet.List <TNObject> > pair in mList)
                {
                    TNet.List <TNObject> list = pair.Value;

                    for (int i = 0; i < list.size; ++i)
                    {
                        TNObject ts = list[i];
                        if (ts.id == tnID)
                        {
                            return(ts);
                        }
                    }
                }
            }
            else
            {
                Dictionary <uint, TNObject> dict;
                if (!mDictionary.TryGetValue(channelID, out dict))
                {
                    return(null);
                }
                if (!dict.TryGetValue(tnID, out tno))
                {
                    return(null);
                }
            }
            return(tno);
        }