コード例 #1
0
        public bool Remove(Trash trash)
        {
            lock (this)
            {
                bool success = false;
                success |= busyTrashes.Remove(trash.Id);

                List <Trash> trashes = new List <Trash> (freeTrashes);
                var          removed = trashes.Remove(trash);

                if (removed)
                {
                    trash.Root = null;

                    freeTrashes.Clear();
                    for (int i = trashes.Count - 1; i >= 0; i--)
                    {
                        freeTrashes.Enqueue(trashes [i]);
                    }
                }

                success |= removed;

                return(success);
            }
        }
コード例 #2
0
        /// <summary>
        /// Take the trash back into the bin
        /// </summary>
        /// <param name="trash"></param>
        public bool TakeIn(Trash trash)
        {
            if (trash == null)
            {
#if UNITY_EDITOR
                Debug.LogWarning("Trash is null, so it cannot be taken into the bin.");
#endif
                return(false);
            }

            if (trash.Bin != this)
            {
#if UNITY_EDITOR
                Debug.LogWarning("The trash does not belong to the bin.");
#endif
                return(false);
            }

            bool ok = busyTrashes.Remove(trash.Id);

            if (ok)
            {
                trash.Active = false;
                trash.Root   = root;
                freeTrashes.Enqueue(trash);
            }

            return(ok);
        }
コード例 #3
0
        private void CreateNewTrash()
        {
            var go    = GameObject.Instantiate(prefab, root);
            var trash = Trash.Create(go, this);

            trash.Active = false;
            freeTrashes.Enqueue(trash);
        }
コード例 #4
0
        /// <summary>
        /// Take trash back into the bin
        /// </summary>
        public static void TakeIn(GameObject go)
        {
            Trash trash = go.GetComponent <Trash> ();

            if (trash == null)
            {
                return;
            }

            trash.ThrowToBin();
        }