// TextMeshProTrigger.csと合わせる private static Component CreateInputField(GameObject gameObject, IAssetLoader assetLoader) { var inputField = gameObject.AddComponent <InputField>(); inputField.transition = Selectable.Transition.None; var texts = gameObject.GetComponentsInDirectChildren <Text>(); if (texts.Length > 0) { var text = texts[0]; var originalText = text.text; inputField.text = string.Empty; text.text = string.Empty; inputField.textComponent = text; if (inputField.placeholder == null) { var placeholder = Object.Instantiate(text.gameObject, text.transform, true); var placeHolderText = placeholder.GetComponent <Text>(); inputField.placeholder = placeHolderText; placeholder.name = "Placeholder"; placeHolderText.text = originalText; } } return(inputField); }
private static Image CreateImage(GameObject gameObject, IAssetLoader assetLoader, ImageComponent imageComponent) { var image = gameObject.AddComponent <Image>(); UpdateImage(gameObject, image, imageComponent, assetLoader); return(image); }
private static Component CreateGridLayout(GameObject gameObject, IAssetLoader assetLoader, GridLayoutComponent gridLayoutComponent) { var gridLayoutGroup = gameObject.AddComponent <GridLayoutGroup>(); var spacing = Vector2.zero; if (gridLayoutComponent.SpacingX != null) { spacing.x = gridLayoutComponent.SpacingX.Value; } if (gridLayoutComponent.SpacingY != null) { spacing.y = gridLayoutComponent.SpacingY.Value; } gridLayoutGroup.spacing = spacing; var children = gameObject.GetDirectChildren(); if (children.Length == 1) { var childRect = RectTransformUtility.CalculateRelativeRectTransformBounds(children[0].GetComponent <RectTransform>()); var cellSize = Vector2.zero; cellSize.x = childRect.size.x; cellSize.y = childRect.size.y; gridLayoutGroup.cellSize = cellSize; } else { Debug.LogWarning($"need children.Length({children.Length}) == 1"); } return(gridLayoutGroup); }
private static Component CreateHorizontalScrollbar(GameObject gameObject, IAssetLoader assetLoader, HorizontalScrollbarComponent horizontalScrollbarComponent) { var scrollbar = gameObject.AddComponent <Scrollbar>(); scrollbar.transition = Selectable.Transition.None; scrollbar.direction = Scrollbar.Direction.RightToLeft; if (scrollbar.handleRect == null) { var handle = new GameObject("Handle"); var handleRect = handle.AddComponent <RectTransform>(); handleRect.SetParent(gameObject.transform); handleRect.anchorMin = Vector2.zero; handleRect.anchorMax = Vector2.one; handleRect.anchoredPosition = Vector2.zero; handleRect.sizeDelta = Vector2.zero; scrollbar.handleRect = handleRect; handle.AddComponent <Image>(); } if (horizontalScrollbarComponent.Image != null) { var image = scrollbar.handleRect.GetComponent <Image>(); UpdateImage(gameObject, image, horizontalScrollbarComponent.Image, assetLoader); } return(scrollbar); }
public TestServices With( IAssetLoader assetLoader = null, IFocusManager focusManager = null, IInputManager inputManager = null, Func <IKeyboardDevice> keyboardDevice = null, ILayoutManager layoutManager = null, IRuntimePlatform platform = null, IRenderer renderer = null, IPlatformRenderInterface renderInterface = null, IRenderLoop renderLoop = null, IStandardCursorFactory standardCursorFactory = null, IStyler styler = null, Func <Styles> theme = null, IPlatformThreadingInterface threadingInterface = null, IWindowImpl windowImpl = null, IWindowingPlatform windowingPlatform = null) { return(new TestServices( assetLoader: assetLoader ?? AssetLoader, focusManager: focusManager ?? FocusManager, inputManager: inputManager ?? InputManager, keyboardDevice: keyboardDevice ?? KeyboardDevice, layoutManager: layoutManager ?? LayoutManager, platform: platform ?? Platform, renderer: renderer ?? Renderer, renderInterface: renderInterface ?? RenderInterface, renderLoop: renderLoop ?? RenderLoop, standardCursorFactory: standardCursorFactory ?? StandardCursorFactory, styler: styler ?? Styler, theme: theme ?? Theme, threadingInterface: threadingInterface ?? ThreadingInterface, windowImpl: windowImpl ?? WindowImpl, windowingPlatform: windowingPlatform ?? WindowingPlatform)); }
protected async void LoadGame(bool isSimulate = true) { var moduleGroupTypeConfigPath = AssetPath.GetAssetPathFromResourcePath(Constant.MODULE_GROUP_TYPE_CONFIG_PATH); var moduleGroupTypeConfig = Resources.Load <LayerMaskConfig>(moduleGroupTypeConfigPath); var worldMgr = WorldManager.Instance; worldMgr.Module.Init(moduleGroupTypeConfig); var unitTypeConfigPath = AssetPath.GetAssetPathFromResourcePath(Constant.UNIT_TYPE_CONFIG_PATH); var unitTypeConfig = Resources.Load <LayerConfig>(unitTypeConfigPath); worldMgr.Unit.Init(unitTypeConfig); RegisterECSModule(); IAssetLoader customLoader = null; #if UNITY_EDITOR if (isSimulate) { customLoader = new SimulateAssetLoader(); } #endif worldMgr.Factory.CreateAssetProcess("http://localhost:8000/AssetBundles"); await AssetProcess.Init(customLoader); worldMgr.Factory.CreateUIProcess(); RegisterGameModule(); StartGame(); }
Bitmap AddOrGetFromCache(Uri uri, IAssetLoader assets, Uri fallbackUri = null) { if (_cache.TryGetValue(uri, out Bitmap image)) { return(image); } try { image = new Bitmap(assets.Open(uri)); _cache.Set(uri, image); } catch (FileNotFoundException) { if (fallbackUri == null) { return(null); } if (_cache.TryGetValue(fallbackUri, out image)) { return(image); } image = new Bitmap(assets.Open(fallbackUri)); _cache.Set(fallbackUri, image); } return(image); }
public TestServices With( IAssetLoader assetLoader = null, IInputManager inputManager = null, ILayoutManager layoutManager = null, IPclPlatformWrapper platformWrapper = null, IPlatformRenderInterface renderInterface = null, IStandardCursorFactory standardCursorFactory = null, IStyler styler = null, Func <Styles> theme = null, IPlatformThreadingInterface threadingInterface = null, IWindowImpl windowImpl = null, IWindowingPlatform windowingPlatform = null) { return(new TestServices( assetLoader: assetLoader ?? AssetLoader, inputManager: inputManager ?? InputManager, layoutManager: layoutManager ?? LayoutManager, platformWrapper: platformWrapper ?? PlatformWrapper, renderInterface: renderInterface ?? RenderInterface, standardCursorFactory: standardCursorFactory ?? StandardCursorFactory, styler: styler ?? Styler, theme: theme ?? Theme, threadingInterface: threadingInterface ?? ThreadingInterface, windowImpl: windowImpl ?? WindowImpl, windowingPlatform: windowingPlatform ?? WindowingPlatform)); }
public TestServices( IAssetLoader assetLoader = null, IFocusManager focusManager = null, IInputManager inputManager = null, Func<IKeyboardDevice> keyboardDevice = null, ILayoutManager layoutManager = null, IPclPlatformWrapper platformWrapper = null, IPlatformRenderInterface renderInterface = null, IStandardCursorFactory standardCursorFactory = null, IStyler styler = null, Func<Styles> theme = null, IPlatformThreadingInterface threadingInterface = null, IWindowImpl windowImpl = null, IWindowingPlatform windowingPlatform = null) { AssetLoader = assetLoader; FocusManager = focusManager; InputManager = inputManager; KeyboardDevice = keyboardDevice; LayoutManager = layoutManager; PlatformWrapper = platformWrapper; RenderInterface = renderInterface; StandardCursorFactory = standardCursorFactory; Styler = styler; Theme = theme; ThreadingInterface = threadingInterface; WindowImpl = windowImpl; WindowingPlatform = windowingPlatform; }
/// <summary> /// Resource异步加载; /// </summary> /// <typeparam name="T">ctrl</typeparam> /// <param name="type">资源类型</param> /// <param name="assetName">资源名字</param> /// <param name="action">资源回调</param> /// <param name="progress">进度回调</param> /// <returns></returns> public IEnumerator LoadResourceAsync <T>(AssetType type, string assetName, Action <T> action, Action <float> progress) where T : Object { string path = FilePathUtil.GetResourcePath(type, assetName); IAssetLoader <T> loader = CreateLoader <T>(type); T ctrl = null; if (path != null) { ResourceRequest request = Resources.LoadAsync <T>(path); while (request.progress < 0.99) { if (progress != null) { progress(request.progress); } yield return(null); } while (!request.isDone) { yield return(null); } ctrl = loader.GetAsset(request.asset as T); } if (action != null) { action(ctrl); } else { Debug.LogError(string.Format("[ResourceMgr]LoadResourceAsync Load Asset {0} failure!", assetName + "." + type.ToString())); } }
public TestServices With( IAssetLoader assetLoader = null, IInputManager inputManager = null, ILayoutManager layoutManager = null, IPclPlatformWrapper platformWrapper = null, IPlatformRenderInterface renderInterface = null, IStandardCursorFactory standardCursorFactory = null, IStyler styler = null, Func<Styles> theme = null, IPlatformThreadingInterface threadingInterface = null, IWindowImpl windowImpl = null, IWindowingPlatform windowingPlatform = null) { return new TestServices( assetLoader: assetLoader ?? AssetLoader, inputManager: inputManager ?? InputManager, layoutManager: layoutManager ?? LayoutManager, platformWrapper: platformWrapper ?? PlatformWrapper, renderInterface: renderInterface ?? RenderInterface, standardCursorFactory: standardCursorFactory ?? StandardCursorFactory, styler: styler ?? Styler, theme: theme ?? Theme, threadingInterface: threadingInterface ?? ThreadingInterface, windowImpl: windowImpl ?? WindowImpl, windowingPlatform: windowingPlatform ?? WindowingPlatform); }
public TestServices( IAssetLoader assetLoader = null, IFocusManager focusManager = null, IInputManager inputManager = null, Func <IKeyboardDevice> keyboardDevice = null, ILayoutManager layoutManager = null, IRuntimePlatform platform = null, IRenderer renderer = null, IPlatformRenderInterface renderInterface = null, IRenderLoop renderLoop = null, IStandardCursorFactory standardCursorFactory = null, IStyler styler = null, Func <Styles> theme = null, IPlatformThreadingInterface threadingInterface = null, IWindowImpl windowImpl = null, IWindowingPlatform windowingPlatform = null) { AssetLoader = assetLoader; FocusManager = focusManager; InputManager = inputManager; KeyboardDevice = keyboardDevice; LayoutManager = layoutManager; Platform = platform; Renderer = renderer; RenderInterface = renderInterface; RenderLoop = renderLoop; StandardCursorFactory = standardCursorFactory; Styler = styler; Theme = theme; ThreadingInterface = threadingInterface; WindowImpl = windowImpl; WindowingPlatform = windowingPlatform; }
/// <summary> /// Resource异步加载; /// </summary> /// <typeparam name="T">ctrl</typeparam> /// <param name="type">资源类型</param> /// <param name="assetName">资源名字</param> /// <param name="action">资源回调</param> /// <param name="progress">进度回调</param> /// <returns></returns> public IEnumerator <float> LoadResAsync <T>(AssetType type, string assetName, Action <T> action, Action <float> progress) where T : Object { string path = FilePathUtility.GetResourcePath(type, assetName); IAssetLoader <T> loader = CreateLoader <T>(type); T ctrl = null; bool isInstance = false; if (path != null) { ResourceRequest request = Resources.LoadAsync <T>(path); while (request.progress < 0.99) { if (progress != null) { progress(request.progress); } yield return(Timing.WaitForOneFrame); } while (!request.isDone) { yield return(Timing.WaitForOneFrame); } ctrl = loader.GetAsset(request.asset as T, out isInstance); } if (action != null) { action(ctrl); } else { LogUtil.LogUtility.PrintError(string.Format("[ResourceMgr]LoadResAsync Load Asset {0} failure!", assetName + "." + type.ToString())); } }
/// <summary> /// Asset sync load from AssetBundle; /// </summary> /// <typeparam name="T">ctrl</typeparam> /// <param name="type">资源类型</param> /// <param name="assetName">资源名字</param> /// <returns>ctrl</returns> public T LoadAssetSync <T>(AssetType type, string assetName) where T : Object { T ctrl = null; IAssetLoader <T> loader = CreateLoader <T>(type); AssetBundle assetBundle = AssetBundleMgr.Instance.LoadAssetBundleSync(type, assetName); bool isInstance = false; if (assetBundle != null) { T tempObject = assetBundle.LoadAsset <T>(assetName); ctrl = loader.GetAsset(tempObject, out isInstance); } if (ctrl == null) { LogUtil.LogUtility.PrintError(string.Format("[ResourceMgr]LoadAssetFromAssetBundleSync Load Asset {0} failure!", assetName + "." + type.ToString())); } else { if (isInstance) { var go = ctrl as GameObject; if (go) { UnityUtility.AddOrGetComponent <AssetBundleTag>(go, (tag) =>//自动卸载; { tag.AssetBundleName = assetName; tag.Type = type; tag.IsClone = false; }); } } } return(ctrl); }
public TextDatabase(IAssetLoader assetLoader, GameState gameState) { _config = gameState.Config; _player = gameState.Player; var deserializer = new Deserializer(); var sr = new StringReader(assetLoader.Get <string>("text.yml")); var data = deserializer.Deserialize <Dictionary <string, Dictionary <Languages, string> > >(sr); _languages = new Dictionary <Languages, Language>(); foreach (Languages language in Enum.GetValues(typeof(Languages))) { if (!data["LanguageFont"].ContainsKey(language)) { continue; } if (!_languages.ContainsKey(language)) { _languages.Add(language, new Language(data["Language"][language], assetLoader.Get <SpriteFont>($"ui/fonts/{data["LanguageFont"][language]}"))); } foreach (var kvp in data.Where(kvp => data[kvp.Key].ContainsKey(language))) { _languages[language].Text.Add(kvp.Key, kvp.Value[language]); } } sr.Dispose(); }
private T Load <T>(string assetName, IAssetLoader <T> assetLoader, string assetSubdirectory, IEnumerable <string> assetFileExtensions) { var filepath = (assetSubdirectory != null) // if subdir is null then the asset is placed in the root of the content directory ? (Path.Combine(AssetDirectory, assetSubdirectory, assetName)) : (Path.Combine(AssetDirectory, assetName)); if (!File.Exists(filepath)) { throw new FileNotFoundException($"Unable to find specified file: {filepath}"); } // find if extension of the file is supported if (assetFileExtensions.All(s => Path.GetExtension(filepath) != s)) { throw new Exception("Cannot load an asset with this extension"); } var asset = assetLoader.LoadAsset(filepath); _loadedAssets.Add(assetName, asset); return(asset); }
public AssetManager(IServiceProvider serviceProvider) { _serviceProvider = serviceProvider; _assetLoader = new AssetLoader(); _assetBatches = new Dictionary <string, IAssetBatch>(); _assetDict = new Dictionary <string, IAsset>(); }
protected virtual object LoadAsset(string id, Type type, IAssetLoadParameters parameters) { IAssetLoader loader = this.GetLoaderByAsset(id); object asset = loader.Load(id, type, parameters, Context); return(asset); }
protected virtual Task <object> LoadAssetAsync(string id, Type type, IAssetLoadParameters parameters) { IAssetLoader loader = this.GetLoaderByAsset(id); Task <object> task = loader.LoadAsync(id, type, parameters, Context); return(task); }
protected virtual Task UnloadAssetAsync(string id, object asset, IAssetUnloadParameters parameters) { IAssetLoader loader = this.GetLoaderByAsset(id); Task task = loader.UnloadAsync(id, asset, parameters, Context); return(task); }
public Overworld(SpriteBatch spriteBatch, IAssetLoader assetLoader, Random random) { _spriteBatch = spriteBatch; _assetLoader = assetLoader; _random = random; _maps = new Dictionary <string, OverworldMap>(); }
/// <summary> /// Apply <paramref name="configurer"/> on every part of the asset loader. /// </summary> /// <param name="assetLoader"></param> /// <param name="configurer">delegate to apply on every part</param> /// <returns>assetLoader</returns> public static IAssetLoader ConfigureParts(this IAssetLoader assetLoader, Action <IAssetLoaderPartOptions> configurer) { foreach (var part in assetLoader.LoaderParts) { configurer(part.Options); } return(assetLoader); }
public static Task <GameObject> InstantiateAsync(this IAssetLoader loader, string assetName, Transform parent = null, object lifetime = null) { return(loader.LoadAssetAsync <GameObject>(assetName, lifetime) .ContinueWith(t => { return Object.Instantiate(t.Result, parent); })); }
public virtual T Load(IAssetLoader loader) { if (Asset == null) { Asset = loader.LoadAsset <T>(Path); } return(Asset); }
public ActorRenderer(ITagContainer diContainer) : base(diContainer.GetTag <DefaultEcs.World>(), CreateEntityContainer, useBuffer: true) { this.diContainer = diContainer; camera = diContainer.GetTag <Camera>(); textureLoader = diContainer.GetTag <IAssetLoader <Texture> >(); addSubscription = World.SubscribeComponentAdded <components.ActorPart>(HandleAddedComponent); removeSubscription = World.SubscribeComponentRemoved <ModelSkinnedMaterial[]>(HandleRemovedComponent); }
public static bool Startup() { #if UNITY_EDITOR && LITE_USE_INTERNAL_ASSET Loader_ = new AssetInternalLoader(); #else Loader_ = new AssetBundleLoader(); #endif return(Loader_.Startup()); }
public CityProvider(IAssetLoader assetLoader) { using (var reader = new StreamReader(assetLoader.OpenAsset("city.list.json"))) { var contents = reader.ReadToEnd(); var cities = JsonConvert.DeserializeObject <City[]>(contents); _cities = cities.ToDictionary(c => c.Id); } }
public ModAssetRepository(AssetReaderCollection assetReaderCollection, IAssetLoader syncLoader, IAsyncAssetLoader asyncLoader, IEnumerable <IContentSource> sources = null) : base(syncLoader, asyncLoader) { AssetReaderCollection = assetReaderCollection; if (sources != null) { SetSources(sources, AssetRequestMode.DoNotLoad); } }
public void InitMode(AssetLoadMode mode, float duration = 120f, float cacheStayTime = 100f) { Debug.LogFormat("[AssetManager]初始化 当前加载模式:{0} 定时清理缓冲间隔:{1}s 缓存驻留时间:{2}s", mode, duration, cacheStayTime); LoadMode = mode; ClearCacheDuration = duration; CacheDataStayTime = cacheStayTime; editorLoader = new EditorAssetLoader(); abLoader = new AssetBundleLoader(GameConfigs.LocalABRootPath, GameConfigs.LocalManifestPath); }
private static Component CreateHorizontalList(GameObject gameObject, IAssetLoader assetLoader, HorizontalListComponent horizontalListComponent) { var scrollRect = gameObject.AddComponent <ScrollRect>(); scrollRect.horizontal = true; scrollRect.vertical = false; gameObject.AddComponent <RectMask2D>(); var content = new GameObject("Content"); content.transform.SetParent(gameObject.transform); var contentRectTransform = content.AddComponent <RectTransform>(); contentRectTransform.pivot = new Vector2(0f, 0.5f); contentRectTransform.sizeDelta = gameObject.GetComponent <RectTransform>().sizeDelta; contentRectTransform.anchoredPosition = new Vector2(contentRectTransform.sizeDelta.x / 2f, 0f); var image = content.AddComponent <Image>(); image.color = Color.clear; var horizontalLayoutGroup = content.AddComponent <HorizontalLayoutGroup>(); horizontalLayoutGroup.childForceExpandWidth = false; horizontalLayoutGroup.childForceExpandHeight = false; if (horizontalListComponent.Spacing != null) { horizontalLayoutGroup.spacing = horizontalListComponent.Spacing.Value; } if (horizontalListComponent.PaddingLeft != null) { horizontalLayoutGroup.padding.left = Mathf.RoundToInt(horizontalListComponent.PaddingLeft.Value); } if (horizontalListComponent.PaddingRight != null) { horizontalLayoutGroup.padding.right = Mathf.RoundToInt(horizontalListComponent.PaddingRight.Value); } var contentSizeFitter = content.AddComponent <ContentSizeFitter>(); contentSizeFitter.horizontalFit = ContentSizeFitter.FitMode.PreferredSize; contentSizeFitter.verticalFit = ContentSizeFitter.FitMode.Unconstrained; scrollRect.content = contentRectTransform; var scrollbars = gameObject.GetComponentsInDirectChildren <Scrollbar>(); if (scrollbars.Length > 0) { var scrollbar = scrollbars[0]; scrollRect.horizontalScrollbar = scrollbar; } return(scrollRect); }
public AssetChangedTriggerHandler(IScriptEngine scriptEngine, IAssetLoader assetLoader) { Guard.NotNull(scriptEngine); Guard.NotNull(assetLoader); this.scriptEngine = scriptEngine; this.assetLoader = assetLoader; }
public AssetChangedTriggerHandler( IScriptEngine scriptEngine, IAssetLoader assetLoader, IAssetRepository assetRepository) { this.scriptEngine = scriptEngine; this.assetLoader = assetLoader; this.assetRepository = assetRepository; }
/// <summary> /// Initializes a new instance of the <see cref="GameAssetManagerProvider"/> class. /// </summary> /// <param name="kernel"> /// The kernel. /// </param> /// <param name="profilers"> /// The profilers. /// </param> /// <param name="rawLoader"> /// The raw loader. /// </param> /// <param name="rawSaver"> /// The raw saver. /// </param> /// <param name="loaders"> /// The loaders. /// </param> /// <param name="savers"> /// The savers. /// </param> /// <param name="transparentAssetCompiler"> /// The transparent asset compiler. /// </param> public GameAssetManagerProvider( IKernel kernel, IProfiler[] profilers, IRawAssetLoader rawLoader, IRawAssetSaver rawSaver, IAssetLoader[] loaders, IAssetSaver[] savers, ITransparentAssetCompiler transparentAssetCompiler) { this.m_AssetManager = new LocalAssetManager( kernel, profilers, rawLoader, rawSaver, loaders, savers, transparentAssetCompiler); }
/// <summary> /// Initializes a new instance of the <see cref="GameAssetManagerProvider"/> class. /// </summary> /// <param name="kernel"> /// The kernel. /// </param> /// <param name="profilers"> /// The profilers. /// </param> /// <param name="rawLoader"> /// The raw loader. /// </param> /// <param name="rawSaver"> /// The raw saver. /// </param> /// <param name="loaders"> /// The loaders. /// </param> /// <param name="savers"> /// The savers. /// </param> /// <param name="transparentAssetCompiler"> /// The transparent asset compiler. /// </param> public ReloadableGameAssetManagerProvider( IKernel kernel, IProfiler[] profilers, IRawAssetLoader rawLoader, IRawAssetSaver rawSaver, IAssetLoader[] loaders, IAssetSaver[] savers, ITransparentAssetCompiler transparentAssetCompiler) { this.m_AssetManager = new LocalAssetManager( kernel, profilers, rawLoader, rawSaver, loaders, savers, transparentAssetCompiler); this.m_AssetManager.GenerateRuntimeProxies = true; }
/// <summary> /// Setup constructor /// </summary> /// <param name="loader">Asset loader</param> /// <param name="source">Asset source</param> /// <param name="parameters">Loading parameters</param> public LoadState( IAssetLoader loader, ISource source, LoadParameters parameters ) { m_Loader = loader; m_Source = source; m_Parameters = parameters ?? loader.CreateDefaultParameters( false ); }
public AssetServiceBase(IConfigSource config, string configName) : base(config) { if (configName != string.Empty) m_ConfigName = configName; string dllName = String.Empty; string connString = String.Empty; // // Try reading the [AssetService] section, if it exists // IConfig assetConfig = config.Configs[m_ConfigName]; if (assetConfig != null) { dllName = assetConfig.GetString("StorageProvider", dllName); connString = assetConfig.GetString("ConnectionString", connString); } // // Try reading the [DatabaseService] section, if it exists // IConfig dbConfig = config.Configs["DatabaseService"]; if (dbConfig != null) { if (dllName == String.Empty) dllName = dbConfig.GetString("StorageProvider", String.Empty); if (connString == String.Empty) connString = dbConfig.GetString("ConnectionString", String.Empty); } // // We tried, but this doesn't exist. We can't proceed. // if (dllName.Equals(String.Empty)) throw new Exception("No StorageProvider configured"); m_Database = LoadPlugin<IAssetDataPlugin>(dllName); if (m_Database == null) throw new Exception(string.Format("Could not find a storage interface in the module {0}", dllName)); m_Database.Initialise(connString); string loaderName = assetConfig.GetString("DefaultAssetLoader", String.Empty); if (loaderName != String.Empty) { m_AssetLoader = LoadPlugin<IAssetLoader>(loaderName); if (m_AssetLoader == null) throw new Exception(string.Format("Asset loader could not be loaded from {0}", loaderName)); } }
public FSAssetConnector(IConfigSource config, string configName) : base(config) { m_FsckProgram = string.Empty; MainConsole.Instance.Commands.AddCommand("fs", false, "show assets", "show assets", "Show asset stats", HandleShowAssets); MainConsole.Instance.Commands.AddCommand("fs", false, "show digest", "show digest <ID>", "Show asset digest", HandleShowDigest); MainConsole.Instance.Commands.AddCommand("fs", false, "delete asset", "delete asset <ID>", "Delete asset from database", HandleDeleteAsset); MainConsole.Instance.Commands.AddCommand("fs", false, "import", "import <conn> <table> [<start> <count>]", "Import legacy assets", HandleImportAssets); MainConsole.Instance.Commands.AddCommand("fs", false, "force import", "force import <conn> <table> [<start> <count>]", "Import legacy assets, overwriting current content", HandleImportAssets); IConfig assetConfig = config.Configs[configName]; if (assetConfig == null) { throw new Exception("No AssetService configuration"); } m_ConnectionString = assetConfig.GetString("ConnectionString", string.Empty); if (m_ConnectionString == string.Empty) { throw new Exception("Missing database connection string"); } m_Realm = assetConfig.GetString("Realm", "fsassets"); m_DataConnector = new FSAssetConnectorData(m_ConnectionString, m_Realm); string str = assetConfig.GetString("FallbackService", string.Empty); if (str != string.Empty) { object[] args = new object[] { config }; m_FallbackService = LoadPlugin<IAssetService>(str, args); if (m_FallbackService != null) { m_log.Info("[FALLBACK]: Fallback service loaded"); } else { m_log.Error("[FALLBACK]: Failed to load fallback service"); } } m_SpoolDirectory = assetConfig.GetString("SpoolDirectory", "/tmp"); string spoolTmp = Path.Combine(m_SpoolDirectory, "spool"); Directory.CreateDirectory(spoolTmp); m_FSBase = assetConfig.GetString("BaseDirectory", String.Empty); if (m_FSBase == String.Empty) { m_log.ErrorFormat("[ASSET]: BaseDirectory not specified"); throw new Exception("Configuration error"); } string loader = assetConfig.GetString("DefaultAssetLoader", string.Empty); if (loader != string.Empty) { m_AssetLoader = LoadPlugin<IAssetLoader>(loader); string loaderArgs = assetConfig.GetString("AssetLoaderArgs", string.Empty); m_log.InfoFormat("[ASSET]: Loading default asset set from {0}", loaderArgs); m_AssetLoader.ForEachDefaultXmlAsset(loaderArgs, delegate(AssetBase a) { Store(a, false); }); } m_log.Info("[ASSET]: FS asset service enabled"); m_WriterThread = new Thread(Writer); m_WriterThread.Start(); m_StatsThread = new Thread(Stats); m_StatsThread.Start(); }
public TestServices With( IAssetLoader assetLoader = null, IFocusManager focusManager = null, IInputManager inputManager = null, Func<IKeyboardDevice> keyboardDevice = null, ILayoutManager layoutManager = null, IRuntimePlatform platform = null, IRenderer renderer = null, IPlatformRenderInterface renderInterface = null, IRenderLoop renderLoop = null, IStandardCursorFactory standardCursorFactory = null, IStyler styler = null, Func<Styles> theme = null, IPlatformThreadingInterface threadingInterface = null, IWindowImpl windowImpl = null, IWindowingPlatform windowingPlatform = null) { return new TestServices( assetLoader: assetLoader ?? AssetLoader, focusManager: focusManager ?? FocusManager, inputManager: inputManager ?? InputManager, keyboardDevice: keyboardDevice ?? KeyboardDevice, layoutManager: layoutManager ?? LayoutManager, platform: platform ?? Platform, renderer: renderer ?? Renderer, renderInterface: renderInterface ?? RenderInterface, renderLoop: renderLoop ?? RenderLoop, standardCursorFactory: standardCursorFactory ?? StandardCursorFactory, styler: styler ?? Styler, theme: theme ?? Theme, threadingInterface: threadingInterface ?? ThreadingInterface, windowImpl: windowImpl ?? WindowImpl, windowingPlatform: windowingPlatform ?? WindowingPlatform); }
public AssetManagerWorld( IAssetManagerProvider assetManagerProvider, I2DRenderUtilities renderUtilities, ISkin skin, IAssetLoader[] loaders) { this.Entities = new List<IEntity>(); this.m_Skin = skin; this.m_Start = DateTime.Now; // Add the asset manager layout. var entity = new CanvasEntity(this.m_Skin); this.m_Layout = new AssetManagerLayout(assetManagerProvider, renderUtilities, loaders, entity); entity.Canvas = this.m_Layout; this.Entities.Add(entity); this.m_Layout.MarkDirty.Click += (sender, e) => { foreach (var asset in this.AssetManager.GetAll()) this.AssetManager.Dirty(asset.Name); }; this.m_Layout.Bake.Click += (sender, e) => { if (this.m_CurrentEditor != null) this.m_CurrentEditor.Bake(this.AssetManager); var item = this.m_Layout.AssetTree.SelectedItem as AssetTreeItem; if (item == null) return; this.AssetManager.Bake(item.Asset); }; this.m_Layout.AssetTree.SelectedItemChanged += (sender, e) => { if (this.m_CurrentEditor != null) this.m_CurrentEditor.FinishLayout(this.m_Layout.EditorContainer, this.AssetManager); var item = this.m_Layout.AssetTree.SelectedItem as AssetTreeItem; if (item != null && m_Editors.ContainsKey(item.Asset.GetType())) { this.m_CurrentEditor = m_Editors[item.Asset.GetType()]; this.m_CurrentEditor.SetAsset(item.Asset); this.m_CurrentEditor.BuildLayout(this.m_Layout.EditorContainer, this.AssetManager); } else { this.m_CurrentEditor = null; this.m_Layout.EditorContainer.SetChild( new Label { Text = "No editor for " + (item == null ? "folders" : item.Asset.GetType().Name) }); } }; this.m_Layout.ExitClick += (sender, e) => { Environment.Exit(0); }; this.m_Layout.BakeAllClick += (sender, e) => { foreach (var asset in this.AssetManager.GetAll()) this.AssetManager.Bake(asset); }; this.m_Layout.CreateNameEntered += (sender, e) => { var asset = e.Loader.GetNew(this.AssetManager, this.m_Layout.PromptName.Text); assetManagerProvider.GetAssetManager(false).Bake(asset); this.m_Layout.AssetTree.AddChild(new AssetTreeItem { Text = this.m_Layout.PromptName.Text, Asset = asset }); }; }
/// <summary> /// Adds an asset loader /// </summary> /// <param name="loader">Loader to add</param> public void AddLoader( IAssetLoader loader ) { m_Loaders.Add( loader ); }
public XAssetServiceBase(IConfigSource config, string configName) : base(config) { string dllName = String.Empty; string connString = String.Empty; // // Try reading the [AssetService] section first, if it exists // IConfig assetConfig = config.Configs[configName]; if (assetConfig != null) { dllName = assetConfig.GetString("StorageProvider", dllName); connString = assetConfig.GetString("ConnectionString", connString); } // // Try reading the [DatabaseService] section, if it exists // IConfig dbConfig = config.Configs["DatabaseService"]; if (dbConfig != null) { if (dllName == String.Empty) dllName = dbConfig.GetString("StorageProvider", String.Empty); if (connString == String.Empty) connString = dbConfig.GetString("ConnectionString", String.Empty); } // // We tried, but this doesn't exist. We can't proceed. // if (dllName.Equals(String.Empty)) throw new Exception("No StorageProvider configured"); m_Database = LoadPlugin<IXAssetDataPlugin>(dllName); if (m_Database == null) throw new Exception("Could not find a storage interface in the given module"); string chainedAssetServiceDesignator = assetConfig.GetString("ChainedServiceModule", null); if (chainedAssetServiceDesignator != null) { m_log.InfoFormat( "[XASSET SERVICE BASE]: Loading chained asset service from {0}", chainedAssetServiceDesignator); Object[] args = new Object[] { config, configName }; m_ChainedAssetService = ServerUtils.LoadPlugin<IAssetService>(chainedAssetServiceDesignator, args); if (!HasChainedAssetService) throw new Exception( String.Format("Failed to load ChainedAssetService from {0}", chainedAssetServiceDesignator)); } m_Database.Initialise(connString); if (HasChainedAssetService) { string loaderName = assetConfig.GetString("DefaultAssetLoader", String.Empty); if (loaderName != String.Empty) { m_AssetLoader = LoadPlugin<IAssetLoader>(loaderName); if (m_AssetLoader == null) throw new Exception("Asset loader could not be loaded"); } } }
/// <summary> /// Queues a loader to load as required by the system. Queue /// is implemented as a first in/first out approach to /// loading. /// </summary> public void Queue(IAssetLoader loader) { queue.InsertLast(loader); queueCount++; }
public CreateEventArgs(IAssetLoader loader) { this.Loader = loader; }
public AssetManagerLayout( IAssetManagerProvider assetManagerProvider, I2DRenderUtilities renderUtilities, IAssetLoader[] loaders, CanvasEntity canvasEntity) { this.m_CanvasEntity = canvasEntity; var toolbarContainer = new HorizontalContainer(); toolbarContainer.AddChild(new SingleContainer(), "*"); toolbarContainer.AddChild(this.Bake = new Button { Text = "Bake" }, "50"); toolbarContainer.AddChild(this.MarkDirty = new Button { Text = "Mark Dirty" }, "80"); var assetContainer = new VerticalContainer(); assetContainer.AddChild(toolbarContainer, "20"); assetContainer.AddChild(this.EditorContainer = new SingleContainer(), "*"); var contentContainer = new HorizontalContainer(); contentContainer.AddChild(this.AssetTree = new TreeView(), "210"); contentContainer.AddChild(assetContainer, "*"); var menuContainer = new VerticalContainer(); menuContainer.AddChild(this.MainMenu = new MainMenu(assetManagerProvider, renderUtilities), "24"); menuContainer.AddChild(contentContainer, "*"); menuContainer.AddChild(this.Status = new Label { Text = "..." }, "24"); this.SetChild(menuContainer); var exitItem = new MenuItem(assetManagerProvider, renderUtilities) { Text = "Exit" }; var bakeAllItem = new MenuItem(assetManagerProvider, renderUtilities) { Text = "Bake All" }; var assetManagerMenuItem = new MenuItem(assetManagerProvider, renderUtilities) { Text = "Asset Manager" }; exitItem.Click += (sender, e) => { if (this.ExitClick != null) this.ExitClick(sender, e); }; bakeAllItem.Click += (sender, e) => { if (this.BakeAllClick != null) this.BakeAllClick(sender, e); (bakeAllItem.Parent as MenuItem).Active = false; }; assetManagerMenuItem.AddChild(bakeAllItem); assetManagerMenuItem.AddChild(exitItem); this.MainMenu.AddChild(assetManagerMenuItem); var newAssetMenuItem = new MenuItem(assetManagerProvider, renderUtilities) { Text = "Create New..." }; foreach (var loader in loaders.Where(x => x.CanNew())) { var createNewMenuItem = new MenuItem(assetManagerProvider, renderUtilities) { Text = loader.GetType().Name }; createNewMenuItem.Click += (sender, e) => { if (this.PromptWindow == null) { this.PromptForCreation(loader.GetType().Name, (_, _2) => { if (this.CreateNameEntered != null) this.CreateNameEntered(this, new CreateEventArgs(loader)); }); } }; newAssetMenuItem.AddChild(createNewMenuItem); } this.MainMenu.AddChild(newAssetMenuItem); }
public Asset(IAssetLoader loader, AssetFile file) { _loader = loader; File = file; _children = new List<Asset>(); }
public Asset(IAssetLoader loader, string fileName, string rootDir) : this(loader, new AssetFile(fileName, rootDir)) { }
/// <summary> /// 传入模块名称,构造 /// </summary> public AssetHelper(string module) { mModuleName = module; mAssetLoader = AssetManager.AssetLoader; }