void LoadImmediate()
            {
                string assetPath = m_ProvideHandle.Location == null ? string.Empty : m_ProvideHandle.Location.InternalId;

                object result = null;

                if (m_ProvideHandle.Type.IsArray)
                {
                    result = ResourceManagerConfig.CreateArrayResult(m_ProvideHandle.Type, AssetDatabase.LoadAllAssetRepresentationsAtPath(assetPath));
                }
                else if (m_ProvideHandle.Type.IsGenericType && typeof(IList <>) == m_ProvideHandle.Type.GetGenericTypeDefinition())
                {
                    result = ResourceManagerConfig.CreateListResult(m_ProvideHandle.Type, AssetDatabase.LoadAllAssetRepresentationsAtPath(assetPath));
                }
                else
                {
                    var    mainType = AssetDatabase.GetMainAssetTypeAtPath(assetPath);
                    Object obj      = null;
                    if (mainType == typeof(Texture2D) && m_ProvideHandle.Type == typeof(Sprite))
                    {
                        obj = AssetDatabase.LoadAssetAtPath(assetPath, m_ProvideHandle.Type);
                    }
                    else if (mainType == typeof(GameObject) && m_ProvideHandle.Type == typeof(Mesh))
                    {
                        obj = AssetDatabase.LoadAssetAtPath(assetPath, m_ProvideHandle.Type);
                    }
                    else
                    {
                        obj = AssetDatabase.LoadAssetAtPath(assetPath, mainType);
                    }

                    result = obj != null && m_ProvideHandle.Type.IsAssignableFrom(obj.GetType()) ? obj : null;
                }
                m_ProvideHandle.Complete(result, result != null, null);
            }
            void LoadImmediate()
            {
                string assetPath = m_ProvideHandle.ResourceManager.TransformInternalId(m_ProvideHandle.Location);
                object result    = null;

                if (m_ProvideHandle.Type.IsArray)
                {
                    result = ResourceManagerConfig.CreateArrayResult(m_ProvideHandle.Type, AssetDatabase.LoadAllAssetsAtPath(assetPath));
                }
                else if (m_ProvideHandle.Type.IsGenericType && typeof(IList <>) == m_ProvideHandle.Type.GetGenericTypeDefinition())
                {
                    result = ResourceManagerConfig.CreateListResult(m_ProvideHandle.Type, AssetDatabase.LoadAllAssetsAtPath(assetPath));
                }
                else
                {
                    if (ResourceManagerConfig.ExtractKeyAndSubKey(assetPath, out string mainPath, out string subKey))
                    {
                        var objs = AssetDatabase.LoadAllAssetRepresentationsAtPath(mainPath);
                        foreach (var o in objs)
                        {
                            if (o.name == subKey)
                            {
                                if (m_ProvideHandle.Type.IsAssignableFrom(o.GetType()))
                                {
                                    result = o;
                                    break;
                                }
                            }
                        }
                    }
        public override void Provide(ProvideHandle pi)
        {
            Type t          = pi.Type;
            bool isList     = t.IsGenericType && typeof(IList <>) == t.GetGenericTypeDefinition();
            var  internalId = pi.ResourceManager.TransformInternalId(pi.Location);

            if (t.IsArray || isList)
            {
                object result = null;
                if (t.IsArray)
                {
                    result = ResourceManagerConfig.CreateArrayResult(t, Resources.LoadAll(internalId, t.GetElementType()));
                }
                else
                {
                    result = ResourceManagerConfig.CreateListResult(t, Resources.LoadAll(internalId, t.GetGenericArguments()[0]));
                }

                pi.Complete(result, result != null, null);
            }
            else
            {
                string assetPath = internalId;
                var    i         = assetPath.LastIndexOf('[');
                if (i > 0)
                {
                    var i2 = assetPath.LastIndexOf(']');
                    if (i2 < i)
                    {
                        pi.Complete <AssetBundle>(null, false, new Exception(string.Format("Invalid index format in internal id {0}", assetPath)));
                    }
                    else
                    {
                        var subObjectName = assetPath.Substring(i + 1, i2 - (i + 1));
                        assetPath = assetPath.Substring(0, i);
                        var    objs   = Resources.LoadAll(assetPath, pi.Type);
                        object result = null;
                        foreach (var o in objs)
                        {
                            if (o.name == subObjectName)
                            {
                                if (pi.Type.IsAssignableFrom(o.GetType()))
                                {
                                    result = o;
                                    break;
                                }
                            }
                        }
                        pi.Complete(result, result != null, null);
                    }
                }
                else
                {
                    new InternalOp().Start(pi);
                }
            }
        }
            public bool Load(long localBandwidth, long remoteBandwidth, float unscaledDeltaTime)
            {
                if (IsDone)
                {
                    return(false);
                }
                var now = m_LastUpdateTime + unscaledDeltaTime;

                if (now > m_LastUpdateTime)
                {
                    m_BytesLoaded   += (long)Math.Ceiling((now - m_LastUpdateTime) * localBandwidth);
                    m_LastUpdateTime = now;
                }
                if (m_BytesLoaded < m_AssetInfo.Size)
                {
                    return(true);
                }
                if (!(Context is IResourceLocation))
                {
                    return(false);
                }
                var    location  = Context as IResourceLocation;
                var    assetPath = m_provideHandle.ResourceManager.TransformInternalId(location);
                object result    = null;

                var pt = m_provideHandle.Type;

                if (pt.IsArray)
                {
                    result = ResourceManagerConfig.CreateArrayResult(pt, AssetDatabaseProvider.LoadAssetsWithSubAssets(assetPath));
                }
                else if (pt.IsGenericType && typeof(IList <>) == pt.GetGenericTypeDefinition())
                {
                    result = ResourceManagerConfig.CreateListResult(pt, AssetDatabaseProvider.LoadAssetsWithSubAssets(assetPath));
                }
                else
                {
                    if (ResourceManagerConfig.ExtractKeyAndSubKey(assetPath, out string mainPath, out string subKey))
                    {
                        var objs = AssetDatabase.LoadAllAssetRepresentationsAtPath(mainPath);
                        foreach (var o in objs)
                        {
                            if (o.name == subKey)
                            {
                                if (pt.IsAssignableFrom(o.GetType()))
                                {
                                    result = o;
                                    break;
                                }
                            }
                        }
                    }
            void LoadImmediate()
            {
                string assetPath = m_ProvideHandle.Location == null ? string.Empty : m_ProvideHandle.Location.InternalId;

                object result = null;

                if (m_ProvideHandle.Type.IsArray)
                {
                    result = ResourceManagerConfig.CreateArrayResult(m_ProvideHandle.Type, AssetDatabase.LoadAllAssetRepresentationsAtPath(assetPath));
                }
                else if (m_ProvideHandle.Type.IsGenericType && typeof(IList <>) == m_ProvideHandle.Type.GetGenericTypeDefinition())
                {
                    result = ResourceManagerConfig.CreateListResult(m_ProvideHandle.Type, AssetDatabase.LoadAllAssetRepresentationsAtPath(assetPath));
                }
                else
                {
                    var i = assetPath.LastIndexOf('[');
                    if (i > 0)
                    {
                        var i2 = assetPath.LastIndexOf(']');
                        if (i2 < i)
                        {
                            m_ProvideHandle.Complete(result, false, new Exception(string.Format("Invalid index format in internal id {0}", assetPath)));
                        }
                        else
                        {
                            var subObjectName = assetPath.Substring(i + 1, i2 - (i + 1));
                            assetPath = assetPath.Substring(0, i);
                            var objs = AssetDatabase.LoadAllAssetRepresentationsAtPath(assetPath);
                            foreach (var o in objs)
                            {
                                if (o.name == subObjectName)
                                {
                                    if (m_ProvideHandle.Type.IsAssignableFrom(o.GetType()))
                                    {
                                        result = o;
                                        break;
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        var obj = AssetDatabase.LoadAssetAtPath(assetPath, m_ProvideHandle.Location.ResourceType);
                        result = obj != null && m_ProvideHandle.Type.IsAssignableFrom(obj.GetType()) ? obj : null;
                    }
                }
                m_ProvideHandle.Complete(result, result != null, null);
            }
Esempio n. 6
0
            private void ActionComplete(AsyncOperation obj)
            {
                object result = null;

                if (m_RequestOperation != null)
                {
                    if (m_ProvideHandle.Type.IsArray)
                    {
                        result = ResourceManagerConfig.CreateArrayResult(m_ProvideHandle.Type, m_RequestOperation.allAssets);
                    }
                    else if (m_ProvideHandle.Type.IsGenericType && typeof(IList <>) == m_ProvideHandle.Type.GetGenericTypeDefinition())
                    {
                        result = ResourceManagerConfig.CreateListResult(m_ProvideHandle.Type, m_RequestOperation.allAssets);
                    }
                    else
                    {
                        if (string.IsNullOrEmpty(subObjectName))
                        {
                            result = (m_RequestOperation.asset != null && m_ProvideHandle.Type.IsAssignableFrom(m_RequestOperation.asset.GetType())) ? m_RequestOperation.asset : null;
                        }
                        else
                        {
                            if (m_RequestOperation.allAssets != null)
                            {
                                foreach (var o in m_RequestOperation.allAssets)
                                {
                                    if (o.name == subObjectName)
                                    {
                                        if (m_ProvideHandle.Type.IsAssignableFrom(o.GetType()))
                                        {
                                            result = o;
                                            break;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                m_ProvideHandle.Complete(result, result != null, null);
            }
            public bool Load(long localBandwidth, long remoteBandwidth, float unscaledDeltaTime)
            {
                if (IsDone)
                {
                    return(false);
                }
                var now = m_LastUpdateTime + unscaledDeltaTime;

                if (now > m_LastUpdateTime)
                {
                    m_BytesLoaded   += (long)Math.Ceiling((now - m_LastUpdateTime) * localBandwidth);
                    m_LastUpdateTime = now;
                }
                if (m_BytesLoaded < m_AssetInfo.Size)
                {
                    return(true);
                }
                if (!(Context is IResourceLocation))
                {
                    return(false);
                }
                var    location  = Context as IResourceLocation;
                var    assetPath = m_AssetInfo.m_AssetPath;
                object result    = null;

                var pt = m_provideHandle.Type;

                if (pt.IsArray)
                {
                    result = ResourceManagerConfig.CreateArrayResult(pt, AssetDatabaseProvider.LoadAssetsWithSubAssets(assetPath));
                }
                else if (pt.IsGenericType && typeof(IList <>) == pt.GetGenericTypeDefinition())
                {
                    result = ResourceManagerConfig.CreateListResult(pt, AssetDatabaseProvider.LoadAssetsWithSubAssets(assetPath));
                }
                else
                {
                    if (ResourceManagerConfig.ExtractKeyAndSubKey(location.InternalId, out string mainPath, out string subKey))
                    {
                        result = AssetDatabaseProvider.LoadAssetSubObject(assetPath, subKey, pt);
                    }
Esempio n. 8
0
            public bool Load(long localBandwidth, long remoteBandwidth)
            {
                if (Time.unscaledTime > m_LastUpdateTime)
                {
                    m_BytesLoaded   += (long)Math.Ceiling((Time.unscaledTime - m_LastUpdateTime) * localBandwidth);
                    m_LastUpdateTime = Time.unscaledDeltaTime;
                }
                if (m_BytesLoaded < m_AssetInfo.Size)
                {
                    return(true);
                }
                if (!(Context is IResourceLocation))
                {
                    return(false);
                }
                var assetPath = (Context as IResourceLocation).InternalId;
                var t         = typeof(TObject);

                if (t.IsArray)
                {
                    SetResult(ResourceManagerConfig.CreateArrayResult <TObject>(AssetDatabase.LoadAllAssetRepresentationsAtPath(assetPath)));
                }
                else if (t.IsGenericType && typeof(IList <>) == t.GetGenericTypeDefinition())
                {
                    SetResult(ResourceManagerConfig.CreateListResult <TObject>(AssetDatabase.LoadAllAssetRepresentationsAtPath(assetPath)));
                }
                else
                {
                    var mainType = AssetDatabase.GetMainAssetTypeAtPath(assetPath);
                    if (mainType == typeof(Texture2D) && typeof(TObject) == typeof(Sprite))
                    {
                        SetResult(AssetDatabase.LoadAssetAtPath(assetPath, typeof(TObject)) as TObject);
                    }
                    else
                    {
                        SetResult(AssetDatabase.LoadAssetAtPath(assetPath, mainType) as TObject);
                    }
                }
                InvokeCompletionEvent();
                return(false);
            }
        public override void Provide(ProvideHandle pi)
        {
            Type t          = pi.Type;
            bool isList     = t.IsGenericType && typeof(IList <>) == t.GetGenericTypeDefinition();
            var  internalId = pi.ResourceManager.TransformInternalId(pi.Location);

            if (t.IsArray || isList)
            {
                object result = null;
                if (t.IsArray)
                {
                    result = ResourceManagerConfig.CreateArrayResult(t, Resources.LoadAll(internalId, t.GetElementType()));
                }
                else
                {
                    result = ResourceManagerConfig.CreateListResult(t, Resources.LoadAll(internalId, t.GetGenericArguments()[0]));
                }

                pi.Complete(result, result != null, result == null ? new Exception($"Unable to load asset of type {pi.Type} from location {pi.Location}.") : null);
            }
            else
            {
                if (ResourceManagerConfig.ExtractKeyAndSubKey(internalId, out string mainPath, out string subKey))
                {
                    var    objs   = Resources.LoadAll(mainPath, pi.Type);
                    object result = null;
                    foreach (var o in objs)
                    {
                        if (o.name == subKey)
                        {
                            if (pi.Type.IsAssignableFrom(o.GetType()))
                            {
                                result = o;
                                break;
                            }
                        }
                    }
                    pi.Complete(result, result != null, result == null ? new Exception($"Unable to load asset of type {pi.Type} from location {pi.Location}.") : null);
                }
            private void ActionComplete(AsyncOperation obj)
            {
                object result = null;
                Type   t      = m_ProvideHandle.Type;

                if (m_RequestOperation != null)
                {
                    if (t.IsArray)
                    {
                        result = ResourceManagerConfig.CreateArrayResult(t, m_RequestOperation.allAssets);
                    }
                    if (t.IsGenericType && typeof(IList <>) == t.GetGenericTypeDefinition())
                    {
                        result = ResourceManagerConfig.CreateListResult(t, m_RequestOperation.allAssets);
                    }
                    else
                    {
                        result = (m_RequestOperation.asset != null && t.IsAssignableFrom(m_RequestOperation.asset.GetType())) ? m_RequestOperation.asset : null;
                    }
                }
                m_ProvideHandle.Complete(result, result != null, null);
            }
            void LoadImmediate()
            {
                if (m_Loaded)
                {
                    return;
                }
                m_Loaded = true;
                string assetPath = m_ProvideHandle.ResourceManager.TransformInternalId(m_ProvideHandle.Location);
                object result    = null;

                if (m_ProvideHandle.Type.IsArray)
                {
                    result = ResourceManagerConfig.CreateArrayResult(m_ProvideHandle.Type, LoadAssetsWithSubAssets(assetPath));
                }
                else if (m_ProvideHandle.Type.IsGenericType && typeof(IList <>) == m_ProvideHandle.Type.GetGenericTypeDefinition())
                {
                    result = ResourceManagerConfig.CreateListResult(m_ProvideHandle.Type, LoadAssetsWithSubAssets(assetPath));
                }
                else
                {
                    if (ResourceManagerConfig.ExtractKeyAndSubKey(assetPath, out string mainPath, out string subKey))
                    {
                        result = LoadAssetSubObject(mainPath, subKey, m_ProvideHandle.Type);
                    }
        public override void Provide(ProvideHandle pi)
        {
            Type t      = pi.Type;
            bool isList = t.IsGenericType && typeof(IList <>) == t.GetGenericTypeDefinition();

            if (t.IsArray || isList)
            {
                object result = null;
                if (t.IsArray)
                {
                    result = ResourceManagerConfig.CreateArrayResult(t, Resources.LoadAll(pi.Location.InternalId, t.GetElementType()));
                }
                else
                {
                    result = ResourceManagerConfig.CreateListResult(t, Resources.LoadAll(pi.Location.InternalId, t.GetGenericArguments()[0]));
                }

                pi.Complete(result, result != null, null);
            }
            else
            {
                new InternalOp().Start(pi);
            }
        }
            public bool Load(long localBandwidth, long remoteBandwidth)
            {
                if (Time.unscaledTime > m_LastUpdateTime)
                {
                    m_BytesLoaded   += (long)Math.Ceiling((Time.unscaledTime - m_LastUpdateTime) * localBandwidth);
                    m_LastUpdateTime = Time.unscaledDeltaTime;
                }
                if (m_BytesLoaded < m_AssetInfo.Size)
                {
                    return(true);
                }
                if (!(Context is IResourceLocation))
                {
                    return(false);
                }
                var    location  = Context as IResourceLocation;
                var    assetPath = m_provideHandle.ResourceManager.TransformInternalId(location);
                object result    = null;

                var pt = m_provideHandle.Type;

                if (pt.IsArray)
                {
                    result = ResourceManagerConfig.CreateArrayResult(pt, AssetDatabase.LoadAllAssetRepresentationsAtPath(assetPath));
                }
                else if (pt.IsGenericType && typeof(IList <>) == pt.GetGenericTypeDefinition())
                {
                    result = ResourceManagerConfig.CreateListResult(pt, AssetDatabase.LoadAllAssetRepresentationsAtPath(assetPath));
                }
                else
                {
                    var i = assetPath.LastIndexOf('[');
                    if (i > 0)
                    {
                        var i2 = assetPath.LastIndexOf(']');
                        if (i2 < i)
                        {
                            Debug.LogErrorFormat("Invalid index format in internal id {0}", assetPath);
                        }
                        else
                        {
                            var subObjectName = assetPath.Substring(i + 1, i2 - (i + 1));
                            assetPath = assetPath.Substring(0, i);
                            var objs = AssetDatabase.LoadAllAssetRepresentationsAtPath(assetPath);
                            foreach (var o in objs)
                            {
                                if (o.name == subObjectName)
                                {
                                    if (pt.IsAssignableFrom(o.GetType()))
                                    {
                                        result = o;
                                        break;
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        var obj = AssetDatabase.LoadAssetAtPath(assetPath, location.ResourceType);
                        result = obj != null && pt.IsAssignableFrom(obj.GetType()) ? obj : null;
                    }
                }
                SetResult(result);
                InvokeCompletionEvent();
                return(false);
            }