Beispiel #1
0
        private void CreatePrefabWithoutDependencies(ProjectItem dropTarget, ExposeToEditor dragObject, Action <AssetItem[]> done)
        {
            IResourcePreviewUtility previewUtility = IOC.Resolve <IResourcePreviewUtility>();

            byte[] previewData = previewUtility.CreatePreviewData(dragObject.gameObject);
            CreatePrefab(dropTarget, new[] { previewData }, new[] { dragObject.gameObject }, done);
        }
Beispiel #2
0
        private void CreatePrefabWithDependencies(ProjectItem dropTarget, ExposeToEditor dragObject, Action <AssetItem[]> done)
        {
            IResourcePreviewUtility previewUtility = IOC.Resolve <IResourcePreviewUtility>();

            m_project.GetDependencies(dragObject.gameObject, true, (error, deps) =>
            {
                object[] objects;
                if (!deps.Contains(dragObject.gameObject))
                {
                    objects = new object[deps.Length + 1];
                    objects[deps.Length] = dragObject.gameObject;
                    for (int i = 0; i < deps.Length; ++i)
                    {
                        objects[i] = deps[i];
                    }
                }
                else
                {
                    objects = deps;
                }

                IUnityObjectFactory uoFactory = IOC.Resolve <IUnityObjectFactory>();
                objects = objects.Where(obj => uoFactory.CanCreateInstance(obj.GetType())).ToArray();

                byte[][] previewData = new byte[objects.Length][];
                for (int i = 0; i < objects.Length; ++i)
                {
                    if (objects[i] is UnityObject)
                    {
                        previewData[i] = previewUtility.CreatePreviewData((UnityObject)objects[i]);
                    }
                }
                CreatePrefab(dropTarget, previewData, objects, done);
            });
        }
Beispiel #3
0
        public void CreateAsset(UnityObject asset, ProjectItem parentFolder)
        {
            if (m_folders == null)
            {
                return;
            }

            IResourcePreviewUtility resourcePreview = IOC.Resolve <IResourcePreviewUtility>();

            byte[] preview = resourcePreview.CreatePreviewData(asset);
            Editor.IsBusy = true;
            m_project.Save(new[] { parentFolder }, new[] { preview }, new[] { asset }, null, (error, assetItems) =>
            {
                if (parentFolder != m_folders.FirstOrDefault())
                {
                    if (ItemDoubleClick != null)
                    {
                        ItemDoubleClick(this, new ProjectTreeEventArgs(new[] { parentFolder }));
                    }
                }

                Editor.ActivateWindow(m_projectFolderView);
                Destroy(asset);
            });
        }
Beispiel #4
0
        private void Start()
        {
            m_editor = IOC.Resolve <IRuntimeEditor>();
            m_editor.Undo.UndoCompleted += OnUndoCompleted;
            m_editor.Undo.RedoCompleted += OnRedoCompleted;
            m_resourcePreviewUtility     = IOC.Resolve <IResourcePreviewUtility>();
            m_editorsMap = IOC.Resolve <IEditorsMap>();

            if ((Materials == null || Materials.Length == 0) && m_editor.Selection.Length > 0)
            {
                Materials = m_editor.Selection.objects.Cast <Material>().ToArray();
            }

            if (Materials == null || Materials.Length == 0 || Materials[0] == null)
            {
                Debug.LogError("Select material");
                return;
            }

            m_previewTexture = new Texture2D(1, 1, TextureFormat.ARGB32, true);

            TxtMaterialName.text = GetMaterialName(Materials);
            TxtShaderName.text   = GetShaderName(Materials);

            UpdatePreview();
            BuildEditor();
        }
        private void Start()
        {
            m_editor = IOC.Resolve <IRuntimeEditor>();
            m_editor.Undo.UndoCompleted += OnUndoCompleted;
            m_editor.Undo.RedoCompleted += OnRedoCompleted;
            m_resourcePreviewUtility     = IOC.Resolve <IResourcePreviewUtility>();
            m_editorsMap = IOC.Resolve <IEditorsMap>();

            if (Material == null)
            {
                Material = m_editor.Selection.activeObject as Material;
            }

            if (Material == null)
            {
                Debug.LogError("Select material");
                return;
            }

            m_previewTexture = new Texture2D(1, 1, TextureFormat.ARGB32, true);

            TxtMaterialName.text = Material.name;
            if (Material.shader != null)
            {
                TxtShaderName.text = Material.shader.name;
            }
            else
            {
                TxtShaderName.text = "Shader missing";
            }

            UpdatePreview(Material);
            BuildEditor();
        }
Beispiel #6
0
        protected virtual void Start()
        {
            if (m_prefab == null)
            {
                Debug.LogWarning("m_prefab is not set");
                return;
            }

            m_editor = IOC.Resolve <IRTE>();
            m_scene  = m_editor.GetWindow(RuntimeWindowType.Scene);

            IResourcePreviewUtility resourcePreview = IOC.Resolve <IResourcePreviewUtility>();

            m_texture = resourcePreview.TakeSnapshot(m_prefab);
            if (m_preview != null)
            {
                m_preview.sprite = Sprite.Create(m_texture, new Rect(0, 0, m_texture.width, m_texture.height), new Vector2(0.5f, 0.5f));
                m_preview.color  = Color.white;
            }

            if (m_prefabName != null)
            {
                m_prefabName.text = m_prefab.name;
            }
        }
        private void OnDetailsDatabinding(object sender, VirtualizingTreeViewItemDataBindingArgs e)
        {
            DetailPrototypeWrapper details = (DetailPrototypeWrapper)e.Item;
            RawImage image = e.ItemPresenter.GetComponentInChildren <RawImage>();

            if (image != null)
            {
                if (image.texture != null && image.texture.name == "TemporaryPreview")
                {
                    Destroy(image.texture);
                }

                if (details.Prototype.usePrototypeMesh && details.Prototype.prototype != null)
                {
                    IResourcePreviewUtility previewUtil = IOC.Resolve <IResourcePreviewUtility>();
                    Texture2D texture = new Texture2D(1, 1, TextureFormat.ARGB32, true);
                    texture.name = "TemporaryPreview";
                    texture.LoadImage(previewUtil.CreatePreviewData(details.Prototype.prototype));
                    image.texture = texture;
                }
                else
                {
                    image.texture = details.Prototype.prototypeTexture;
                }
            }
        }
Beispiel #8
0
        public ProjectAsyncOperation <AssetItem> UpdatePreview(UnityObject obj, Action <AssetItem> done)
        {
            ProjectAsyncOperation <AssetItem> ao = new ProjectAsyncOperation <AssetItem>();

            IProject  project   = IOC.Resolve <IProject>();
            AssetItem assetItem = project.ToAssetItem(obj);

            if (assetItem != null)
            {
                IResourcePreviewUtility resourcePreviewUtility = IOC.Resolve <IResourcePreviewUtility>();
                byte[] preview = resourcePreviewUtility.CreatePreviewData(obj);
                assetItem.Preview = new Preview {
                    ItemID = assetItem.ItemID, PreviewData = preview
                };
            }

            if (done != null)
            {
                done(assetItem);
            }

            ao.Error       = new Error();
            ao.Result      = assetItem;
            ao.IsCompleted = true;
            return(ao);
        }
        private void CreateMaterial(string arg)
        {
            bool currentFolder = !string.IsNullOrEmpty(arg);

            ProjectItem parentFolder = currentFolder ? m_folders.FirstOrDefault() : (ProjectItem)m_listBox.SelectedItem;

            if (parentFolder == null)
            {
                return;
            }

            IUnityObjectFactory objectFactory = IOC.Resolve <IUnityObjectFactory>();
            UnityObject         unityObject   = objectFactory.CreateInstance(typeof(Material), null);

            IResourcePreviewUtility resourcePreview = IOC.Resolve <IResourcePreviewUtility>();

            byte[] preview = resourcePreview.CreatePreviewData(unityObject);
            Editor.IsBusy = true;
            m_project.Save(new[] { parentFolder }, new[] { preview }, new[] { unityObject }, null, (error, assetItems) =>
            {
                if (!currentFolder)
                {
                    if (ItemDoubleClick != null)
                    {
                        ItemDoubleClick(this, new ProjectTreeEventArgs(new[] { parentFolder }));
                    }
                }

                Editor.ActivateWindow(this);
                Destroy(unityObject);
            });
        }
Beispiel #10
0
        protected virtual void Start()
        {
            m_projectView   = GetComponent <ProjectView>();
            m_projectTree   = m_projectView.ProjectTree.GetComponent <ProjectTreeViewImpl>();
            m_projectFolder = m_projectView.ProjectFolder.GetComponent <ProjectFolderViewImpl>();
            m_filterInput   = m_projectView.FilterInput;

            m_editor        = IOC.Resolve <IRuntimeEditor>();
            m_windowManager = IOC.Resolve <IWindowManager>();
            m_localization  = IOC.Resolve <ILocalization>();
            m_project       = IOC.Resolve <IProject>();
            if (m_project == null)
            {
                Debug.LogWarning("RTSLDeps.Get.Project is null");
                Destroy(gameObject);
                return;
            }

            m_resourcePreview = IOC.Resolve <IResourcePreviewUtility>();
            if (m_resourcePreview == null)
            {
                Debug.LogWarning("RTEDeps.Get.ResourcePreview is null");
            }

            DockPanel dockPanelsRoot = GetComponent <DockPanel>();

            if (dockPanelsRoot != null)
            {
                dockPanelsRoot.CursorHelper = Editor.CursorHelper;
            }

            UnityEventHelper.AddListener(m_filterInput, inputField => inputField.onValueChanged, OnFiltering);

            m_projectFolder.ItemDoubleClick  += OnProjectFolderItemDoubleClick;
            m_projectFolder.ItemRenamed      += OnProjectFolderItemRenamed;
            m_projectFolder.ItemsDeleted     += OnProjectFolderItemDeleted;
            m_projectFolder.SelectionChanged += OnProjectFolderSelectionChanged;

            m_projectTree.SelectionChanged += OnProjectTreeSelectionChanged;
            m_projectTree.ItemRenamed      += OnProjectTreeItemRenamed;
            m_projectTree.ItemsDeleted     += OnProjectTreeItemDeleted;

            m_project.OpenProjectCompleted    += OnProjectOpenCompleted;
            m_project.CloseProjectCompleted   += OnCloseProjectCompleted;
            m_project.ImportCompleted         += OnImportCompleted;
            m_project.BeforeDeleteCompleted   += OnBeforeDeleteCompleted;
            m_project.DeleteCompleted         += OnDeleteCompleted;
            m_project.RenameCompleted         += OnRenameCompleted;
            m_project.CreateCompleted         += OnCreateCompleted;
            m_project.MoveCompleted           += OnMoveCompleted;
            m_project.SaveCompleted           += OnSaveCompleted;
            m_project.DuplicateItemsCompleted += OnDuplicateCompleted;

            if (m_project.IsOpened)
            {
                m_projectTree.LoadProject(m_project.Root);
                m_projectTree.SelectedItem = m_project.Root;
            }
        }
Beispiel #11
0
 protected virtual void OnDestroy()
 {
     if (this == (MonoBehaviour)Get)
     {
         Get = null;
         m_resourcePreview = null;
     }
 }
Beispiel #12
0
 protected virtual void Awake()
 {
     if (Get != null)
     {
         Destroy(((MonoBehaviour)Get).gameObject);
         Debug.LogWarning("Another instance of RTSL2Deps exist");
     }
     Get = this;
     m_resourcePreview = FindObjectOfType <ResourcePreviewUtility>();
 }
Beispiel #13
0
        protected virtual void AwakeOverride()
        {
            m_rte = RTE;
            IOC.Register <IRTE>(m_rte);
            IOC.Register(m_rte);


            m_resourcePreview = ResourcePreview;
            m_rteAppearance   = RTEAppearance;
        }
Beispiel #14
0
        private void Start()
        {
            m_windowManager = IOC.Resolve <IWindowManager>();
            m_project       = IOC.Resolve <IProject>();
            if (m_project == null)
            {
                Debug.LogWarning("RTSLDeps.Get.Project is null");
                Destroy(gameObject);
                return;
            }

            m_resourcePreview = IOC.Resolve <IResourcePreviewUtility>();
            if (m_resourcePreview == null)
            {
                Debug.LogWarning("RTEDeps.Get.ResourcePreview is null");
            }

            DockPanel dockPanelsRoot = GetComponent <DockPanel>();

            if (dockPanelsRoot != null)
            {
                dockPanelsRoot.CursorHelper = Editor.CursorHelper;
            }

            m_projectResources.ItemDoubleClick  += OnProjectResourcesDoubleClick;
            m_projectResources.ItemRenamed      += OnProjectResourcesRenamed;
            m_projectResources.ItemDeleted      += OnProjectResourcesDeleted;
            m_projectResources.SelectionChanged += OnProjectResourcesSelectionChanged;

            m_projectTree.SelectionChanged += OnProjectTreeSelectionChanged;
            m_projectTree.ItemRenamed      += OnProjectTreeItemRenamed;
            m_projectTree.ItemDeleted      += OnProjectTreeItemDeleted;

            m_project.OpenProjectCompleted  += OnProjectOpenCompleted;
            m_project.CloseProjectCompleted += OnCloseProjectCompleted;
            m_project.ImportCompleted       += OnImportCompleted;
            m_project.BeforeDeleteCompleted += OnBeforeDeleteCompleted;
            m_project.DeleteCompleted       += OnDeleteCompleted;
            m_project.RenameCompleted       += OnRenameCompleted;
            m_project.CreateCompleted       += OnCreateCompleted;
            m_project.MoveCompleted         += OnMoveCompleted;
            m_project.SaveCompleted         += OnSaveCompleted;
            m_project.DuplicateCompleted    += OnDuplicateCompleted;

            if (!m_project.IsOpened && !m_project.IsBusy)
            {
                Editor.IsBusy = true;
                m_project.OpenProject(ProjectName);
            }
            else
            {
                m_projectTree.LoadProject(m_project.Root);
                m_projectTree.SelectedFolder = m_project.Root;
            }
        }
Beispiel #15
0
        private void UpdateDependantAssetPreviews(AssetItem[] assetItems, Action callback)
        {
            IResourcePreviewUtility previewUtil = IOC.Resolve <IResourcePreviewUtility>();

            AssetItem[] dependantItems = m_project.GetDependantAssetItems(assetItems).Where(item => !m_project.IsScene(item)).ToArray();
            if (dependantItems.Length > 0)
            {
                m_project.Load(dependantItems, (loadError, loadedObjects) =>
                {
                    if (loadError.HasError)
                    {
                        IsBusy = false;
                        m_wm.MessageBox("Unable to load assets", loadError.ErrorText);
                        return;
                    }

                    for (int i = 0; i < loadedObjects.Length; ++i)
                    {
                        UnityObject loadedObject = loadedObjects[i];
                        AssetItem dependantItem  = dependantItems[i];
                        if (loadedObject != null)
                        {
                            byte[] previewData    = previewUtil.CreatePreviewData(loadedObject);
                            dependantItem.Preview = new Preview {
                                ItemID = dependantItem.ItemID, PreviewData = previewData
                            };
                        }
                        else
                        {
                            dependantItem.Preview = new Preview {
                                ItemID = dependantItem.ItemID
                            };
                        }
                    }

                    m_project.SavePreview(dependantItems, (savePreviewError, savedAssetItems) =>
                    {
                        if (savePreviewError.HasError)
                        {
                            IsBusy = false;
                            m_wm.MessageBox("Unable to load assets", savePreviewError.ErrorText);
                            return;
                        }

                        callback();
                    });
                });
            }
            else
            {
                callback();
            }
        }
Beispiel #16
0
        private void Start()
        {
            m_project = IOC.Resolve <IProject>();
            if (m_project == null)
            {
                Debug.LogWarning("RTSL2Deps.Get.Project is null");
                Destroy(gameObject);
                return;
            }

            m_resourcePreview = IOC.Resolve <IResourcePreviewUtility>();
            if (m_resourcePreview == null)
            {
                Debug.LogWarning("RTEDeps.Get.ResourcePreview is null");
            }

            if (m_ddCreate != null)
            {
                m_ddCreate.onValueChanged.AddListener(OnCreate);
            }

            if (m_btnImport != null)
            {
                m_btnImport.onClick.AddListener(SelectLibrary);
            }

            if (m_btnProjects != null)
            {
                m_btnProjects.onClick.AddListener(ManageProjects);
            }

            m_projectResources.ItemDoubleClick += OnProjectResourcesDoubleClick;
            m_projectResources.ItemRenamed     += OnProjectResourcesRenamed;
            m_projectResources.ItemDeleted     += OnProjectResourcesDeleted;

            m_projectTree.SelectionChanged += OnProjectTreeSelectionChanged;
            m_projectTree.ItemRenamed      += OnProjectTreeItemRenamed;
            m_projectTree.ItemDeleted      += OnProjectTreeItemDeleted;

            m_project.OpenProjectCompleted  += OnProjectOpenCompleted;
            m_project.CloseProjectCompleted += OnCloseProjectCompleted;
            m_project.ImportCompleted       += OnImportCompleted;
            m_project.DeleteCompleted       += OnDeleteCompleted;
            m_project.RenameCompleted       += OnRenameCompleted;
            m_project.MoveCompleted         += OnMoveCompleted;
            m_project.CreateCompleted       += OnPrefabCreateCompleted;
            m_project.SaveCompleted         += OnSaveCompleted;

            ShowProgress  = true;
            Editor.IsBusy = true;

            m_project.OpenProject(ProjectName);
        }
Beispiel #17
0
        public override IEnumerator Import(string filePath, string targetPath)
        {
            Mesh mesh = ImportFile(filePath);

            IProject project = IOC.Resolve <IProject>();
            IResourcePreviewUtility previewUtility = IOC.Resolve <IResourcePreviewUtility>();

            byte[] preview = previewUtility.CreatePreviewData(mesh);
            yield return(project.Save(targetPath, mesh, preview));

            Object.Destroy(mesh);
        }
Beispiel #18
0
        private void Start()
        {
            m_editor      = IOC.Resolve <IRTE>();
            m_parentPopup = GetComponentInParent <PopupWindow>();
            if (m_parentPopup != null)
            {
                m_parentPopup.OK.AddListener(OnOK);
            }

            m_treeView = GetComponentInChildren <VirtualizingTreeView>();
            if (m_treeView == null)
            {
                m_treeView = Instantiate(TreeViewPrefab);
                m_treeView.transform.SetParent(transform, false);
            }

            m_treeView.ItemDataBinding += OnItemDataBinding;
            m_treeView.ItemDoubleClick += OnItemDoubleClick;
            m_treeView.ItemExpanding   += OnItemExpanding;

            m_treeView.CanDrag = false;
            m_treeView.CanEdit = false;

            m_project = IOC.Resolve <IProject>();

            m_editor.IsBusy = true;
            m_project.LoadAssetLibrary(Array.IndexOf(m_project.AssetLibraries, m_selectedAssetLibrary), (error, root) =>
            {
                m_editor.IsBusy = false;
                if (error.HasError)
                {
                    PopupWindow.Show("Unable to load AssetLibrary", error.ErrorText, "OK", arg =>
                    {
                        m_parentPopup.Close(false);
                    });
                }
                else
                {
                    m_treeView.Items         = new[] { root };
                    m_treeView.SelectedItems = root.Flatten(false);
                    ExpandAll(root);


                    IResourcePreviewUtility resourcePreview = IOC.Resolve <IResourcePreviewUtility>();
                    StartCoroutine(ProjectItemView.CoCreatePreviews(root.Flatten(false), m_project, resourcePreview));
                }
            });
        }
Beispiel #19
0
        private void OnDestroy()
        {
            if (m_instance == this)
            {
                m_instance = null;
            }

            OnDestroyOverride();

            IOC.Unregister <IRTE>(m_rte);
            IOC.Unregister(m_rte);

            m_resourcePreview = null;
            m_rteAppearance   = null;
            m_rte             = null;
        }
Beispiel #20
0
        protected virtual void AwakeOverride()
        {
            m_rte = RTE;
            IOC.Register <IRTE>(m_rte);
            IOC.Register(m_rte);

            m_resourcePreview         = ResourcePreview;
            m_rteAppearance           = RTEAppearance;
            m_windowManager           = WindowManager;
            m_console                 = RuntimeConsole;
            m_gameObjectCmd           = GameObjectCmd;
            m_editCmd                 = EditCmd;
            m_contextMenu             = ContextMenu;
            m_runtimeHandlesComponent = RuntimeHandlesComponent;
            m_editorsMap              = EditorsMap;
        }
Beispiel #21
0
        protected override void OnEditorExist()
        {
            base.OnEditorExist();

            if (!FirstRun)
            {
                return;
            }
            FirstRun = false;

            IProject project = IOC.Resolve <IProject>();
            IRTE     editor  = IOC.Resolve <IRTE>();

            project.LoadImportItems("DemoAssetLibrary", true, (error, root) =>
            {
                if (error.HasError)
                {
                    editor.IsBusy = false;
                    Debug.LogError(error.ToString());
                }
                else
                {
                    IResourcePreviewUtility resourcePreview = IOC.Resolve <IResourcePreviewUtility>();
                    ImportItem[] importItems = root.Flatten(true).OfType <ImportItem>().ToArray();
                    for (int i = 0; i < importItems.Length; ++i)
                    {
                        ImportItem importItem = importItems[i];
                        importItem.Preview    = new Preview
                        {
                            ItemID      = importItem.ItemID,
                            PreviewData = resourcePreview.CreatePreviewData(importItems[i].Object)
                        };
                    }
                    project.UnloadImportItems(root);

                    project.Import(importItems, (importError, assetItems) =>
                    {
                        if (importError.HasError)
                        {
                            Debug.LogError(importError.HasError);
                        }

                        editor.IsBusy = false;
                    });
                }
            });
        }
Beispiel #22
0
        public override IEnumerator Import(string filePath, string targetPath)
        {
            byte[] bytes = File.ReadAllBytes(filePath);

            Texture2D texture = new Texture2D(4, 4);

            if (texture.LoadImage(bytes, false))
            {
                IProject project = IOC.Resolve <IProject>();
                IResourcePreviewUtility previewUtility = IOC.Resolve <IResourcePreviewUtility>();
                byte[] preview = previewUtility.CreatePreviewData(texture);
                yield return(project.Save(targetPath, texture, preview));
            }
            else
            {
                Debug.LogError("Unable to load image " + filePath);
            }

            Object.Destroy(texture);
        }
Beispiel #23
0
        private void OnDestroy()
        {
            if (m_instance == this)
            {
                m_instance = null;
            }

            OnDestroyOverride();

            IOC.Unregister <IRTE>(m_rte);
            IOC.Unregister(m_rte);

            m_resourcePreview         = null;
            m_rteAppearance           = null;
            m_windowManager           = null;
            m_console                 = null;
            m_gameObjectCmd           = null;
            m_editCmd                 = null;
            m_contextMenu             = null;
            m_runtimeHandlesComponent = null;
            m_editorsMap              = null;
        }
        private void OnTreesDatabinding(object sender, VirtualizingTreeViewItemDataBindingArgs e)
        {
            TreePrototype tree  = (TreePrototype)e.Item;
            RawImage      image = e.ItemPresenter.GetComponentInChildren <RawImage>();

            if (image != null)
            {
                if (image.texture != null && image.texture.name == "TemporaryPreview")
                {
                    Destroy(image.texture);
                }

                if (tree.prefab != null)
                {
                    IResourcePreviewUtility previewUtil = IOC.Resolve <IResourcePreviewUtility>();
                    Texture2D texture = new Texture2D(1, 1, TextureFormat.ARGB32, true);
                    texture.name = "TemporaryPreview";
                    texture.LoadImage(previewUtil.CreatePreviewData(tree.prefab));
                    image.texture = texture;
                }
            }
        }
        public override IEnumerator Import(string filePath, string targetPath)
        {
            byte[] bytes = File.ReadAllBytes(filePath);

            Texture2D texture = new Texture2D(4, 4);

            if (texture.LoadImage(bytes, false))
            {
                if (texture.format == TextureFormat.RGBA32 || texture.format == TextureFormat.ARGB32)
                {
                    bool      opaque = true;
                    Color32[] pixels = texture.GetPixels32();
                    for (int i = 0; i < pixels.Length; ++i)
                    {
                        if (pixels[i].a != 255)
                        {
                            opaque = false;
                            break;
                        }
                    }

                    if (opaque)
                    {
                        texture.LoadImage(texture.EncodeToJPG(), false);
                    }
                }

                IProject project = IOC.Resolve <IProject>();
                IResourcePreviewUtility previewUtility = IOC.Resolve <IResourcePreviewUtility>();
                byte[] preview = previewUtility.CreatePreviewData(texture);
                yield return(project.Save(targetPath, texture, preview));
            }
            else
            {
                Debug.LogError("Unable to load image " + filePath);
            }

            Object.Destroy(texture);
        }
Beispiel #26
0
        private void Start()
        {
            m_project = RTSL2Deps.Get.Project;
            if (m_project == null)
            {
                Debug.LogWarning("RTSL2Deps.Get.Project is null");
                Destroy(gameObject);
                return;
            }

            m_resourcePreview = RTEDeps.Get.ResourcePreview;
            if (m_resourcePreview == null)
            {
                Debug.LogWarning("RTEDeps.Get.ResourcePreview is null");
            }

            m_assetDB = RTSL2Deps.Get.AssetDB;
            if (m_assetDB == null)
            {
                Debug.LogWarning("RTSL2Deps.Get.AssetDB is null");
            }
            //RuntimeEditorApplication.SaveSelectedObjectsRequired += OnSaveSelectedObjectsRequest;

            //m_projectResources.SelectionChanged += OnProjectResourcesSelectionChanged;
            //m_projectResources.DoubleClick += OnProjectResourcesDoubleClick;
            //m_projectResources.Renamed += OnProjectResourcesRenamed;
            //m_projectResources.Deleted += OnProjectResourcesDeleted;
            //m_projectResources.BeginDrag += OnProjectResourcesBeginDrag;
            //m_projectResources.Drop += OnProjectResourcesDrop;

            m_projectTree.SelectionChanged += OnProjectTreeSelectionChanged;
            //m_projectTree.Renamed += OnProjectTreeItemRenamed;
            //m_projectTree.Deleted += OnProjectTreeItemDeleted;
            //m_projectTree.Drop += OnProjectTreeItemDrop;

            ShowProgress = true;

            m_staticReferencesMapping = new MappingInfo();
            for (int i = 0; i < m_project.StaticReferences.Length; ++i)
            {
                AssetLibraryReference reference = m_project.StaticReferences[i];
                if (reference != null)
                {
                    reference.LoadIDMappingTo(m_staticReferencesMapping, false, true);
                }
            }

            m_project.Open(ProjectName, error =>
            {
                if (error.HasError)
                {
                    PopupWindow.Show("Can't open project", error.ToString(), "OK");
                    return;
                }

                ShowProgress = false;

                m_projectTree.LoadProject(m_project.Root);

                m_projectTree.SelectedFolder = m_project.Root;



                //StartCoroutine(CreatePreviewForStaticResources(m_project.Root));
            });

            //m_projectManager.DynamicResourcesAdded += OnDynamicResourcesAdded;
            //m_projectManager.BundledResourcesAdded += OnBundledResourcesAdded;
            //m_projectManager.SceneCreated += OnSceneCreated;
            //m_projectManager.SceneLoaded += OnSceneLoaded;
            //m_projectManager.SceneSaved += OnSceneSaved;

            //if (m_btnDuplicate != null)
            //{
            //    m_btnDuplicate.onClick.AddListener(DuplicateProjectResources);
            //}

            //if(m_btnAddFolder != null)
            //{
            //    m_btnAddFolder.onClick.AddListener(AddFolder);
            //}
        }
        public static IEnumerator CoCreatePreviews(ProjectItem[] items, IProject project, IResourcePreviewUtility resourcePreview, Action done = null)
        {
            if (resourcePreview == null)
            {
                if (done != null)
                {
                    done();
                }
                yield break;
            }

            IRTE rte = IOC.Resolve <IRTE>();

            if (rte.Selection.activeObject != null)
            {
                long        id = project.ToID(rte.Selection.activeObject);
                ProjectItem selectedProjectItem = items.Where(item => item.ItemID == id).FirstOrDefault();
                if (selectedProjectItem != null && selectedProjectItem is AssetItem)
                {
                    AssetItem selectedAssetItem = (AssetItem)selectedProjectItem;
                    selectedAssetItem.Preview = null;
                }
            }

            for (int i = 0; i < items.Length; ++i)
            {
                ImportItem importItem = items[i] as ImportItem;
                if (importItem != null)
                {
                    if (/*importItem.Preview == null &&*/ importItem.Object != null)
                    {
                        importItem.Preview = new Preview
                        {
                            ItemID      = importItem.ItemID,
                            PreviewData = resourcePreview.CreatePreviewData(importItem.Object)
                        };
                    }
                }
                else
                {
                    AssetItem assetItem = items[i] as AssetItem;
                    if (assetItem != null)
                    {
                        UnityObject obj = null;
                        if (assetItem.Preview == null)
                        {
                            obj = project.FromID <UnityObject>(assetItem.ItemID);
                        }

                        if (obj != null)
                        {
                            assetItem.Preview = new Preview
                            {
                                ItemID      = assetItem.ItemID,
                                PreviewData = resourcePreview.CreatePreviewData(obj)
                            };
                        }
                    }
                }

                if (i % 10 == 0)
                {
                    yield return(new WaitForSeconds(0.005f));
                }
            }

            if (done != null)
            {
                done();
            }
        }
Beispiel #28
0
        private void Start()
        {
            m_parentDialog                 = GetComponentInParent <Dialog>();
            m_parentDialog.IsOkVisible     = true;
            m_parentDialog.IsCancelVisible = true;
            m_parentDialog.OkText          = m_localization.GetString("ID_RTEditor_SelectObjectDialog_Select", "Select");
            m_parentDialog.CancelText      = m_localization.GetString("ID_RTEditor_SelectObjectDialog_Cancel", "Cancel");
            m_parentDialog.Ok             += OnOk;

            m_toggleAssets.onValueChanged.AddListener(OnAssetsTabSelectionChanged);

            m_project       = IOC.Resolve <IProject>();
            m_windowManager = IOC.Resolve <IWindowManager>();

            IResourcePreviewUtility resourcePreview = IOC.Resolve <IResourcePreviewUtility>();

            AssetItem[] assetItems = m_project.Root.Flatten(true, false).Where(item =>
            {
                Type type = m_project.ToType((AssetItem)item);
                if (type == null)
                {
                    return(false);
                }
                return(type == ObjectType || type.IsSubclassOf(ObjectType));
            }).OfType <AssetItem>().ToArray();

            m_treeView.SelectionChanged += OnSelectionChanged;
            m_treeView.ItemDataBinding  += OnItemDataBinding;
            Editor.IsBusy = true;
            m_parentDialog.IsOkInteractable = false;
            m_project.GetAssetItems(assetItems, (error, assetItemsWithPreviews) =>
            {
                if (error.HasError)
                {
                    Editor.IsBusy = false;
                    m_windowManager.MessageBox(m_localization.GetString("ID_RTEditor_SelectObjectDialog_CantGetAssets", "Can't GetAssets"), error.ToString());
                    return;
                }

                AssetItem none = new AssetItem();
                none.Name      = m_localization.GetString("ID_RTEditor_SelectObjectDialog_None", "None");
                none.TypeGuid  = m_noneGuid;

                assetItemsWithPreviews = new[] { none }.Union(assetItemsWithPreviews).ToArray();

                m_previewsCreated = false;
                StartCoroutine(ProjectItemView.CoCreatePreviews(assetItemsWithPreviews, m_project, resourcePreview, () =>
                {
                    m_previewsCreated = true;
                    HandleSelectionChanged((AssetItem)m_treeView.SelectedItem);
                    m_treeView.ItemDoubleClick     += OnItemDoubleClick;
                    m_parentDialog.IsOkInteractable = m_previewsCreated && m_treeView.SelectedItem != null;
                    Editor.IsBusy = false;

                    if (m_filter != null)
                    {
                        if (!string.IsNullOrEmpty(m_filter.text))
                        {
                            ApplyFilter(m_filter.text);
                        }
                        m_filter.onValueChanged.AddListener(OnFilterValueChanged);
                    }
                }));

                m_assetsCache    = assetItemsWithPreviews;
                m_treeView.Items = m_assetsCache;

                List <AssetItem> sceneCache = new List <AssetItem>();
                sceneCache.Add(none);

                m_sceneObjects = new Dictionary <long, UnityObject>();
                ExposeToEditor[] sceneObjects = Editor.Object.Get(false, true).ToArray();
                for (int i = 0; i < sceneObjects.Length; ++i)
                {
                    ExposeToEditor exposeToEditor = sceneObjects[i];
                    UnityObject obj = null;
                    if (ObjectType == typeof(GameObject))
                    {
                        obj = exposeToEditor.gameObject;
                    }
                    else if (ObjectType.IsSubclassOf(typeof(Component)))
                    {
                        obj = exposeToEditor.GetComponent(ObjectType);
                    }

                    if (obj != null)
                    {
                        AssetItem assetItem = new AssetItem()
                        {
                            ItemID = m_project.ToID(exposeToEditor),
                            Name   = exposeToEditor.name,
                        };
                        assetItem.TypeGuid = m_project.ToGuid(typeof(GameObject));
                        assetItem.Preview  = new Preview {
                            ItemID = assetItem.ItemID, PreviewData = new byte[0]
                        };
                        sceneCache.Add(assetItem);
                        m_sceneObjects.Add(assetItem.ItemID, obj);
                    }
                }
                m_sceneCache = sceneCache.ToArray();
            });
        }
Beispiel #29
0
        public static IEnumerator CoCreatePreviews(ProjectItem[] items, IProject project, IResourcePreviewUtility resourcePreview)
        {
            if (resourcePreview == null)
            {
                yield break;
            }


            for (int i = 0; i < items.Length; ++i)
            {
                ImportItem importItem = items[i] as ImportItem;
                if (importItem != null)
                {
                    if (importItem.Preview == null && importItem.Object != null)
                    {
                        importItem.Preview = new Preview
                        {
                            ItemID      = importItem.ItemID,
                            PreviewData = resourcePreview.CreatePreviewData(importItem.Object)
                        };
                    }
                }
                else
                {
                    ImportItem assetItem = items[i] as ImportItem;
                    if (assetItem != null)
                    {
                        UnityObject obj;
                        if (project.IsStatic(assetItem))
                        {
                            #warning CommentedOut
                            //if (!project.TryGetFromStaticReferences(assetItem, out obj))
                            {
                                obj = null;
                            }
                        }
                        else
                        {
                            if (assetItem.Preview == null)
                            {
                                obj = project.FromID <UnityObject>(assetItem.ItemID);
                            }
                            else
                            {
                                obj = null;
                            }
                        }

                        if (obj != null)
                        {
                            assetItem.Preview = new Preview
                            {
                                ItemID      = assetItem.ItemID,
                                PreviewData = resourcePreview.CreatePreviewData(obj)
                            };
                        }
                    }
                }

                yield return(new WaitForSeconds(0.01f));
            }
        }
        public static IEnumerator CoCreatePreviews(ProjectItem[] items, IProject project, IResourcePreviewUtility resourcePreview, Action done = null)
        {
            if (resourcePreview == null)
            {
                if (done != null)
                {
                    done();
                }
                yield break;
            }

            for (int i = 0; i < items.Length; ++i)
            {
                ImportItem importItem = items[i] as ImportItem;
                if (importItem != null)
                {
                    if (importItem.Preview == null && importItem.Object != null)
                    {
                        importItem.Preview = new Preview
                        {
                            ItemID      = importItem.ItemID,
                            PreviewData = resourcePreview.CreatePreviewData(importItem.Object)
                        };
                    }
                }
                else
                {
                    AssetItem assetItem = items[i] as AssetItem;
                    if (assetItem != null)
                    {
                        UnityObject obj = null;
                        if (assetItem.Preview == null)
                        {
                            obj = project.FromID <UnityObject>(assetItem.ItemID);
                        }

                        if (obj != null)
                        {
                            assetItem.Preview = new Preview
                            {
                                ItemID      = assetItem.ItemID,
                                PreviewData = resourcePreview.CreatePreviewData(obj)
                            };
                        }
                    }
                }

                yield return(new WaitForSeconds(0.01f));
            }

            if (done != null)
            {
                done();
            }
        }