public int CompareTo(MeshLoadOperation other)
 {
     if (this.Priority != other.Priority)
     {
         int order    = PrioritySortOrder == MeshLoadOperationSortOrder.Ascending ? -1 : 1;
         int priority = this.Priority > other.Priority ? -1 : 1;
         return(order * priority);
     }
     if (this.Timestamp != other.Timestamp)
     {
         int order    = TimestampSortOrder == MeshLoadOperationSortOrder.Ascending ? -1 : 1;
         int priority = this.Timestamp > other.Timestamp ? -1 : 1;
         return(order * priority);
     }
     return(0);
 }
Esempio n. 2
0
        public MeshLoadOperation Load(string assetGuid, int priority)
        {
            MeshLoadOperation operation;

            operation = this.Find(assetGuid);

            if (operation != null)
            {
                operation.Priority  = System.Math.Max(operation.Priority, priority);
                operation.Timestamp = Time.realtimeSinceStartup;
            }
            else
            {
                operation           = new MeshLoadOperation();
                operation.AssetGuid = assetGuid;
                operation.Behaviour = this;
                operation.Priority  = priority;
                operation.Timestamp = Time.realtimeSinceStartup;
                this.CachedOperations.Add(assetGuid, new System.WeakReference(operation));
            }

            if (operation.Asset != null || operation.State == MeshLoadOperationState.Done)
            {
                operation.State = MeshLoadOperationState.Done;
                return(operation);
            }

            if (operation.State == MeshLoadOperationState.Cancelled)
            {
                operation.State = MeshLoadOperationState.Unknown;
            }

            if (!this.ActiveOperations.Contains(operation))
            {
                this.ActiveOperations.Add(operation);
            }

            return(operation);
        }
Esempio n. 3
0
        IEnumerator Start()
        {
            while (true)
            {
                // load
                if (this.ActiveOperations.Count == 0)
                {
                    yield return(null);
                }
                else
                {
                    // make sure cancelled and done operations are removed
                    // BEFORE running the next operation, otherwise an
                    // operation can keep adding itself to the queue every
                    // frame and get sorted to the top.
                    this.CleanupActiveOperations();
                    this.SortActiveOperations();

                    // Calling CleanupActiveOperations() may remove operations
                    // from the list, so we need to check the count again to
                    // avoid throwing an ArgumentOutOfRangeException.
                    // See: https://sagosago.atlassian.net/browse/SW-91
                    if (this.ActiveOperations.Count != 0)
                    {
                        MeshLoadOperation operation = this.ActiveOperations[0];
                        yield return(operation.Run());

                        operation = null;
                    }
                    else
                    {
                        yield return(null);
                    }
                }

                // cleanup
                this.CleanupActiveOperations();

                // unload
                if (UnloadUnusedAssetsFlag)
                {
                    List <string> operationsToRemove = new List <string>();
                    foreach (KeyValuePair <string, System.WeakReference> pair in CachedOperations)
                    {
                        MeshLoadOperation operation = (
                            pair.Value.IsAlive ?
                            pair.Value.Target as MeshLoadOperation :
                            null
                            );
                        if (operation == null)
                        {
                            operationsToRemove.Add(pair.Key);
                        }
                    }
                    foreach (string key in operationsToRemove)
                    {
                        this.CachedOperations.Remove(key);
                    }
                    if (OnUnloadUnusedAssets != null)
                    {
                        yield return(OnUnloadUnusedAssets());
                    }
                    else
                    {
                        yield return(Resources.UnloadUnusedAssets());
                    }
                    UnloadUnusedAssetsFlag = false;
                }
            }
        }