同步操作将从 jzt/UnityFun 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
using System.IO;using System.Xml;using UnityEngine;using UnityEditor;public class CSProjectFile{public string AssemblyName;public string ProjectPath;public string[] SrcList;public CSProjectFile(string assemblyName, string projectPath, string[] srcList){AssemblyName = assemblyName;ProjectPath = projectPath;SrcList = srcList;}public void GenerateCSProject(CSProjectFile csproj){string csprojDir = Path.GetDirectoryName(csproj.ProjectPath);if (!Directory.Exists(csprojDir)){Directory.CreateDirectory(csprojDir);}var doc = new XmlDocument();doc.AppendChild(doc.CreateXmlDeclaration("1.0", "utf-8", null));var project = doc.CreateElement("Project");project.SetAttribute("ToolsVersion", "4.0");project.SetAttribute("DefaultTargets", "Build");project.SetAttribute("xmlns", "http://schemas.microsoft.com/developer/msbuild/2003");var propertyGroup = doc.CreateElement("PropertyGroup");var configuration = doc.CreateElement("Configuration");configuration.SetAttribute("Condition", " '$(Configuration)' == '' ");configuration.InnerText = "Debug";propertyGroup.AppendChild(configuration);var platform = doc.CreateElement("Platform");platform.SetAttribute("Condition", " '$(Platform)' == '' ");platform.InnerText = "AnyCPU";propertyGroup.AppendChild(platform);var projectGuid = doc.CreateElement("ProjectGuid");projectGuid.InnerText = "{05ABCACF-71A2-4C54-95F9-04BCF0C913F3}";propertyGroup.AppendChild(projectGuid);var outputType = doc.CreateElement("OutputType");outputType.InnerText = "Library";propertyGroup.AppendChild(outputType);var assemblyName = doc.CreateElement("AssemblyName");assemblyName.InnerText = csproj.AssemblyName;propertyGroup.AppendChild(assemblyName);var targetFrameworkIdentifier = doc.CreateElement("TargetFrameworkIdentifier");targetFrameworkIdentifier.InnerText = ".NETFramework";propertyGroup.AppendChild(targetFrameworkIdentifier);var targetFrameworkVersion = doc.CreateElement("TargetFrameworkVersion");targetFrameworkVersion.InnerText = "v3.5";propertyGroup.AppendChild(targetFrameworkVersion);project.AppendChild(propertyGroup);project.AppendChild(GeneratePlatformPropertyGroup(doc, "Debug"));project.AppendChild(GeneratePlatformPropertyGroup(doc, "Release"));project.AppendChild(GenReferenceItemGroup(doc));var itemGroup = doc.CreateElement("ItemGroup");foreach (var src in csproj.SrcList){var compile = doc.CreateElement("Compile");compile.SetAttribute("Include", src);itemGroup.AppendChild(compile);}project.AppendChild(itemGroup);var import = doc.CreateElement("Import");import.SetAttribute("Project", @"$(MSBuildToolsPath)\Microsoft.CSharp.targets");project.AppendChild(import);var target = doc.CreateElement("Target");target.SetAttribute("Name", "AfterBuild");var copy = doc.CreateElement("Copy");copy.SetAttribute("SourceFiles", string.Format(@"$(OutputPath){0}.dll", AssemblyName));copy.SetAttribute("DestinationFolder", string.Format(@"{0}\Assets\Plugins", System.Environment.CurrentDirectory));copy.SetAttribute("ContinueOnError", "false");target.AppendChild(copy);project.AppendChild(target);doc.AppendChild(project);doc.Save(csproj.ProjectPath);}private static XmlElement GeneratePlatformPropertyGroup(XmlDocument doc, string mode){var propertyGroup = doc.CreateElement("PropertyGroup");propertyGroup.SetAttribute("Condition", " '$(Configuration)|$(Platform)' == '" + mode + "|AnyCPU' ");var debugType = doc.CreateElement("DebugType");debugType.InnerText = "pdbonly";propertyGroup.AppendChild(debugType);var optimize = doc.CreateElement("Optimize");optimize.InnerText = "false";propertyGroup.AppendChild(optimize);var outputPath = doc.CreateElement("OutputPath");outputPath.InnerText = string.Format(@"bin\{0}\", mode);propertyGroup.AppendChild(outputPath);var intermediateOutputPath = doc.CreateElement("IntermediateOutputPath");intermediateOutputPath.InnerText = string.Format(@"obj\{0}\", mode);propertyGroup.AppendChild(intermediateOutputPath);var errorRepoert = doc.CreateElement("ErrorReport");errorRepoert.InnerText = "prompt";propertyGroup.AppendChild(errorRepoert);var warningLevel = doc.CreateElement("WarningLevel");warningLevel.InnerText = "4";propertyGroup.AppendChild(warningLevel);var defineStr ="TRACE;ENABLE_PROFILER";var defineConstants = doc.CreateElement("DefineConstants");defineConstants.InnerText = string.Format("{0};{1}", mode.ToUpper(), defineStr);propertyGroup.AppendChild(defineConstants);var allowUnsafeBlocks = doc.CreateElement("AllowUnsafeBlocks");allowUnsafeBlocks.InnerText = "false";propertyGroup.AppendChild(allowUnsafeBlocks);return propertyGroup;}private static XmlElement GenReferenceItemGroup(XmlDocument doc){var itemGroup = doc.CreateElement("ItemGroup");itemGroup.AppendChild(GenerateReference(doc, "mscorlib"));itemGroup.AppendChild(GenerateReference(doc, "System"));itemGroup.AppendChild(GenerateReference(doc, "System.XML"));itemGroup.AppendChild(GenerateReference(doc, "System.Core"));itemGroup.AppendChild(GenerateReference(doc, "System.Runtime.Serialization"));itemGroup.AppendChild(GenerateReference(doc, "System.Xml.Linq"));itemGroup.AppendChild(GenerateReference(doc, "UnityEngine", Path.Combine(UnityEditorPathTool.GetManagedFolder(), @"UnityEngine.dll")));itemGroup.AppendChild(GenerateReference(doc, "UnityEditor", Path.Combine(UnityEditorPathTool.GetManagedFolder(), @"UnityEditor.dll")));itemGroup.AppendChild(GenerateReference(doc, "UnityEngine.UI",Path.Combine(UnityEditorPathTool.GetContentFolder(), @"UnityExtensions\Unity\GUISystem\UnityEngine.UI.dll")));itemGroup.AppendChild(GenerateReference(doc, "Assembly-CSharp",string.Format(@"{0}\Library\ScriptAssemblies\Assembly-CSharp.dll",System.Environment.CurrentDirectory)));itemGroup.AppendChild(GenerateReference(doc, "Assembly-CSharp-firstpass",string.Format(@"{0}\Library\ScriptAssemblies\Assembly-CSharp-firstpass.dll",System.Environment.CurrentDirectory)));itemGroup.AppendChild(GenerateReference(doc, "DOTween",string.Format(@"{0}\Assets\ThirdParty\DOTween\DOTween.dll",System.Environment.CurrentDirectory)));return itemGroup;}private static XmlElement GenerateReference(XmlDocument doc, string library, string hintPath = null){var reference = doc.CreateElement("Reference");reference.SetAttribute("Include", library);if (hintPath != null){var hintPathNode = doc.CreateElement("HintPath");hintPathNode.InnerText = hintPath;reference.AppendChild(hintPathNode);}return reference;}}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。