Пример #1
0
        public IAssetReference <TextureAsset> GetTextureFromHintPath(string hintPath)
        {
            if (_hintPathCache.ContainsKey(hintPath))
            {
                return(_hintPathCache[hintPath]);
            }

            var baseName = hintPath.Split('/').Last();
            var baseNameWithoutExtension = baseName.Substring(0, baseName.LastIndexOf(".", StringComparison.InvariantCulture));
            var fullName = hintPath.Replace('/', '.');
            var fullNameWithoutExtension = fullName.Substring(0, fullName.LastIndexOf(".", StringComparison.InvariantCulture));
            var hintPathsToAttempt       = new[]
            {
                baseNameWithoutExtension,
                "texture." + baseNameWithoutExtension,
                baseName,
                "texture." + baseName,
                fullNameWithoutExtension,
                "texture." + fullNameWithoutExtension,
                fullName,
                "texture." + fullName,
            };

            _hintPathCache[hintPath] = _assetManager.GetPreferred <TextureAsset>(hintPathsToAttempt);
            return(_hintPathCache[hintPath]);
        }
Пример #2
0
        public LocatorEntity(
            IEditorQuery <LocatorEntity> editorQuery,
            IAssetManager assetManager,
            Render3DModelComponent modelComponent)
        {
            if (editorQuery.Mode != EditorQueryMode.BakingSchema)
            {
                _modelComponent = modelComponent;
                RegisterComponent(_modelComponent);

                editorQuery.MapTransform(this, Transform.Assign);

                var modelUri = editorQuery.GetRawResourceUris().FirstOrDefault();
                if (modelUri != null)
                {
                    var extIndex = modelUri.LastIndexOf(".", StringComparison.InvariantCulture);
                    if (extIndex != -1)
                    {
                        modelUri = modelUri.Substring(0, extIndex);
                    }
                    var pathComponents = modelUri.Split('/').ToList();
                    while (pathComponents[0] == "..")
                    {
                        pathComponents.RemoveAt(0);
                    }

                    var paths = new List <string>();
                    while (pathComponents.Count > 0)
                    {
                        var attemptAsset = string.Join(".", pathComponents);
                        paths.Add(attemptAsset);
                        pathComponents.RemoveAt(0);
                    }

                    _modelComponent.Model = assetManager.GetPreferred <ModelAsset>(paths.ToArray());
                }
            }
        }