Esempio n. 1
0
        /// <summary>
        /// Called when a search result is selected.
        /// </summary>
        /// <param name="guid">The <see cref="Guid"/> of the selected resource.</param>
        /// <remarks>Runs on the UI thread.</remarks>
        void search_OnResultSelected(Guid guid)
        {
            // If the tree already has it, then ignore this after telling the user
            if (ResourceTree.ResourceExistsInTree(guid))
            {
                MessageBox.Show("The selected item is already present.");
                return;
            }

            GetResourceJob.UpdateUIDelegate actUpdateUI = GetResourceCallback;
            MetaAsset ma       = new MetaAsset(guid, _couchdb);
            Version   resource = new Version(ma, _couchdb);

            ResourceTree.StartDownload(resource, Master.JobType.CheckoutJob);

            _workMaster.AddJob(new JobArgs()
            {
                CouchDB          = _couchdb,
                ErrorManager     = ErrorManager,
                FileSystem       = FileSystem,
                JobType          = Master.JobType.CheckoutJob,
                ProgressMethod   = JobBase.ProgressMethodType.Determinate,
                RequestingUser   = TEMP_USERNAME,
                Requestor        = this,
                Resource         = resource,
                Timeout          = 100000,
                UpdateUICallback = actUpdateUI
            });
        }
Esempio n. 2
0
        public Dictionary <AssetTypes, List <MetaAsset> > LoadProjectAssets(bool refresh)
        {
            if (!refresh && CachedAssetsTable != null)
            {
                return(CachedAssetsTable);
            }
            CachedAssetsTable = new Dictionary <AssetTypes, List <MetaAsset> >();

            AssetTypes type;

            for (int i = 0; i < Enum.GetNames(typeof(AssetTypes)).Length; i++)
            {
                type = (AssetTypes)i;
                if (type == AssetTypes.Invalid || type == AssetTypes.Meta)
                {
                    continue;
                }
                List <MetaAsset> result = new List <MetaAsset>();
                string[]         names  = DetectAssetsNamesByType(type);
                foreach (string name in names)
                {
                    MetaAsset asset = LoadMetaAsset(name, type);
                    if (!asset.IsInvalid)
                    {
                        result.Add(asset);
                    }
                }
                CachedAssetsTable.Add(type, result);
            }
            return(CachedAssetsTable);
        }
Esempio n. 3
0
        internal static string GetAssetPath(BaseAsset asset, string posibleName)
        {
            string     path;
            AssetTypes tType;

            if (asset.Type == AssetTypes.Meta)
            {
                MetaAsset MA = ((MetaAsset)asset);
                tType = MA.InfoType;
            }
            else
            {
                tType = asset.Type;
            }

            path = GetAssetTypePath(tType);
            string name = asset.Name;

            if (!string.IsNullOrEmpty(posibleName))
            {
                name = posibleName;
            }
            string file = name + (tType == AssetTypes.Shader ? ShaderExtension : Extension);

            path = Path.Combine(path, file);
            return(path);
        }
        /// <summary>
        /// Tries to add a new entry to the cache. Does nothing to disk.
        /// </summary>
        /// <returns><c>true</c>, if add was successful, <c>false</c> otherwise.</returns>
        /// <param name="uuid">Asset ID.</param>
        /// <param name="size">Size of asset in bytes.</param>
        /// <param name="partitionPath">Path to partition wherein to store the asset.</param>
        public bool TryAdd(Guid uuid, ulong size, out string partitionPath)
        {
            var meta = new MetaAsset {
                Id   = uuid,
                Size = size,
            };

            return(TryAdd(meta, out partitionPath));
        }
Esempio n. 5
0
        public MetaAsset LoadMetaAsset(string Name, AssetTypes Type)
        {
            MetaAsset asset = new MetaAsset();

            asset.Name     = Name;
            asset.InfoType = Type;
            FSWorker.LoadAssetFile(asset);
            return(asset);
        }
Esempio n. 6
0
        public bool RegisterMetaAsset(MetaAsset meta)
        {
            if (meta == null || m_metaAssets.Exists(item => item.Name == meta.Name))
            {
                return(false);
            }

            m_metaAssets.Add(meta);
            return(true);
        }
Esempio n. 7
0
        /// <summary>
        /// Loads all resources on the local file system.
        /// </summary>
        /// <remarks>Runs on the UI thread.</remarks>
        void LoadLocalResources()
        {
            MetaAsset ma;
            Version   resource = null;
            Guid      guid     = Guid.Empty;
            string    temp;

            CheckUpdateStatusJob.UpdateUIDelegate actUpdateUI = CheckUpdateStatus;
            string[] files = FileSystem.GetFiles(Common.FileSystem.Path.RelativeMetaPath);

            for (int i = 0; i < files.Length; i++)
            {
                temp     = files[i];
                files[i] = System.IO.Path.GetFileNameWithoutExtension(files[i]);

                try { guid = new Guid(files[i]); }
                catch
                {
                    guid = Guid.Empty;
                }

                if (guid != Guid.Empty)
                {
                    ma = new MetaAsset(guid, _couchdb);

                    if (ma.LoadFromLocal(null, ma.RelativePath, FileSystem))
                    {
                        resource = new Version(ma, _couchdb);
                        _workMaster.AddJob(new JobArgs()
                        {
                            CouchDB          = _couchdb,
                            ErrorManager     = ErrorManager,
                            FileSystem       = FileSystem,
                            JobType          = Master.JobType.CheckUpdateStatus,
                            RequestingUser   = TEMP_USERNAME,
                            Requestor        = this,
                            Resource         = resource,
                            Timeout          = 100000,
                            UpdateUICallback = actUpdateUI
                        });
                    }
                    else
                    {
                        MessageBox.Show("The resource with id " + guid.ToString("N") + " failed to load, please verify the formatting of its meta data.");
                    }
                }
            }
        }
 private void SetAssetTypesListValues()
 {
     AssetTypesList.ItemsSource       = AssetTypesDataList;
     AssetTypesList.SelectionChanged += new SelectionChangedEventHandler((object o, SelectionChangedEventArgs e) => {
         SelectedType = (AssetTypes)AssetTypesList.SelectedItem;
         AssetNamesList.ItemsSource = MetaAssets[SelectedType];
     });
     AssetNamesList.SelectionChanged += new SelectionChangedEventHandler((object o, SelectionChangedEventArgs e) => {
         SelectedAsset = (MetaAsset)AssetNamesList.SelectedItem;
         SetPreviewAsset(SelectedAsset);
         ZoomSlider.Value        = 1.0;
         YawSlider.Value         = 0;
         PitchSlider.Value       = 0;
         ViewsList.SelectedIndex = 0;
     });
 }
Esempio n. 9
0
        public void PreviewAsset(MetaAsset asset)
        {
            if (asset == null)
            {
                return;
            }

            CurrentAssetView?.Hide();
            CurrentAssetView = null;

            switch (asset.InfoType)
            {
            case AssetTypes.Invalid:
                break;

            case AssetTypes.Mesh:
                CurrentAssetView = MeshAssetViewRef;
                break;

            case AssetTypes.Texture2D:
                CurrentAssetView = Texture2DAssetViewRef;
                break;

            case AssetTypes.TextureCube:
                CurrentAssetView = TextureCubeAssetViewRef;
                break;

            case AssetTypes.Material:
                CurrentAssetView = MaterialAssetViewRef;
                break;

            case AssetTypes.Shader:
                break;

            case AssetTypes.Meta:
                break;

            default:
                break;
            }
            CurrentAssetView?.Show(asset.Name);
        }
Esempio n. 10
0
        public void SetPreviewAsset(MetaAsset SelectedAsset)
        {
            ZoomValue            = 1;
            YawValue             = 0;
            PitchValue           = 0;
            ViewValue            = 0;
            ControlsVisibleFlags = new bool[] { false, false, false, false, false };

            var AM = AssetsManager.AssetsManagerInstance.GetManager();

            switch (SelectedAsset.InfoType)
            {
            case AssetTypes.Invalid:
                break;

            case AssetTypes.Mesh:
                break;

            case AssetTypes.Texture2D:
                break;

            case AssetTypes.TextureCube:
                break;

            case AssetTypes.Material:
                MaterialAsset asset = AM.LoadAsset <MaterialAsset>(SelectedAsset.Name);
                AssetObject = new MaterialAssetModelView(asset, EngineRef);
                MAMV?.Invoke(AssetObject);
                break;

            case AssetTypes.Shader:
                break;

            case AssetTypes.Meta:
                break;

            default:
                break;
            }
            EngineRef?.PreviewAsset(SelectedAsset);
        }
Esempio n. 11
0
        /// <summary>
        /// Called when a search result is selected.
        /// </summary>
        /// <param name="guid">The <see cref="Guid"/> of the selected resource.</param>
        /// <remarks>Runs on the UI thread.</remarks>
        void search_OnResultSelected(Guid guid)
        {
            // If the tree already has it, then ignore this after telling the user
            if (ResourceTree.ResourceExistsInTree(guid))
            {
                MessageBox.Show("The selected item is already present.");
                return;
            }

            GetResourceJob.UpdateUIDelegate actUpdateUI = GetResourceCallback;
            MetaAsset ma = new MetaAsset(guid, _couchdb);
            Version resource = new Version(ma, _couchdb);

            ResourceTree.StartDownload(resource, Master.JobType.CheckoutJob);

            _workMaster.AddJob(new JobArgs()
            {
                CouchDB = _couchdb,
                ErrorManager = ErrorManager,
                FileSystem = FileSystem,
                JobType = Master.JobType.CheckoutJob,
                ProgressMethod = JobBase.ProgressMethodType.Determinate,
                RequestingUser = TEMP_USERNAME,
                Requestor = this,
                Resource = resource,
                Timeout = 100000,
                UpdateUICallback = actUpdateUI
            });
        }
Esempio n. 12
0
        /// <summary>
        /// Loads all resources on the local file system.
        /// </summary>
        /// <remarks>Runs on the UI thread.</remarks>
        void LoadLocalResources()
        {
            MetaAsset ma;
            Version resource = null;
            Guid guid = Guid.Empty;
            string temp;

            CheckUpdateStatusJob.UpdateUIDelegate actUpdateUI = CheckUpdateStatus;
            string[] files = FileSystem.GetFiles(Common.FileSystem.Path.RelativeMetaPath);

            for (int i = 0; i < files.Length; i++)
            {
                temp = files[i];
                files[i] = System.IO.Path.GetFileNameWithoutExtension(files[i]);

                try { guid = new Guid(files[i]); }
                catch
                {
                    guid = Guid.Empty;
                }

                if (guid != Guid.Empty)
                {
                    ma = new MetaAsset(guid, _couchdb);

                    if (ma.LoadFromLocal(null, ma.RelativePath, FileSystem))
                    {
                        resource = new Version(ma, _couchdb);
                        _workMaster.AddJob(new JobArgs()
                        {
                            CouchDB = _couchdb,
                            ErrorManager = ErrorManager,
                            FileSystem = FileSystem,
                            JobType = Master.JobType.CheckUpdateStatus,
                            RequestingUser = TEMP_USERNAME,
                            Requestor = this,
                            Resource = resource,
                            Timeout = 100000,
                            UpdateUICallback = actUpdateUI
                        });
                    }
                    else
                    {
                        MessageBox.Show("The resource with id " + guid.ToString("N") + " failed to load, please verify the formatting of its meta data.");
                    }
                }
            }
        }
Esempio n. 13
0
        private void OnAction(Action action)
        {
            if (action == null)
            {
                return;
            }

            if (action.Id == "CbpChanged")
            {
                Console.WriteLine("CBP project file changed!");
                if (ProjectModel != null)
                {
                    ProjectModel.UpdateFromCbp();
                    MetaComponentsManager.Instance.UnregisterAllMetaComponents();
                    Parallel.Invoke(
                        () => LoadSdkMetaFiles(),
                        () => GenerateProjectMetaFiles()
                        );
                    if (m_buildPage != null)
                    {
                        m_buildPage.RefreshContent();
                    }
                    if (m_projectManagerPanel != null)
                    {
                        m_projectManagerPanel.RebuildList();
                    }
                }
            }
            else if (action.Id == "EditorCbpChanged")
            {
                Console.WriteLine("Editor CBP project file changed!");
                if (m_buildPage != null && !m_buildPage.IsBatchProcessRunning && ProjectModel != null && !string.IsNullOrEmpty(ProjectModel.EditorCbpPath))
                {
                    if (m_scenePage != null)
                    {
                        m_scenePage.SaveSceneBackup();
                    }
                    SceneViewPlugin.Unload();
                    m_buildPage.BatchOperationProject(
                        BuildPageControl.BatchOperationMode.Rebuild,
                        null,
                        ProjectModel.WorkingDirectory + @"\" + ProjectModel.EditorCbpPath
                        );
                }
            }
            else if (action.Id == "SceneViewPluginChanged")
            {
                Console.WriteLine("Editor components plugin changed!");
                if (ProjectModel != null && !string.IsNullOrEmpty(ProjectModel.EditorPluginPath))
                {
                    string pluginPath = ProjectModel.WorkingDirectory + @"\" + ProjectModel.EditorPluginPath;
                    SceneViewPlugin.Unload();
                    if (SceneViewPlugin.Load(pluginPath))
                    {
                        if (m_scenePage != null)
                        {
                            m_scenePage.ReinitializeRenderer();
                        }
                        List <string> clist = SceneViewPlugin.ListComponents();
                        if (clist != null && clist.Count > 0)
                        {
                            foreach (string c in clist)
                            {
                                Console.WriteLine("Registered component: " + c);
                            }
                        }
                        if (m_scenePage != null)
                        {
                            m_scenePage.OpenSceneBackup();
                        }
                    }
                }
            }
            else if (action.Id == "LoadMetaComponent" && action.Params != null && action.Params.Length > 0)
            {
                string path = action.Params[0] as string;
                if (!String.IsNullOrEmpty(path) && ProjectModel != null)
                {
                    Console.WriteLine("Load meta-component for: \"{0}\"", path);
                    string metaPath = path + ".meta";
                    if (File.Exists(metaPath))
                    {
                        string        json = File.ReadAllText(metaPath);
                        MetaComponent meta = Newtonsoft.Json.JsonConvert.DeserializeObject <MetaComponent>(json);
                        MetaComponentsManager.Instance.UnregisterMetaComponent(meta);
                        ProjectModel.MetaComponentPaths.Remove(path);
                        if (meta != null)
                        {
                            MetaComponentsManager.Instance.RegisterMetaComponent(meta);
                            ProjectModel.MetaComponentPaths.Add(path, meta);
                            if (meta.Properties != null && meta.Properties.Count > 0)
                            {
                                foreach (MetaProperty prop in meta.Properties)
                                {
                                    if (PropertyEditorsManager.Instance.FindPropertyEditor(prop.ValueType) == null)
                                    {
                                        Console.WriteLine("Property editor for type: \"{0}\" (component: \"{1}\", property: \"{2}\") not found!", prop.ValueType, meta.Name, prop.Name);
                                    }
                                }
                            }
                        }
                    }
                    if (m_projectManagerPanel != null)
                    {
                        m_projectManagerPanel.UpdateFile(path);
                    }
                    GenerateProjectCodeFiles();
                }
            }
            else if (action.Id == "RemoveMetaComponent" && action.Params != null && action.Params.Length > 0)
            {
                string path = action.Params[0] as string;
                if (!String.IsNullOrEmpty(path) && ProjectModel != null && ProjectModel.MetaComponentPaths.ContainsKey(path))
                {
                    Console.WriteLine("Remove meta-component for: \"{0}\"", path);
                    MetaComponentsManager.Instance.UnregisterMetaComponent(ProjectModel.MetaComponentPaths[path]);
                    ProjectModel.MetaComponentPaths.Remove(path);
                    if (m_projectManagerPanel != null)
                    {
                        m_projectManagerPanel.UpdateFile(path);
                    }
                    GenerateProjectCodeFiles();
                }
            }
            else if (action.Id == "LoadMetaAsset" && action.Params != null && action.Params.Length > 0)
            {
                string path = action.Params[0] as string;
                if (!String.IsNullOrEmpty(path) && ProjectModel != null)
                {
                    Console.WriteLine("Load meta-asset for: \"{0}\"", path);
                    string metaPath = path + ".meta";
                    if (File.Exists(metaPath))
                    {
                        string    json = File.ReadAllText(metaPath);
                        MetaAsset meta = Newtonsoft.Json.JsonConvert.DeserializeObject <MetaAsset>(json);
                        MetaAssetsManager.Instance.UnregisterMetaAsset(meta);
                        ProjectModel.MetaAssetsPaths.Remove(path);
                        if (meta != null)
                        {
                            MetaAssetsManager.Instance.RegisterMetaAsset(meta);
                            ProjectModel.MetaAssetsPaths.Add(path, meta);
                        }
                    }
                    if (m_projectManagerPanel != null)
                    {
                        m_projectManagerPanel.UpdateFile(path);
                    }
                    GenerateProjectCodeFiles();
                }
            }
            else if (action.Id == "RemoveMetaAsset" && action.Params != null && action.Params.Length > 0)
            {
                string path = action.Params[0] as string;
                if (!String.IsNullOrEmpty(path) && ProjectModel != null && ProjectModel.MetaAssetsPaths.ContainsKey(path))
                {
                    Console.WriteLine("Remove meta-asset for: \"{0}\"", path);
                    MetaAssetsManager.Instance.UnregisterMetaAsset(ProjectModel.MetaAssetsPaths[path]);
                    ProjectModel.MetaAssetsPaths.Remove(path);
                    if (m_projectManagerPanel != null)
                    {
                        m_projectManagerPanel.UpdateFile(path);
                    }
                    GenerateProjectCodeFiles();
                }
            }
            else if (action.Id == "GameObjectIdChanged" && action.Params != null && action.Params.Length > 0)
            {
                if (m_scenePage != null)
                {
                    m_scenePage.SceneTreeChangeGameObjectId((int)action.Params[0]);
                }
            }
        }
Esempio n. 14
0
 private void SetPreviewAsset(MetaAsset SelectedAsset)
 {
     EngineRef?.PreviewAsset(SelectedAsset);
 }
Esempio n. 15
0
 public bool UnregisterMetaAsset(MetaAsset meta)
 {
     return(m_metaAssets.Remove(meta));
 }