예제 #1
0
        internal void GetIcons()
        {
            // Load asset
            var iconsAtlas = FlaxEngine.Content.LoadAsyncInternal <SpriteAtlas>(EditorAssets.IconsAtlas);

            if (iconsAtlas == null)
            {
                Editor.LogError("Cannot load editor icons atlas.");
                return;
            }
            if (iconsAtlas.WaitForLoaded())
            {
                Editor.LogError("Failed to load editor icons atlas.");
                return;
            }

            // Find icons
            var fields = GetType().GetFields(BindingFlags.Instance | BindingFlags.Public);

            for (int i = 0; i < fields.Length; i++)
            {
                var field  = fields[i];
                var sprite = iconsAtlas.FindSprite(field.Name);
                if (!sprite.IsValid)
                {
                    Editor.LogWarning(string.Format("Failed to load sprite icon \'{0}\'.", field.Name));
                }
                field.SetValue(this, sprite);
            }
        }
예제 #2
0
        /// <summary>
        /// Loads the project from the specified file.
        /// </summary>
        /// <param name="path">The path.</param>
        /// <returns>The loaded project.</returns>
        public static ProjectInfo Load(string path)
        {
            // Try to reuse loaded file
            path = StringUtils.RemovePathRelativeParts(path);
            if (_projectsCache == null)
            {
                _projectsCache = new List <ProjectInfo>();
            }
            for (int i = 0; i < _projectsCache.Count; i++)
            {
                if (_projectsCache[i].ProjectPath == path)
                {
                    return(_projectsCache[i]);
                }
            }

            try
            {
                // Load
                var contents = File.ReadAllText(path);
                var project  = JsonConvert.DeserializeObject <ProjectInfo>(contents);
                project.ProjectPath       = path;
                project.ProjectFolderPath = StringUtils.NormalizePath(Path.GetDirectoryName(path));

                // Process project data
                if (string.IsNullOrEmpty(project.Name))
                {
                    throw new Exception("Missing project name.");
                }
                if (project.Version == null)
                {
                    project.Version = new Version(1, 0);
                }
                if (project.Version.Revision == 0)
                {
                    project.Version = new Version(project.Version.Major, project.Version.Minor, project.Version.Build);
                }
                if (project.Version.Build == 0 && project.Version.Revision == -1)
                {
                    project.Version = new Version(project.Version.Major, project.Version.Minor);
                }
                foreach (var reference in project.References)
                {
                    string referencePath;
                    if (reference.Name.StartsWith("$(EnginePath)"))
                    {
                        // Relative to engine root
                        referencePath = Path.Combine(Globals.StartupFolder, reference.Name.Substring(14));
                    }
                    else if (reference.Name.StartsWith("$(ProjectPath)"))
                    {
                        // Relative to project root
                        referencePath = Path.Combine(project.ProjectFolderPath, reference.Name.Substring(15));
                    }
                    else if (Path.IsPathRooted(reference.Name))
                    {
                        // Relative to workspace
                        referencePath = Path.Combine(Environment.CurrentDirectory, reference.Name);
                    }
                    else
                    {
                        // Absolute
                        referencePath = reference.Name;
                    }
                    referencePath = StringUtils.RemovePathRelativeParts(referencePath);

                    // Load referenced project
                    reference.Project = Load(referencePath);
                }

                // Project loaded
                Editor.Log($"Loaded project {project.Name}, version {project.Version}");
                _projectsCache.Add(project);
                return(project);
            }
            catch
            {
                // Failed to load project
                Editor.LogError("Failed to load project \"" + path + "\".");
                throw;
            }
        }