Ejemplo n.º 1
0
 private void Move(ProjectItem item, ProjectEventHandler callback, string srcPath, string dstPath)
 {
     if (item.IsFolder)
     {
         m_storage.MoveFolder(srcPath, dstPath, payload =>
         {
             if (callback != null)
             {
                 callback(new ProjectPayload());
             }
         });
     }
     else
     {
         m_storage.MoveFiles(
             new[] { srcPath, srcPath + "." + FileMetaExt },
             new[] { dstPath, dstPath + "." + FileMetaExt },
             payload =>
         {
             if (callback != null)
             {
                 callback(new ProjectPayload());
             }
         });
     }
 }
Ejemplo n.º 2
0
        public void Delete(ProjectItem item, ProjectEventHandler callback)
        {
            if (item == null)
            {
                callback(new ProjectPayload());
                return;
            }
            string path = item.ToString();

            if (item.IsFolder)
            {
                m_storage.DeleteFolder(path, payload =>
                {
                    if (callback != null)
                    {
                        callback(new ProjectPayload());
                    }
                });
            }
            else
            {
                string[] filePath = new[]
                {
                    path,
                    path + "." + FileMetaExt
                };
                m_storage.DeleteFiles(filePath, payload =>
                {
                    if (callback != null)
                    {
                        callback(new ProjectPayload());
                    }
                });
            }
        }
Ejemplo n.º 3
0
        public void Parallel(Action <ProjectEventHandler>[] actions, ProjectEventHandler callback)
        {
            if (actions == null || actions.Length == 0)
            {
                callback(new ProjectPayload());
            }

            int  counter  = actions.Length;
            bool hasError = false;

            foreach (Action <ProjectEventHandler> action in actions)
            {
                action(actionCallback =>
                {
                    hasError |= actionCallback.HasError;
                    counter--;
                    if (counter == 0)
                    {
                        callback(new ProjectPayload {
                            HasError = hasError
                        });
                    }
                });
            }
        }
        public ProjectAsyncOperation SetValue <T>(string key, T obj, ProjectEventHandler callback = null)
        {
            ProjectAsyncOperation ao = new ProjectAsyncOperation();
            ITypeMap typeMap         = IOC.Resolve <ITypeMap>();
            Type     persistentType  = typeMap.ToPersistentType(typeof(T));

            if (persistentType == null)
            {
                ao.Error = new Error(Error.E_NotFound);
                if (callback != null)
                {
                    callback(ao.Error);
                }
                ao.IsCompleted = true;
            }
            else
            {
                PersistentSurrogate surrogate = (PersistentSurrogate)Activator.CreateInstance(persistentType);
                surrogate.ReadFrom(obj);
                ISerializer serializer = IOC.Resolve <ISerializer>();
                byte[]      bytes      = serializer.Serialize(surrogate);
                string      data       = Convert.ToBase64String(bytes);
                PlayerPrefs.SetString(key, data);
                ao.Error = Error.NoError;
                if (callback != null)
                {
                    callback(ao.Error);
                }
                ao.IsCompleted = true;
            }

            return(ao);
        }
Ejemplo n.º 5
0
        public void Save(ProjectItem[] items, bool metaOnly, ProjectEventHandler callback)
        {
            ProjectItem[] folders    = items.Where(item => item.IsFolder).ToArray();
            string[]      folderPath = folders.Select(item => item.ToString()).ToArray();

            ProjectItem[] files = items;//items.Where(item => !item.IsFolder).ToArray();

            byte[][] fileData = metaOnly ?
                                files.Select(item => m_serializer.Serialize(item.Internal_Meta)).ToArray() :
                                files.Where(item => item.Internal_Data != null).Select(item => m_serializer.Serialize(item.Internal_Data)).
                                Union(files.Select(item => m_serializer.Serialize(item.Internal_Meta))).ToArray();

            string[] filePath = metaOnly ?
                                files.Select(item => item.ToString() + "." + FileMetaExt).ToArray() :
                                files.Where(item => item.Internal_Data != null).Select(item => item.ToString()).Union(files.Select(item => item.ToString() + "." + FileMetaExt)).ToArray();

            m_storage.CreateFolders(folderPath, foldersCreatedCallback =>
            {
                m_storage.SaveFiles(filePath, fileData, saveFilesCallback =>
                {
                    if (callback != null)
                    {
                        callback(new ProjectPayload());
                    }
                });
            });
        }
Ejemplo n.º 6
0
        public ProjectAsyncOperation Open(string project, ProjectEventHandler callback)
        {
            ProjectAsyncOperation ao = new ProjectAsyncOperation();

            m_projectPath = project;

            m_assetDB.UnloadLibraries();

            m_storage.GetProject(m_projectPath, (error, projectInfo) =>
            {
                if (error.HasError)
                {
                    if (callback != null)
                    {
                        callback(error);
                    }

                    ao.Error       = error;
                    ao.IsCompleted = true;
                    return;
                }

                OnOpened(project, projectInfo, ao, callback);
            });
            return(ao);
        }
Ejemplo n.º 7
0
 /// <summary>
 /// 加载工程之前的操作
 /// </summary>
 private static void BeforeLoadProject()
 {
     if (!Isinitialized)
     {
         Isinitialized = true;
         ProjectService.ProjectLoaded += ProjectSeviceProjectLoaded;
     }
 }
Ejemplo n.º 8
0
        public ProjectAsyncOperation Save(AssetItem assetItem, object obj, ProjectEventHandler callback)
        {
            if (m_root == null)
            {
                throw new InvalidOperationException("Project is not opened. Use OpenProject method");
            }

            if (obj == null)
            {
                throw new ArgumentNullException("obj");
            }

            Type persistentType = m_typeMap.ToPersistentType(obj.GetType());

            if (persistentType == null)
            {
                throw new ArgumentException(string.Format("PersistentClass for {0} does not exist", obj.GetType()), "obj");
            }

            if (persistentType == typeof(PersistentGameObject))
            {
                persistentType = typeof(PersistentRuntimePrefab);
            }

            PersistentObject persistentObject = (PersistentObject)Activator.CreateInstance(persistentType);

            persistentObject.ReadFrom(obj);

            if (persistentObject is PersistentRuntimePrefab)
            {
                PersistentRuntimePrefab persistentPrefab = (PersistentRuntimePrefab)persistentObject;
                if (persistentPrefab.Descriptors != null)
                {
                    List <PrefabPart> prefabParts = new List <PrefabPart>();
                    PersistentDescriptorsToPrefabPartItems(persistentPrefab.Descriptors, prefabParts);
                    assetItem.Parts = prefabParts.ToArray();
                }
            }

            GetDepsContext getDepsCtx = new GetDepsContext();

            persistentObject.GetDeps(getDepsCtx);

            assetItem.Dependencies = getDepsCtx.Dependencies.ToArray();
            ProjectAsyncOperation ao = new ProjectAsyncOperation();

            m_storage.Save(m_projectPath, assetItem.Parent.ToString(), assetItem, persistentObject, m_projectInfo, error =>
            {
                if (callback != null)
                {
                    callback(error);
                }
                ao.Error       = error;
                ao.IsCompleted = true;
            });
            return(ao);
        }
Ejemplo n.º 9
0
        public void Delete(ProjectItem[] items, ProjectEventHandler callback)
        {
            items = ProjectItem.GetRootItems(items);
            string[]      folderPath = items.Where(item => item.IsFolder).Select(item => item.ToString()).ToArray();
            ProjectItem[] files      = items.Where(item => !item.IsFolder).ToArray();
            string[]      filePath   = files.Select(item => item.ToString()).Union(files.Select(item => item.ToString() + "." + FileMetaExt)).ToArray();

            GroupOperation(folderPath, filePath, m_storage.DeleteFolders, m_storage.DeleteFiles, callback);
        }
Ejemplo n.º 10
0
        public void Move(ProjectItem item, ProjectItem parent, ProjectEventHandler callback)
        {
            string srcPath = item.ToString();

            parent.AddChild(item);
            item.Name = ProjectItem.GetUniqueName(item.Name, item, item.Parent);
            string dstPath = item.ToString();

            Move(item, callback, srcPath, dstPath);
        }
Ejemplo n.º 11
0
        private void OnOpened(string project, ProjectEventHandler callback, ProjectInfo projectInfo)
        {
            if (projectInfo == null)
            {
                projectInfo = new ProjectInfo();
            }

            m_projectInfo = projectInfo;
            GetProjectTree(project, callback);
        }
Ejemplo n.º 12
0
 public void SaveProjectMeta(string name, ProjectMeta meta, ProjectEventHandler callback)
 {
     m_storage.SaveFile(name + "." + ProjectMetaExt, m_serializer.Serialize(meta), saveMetaCompleted =>
     {
         if (callback != null)
         {
             callback(new ProjectPayload());
         }
     });
 }
Ejemplo n.º 13
0
 public AsyncOperation Unload(ProjectEventHandler callback = null)
 {
     UnloadUnregisterDestroy();
     return(m_assetDB.UnloadUnusedAssets(ao =>
     {
         if (callback != null)
         {
             callback(new Error());
         }
     }));
 }
Ejemplo n.º 14
0
 private void GroupOperation(
     string[] folderPath,
     string[] filePath,
     string[] folderDstPath,
     string[] fileDstPath,
     Action <string[], string[], StorageEventHandler <string[], string[]> > folderOperation,
     Action <string[], string[], StorageEventHandler <string[], string[]> > fileOperation,
     ProjectEventHandler callback)
 {
     if (folderPath.Length > 0)
     {
         folderOperation(folderPath, folderDstPath, folderOperationCompleted =>
         {
             if (filePath.Length > 0)
             {
                 fileOperation(filePath, fileDstPath, fileOperationCompleted =>
                 {
                     if (callback != null)
                     {
                         callback(new ProjectPayload());
                     }
                 });
             }
             else
             {
                 if (callback != null)
                 {
                     callback(new ProjectPayload());
                 }
             }
         });
     }
     else
     {
         if (filePath.Length > 0)
         {
             fileOperation(filePath, fileDstPath, fileOperationCompleted =>
             {
                 if (callback != null)
                 {
                     callback(new ProjectPayload());
                 }
             });
         }
         else
         {
             if (callback != null)
             {
                 callback(new ProjectPayload());
             }
         }
     }
 }
Ejemplo n.º 15
0
 public void GetAssetItems(ProjectItem[] folders, ProjectEventHandler <ProjectItem[]> callback)
 {
     m_storage.GetPreviews(m_projectPath, folders.Select(f => f.ToString()).ToArray(), (error, result) =>
     {
         if (error.HasError)
         {
             callback(error, new AssetItem[0]);
             return;
         }
         OnGetPreviewsCompleted(folders, callback, error, result);
     });
 }
        public ProjectAsyncOperation DeleteValue <T>(string key, ProjectEventHandler callback = null)
        {
            ProjectAsyncOperation ao = new ProjectAsyncOperation();

            PlayerPrefs.DeleteKey(key);
            if (callback != null)
            {
                callback(Error.NoError);
            }
            ao.Error       = Error.NoError;
            ao.IsCompleted = true;
            return(ao);
        }
Ejemplo n.º 17
0
        private void GetProjectTree(string project, ProjectEventHandler callback)
        {
            m_storage.GetProjectTree(project, (error, rootFolder) =>
            {
                if (error.HasError)
                {
                    callback(error);
                    return;
                }

                OnGetProjectTreeCompleted(error, rootFolder, callback);
            });
        }
Ejemplo n.º 18
0
        private void OnExhausted(ProjectEventHandler <AssetItem> callback, ProjectAsyncOperation <AssetItem> ao, int assetIdBackup)
        {
            m_projectInfo.AssetIdentifier = assetIdBackup;
            Error error = new Error(Error.E_InvalidOperation);

            if (callback != null)
            {
                callback(error, null);
            }
            ao.Error       = error;
            ao.Result      = null;
            ao.IsCompleted = true;
        }
Ejemplo n.º 19
0
        public void Open(string project, ProjectEventHandler callback)
        {
            m_projectPath = project;

            m_assetDB.UnloadLibraries();

            m_storage.GetProject(m_projectPath, (error, projectInfo) =>
            {
                if (error.HasError)
                {
                    callback(error);
                    return;
                }

                OnOpened(project, callback, projectInfo);
            });
        }
Ejemplo n.º 20
0
        public ProjectAsyncOperation <UnityObject> Load(AssetItem assetItem, ProjectEventHandler <UnityObject> callback)
        {
            Type type = m_typeMap.ToType(assetItem.TypeGuid);

            if (type == null)
            {
                throw new ArgumentException("assetItem", string.Format("Unable to resolve type using TypeGuid {0}", assetItem.TypeGuid));
            }

            if (type == typeof(Scene))
            {
                m_assetDB.UnregisterSceneObjects();
            }

            HashSet <AssetItem> loadAssetItemsHs = new HashSet <AssetItem>();

            GetAssetItemsToLoad(assetItem, loadAssetItemsHs);

            Type[] persistentTypes = loadAssetItemsHs.Select(item => m_typeMap.ToPersistentType(m_typeMap.ToType(item.TypeGuid))).ToArray();
            for (int i = 0; i < persistentTypes.Length; ++i)
            {
                if (persistentTypes[i] == typeof(PersistentGameObject))
                {
                    persistentTypes[i] = typeof(PersistentRuntimePrefab);
                }
            }

            ProjectAsyncOperation <UnityObject> ao = new ProjectAsyncOperation <UnityObject>();

            m_storage.Load(m_projectPath, loadAssetItemsHs.Select(item => item.ToString()).ToArray(), persistentTypes, (error, persistentObjects) =>
            {
                if (error.HasError)
                {
                    if (callback != null)
                    {
                        callback(error, null);
                    }
                    ao.Error = error;
                    return;
                }

                OnLoadCompleted(assetItem, loadAssetItemsHs.ToArray(), persistentObjects, ao, callback);
            });
            return(ao);
        }
Ejemplo n.º 21
0
        public ProjectAsyncOperation <ProjectItem> LoadAssetLibrary(int index, ProjectEventHandler <ProjectItem> callback = null)
        {
            ProjectAsyncOperation <ProjectItem> pao = new ProjectAsyncOperation <ProjectItem>();
            ResourceRequest         request         = Resources.LoadAsync <AssetLibraryAsset>(AssetLibraries[index]);
            Action <AsyncOperation> completed       = null;

            completed = ao =>
            {
                request.completed -= completed;

                ProjectItem result = new ProjectItem();

                AssetLibraryAsset asset = (AssetLibraryAsset)request.asset;

                Error error = new Error(Error.OK);
                if (asset == null)
                {
                    error.ErrorCode = Error.E_NotFound;
                    error.ErrorText = "Asset Library " + AssetLibraries[index] + " does not exist";
                    if (callback != null)
                    {
                        callback(error, result);
                    }

                    pao.Result      = null;
                    pao.IsCompleted = true;
                    return;
                }

                TreeModel <AssetFolderInfo> model = new TreeModel <AssetFolderInfo>(asset.AssetLibrary.Folders);

                BuildTree(result, (AssetFolderInfo)model.root.children[0], index);


                if (callback != null)
                {
                    callback(error, result);
                }

                pao.Result      = result;
                pao.IsCompleted = true;
            };
            request.completed += completed;
            return(pao);
        }
Ejemplo n.º 22
0
        //public void SaveProjectData(string name, ProjectData data, ProjectEventHandler callback)
        //{
        //    m_storage.SaveFile(name + ".rtpdata", m_serializer.Serialize(data), saveDataCompleted =>
        //    {
        //        if (callback != null)
        //        {
        //            callback(new ProjectPayload());
        //        }
        //    });
        //}

        //public void Load(ProjectItem folder, ProjectEventHandler<ProjectItem[]> callback, params int[] exceptTypes)
        //{
        //    string folderPath = folder.ToString();
        //    m_storage.GetFiles(folderPath, getFilesResult =>
        //    {
        //        string[] path = getFilesResult.Data.Where(filePath => filePath.EndsWith("." + FileMetaExt)).ToArray();
        //        Array.Resize(ref path, path.Length + path.Length);
        //        for (int i = path.Length; i < path.Length + path.Length; ++i)
        //        {
        //            path[path.Length + i] = path[i];
        //            path[i] = path[i].Remove(path[i].LastIndexOf("." + FileMetaExt));
        //        }

        //        HashSet<int> exceptTypesHs = null;
        //        if(exceptTypes != null && exceptTypes.Length > 0)
        //        {
        //            exceptTypesHs = new HashSet<int>();
        //            for(int i = 0; i < exceptTypes.Length; ++i)
        //            {
        //                if(!exceptTypesHs.Contains(exceptTypes[i]))
        //                {
        //                    exceptTypesHs.Add(exceptTypes[i]);
        //                }
        //            }
        //        }
        //        m_storage.LoadFiles(path, loadFilesResult =>
        //        {
        //            List<ProjectItem> loadedItems = new List<ProjectItem>();
        //            for (int i = 0; i < path.Length; ++i)
        //            {
        //                byte[] dataRaw = loadFilesResult.Data[i];
        //                byte[] metaRaw = loadFilesResult.Data[path.Length + i];
        //                if (dataRaw != null && metaRaw != null)
        //                {
        //                    ProjectItemMeta meta = m_serializer.Deserialize<ProjectItemMeta>(metaRaw);
        //                    bool loadData = exceptTypesHs == null || !exceptTypesHs.Contains(meta.Type);

        //                    ProjectItemData data = loadData ? m_serializer.Deserialize<ProjectItemData>(dataRaw) : null;
        //                    loadedItems.Add(new ProjectItem(meta, data) { Parent = folder });
        //                }
        //            }
        //            callback(new ProjectPayload<ProjectItem[]>(loadedItems.ToArray()));
        //        });
        //    });
        //}

        public void Load(string[] path, ProjectEventHandler <ProjectItem[]> callback, params int[] exceptTypes)
        {
            int pathLength = path.Length;

            Array.Resize(ref path, pathLength + pathLength);
            for (int i = 0; i < pathLength; ++i)
            {
                path[pathLength + i] = path[i] + "." + FileMetaExt;
            }

            HashSet <int> exceptTypesHs = null;

            if (exceptTypes != null && exceptTypes.Length > 0)
            {
                exceptTypesHs = new HashSet <int>();
                for (int i = 0; i < exceptTypes.Length; ++i)
                {
                    if (!exceptTypesHs.Contains(exceptTypes[i]))
                    {
                        exceptTypesHs.Add(exceptTypes[i]);
                    }
                }
            }

            m_storage.LoadFiles(path, loadFilesResult =>
            {
                List <ProjectItem> loadedItems = new List <ProjectItem>();
                for (int i = 0; i < pathLength; ++i)
                {
                    byte[] dataRaw = loadFilesResult.Data[i];
                    byte[] metaRaw = loadFilesResult.Data[pathLength + i];
                    if (dataRaw != null && metaRaw != null)
                    {
                        ProjectItemMeta meta = m_serializer.Deserialize <ProjectItemMeta>(metaRaw);
                        bool loadData        = exceptTypesHs == null || !exceptTypesHs.Contains(meta.TypeCode);

                        ProjectItemData data = loadData ? m_serializer.Deserialize <ProjectItemData>(dataRaw) : null;
                        loadedItems.Add(new ProjectItem(meta, data));
                    }
                }
                callback(new ProjectPayload <ProjectItem[]>(loadedItems.ToArray()));
            });
        }
Ejemplo n.º 23
0
        public void Move(ProjectItem[] items, ProjectItem parent, ProjectEventHandler callback)
        {
            items = ProjectItem.GetRootItems(items);
            string[] folderSrcPath = items.Where(item => item.IsFolder).Select(item => item.ToString()).ToArray();

            ProjectItem[] files       = items.Where(item => !item.IsFolder).ToArray();
            string[]      fileSrcPath = files.Select(item => item.ToString()).Union(files.Select(item => item.ToString() + "." + FileMetaExt)).ToArray();
            foreach (ProjectItem item in items)
            {
                parent.AddChild(item);
                item.Name = ProjectItem.GetUniqueName(item.Name, item, item.Parent);
            }

            string[] folderDstPath = items.Where(item => item.IsFolder).Select(item => item.ToString()).ToArray();
            string[] fileDstPath   = files.Select(item => item.ToString()).Union(files.Select(item => item.ToString() + "." + FileMetaExt)).ToArray();

            GroupOperation(folderSrcPath, fileSrcPath, folderDstPath, fileDstPath,
                           m_storage.MoveFolders, m_storage.MoveFiles, callback);
        }
Ejemplo n.º 24
0
        private void GetProjectTree(string project, ProjectAsyncOperation ao, ProjectEventHandler callback)
        {
            m_storage.GetProjectTree(project, (error, rootFolder) =>
            {
                if (error.HasError)
                {
                    if (callback != null)
                    {
                        callback(error);
                    }

                    ao.Error       = error;
                    ao.IsCompleted = true;
                    return;
                }

                OnGetProjectTreeCompleted(error, rootFolder, ao, callback);
            });
        }
Ejemplo n.º 25
0
        public void Rename(ProjectItem item, string name, ProjectEventHandler callback)
        {
            string srcPath = item.ToString();
            string srcName = item.Name;

            item.Name = ProjectItem.GetUniqueName(name, item, item.Parent);
            string dstPath = item.ToString();

            if (!item.IsFolder && !item.IsScene)
            {
                m_storage.LoadFile(srcPath, loadFilesResult =>
                {
                    byte[] dataRaw = loadFilesResult.Data;
                    if (dataRaw != null)
                    {
                        ProjectItemData data = m_serializer.Deserialize <ProjectItemData>(dataRaw);
                        item.Internal_Data   = data;
                        item.Rename(name);
                    }

                    Save(item, srcPath, false, saveCompleted =>
                    {
                        UnloadData(item);
                        Move(item, callback, srcPath, dstPath);
                    });
                });
            }
            else
            {
                if (!item.IsFolder)
                {
                    Save(item, srcPath, true, saveCompleted =>
                    {
                        Move(item, callback, srcPath, dstPath);
                    });
                }
                else
                {
                    Move(item, callback, srcPath, dstPath);
                }
            }
        }
Ejemplo n.º 26
0
        private void LoadFolders(ProjectItem item, ProjectEventHandler callback)
        {
            m_storage.GetFolders(item.ToString(), getFoldersCompleted =>
            {
                string[] names = getFoldersCompleted.Data;

                if (names != null && names.Length > 0)
                {
                    Action <ProjectEventHandler>[] loadFoldersActions = new Action <ProjectEventHandler> [names.Length];

                    if (item.Children == null)
                    {
                        item.Children = new List <ProjectItem>(names.Length);
                    }

                    for (int i = 0; i < names.Length; ++i)
                    {
                        string name           = names[i];
                        ProjectItem childItem = ProjectItem.CreateFolder(name);
                        item.AddChild(childItem);
                        loadFoldersActions[i] = cb => LoadFolders(childItem, cb);
                    }

                    Parallel(loadFoldersActions, parallelCallback =>
                    {
                        if (callback != null)
                        {
                            callback(new ProjectPayload());
                        }
                    });
                }
                else
                {
                    if (callback != null)
                    {
                        callback(new ProjectPayload());
                    }
                }
            },
                                 false);
        }
Ejemplo n.º 27
0
 private void Save(ProjectItem item, string path, bool metaOnly, ProjectEventHandler callback)
 {
     if (item.IsFolder)
     {
         ProjectItem[] filesAndFolders = item.FlattenHierarchy(true);
         Save(filesAndFolders, metaOnly, callback);
     }
     else
     {
         m_storage.SaveFile(path + "." + FileMetaExt, m_serializer.Serialize(item.Internal_Meta), saveMetaCompleted =>
         {
             if (item.Internal_Data != null)
             {
                 if (metaOnly)
                 {
                     if (callback != null)
                     {
                         callback(new ProjectPayload());
                     }
                 }
                 else
                 {
                     m_storage.SaveFile(path, m_serializer.Serialize(item.Internal_Data), saveDataCompleted =>
                     {
                         if (callback != null)
                         {
                             callback(new ProjectPayload());
                         }
                     });
                 }
             }
             else
             {
                 if (callback != null)
                 {
                     callback(new ProjectPayload());
                 }
             }
         });
     }
 }
Ejemplo n.º 28
0
        public void Save(AssetItem assetItem, object obj, ProjectEventHandler callback)
        {
            if (obj == null)
            {
                throw new ArgumentNullException("obj");
            }

            Type persistentType = m_typeMap.ToPersistentType(obj.GetType());

            if (persistentType == null)
            {
                throw new ArgumentException(string.Format("PersistentClass for {0} does not exist", obj.GetType()), "obj");
            }

            PersistentObject persistentObject = (PersistentObject)Activator.CreateInstance(persistentType);

            persistentObject.ReadFrom(obj);

            if (persistentObject is PersistentPrefab)
            {
                PersistentPrefab persistentPrefab = (PersistentPrefab)persistentObject;
                if (persistentPrefab.Descriptors != null)
                {
                    List <PrefabPart> prefabParts = new List <PrefabPart>();
                    PersistentDescriptorsToPrefabPartItems(persistentPrefab.Descriptors, prefabParts);
                    assetItem.Parts = prefabParts.ToArray();
                }
            }

            GetDepsContext getDepsCtx = new GetDepsContext();

            persistentObject.GetDeps(getDepsCtx);

            assetItem.Dependencies = getDepsCtx.Dependencies.ToArray();

            m_storage.Save(m_projectPath, assetItem.Parent.ToString(), assetItem, persistentObject, m_projectInfo, error =>
            {
                callback(error);
            });
        }
Ejemplo n.º 29
0
        private void OnGetPreviewsCompleted(ProjectItem[] folders, ProjectEventHandler <ProjectItem[]> callback, Error error, Preview[][] result)
        {
            for (int i = 0; i < result.Length; ++i)
            {
                ProjectItem folder   = folders[i];
                Preview[]   previews = result[i];
                if (previews != null && previews.Length > 0)
                {
                    for (int j = 0; j < previews.Length; ++j)
                    {
                        Preview   preview = previews[j];
                        AssetItem assetItem;

                        if (m_idToAssetItem.TryGetValue(preview.ItemID, out assetItem))
                        {
                            if (assetItem.Parent == null)
                            {
                                Debug.LogErrorFormat("asset item {0} parent is null", assetItem.ToString());
                                continue;
                            }

                            if (assetItem.Parent.ItemID != folder.ItemID)
                            {
                                Debug.LogErrorFormat("asset item {0} with wrong parent selected. Expected parent {1}. Actual parent {2}", folder.ToString(), assetItem.Parent.ToString());
                                continue;
                            }

                            assetItem.Preview = preview;
                        }
                        else
                        {
                            Debug.LogWarningFormat("AssetItem with ItemID {0} does not exists", preview.ItemID);
                        }
                    }
                }
            }

            callback(error, folders.Where(f => f.Children != null).SelectMany(f => f.Children).ToArray());
        }
Ejemplo n.º 30
0
        public ProjectAsyncOperation Open(string project, ProjectEventHandler callback)
        {
            m_staticReferencesMapping = new MappingInfo();

            /*
             * for (int i = 0; i < StaticReferences.Length; ++i)
             * {
             *  AssetLibraryAsset reference = StaticReferences[i];
             *  if (reference != null)
             *  {
             *      reference.LoadIDMappingTo(m_staticReferencesMapping, false, true);
             *  }
             * }
             */
            ProjectAsyncOperation ao = new ProjectAsyncOperation();

            m_projectPath = project;

            m_assetDB.UnloadLibraries();

            m_storage.GetProject(m_projectPath, (error, projectInfo) =>
            {
                if (error.HasError)
                {
                    if (callback != null)
                    {
                        callback(error);
                    }

                    ao.Error       = error;
                    ao.IsCompleted = true;
                    return;
                }

                OnOpened(project, projectInfo, ao, callback);
            });
            return(ao);
        }
Ejemplo n.º 31
0
 /// <summary>
 /// 加载工程之前的操作
 /// </summary>
 private static void BeforeLoadProject()
 {
     if (!Isinitialized)
     {
         Isinitialized = true;
         ProjectService.ProjectLoaded += ProjectSeviceProjectLoaded;
     }
 }