Пример #1
0
    public static string ReadExportPath()
    {
        string exportPath = null;

        if (File.Exists(m_ExportConfigPath))
        {
            UniversalEditorUtility.MakeFileWriteable(m_ExportConfigPath);
            XmlDocument docment = new XmlDocument();
            docment.Load(m_ExportConfigPath);
            XmlNode root = docment.SelectSingleNode("ExportInfoConfig");
            if (root != null)
            {
                XmlNode nodeExportPath = root.SelectSingleNode("ExportPath");
                if (nodeExportPath != null)
                {
                    exportPath = nodeExportPath.InnerText;
                }
            }
        }

        if ((exportPath != null) && (exportPath != ""))
        {
            ExportPath = exportPath;
        }

        return(exportPath);
    }
Пример #2
0
    public void OpenFilterConfigFile()
    {
        List <string> refTag = new List <string>();

        if (!File.Exists(m_configPath))
        {
            StreamWriter fileWriter = File.CreateText(m_configPath);
            UniversalEditorUtility.MakeFileWriteable(m_configPath);

            refTag.Add("正向引用过滤:" + Environment.NewLine);
            refTag.Add("反向引用过滤:" + Environment.NewLine);
            refTag.Add("无引用过滤:" + Environment.NewLine);

            foreach (var item in refTag)
            {
                fileWriter.WriteLine(item);
            }

            fileWriter.Close();
        }

        //System.Diagnostics.Process.Start(m_configPath);
        //UniversalEditorUtility.MakeFileWriteable(m_configPath);

        System.Diagnostics.Process myProcess = new System.Diagnostics.Process();
        myProcess.StartInfo.FileName        = @m_configPath;
        myProcess.StartInfo.LoadUserProfile = true;
        myProcess.StartInfo.Verb            = "open";
        myProcess.Start();
        myProcess.WaitForExit(1);
        myProcess.Close();
        //myProcess = System.Diagnostics.Process.Start(@m_configPath);
    }
Пример #3
0
    public void WirteEditorLayoutInfo(string baseDir, EditorRoot root)
    {
        if (
            (null == root) ||
            string.IsNullOrEmpty(baseDir)
            )
        {
            return;
        }

        object obj = GetSerializeObject(root);

        if (null == obj)
        {
            return;
        }

        string eidtorLayoutInfoPath = baseDir + root.editorName + "/" + "EditorLayoutInfo.layout";

        if (!Directory.Exists(baseDir + root.editorName))
        {
            Directory.CreateDirectory(baseDir + root.editorName);
        }

        UniversalEditorUtility.MakeFileWriteable(eidtorLayoutInfoPath);

        StreamWriter yamlWriter     = File.CreateText(eidtorLayoutInfoPath);
        Serializer   yamlSerializer = new Serializer();

        yamlSerializer.Serialize(yamlWriter, obj);

        yamlWriter.Close();
    }
Пример #4
0
    public static string ReadPublishPath()
    {
        FileStream   fileStream  = null;
        StreamReader streamR     = null;
        string       publishPath = null;

        if (File.Exists(m_PublishConfigPath))
        {
            UniversalEditorUtility.MakeFileWriteable(m_PublishConfigPath);
            fileStream = new FileStream(m_PublishConfigPath, FileMode.Open);
            streamR    = new StreamReader(fileStream);

            while (!streamR.EndOfStream)
            {
                publishPath += streamR.ReadLine();
            }

            streamR.Close();
            fileStream.Close();
        }

        if ((publishPath != null) && (publishPath != ""))
        {
            PublishPath = publishPath;
        }

        return(publishPath);
    }
Пример #5
0
    public static void WriteManualPath(string path)
    {
        if (null == path)
        {
            return;
        }

        if (!File.Exists(m_ExportConfigPath))
        {
            CreateXMLConifg(m_ExportConfigPath);

            UniversalEditorUtility.MakeFileWriteable(m_ExportConfigPath);

            XmlDocument docment = new XmlDocument();
            XmlElement  root    = docment.CreateElement("ExportInfoConfig");
            docment.AppendChild(root);

            XmlElement nodeExportPath = docment.CreateElement("ExportPath");
            root.AppendChild(nodeExportPath);

            XmlElement nodeManualPath = docment.CreateElement("ManualPath");
            nodeManualPath.InnerText = path;
            root.AppendChild(nodeManualPath);

            docment.Save(m_ExportConfigPath);
        }
        else
        {
            XmlDocument docment = new XmlDocument();
            docment.Load(m_ExportConfigPath);
            XmlNode root = docment.SelectSingleNode("ExportInfoConfig");
            if (root != null)
            {
                XmlNode nodeExportPath = root.SelectSingleNode("ManualPath");
                if (nodeExportPath != null)
                {
                    nodeExportPath.InnerText = path;
                }
                else
                {
                    nodeExportPath           = docment.CreateElement("ManualPath");
                    nodeExportPath.InnerText = path;
                    root.AppendChild(nodeExportPath);
                }
            }
            else
            {
                root = docment.CreateElement("ExportInfoConfig");
                docment.AppendChild(root);

                XmlNode nodeExportPath = docment.CreateElement("ManualPath");
                nodeExportPath.InnerText = path;
                root.AppendChild(nodeExportPath);
            }

            docment.Save(m_ExportConfigPath);
        }

        ManualPath = path;
    }
Пример #6
0
    public static string ReadReferenceResultPath()
    {
        string path = string.Empty;

        if (File.Exists(configPath))
        {
            UniversalEditorUtility.MakeFileWriteable(configPath);
            XmlDocument docment = new XmlDocument();
            docment.Load(configPath);
            XmlNode root = docment.SelectSingleNode("UIAtlasConfig");
            if (root != null)
            {
                XmlNode nodeReferenceResultPath = root.SelectSingleNode("ReferenceResultPath");
                if (nodeReferenceResultPath != null)
                {
                    path = nodeReferenceResultPath.InnerText;
                }
            }
        }

        if (!string.IsNullOrEmpty(path))
        {
            ReferenceResultPath = path;
        }

        return(path);
    }
Пример #7
0
    public static void WriteImageBasePath(string path)
    {
        if (string.IsNullOrEmpty(path))
        {
            return;
        }

        if (!File.Exists(configPath))
        {
            CreateXMLConifg(configPath);

            UniversalEditorUtility.MakeFileWriteable(configPath);

            XmlDocument docment = new XmlDocument();
            XmlElement  root    = docment.CreateElement("UIAtlasConfig");
            docment.AppendChild(root);

            XmlElement nodeImageBasePath = docment.CreateElement("ImageBasePath");
            nodeImageBasePath.InnerText = path;
            root.AppendChild(nodeImageBasePath);

            XmlElement nodeProjectPath = docment.CreateElement("ProjectPath");
            root.AppendChild(nodeProjectPath);

            docment.Save(configPath);
        }
        else
        {
            XmlDocument docment = new XmlDocument();
            docment.Load(configPath);
            XmlNode root = docment.SelectSingleNode("UIAtlasConfig");
            if (root != null)
            {
                XmlNode nodeImageBasePath = root.SelectSingleNode("ImageBasePath");
                if (nodeImageBasePath != null)
                {
                    nodeImageBasePath.InnerText = path;
                }
                else
                {
                    nodeImageBasePath           = docment.CreateElement("ImageBasePath");
                    nodeImageBasePath.InnerText = path;
                    root.AppendChild(nodeImageBasePath);
                }
            }
            else
            {
                root = docment.CreateElement("UIAtlasConfig");
                docment.AppendChild(root);

                XmlNode nodeImageBasePath = docment.CreateElement("ImageBasePath");
                nodeImageBasePath.InnerText = path;
                root.AppendChild(nodeImageBasePath);
            }
            docment.Save(configPath);
        }

        imageBasePath = path;
        onBasePathChange(path);
    }
Пример #8
0
    //Add by liteng for 发布工具改善 start
    public static void SetPublishMode(bool bIsDebugMode)
    {
        if (!Directory.Exists(Path.GetDirectoryName(m_ConfigXMLPath)))
        {
            Directory.CreateDirectory(Path.GetDirectoryName(m_ConfigXMLPath));
        }

        UniversalEditorUtility.MakeFileWriteable(m_ConfigXMLPath);

        XmlDocument docment = new XmlDocument();
        XmlElement  root    = docment.CreateElement("PublishModeConfig");

        docment.AppendChild(root);

        XmlElement nodeMode = docment.CreateElement("Mode");

        if (bIsDebugMode)
        {
            nodeMode.InnerText = "Debug";
        }
        else
        {
            nodeMode.InnerText = "Release";
        }
        root.AppendChild(nodeMode);

        docment.Save(m_ConfigXMLPath);

        debugMode = bIsDebugMode;
    }
Пример #9
0
    public static void WriteFile(string filePath, string[] fileData)
    {
        if (string.IsNullOrEmpty(filePath))
        {
            return;
        }

        int count = 1;

        WriteFileProgresser.GetInstance().InitProgresser(fileData.Length, "CSV文件写入中");

        StreamWriter fileWriter = File.CreateText(filePath);

        if (fileWriter != null)
        {
            UniversalEditorUtility.MakeFileWriteable(filePath);
            foreach (var item in fileData)
            {
                fileWriter.WriteLine(item);
                WriteFileProgresser.GetInstance().UpdateProgress(count++);
            }
            fileWriter.Close();
            //File.WriteAllLines(filePath, fileData);
        }
    }
Пример #10
0
    public void WriteRecentOpenProjectPath(string path)
    {
        if (string.IsNullOrEmpty(path))
        {
            return;
        }

        if (!File.Exists(recentOpenProjectConfigPath))
        {
            if (!Directory.Exists(Path.GetDirectoryName(recentOpenProjectConfigPath)))
            {
                Directory.CreateDirectory(Path.GetDirectoryName(recentOpenProjectConfigPath));
            }

            UniversalEditorUtility.MakeFileWriteable(recentOpenProjectConfigPath);

            XmlDocument docment = new XmlDocument();
            XmlElement  root    = docment.CreateElement("UIAtlasMaker");
            docment.AppendChild(root);

            XmlElement nodeRecentOpenProjectPath = docment.CreateElement("RecentOpenProject");
            nodeRecentOpenProjectPath.InnerText = path;
            root.AppendChild(nodeRecentOpenProjectPath);


            docment.Save(recentOpenProjectConfigPath);
        }
        else
        {
            XmlDocument docment = new XmlDocument();
            docment.Load(recentOpenProjectConfigPath);
            XmlNode root = docment.SelectSingleNode("UIAtlasMaker");
            if (root != null)
            {
                XmlNode nodeRecentOpenProjectPath = root.SelectSingleNode("RecentOpenProject");
                if (nodeRecentOpenProjectPath != null)
                {
                    nodeRecentOpenProjectPath.InnerText = path;
                }
                else
                {
                    nodeRecentOpenProjectPath           = docment.CreateElement("RecentOpenProject");
                    nodeRecentOpenProjectPath.InnerText = path;
                    root.AppendChild(nodeRecentOpenProjectPath);
                }
            }
            else
            {
                root = docment.CreateElement("UIAtlasMaker");
                docment.AppendChild(root);

                XmlNode nodeRecentOpenProjectPath = docment.CreateElement("RecentOpenProject");
                nodeRecentOpenProjectPath.InnerText = path;
                root.AppendChild(nodeRecentOpenProjectPath);
            }
            docment.Save(recentOpenProjectConfigPath);
        }
    }
Пример #11
0
    public bool SaveXMLConfig()
    {
        bool bRet = true;

        if (IsPackageInfoNull())
        {
            ErrorType = PACKAGE_FAILED_TYPE.PACKAGE_FAILED_UNKNOW_ERROR;
            return(false);
        }

        if (string.IsNullOrEmpty(PackageExportConfig.AssetsConfigPath))
        {
            ErrorType = PACKAGE_FAILED_TYPE.PACKAGE_FAILED_XMLCONFIG_PATH_ERROR;
            return(false);
        }

        if (!IsSubPackageVersionValid())
        {
            ErrorType = PACKAGE_FAILED_TYPE.PACKAGE_FAILED_VERSION_NONE_ERROR;
            return(false);
        }

        PackageExportConfig.CreateXMLConifg(PackageExportConfig.AssetsConfigPath);
        UniversalEditorUtility.MakeFileWriteable(PackageExportConfig.AssetsConfigPath);

        XmlDocument docment = new XmlDocument();
        XmlElement  root    = docment.CreateElement("ExportPackageConfig");

        docment.AppendChild(root);

        XmlElement nodeVersion = docment.CreateElement("Version");

        UpdatePackageVersion();
        nodeVersion.InnerText = m_Assets.PackageInfo.VersionNum;
        root.AppendChild(nodeVersion);

        XmlElement nodePath = docment.CreateElement("Path");

        root.AppendChild(nodePath);
        foreach (string sPath in m_Assets.PackageInfo.ExportAssets)
        {
            XmlElement node = docment.CreateElement("Item");
            node.InnerText = sPath;
            nodePath.AppendChild(node);
        }

        try
        {
            docment.Save(PackageExportConfig.AssetsConfigPath);
        }
        catch (System.Exception e)
        {
            bRet = false;
            Debug.Log("保存打包工具配置文件失败: " + e.Message);
        }

        return(bRet);
    }
Пример #12
0
    public void Save()
    {
        _TouchConfigDir();
        UniversalEditorUtility.MakeFileWriteable(_GetConfigFilePath());
        var        configWriter  = File.CreateText(_GetConfigFilePath());
        Serializer yamlSerialzer = new Serializer();

        yamlSerialzer.Serialize(configWriter, Paths);
        configWriter.Close();
    }
Пример #13
0
    public void Save()
    {
        _TouchCacheFolder();
        UniversalEditorUtility.MakeFileWriteable(_GetCacheFilePath());
        StreamWriter yamlWriter     = File.CreateText(_GetCacheFilePath());
        Serializer   yamlSerializer = new Serializer();
        object       obj            = _GetSerializeObject();

        yamlSerializer.Serialize(yamlWriter, obj);
        yamlWriter.Close();
    }
Пример #14
0
    public string PrepareCompressDirectory()
    {
        string zipName    = null;
        string mainVerDir = null;

        if (IsPackageInfoNull())
        {
            return(string.Empty);
        }

        if (string.IsNullOrEmpty(PackageExportConfig.ExportPath))
        {
            return(string.Empty);
        }

        if (string.IsNullOrEmpty(PackageExportConfig.PackageName))
        {
            return(string.Empty);
        }

        if (!IsSubPackageVersionValid())
        {
            return(string.Empty);
        }

        if (m_IsWithManual && string.IsNullOrEmpty(PackageExportConfig.ManualPath))
        {
            return(string.Empty);
        }

        mainVerDir = PackageExportConfig.ExportPath + "Ver" + m_PackageVer.MainVers + "." + m_PackageVer.UpgradeVer + "/";
        zipName    = mainVerDir + Path.GetFileNameWithoutExtension(PackageExportConfig.PackageName) + "_Ver" + m_Assets.PackageInfo.VersionNum;

        if (Directory.Exists(zipName))
        {
            DirectoryInfo info = new DirectoryInfo(zipName);
            UniversalEditorUtility.MakeDictionaryWriteable(info);

            UniversalEditorUtility.DeleteFileByDirectory(info);
        }

        Directory.CreateDirectory(zipName);

        File.Copy(PackageExportConfig.ExportPath + PackageExportConfig.PackageName, zipName + "/" + PackageExportConfig.PackageName, true);

        if (m_IsWithManual)
        {
            UniversalEditorUtility.CopyDirectory(PackageExportConfig.ManualPath, zipName + "/Manual/", true);
        }

        return(zipName);
    }
Пример #15
0
    public static void WritePublishPath(string path)
    {
        FileStream   fileStream = null;
        StreamWriter streamW    = null;

        fileStream = new FileStream(m_PublishConfigPath, FileMode.Create);
        UniversalEditorUtility.MakeFileWriteable(m_PublishConfigPath);

        streamW = new StreamWriter(fileStream);
        streamW.Write(path);

        streamW.Close();
        fileStream.Close();

        PublishPath = path;
    }
Пример #16
0
    public void InitEidtorFromLayout(EditorRoot e)
    {
        if (null == e)
        {
            return;
        }

        string editorName = e.editorName;
        string initCallbackRefTypeName = e.initCallbackRefType;
        string initCallbackName        = e.initCallback;

//        object userData = e.UserData;

        e.Init();

        Type       refType          = Assembly.GetExecutingAssembly().GetType(initCallbackRefTypeName);
        MethodInfo initCallbackInfo = refType.GetMethod(initCallbackName, BindingFlags.Public | BindingFlags.Static);

        if (refType == null || initCallbackInfo == null)
        {
            Debug.Log("编辑器\"" + editorName + "\"恢复失败!");
            return;
        }

        VoidDelegate initDelegate = Delegate.CreateDelegate(typeof(VoidDelegate), null, initCallbackInfo, false) as VoidDelegate;

        initDelegate(e);

        EditorManager.GetInstance().AssignCtrlID(e, e.RootCtrl);

        UniversalEditorUtility.LoadEditorLayout(e);

        if (e.onAwake != null)
        {
            e.onAwake(e);
        }

        if (e.onEnable != null)
        {
            e.onEnable(e);
        }

        if (!roots.ContainsKey(editorName))
        {
            roots.Add(editorName, e);
        }
    }
Пример #17
0
    public void SaveAtlasSerializeObject(string filePath, object obj)
    {
        if (
            string.IsNullOrEmpty(filePath) ||
            (null == obj)
            )
        {
            return;
        }

        UniversalEditorUtility.MakeFileWriteable(filePath);
        StreamWriter yamlWriter     = File.CreateText(filePath);
        Serializer   yamlSerializer = new Serializer();

        //将持久化对象写入工程文件
        yamlSerializer.Serialize(yamlWriter, obj);
        yamlWriter.Close();
    }
Пример #18
0
    public static bool CompressDirectory(string directoryPath, string outputFileName, bool bIsDelete)
    {
        bool bRet = true;

        if (string.IsNullOrEmpty(directoryPath) || string.IsNullOrEmpty(outputFileName))
        {
            return(false);
        }

        if (!Directory.Exists(directoryPath))
        {
            return(false);
        }

        using (ZipOutputStream zipoutputstream = new ZipOutputStream(File.Create(outputFileName)))
        {
            zipoutputstream.SetLevel(9);

            Dictionary <string, DateTime> fileList = UniversalEditorUtility.GetAllFies(directoryPath);
            foreach (KeyValuePair <string, DateTime> item in fileList)
            {
                FileStream fs     = File.OpenRead(item.Key.ToString());
                byte[]     buffer = new byte[fs.Length];
                fs.Read(buffer, 0, buffer.Length);
                ZipEntry entry = new ZipEntry(item.Key.Substring(directoryPath.Length));
                entry.DateTime = item.Value;
                entry.Size     = fs.Length;
                fs.Close();

                zipoutputstream.PutNextEntry(entry);
                zipoutputstream.Write(buffer, 0, buffer.Length);
            }
        }

        if (bIsDelete)
        {
            DirectoryInfo info = new DirectoryInfo(directoryPath);
            UniversalEditorUtility.MakeDictionaryWriteable(info);

            Directory.Delete(directoryPath, true);
        }

        return(bRet);
    }
Пример #19
0
    private void DeleteTempFiles()
    {
        do
        {
            if (string.IsNullOrEmpty(PackageExportConfig.ExportPath))
            {
                break;
            }

            if (string.IsNullOrEmpty(PackageExportConfig.PackageName))
            {
                break;
            }

            if (File.Exists(PackageExportConfig.ExportPath + PackageExportConfig.PackageName))
            {
                UniversalEditorUtility.MakeFileWriteable(PackageExportConfig.ExportPath + PackageExportConfig.PackageName);
                File.Delete(PackageExportConfig.ExportPath + PackageExportConfig.PackageName);
            }
        } while (false);
    }
Пример #20
0
    private List <string> GetAllAtlasPrefabFilePath(string dir)
    {
        List <string> atlasPrefabPath = new List <string>();

        if (string.IsNullOrEmpty(dir))
        {
            return(atlasPrefabPath);
        }

        List <string> filePath = UniversalEditorUtility.GetAllFilePath(dir);

        foreach (var item in filePath)
        {
            if (YAMLAnalyser.IsAtlasPrefab(item))
            {
                atlasPrefabPath.Add(item);
            }
        }

        return(atlasPrefabPath);
    }
Пример #21
0
    public string ReadRecentOpenProjectPath()
    {
        string projectPath = string.Empty;

        if (File.Exists(recentOpenProjectConfigPath))
        {
            UniversalEditorUtility.MakeFileWriteable(recentOpenProjectConfigPath);
            XmlDocument docment = new XmlDocument();
            docment.Load(recentOpenProjectConfigPath);
            XmlNode root = docment.SelectSingleNode("UIAtlasMaker");
            if (root != null)
            {
                XmlNode nodeRecentOpenProjectPath = root.SelectSingleNode("RecentOpenProject");
                if (nodeRecentOpenProjectPath != null)
                {
                    projectPath = nodeRecentOpenProjectPath.InnerText;
                }
            }
        }

        return(projectPath);
    }
    //public bool UnloadTexture(string path)
    //{//卸载纹理
    //    bool bRet = true;

    //    if(path == null)
    //    {
    //        return false;
    //    }

    //    foreach (var textureInfo in textureCache)
    //    {
    //        if (textureInfo.Key == path)
    //        {
    //            AssetDatabase.DeleteAsset(textureInfo.Value.TempPath);
    //            AssetDatabase.DeleteAsset(textureInfo.Value.TempPathZoom);

    //            textureCache.Remove(path);
    //            bRet = true;
    //            break;
    //        }
    //    }

    //    return bRet;
    //}

    public Texture2D ZoomTexture(string spritePath, string atlasPath, float scaleFactor)
    {//缩放纹理
        Texture2D       tex        = null;
        TempTextureInfo spriteInfo = null;

        if ((string.IsNullOrEmpty(spritePath)) || (string.IsNullOrEmpty(atlasPath)) ||
            ((-0.000001f < scaleFactor) && (scaleFactor < 0.000001f)))
        {
            return(null);
        }

        if (IsSpriteInfoInCache(spritePath, atlasPath, out spriteInfo))
        {
            spriteInfo.ZoomTexture = ScaleTextureBilinear(spriteInfo.Texture, scaleFactor);
            spriteInfo.ZoomScale   = scaleFactor;

            byte[] bytes     = spriteInfo.ZoomTexture.EncodeToPNG();
            string newPath   = Path.GetFileNameWithoutExtension(spriteInfo.TempPath);
            string extension = Path.GetExtension(spriteInfo.TempPath);
            newPath = GetAtlasTempDir(atlasPath) + newPath + m_zoomStr + extension;

            UniversalEditorUtility.MakeFileWriteable(newPath);
            System.IO.File.WriteAllBytes(newPath, bytes);

            bytes = null;

            AssetDatabase.ImportAsset(newPath);
            MakeTextureReadable(newPath, false);
            AssetDatabase.Refresh(ImportAssetOptions.ForceSynchronousImport);

            spriteInfo.ZoomTexture = AssetDatabase.LoadAssetAtPath(newPath, typeof(Texture)) as Texture2D;

            tex = spriteInfo.ZoomTexture;
        }

        return(tex);
    }
Пример #23
0
    void OnDestroy()
    {
        coroutine = null;

        UniversalEditorUtility.SaveEditorLayout(this);

        if (rootCtrl == null)
        {
            return;
        }

        if (onDestroy != null)
        {
            onDestroy(this);
        }

        geometryTool.ReleaseAllGeometryObj();

        renderer.Destroy(rootCtrl);
        rootCtrl = null;
        EditorManager.GetInstance().RemoveEditor(editorName);


        onAwake                 = null;
        onEnable                = null;
        onDisable               = null;
        onUpdate                = null;
        onGUI                   = null;
        onDestroy               = null;
        onMessage               = null;
        onCoroutineMessage      = null;
        onCoroutineTaskFinished = null;

        renderer = null;
        GC.Collect();
    }
Пример #24
0
    void ClearPreview()
    {
        MainViewCtrl spriteView = _GetControl <MainViewCtrl>(m_SpriteViewName);

        if (null == spriteView)
        {
            return;
        }

        MainViewCtrl atlasView = _GetControl <MainViewCtrl>(m_AtlasViewName);

        if (null == atlasView)
        {
            return;
        }

        LabelCtrl spriteInfo = _GetControl <LabelCtrl>(m_SpriteInfoLabel);

        if (null == spriteInfo)
        {
            return;
        }

        LabelCtrl atlasInfo = _GetControl <LabelCtrl>(m_AtlasInfoLabel);

        if (null == atlasInfo)
        {
            return;
        }

        UniversalEditorUtility.DestoryChildren(spriteView.GetBindingTarget());
        UniversalEditorUtility.DestoryChildren(atlasView.GetBindingTarget());

        spriteInfo.Caption = "";
        atlasInfo.Caption  = "";
    }
Пример #25
0
    private List <string> GetAllAssetFilePath()
    {
        List <string> filePathTbl = UniversalEditorUtility.GetAllFilePath(m_inputInfo.PrefebPath);

        filePathTbl.AddRange(UniversalEditorUtility.GetAllFilePath(m_inputInfo.ScenePath));

        List <string> prefabPathTbl = new List <string>();

        foreach (var item in filePathTbl)
        {
            if (
                item.EndsWith(".prefab") ||
                item.EndsWith(".unity")
                )
            {
                if (!prefabPathTbl.Contains(item))
                {
                    prefabPathTbl.Add(item);
                }
            }
        }

        return(prefabPathTbl);
    }
Пример #26
0
    void OnSelectListItem(EditorControl c, int index)
    {
        if (
            (m_SearchResultInfo == null) ||
            (m_SearchResultInfo.SearchSpriteInfo == null)
            )
        {
            return;
        }

        ListViewCtrl searchList = c as ListViewCtrl;

        if (null == searchList)
        {
            return;
        }

        MainViewCtrl spriteView = _GetControl <MainViewCtrl>(m_SpriteViewName);

        if (null == spriteView)
        {
            return;
        }

        MainViewCtrl atlasView = _GetControl <MainViewCtrl>(m_AtlasViewName);

        if (null == atlasView)
        {
            return;
        }

        LabelCtrl spriteInfo = _GetControl <LabelCtrl>(m_SpriteInfoLabel);

        if (null == spriteInfo)
        {
            return;
        }

        LabelCtrl atlasInfo = _GetControl <LabelCtrl>(m_AtlasInfoLabel);

        if (null == atlasInfo)
        {
            return;
        }

        SearchSpriteInfo info = m_SearchResultInfo.SearchSpriteInfo[index];

        Texture atlasTex = info.AtlasTexture;

        //获取Sprite在Atlas中的位置
        Rect spriteUVRect = info.SpriteRect;
        //m_SearchResultInfo.GetSpirteUVRect(index);
        Rect spriteUVRectReal = UtilityForNGUI.ConvertToTexCoords(spriteUVRect, atlasTex.width, atlasTex.height);

        float aspect = (float)atlasTex.width / (float)atlasTex.height;
        float w1     = 10.0f;
        float h1     = w1 / aspect;

        float aspect2 = (float)spriteUVRect.width / (float)spriteUVRect.height;
        float w2      = 3.0f;
        float h2      = w2 / aspect2;

        //创建预览Object
        GameObject spritePreviewObj = _GenTexturePreviewObject(w2, h2, atlasTex, spriteUVRectReal);
        GameObject atlasPreviewObj  = _GenTexturePreviewObject(w1, h1, atlasTex, new Rect(0, 0, 1, 1));

        //将预览Object绑定至MainView的主相机之下
        UniversalEditorUtility.DestoryChildren(spriteView.GetBindingTarget());
        spritePreviewObj.transform.parent        = spriteView.GetBindingTarget().transform;
        spritePreviewObj.transform.localPosition = Vector3.zero;

        UniversalEditorUtility.DestoryChildren(atlasView.GetBindingTarget());
        atlasPreviewObj.transform.parent        = atlasView.GetBindingTarget().transform;
        atlasPreviewObj.transform.localPosition = Vector3.zero;

        //更新预览信息
        string atlasName = Path.GetFileNameWithoutExtension(info.AtlasPath);

        spriteInfo.Caption = "Sprite: " + info.SpriteName + " , " + spriteUVRect.width + " * " + spriteUVRect.height;
        atlasInfo.Caption  = "Atlas: " + atlasName + " , " + info.AtlasTexture.width + " * " + info.AtlasTexture.height;
        //spriteView.mainViewUVRect = spriteUVRect;

        RequestRepaint();
    }
Пример #27
0
    private void CheckUnConsistentSpriteInProject(AtlasProject project, out bool isAtlasConsistent, out List <SpriteConsistencyInfo> consistencyInfoTbl)
    {
        consistencyInfoTbl = new List <SpriteConsistencyInfo>();
        isAtlasConsistent  = true;

        if (null == project)
        {
            return;
        }

        List <string> spriteNameTblInProject = GetAllSpritePathInProject(project);
        List <string> spriteNameTblInPrefab  = GetAllSpriteNameInPrefab(project.DescribePath);

        //查找project
        foreach (var item in spriteNameTblInProject)
        {
            SpriteConsistencyInfo newConsistencyInfo = new SpriteConsistencyInfo();
            string spriteNameWithoutExt = Path.GetFileNameWithoutExtension(item);

            if (spriteNameTblInPrefab.Contains(spriteNameWithoutExt))
            {
                if (!File.Exists(@item))
                {
                    newConsistencyInfo.SpriteName      = spriteNameWithoutExt;
                    newConsistencyInfo.ProjectPath     = project.Path;
                    newConsistencyInfo.ExistInProject  = true;
                    newConsistencyInfo.ExistInPrefab   = true;
                    newConsistencyInfo.ExistInSourceAB = false;
                    newConsistencyInfo.IsConsistent    = false;

                    consistencyInfoTbl.Add(newConsistencyInfo);
                }

                //从prefab中移除该Sprite
                spriteNameTblInPrefab.Remove(spriteNameWithoutExt);
            }
            else
            {
                if (!File.Exists(item))
                {
                    newConsistencyInfo.ExistInSourceAB = false;
                }
                else
                {
                    newConsistencyInfo.ExistInSourceAB = true;
                }

                newConsistencyInfo.SpriteName     = spriteNameWithoutExt;
                newConsistencyInfo.ProjectPath    = project.Path;
                newConsistencyInfo.ExistInProject = true;
                newConsistencyInfo.ExistInPrefab  = false;
                newConsistencyInfo.IsConsistent   = false;

                consistencyInfoTbl.Add(newConsistencyInfo);
            }
        }

        //查找prefab
        if (spriteNameTblInPrefab.Count != 0)
        {
            List <string> sourcePicFilePath = UniversalEditorUtility.GetAllFileNameWithoutExtension(m_inputInfo.SourceSpriteDir);

            foreach (var item in spriteNameTblInPrefab)
            {
                SpriteConsistencyInfo newConsistencyInfo = new SpriteConsistencyInfo();
                if (!sourcePicFilePath.Contains(item))
                {
                    newConsistencyInfo.ExistInSourceAB = false;
                }
                else
                {
                    newConsistencyInfo.ExistInSourceAB = true;
                }

                newConsistencyInfo.SpriteName     = item;
                newConsistencyInfo.ProjectPath    = project.Path;
                newConsistencyInfo.ExistInProject = false;
                newConsistencyInfo.ExistInPrefab  = true;
                newConsistencyInfo.IsConsistent   = false;

                consistencyInfoTbl.Add(newConsistencyInfo);
            }
        }


        if (0 == consistencyInfoTbl.Count)
        {
            isAtlasConsistent = true;
        }
        else
        {
            isAtlasConsistent = false;
        }
    }
Пример #28
0
    public EditorRoot CreateEditor <T>(string name, bool utility, VoidDelegate initCallback, object userData = null)
        where T : EditorRoot, new()
    {
        if (roots.ContainsKey(name))
        {//有重名编辑器
            Debug.LogError("出现重名编辑器" + "\"name\"!");
            return(null);
        }

        //流程一:先实例化了一个Editor
        EditorRoot newEditor = EditorWindow.CreateInstance <T>();

        //初始化编辑器,实例化了一个EditorRender;
        newEditor.Init();

        //记录初始化回调,用于反射重生;

        //填写回调函数所在的类型;
        newEditor.initCallbackRefType = initCallback.Method.ReflectedType.FullName;
        //填写回调函数的函数名;
        newEditor.initCallback = initCallback.Method.Name;
        //填写是否为是Utility类型窗口;
        newEditor.isUtility = utility;
        //填写Editor的名称
        newEditor.editorName = name;
#if UNITY_5_1
        newEditor.titleContent = new GUIContent(name);
#else
        newEditor.title = name;
#endif

        newEditor.UserData = userData;

        //区分是否是utility类型调用Show方法;
        if (utility)
        {
            newEditor.ShowUtility();
        }
        else
        {
            newEditor.Show();
        }
        newEditor.Focus();

        //初始化控件
        initCallback(newEditor);

        AssignCtrlID(newEditor, newEditor.RootCtrl);

        UniversalEditorUtility.LoadEditorLayout(newEditor);

        if (newEditor.onAwake != null)
        {
            newEditor.onAwake(newEditor);
        }

        if (newEditor.onEnable != null)
        {
            newEditor.onEnable(newEditor);
        }

        roots.Add(name, newEditor);


        return(newEditor);
    }
    public Texture2D LoadTexture(string spritePath, string atlasPath, float scaleFactor)
    {
        if (
            string.IsNullOrEmpty(spritePath) ||
            string.IsNullOrEmpty(atlasPath) ||
            ((-0.000001f < scaleFactor) && (scaleFactor < 0.000001f))
            )
        {
            return(null);
        }

        _TouchTempDir();

        string tempAtlasDir = CreateAtlasTempDir(atlasPath);

        if (string.IsNullOrEmpty(tempAtlasDir))
        {
            return(null);
        }

        TempTextureInfo spriteInfo = null;

        string fileName           = Path.GetFileName(spritePath);
        string extension          = Path.GetExtension(spritePath);
        string fileNameWithoutext = Path.GetFileNameWithoutExtension(spritePath);
        string zoomedName         = string.Empty;

        bool isNeedRename = false;
        bool needCopy     = false;

        if (!IsEnableTextureFile(fileName))
        {
            return(null);
        }

        if (!File.Exists(spritePath))
        {
            DeleteUnuseAsset(spritePath, atlasPath);
            return(null);
        }

        if (IsSpriteInTempFloder(spritePath, atlasPath, out isNeedRename))
        {
            if (!IsSouceSpriteFileNoChange(spritePath, atlasPath))
            {
                needCopy = true;
            }
        }
        else
        {
            needCopy = true;
        }

        if (needCopy)
        {
            if (isNeedRename)
            {
                fileName   = fileNameWithoutext + "副本" + extension;
                zoomedName = fileNameWithoutext + "副本" + m_zoomStr + extension;
            }
            else
            {
                zoomedName = fileNameWithoutext + m_zoomStr + extension;
            }

            string absTempAtlasDir = EditorHelper.GetProjectPath() + tempAtlasDir;

            UniversalEditorUtility.MakeFileWriteable(absTempAtlasDir + fileName);
            File.Copy(spritePath, absTempAtlasDir + fileName, true);

            UniversalEditorUtility.MakeFileWriteable(absTempAtlasDir + zoomedName);
            File.Copy(spritePath, absTempAtlasDir + zoomedName, true);

            AssetDatabase.Refresh(ImportAssetOptions.ForceSynchronousImport);
        }


        //TempTextureInfo retTexInfo = null;
        if (!IsSpriteInfoInCache(spritePath, atlasPath, out spriteInfo))
        {//还未载入内存
            AssetDatabase.ImportAsset(tempAtlasDir + fileName);
            MakeTextureReadable(tempAtlasDir + fileName, false);
            TempTextureInfo newTexInfo = new TempTextureInfo();
            newTexInfo.SourcePath   = spritePath;
            newTexInfo.TempPath     = tempAtlasDir + fileName;
            newTexInfo.TempPathZoom = tempAtlasDir + zoomedName;
            newTexInfo.Texture      = AssetDatabase.LoadAssetAtPath(newTexInfo.TempPath, typeof(Texture)) as Texture2D;
            newTexInfo.ZoomScale    = scaleFactor;

            AssetDatabase.Refresh(ImportAssetOptions.ForceSynchronousImport);

            if (newTexInfo.Texture != null)
            {
                newTexInfo.ZoomTexture = newTexInfo.Texture;
                AddSpriteInCache(spritePath, atlasPath, newTexInfo);

                if (scaleFactor != 1.0f)
                {
                    ZoomTexture(spritePath, atlasPath, scaleFactor);
                }
            }
        }


        return(GetSpriteTexture(spritePath, atlasPath));
    }
Пример #30
0
    public static void CreateXMLConfigWithNode(string path, string NodeType, string NodeValue)
    {
        if (!Directory.Exists(Path.GetDirectoryName(path)))
        {
            Directory.CreateDirectory(Path.GetDirectoryName(path));
        }

        UniversalEditorUtility.MakeFileWriteable(configPath);

        XmlDocument docment = new XmlDocument();
        XmlElement  root    = docment.CreateElement("UIAtlasConfig");

        docment.AppendChild(root);

        XmlElement nodeImageBasePath = docment.CreateElement("ImageBasePath");

        root.AppendChild(nodeImageBasePath);

        XmlElement nodeProjectPath = docment.CreateElement("ProjectPath");

        root.AppendChild(nodeProjectPath);

        XmlElement nodeConsistencyResultPath = docment.CreateElement("ConsistencyResultPath");

        root.AppendChild(nodeConsistencyResultPath);

        XmlElement nodeConsistencyPrefabPath = docment.CreateElement("ConsistencyPrefabPath");

        root.AppendChild(nodeConsistencyPrefabPath);

        XmlElement nodeReferencePrefabPath = docment.CreateElement("ReferencePrefabPath");

        root.AppendChild(nodeReferencePrefabPath);

        XmlElement nodeReferenceScenePath = docment.CreateElement("ReferenceScenePath");

        root.AppendChild(nodeReferenceScenePath);

        XmlElement nodeReferenceResultPath = docment.CreateElement("ReferenceResultPath");

        root.AppendChild(nodeReferenceResultPath);

        switch (NodeType)
        {
        case "ImageBasePath":
            nodeImageBasePath.InnerText = NodeValue;
            break;

        case "ProjectPath":
            nodeProjectPath.InnerText = NodeValue;
            break;

        case "ConsistencyResultPath":
            nodeConsistencyResultPath.InnerText = NodeValue;
            break;

        case "ConsistencyPrefabPath":
            nodeConsistencyPrefabPath.InnerText = NodeValue;
            break;

        case "ReferencePrefabPath":
            nodeReferencePrefabPath.InnerText = NodeValue;
            break;

        case "ReferenceScenePath":
            nodeReferenceScenePath.InnerText = NodeValue;
            break;

        case "ReferenceResultPath":
            nodeReferenceResultPath.InnerText = NodeValue;
            break;

        default:
            break;
        }

        docment.Save(configPath);
    }