diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 0000000..b8d0037 --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1,12 @@ +# These are supported funding model platforms + +github: mob-sakai # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2] +patreon: mob_sakai # Replace with a single Patreon username +open_collective: # Replace with a single Open Collective username +ko_fi: # Replace with a single Ko-fi username +tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel +community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry +liberapay: # Replace with a single Liberapay username +issuehunt: # Replace with a single IssueHunt username +otechie: # Replace with a single Otechie username +custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2'] diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md new file mode 100644 index 0000000..6e2802e --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -0,0 +1,35 @@ +--- +name: Bug report +about: Create a report to help us improve +title: '' +labels: bug +assignees: mob-sakai + +--- + +NOTE: Your issue may already be reported! Please search on the [issue tracker](../) before creating one. + +**Describe the bug** +A clear and concise description of what the bug is. + +**To Reproduce** +Steps to reproduce the behavior: +1. Go to '...' +2. Click on '....' +3. Scroll down to '....' +4. See error + +**Expected behavior** +A clear and concise description of what you expected to happen. + +**Screenshots** +If applicable, add screenshots to help explain your problem. + +**Environment (please complete the following information):** + - Version [e.g. 1.0.0] + - Platform: [e.g. Editor(Windows/Mac), Standalone(Windows/Mac), iOS, Android, WebGL] + - Unity version: [e.g. 2018.2.8f1] + - Build options: [e.g. IL2CPP, .Net 4.x, LWRP] + +**Additional context** +Add any other context about the problem here. diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md new file mode 100644 index 0000000..e55417e --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -0,0 +1,22 @@ +--- +name: Feature request +about: Suggest an idea for this project +title: '' +labels: enhancement +assignees: mob-sakai + +--- + +NOTE: Your issue may already be reported! Please search on the [issue tracker](../) before creating one. + +**Is your feature request related to a problem? Please describe.** +A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] + +**Describe the solution you'd like** +A clear and concise description of what you want to happen. + +**Describe alternatives you've considered** +A clear and concise description of any alternative solutions or features you've considered. + +**Additional context** +Add any other context or screenshots about the feature request here. diff --git a/.github/ISSUE_TEMPLATE/question.md b/.github/ISSUE_TEMPLATE/question.md new file mode 100644 index 0000000..8fa7151 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/question.md @@ -0,0 +1,16 @@ +--- +name: Question +about: Ask a question about this project +title: '' +labels: question +assignees: mob-sakai + +--- + +NOTE: Your issue may already be reported! Please search on the [issue tracker](../) before creating one. + +**Describe what help do you need** +A description of the question. + +**Additional context** +Add any other context or screenshots about the question here. diff --git a/CHANGELOG.md b/CHANGELOG.md index cb7cb94..0029ab5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +# [3.0.0-preview.4](https://github.com/mob-sakai/ParticleEffectForUGUI/compare/v3.0.0-preview.3...v3.0.0-preview.4) (2020-02-18) + + +### Bug Fixes + +* compile error in Unity 2019.1 or later ([28ca922](https://github.com/mob-sakai/ParticleEffectForUGUI/commit/28ca922167afff3ef8341fa747968357d4487d1f)), closes [#70](https://github.com/mob-sakai/ParticleEffectForUGUI/issues/70) [#71](https://github.com/mob-sakai/ParticleEffectForUGUI/issues/71) + # [3.0.0-preview.3](https://github.com/mob-sakai/ParticleEffectForUGUI/compare/v3.0.0-preview.2...v3.0.0-preview.3) (2020-02-17) diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md new file mode 100644 index 0000000..e963f2b --- /dev/null +++ b/CODE_OF_CONDUCT.md @@ -0,0 +1,84 @@ +# Contributor Covenant Code of Conduct + +## Our Pledge + +We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation. + +We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community. + +## Our Standards + +Examples of behavior that contributes to a positive environment for our community include: + +* Demonstrating empathy and kindness toward other people +* Being respectful of differing opinions, viewpoints, and experiences +* Giving and gracefully accepting constructive feedback +* Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience +* Focusing on what is best not just for us as individuals, but for the overall community + +Examples of unacceptable behavior include: + +* The use of sexualized language or imagery, and sexual attention or + advances of any kind +* Trolling, insulting or derogatory comments, and personal or political attacks +* Public or private harassment +* Publishing others' private information, such as a physical or email + address, without their explicit permission +* Other conduct which could reasonably be considered inappropriate in a + professional setting + +## Enforcement Responsibilities + +Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful. + +Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate. + +## Scope + +This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. + +## Enforcement + +Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at sakai861104@gmail.com. All complaints will be reviewed and investigated promptly and fairly. + +All community leaders are obligated to respect the privacy and security of the reporter of any incident. + +## Enforcement Guidelines + +Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct: + +### 1. Correction + +**Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community. + +**Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested. + +### 2. Warning + +**Community Impact**: A violation through a single incident or series of actions. + +**Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban. + +### 3. Temporary Ban + +**Community Impact**: A serious violation of community standards, including sustained inappropriate behavior. + +**Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban. + +### 4. Permanent Ban + +**Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals. + +**Consequence**: A permanent ban from any sort of public interaction within the community. + +## Attribution + +This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0, +available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html. + +Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity). + +[homepage]: https://www.contributor-covenant.org + +For answers to common questions about this code of conduct, see the FAQ at +https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations. \ No newline at end of file diff --git a/CODE_OF_CONDUCT.md.meta b/CODE_OF_CONDUCT.md.meta new file mode 100644 index 0000000..1fd5086 --- /dev/null +++ b/CODE_OF_CONDUCT.md.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: dced951d19ddf4b2c8f4a6053d82125a +TextScriptImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..85176fb --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,30 @@ +# Contributing + +## How to Contribute + +#### Code of Conduct + +This repository has adopted the Contributor Covenant as it's +Code of Conduct. It is expected that participants adhere to it. + +#### Proposing a Change + +If you are unsure about whether or not a change is desired, +you can create an issue. This is useful because it creates +the possibility for a discussion that's visible to everyone. + +When fixing a bug it is fine to submit a pull request right away. + +#### Sending a Pull Request + +Steps to be performed to submit a pull request: + +1. Fork the repository and create your branch from `develop`. +2. If you have fixed a bug or added code that should be tested, add tests. +3. Click `Window > Generals > Test Runner` to test +4. Commit with a massage based on [Angular Commit Message Conventions](https://gist.github.com/stephenparish/9941e89d80e2bc58a153). +5. Fill out the description, link any related issues and submit your pull request. + +#### License + +By contributing to this repository, you agree that your contributions will be licensed under its MIT license. diff --git a/CONTRIBUTING.md.meta b/CONTRIBUTING.md.meta new file mode 100644 index 0000000..5f9397b --- /dev/null +++ b/CONTRIBUTING.md.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: dbeb9a981ffa640d7a1e88a19b66efb5 +TextScriptImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/README.md b/README.md index 245ffd1..f430376 100644 --- a/README.md +++ b/README.md @@ -70,25 +70,28 @@ Compares this "Baking mesh" approach with the conventional approach:



## Install -#### Using UnityPackageManager (for Unity 2018.3+) +#### Using UnityPackageManager (for Unity 2018.3 or later) Find the manifest.json file in the Packages folder of your project and edit it to look like this: ```js { "dependencies": { - "com.coffee.ui-particle": "https://github.com/mob-sakai/ParticleEffectForUGUI.git#2.2.1", + "com.coffee.ui-particle": "https://github.com/mob-sakai/ParticleEffectForUGUI.git", ... }, } ``` -To update the package, change `#{version}` to the target version. -Or, use [UpmGitExtension](https://github.com/mob-sakai/UpmGitExtension). -#### Using .unitypackage file (for Unity 2018.2+) +To update the package, change suffix `#{version}` to the target version. -Download `*.unitypackage` from [Releases](https://github.com/mob-sakai/ParticleEffectForUGUI/releases) and import the package into your Unity project. -Select `Assets > Import Package > Custom Package` from the menu. -![](https://user-images.githubusercontent.com/12690315/46570979-edbb5a00-c9a7-11e8-845d-c5ee279effec.png) +* e.g. `"com.coffee.open-sesame-compiler": "https://github.com/mob-sakai/OpenSesameCompilerForUnity.git#1.0.0",` + +Or, use [UpmGitExtension](https://github.com/mob-sakai/UpmGitExtension) to install and update the package. + +#### Using zip file (for Unity 2018.2) + +1. Download a source code zip file from [Releases](https://github.com/mob-sakai/ParticleEffectForUGUI/releases) page +2. Extract and import it into your Unity project diff --git a/Scripts/Editor/AsmdefEx.cs b/Scripts/Editor/AsmdefEx.cs new file mode 100644 index 0000000..9221c90 --- /dev/null +++ b/Scripts/Editor/AsmdefEx.cs @@ -0,0 +1,447 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Diagnostics; +using System.IO; +using System.Linq; +using System.Net; +using System.Net.Security; +using System.Reflection; +using System.Security.Cryptography.X509Certificates; +using System.Text.RegularExpressions; +using UnityEditor; +using UnityEngine; +using UnityEditor.Compilation; + +namespace Coffee.AsmdefEx +{ + internal static class ReflectionExtensions + { + const BindingFlags FLAGS = BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic; + static object Inst(this object self) + { + return (self is Type) ? null : self; + } + + static Type Type(this object self) + { + return (self as Type) ?? self.GetType(); + } + + public static object New(this Type self, params object[] args) + { + var types = args.Select(x => x.GetType()).ToArray(); + return self.Type().GetConstructor(types) + .Invoke(args); + } + + public static object Call(this object self, string methodName, params object[] args) + { + var types = args.Select(x => x.GetType()).ToArray(); + return self.Type().GetMethod(methodName, types) + .Invoke(self.Inst(), args); + } + + public static object Call(this object self, Type[] genericTypes, string methodName, params object[] args) + { + return self.Type().GetMethod(methodName, FLAGS) + .MakeGenericMethod(genericTypes) + .Invoke(self.Inst(), args); + } + + public static object Get(this object self, string memberName, MemberInfo mi = null) + { + mi = mi ?? self.Type().GetMember(memberName, FLAGS)[0]; + return mi is PropertyInfo + ? (mi as PropertyInfo).GetValue(self.Inst(), new object[0]) + : (mi as FieldInfo).GetValue(self.Inst()); + } + + public static void Set(this object self, string memberName, object value, MemberInfo mi = null) + { + mi = mi ?? self.Type().GetMember(memberName, FLAGS)[0]; + if (mi is PropertyInfo) + (mi as PropertyInfo).SetValue(self.Inst(), value, new object[0]); + else + (mi as FieldInfo).SetValue(self.Inst(), value); + } + } + + internal class Settings + { + public bool IgnoreAccessChecks; + public string ModifySymbols = ""; + + public bool SholdChangeCompilerProcess { get { return IgnoreAccessChecks || !string.IsNullOrEmpty(ModifySymbols); } } + public bool SholdModifyDefines { get { return IgnoreAccessChecks || !string.IsNullOrEmpty(ModifySymbols); } } + + public static Settings GetAtPath(string path) + { + var setting = new Settings(); + if (string.IsNullOrEmpty(path)) + return setting; + + // If input path is directory, find asmdef file. + if (Directory.Exists(path)) + path = Directory.GetFiles(path, "*.asmdef") + .Select(x => x.Replace(Environment.CurrentDirectory + Path.DirectorySeparatorChar, "")) + .FirstOrDefault(); + + // Not find asmdef file. + if (string.IsNullOrEmpty(path) || !File.Exists(path) || !File.Exists(path + ".meta")) + return setting; + + try + { + var json = AssetImporter.GetAtPath(path).userData; + GetSettingssFromJson(json, out setting.IgnoreAccessChecks, out setting.ModifySymbols); + } + catch { } + return setting; + } + + public string ToJson() + { + return string.Format("{{\"IgnoreAccessChecks\":{0},\"ModifySymbols\":\"{1}\"}}", IgnoreAccessChecks ? "true" : "false", ModifySymbols ?? ""); + } + + public static Settings CreateFromJson(string json = "") + { + var setting = new Settings(); + GetSettingssFromJson(json, out setting.IgnoreAccessChecks, out setting.ModifySymbols); + return setting; + } + + static void GetSettingssFromJson(string json, out bool IgnoreAccessChecks, out string modifySymbols) + { + IgnoreAccessChecks = false; + modifySymbols = ""; + if (string.IsNullOrEmpty(json)) + return; + + IgnoreAccessChecks = Regex.Match(json, "\"IgnoreAccessChecks\":\\s*(true|false)").Groups[1].Value == "true"; + modifySymbols = Regex.Match(json, "\"ModifySymbols\":\\s*\"([^\"]*)\"").Groups[1].Value; + } + } + + internal static class OpenSesameCompiler + { + static bool s_IsInstallFailed; + static string s_InstallPath; + const string k_Version = "3.4.0"; + const string k_LogHeader = "[OpenSesameCompiler] "; + + static void Log(string format, params object[] args) + { + if (Core.LogEnabled) + UnityEngine.Debug.LogFormat(k_LogHeader + format, args); + } + + public static string GetInstalledPath() + { + if (s_IsInstallFailed) + return ""; + + if (!string.IsNullOrEmpty(s_InstallPath)) + return s_InstallPath; + + try + { + s_InstallPath = Install(k_Version); + } + catch (Exception ex) + { + s_IsInstallFailed = true; + UnityEngine.Debug.LogException(new Exception(k_LogHeader + ex.Message, ex.InnerException)); + } + finally + { + EditorUtility.ClearProgressBar(); + } + return s_InstallPath; + } + + static string Install(string version) + { + string packageId = "OpenSesameCompiler." + version; + string url = "https://globalcdn.nuget.org/packages/" + packageId.ToLower() + ".nupkg"; + string dowloadPath = Path.GetTempFileName() + ".nuget"; + string installPath = ("Library/" + packageId).Replace('/', Path.DirectorySeparatorChar); + string cscToolExe = (installPath + "/tools/csc.exe").Replace('/', Path.DirectorySeparatorChar); + + // OpenSesame compiler is already installed. + if (File.Exists(cscToolExe)) + { + Log("{0} is already installed at {1}", packageId, cscToolExe); + return cscToolExe; + } + + if (Directory.Exists(installPath)) + Directory.Delete(installPath, true); + + // Download csc from nuget. + UnityEngine.Debug.LogFormat(k_LogHeader + "Download {0} from nuget: {1}", packageId, url); + EditorUtility.DisplayProgressBar("Open Sesame Installer", string.Format("Download {0} from nuget", packageId), 0.2f); + try + { + using (var client = new WebClient()) + client.DownloadFile(url, dowloadPath); + } + catch + { + using (var client = new WebClient()) + { + ServicePointManager.ServerCertificateValidationCallback += OnServerCertificateValidation; + client.DownloadFile(url, dowloadPath); + } + } + finally + { + EditorUtility.ClearProgressBar(); + ServicePointManager.ServerCertificateValidationCallback -= OnServerCertificateValidation; + } + + // Extract zip. + string args = string.Format("x {0} -o{1}", dowloadPath, installPath); + string exe = Path.Combine(EditorApplication.applicationContentsPath, + Application.platform == RuntimePlatform.WindowsEditor ? "Tools\\7z.exe" : "Tools/7za"); + UnityEngine.Debug.LogFormat(k_LogHeader + "Extract {0} to {1} with 7z command: {2} {3}", dowloadPath, installPath, exe, args); + try + { + EditorUtility.DisplayProgressBar("Open Sesame Installer", string.Format("Extract {0}", dowloadPath), 0.4f); + } + finally + { + Process.Start(exe, args).WaitForExit(); + } + + if (File.Exists(cscToolExe)) + return cscToolExe; + + throw new FileNotFoundException("Open Sesame compiler is not found at " + cscToolExe); + } + + private static bool OnServerCertificateValidation(object _, X509Certificate __, X509Chain ___, SslPolicyErrors ____) + { + return true; + } + } + + [InitializeOnLoad] + internal static class Core + { + public static bool LogEnabled { get; private set; } + public static string k_LogHeader = "[AsmdefEx] "; + + static void Log(string format, params object[] args) + { + if (LogEnabled) + LogEx(format, args); + } + + public static void LogEx(string format, params object[] args) + { + UnityEngine.Debug.LogFormat(k_LogHeader + format, args); + } + + public static void Error(Exception e) + { + UnityEngine.Debug.LogException(new Exception(k_LogHeader + e.Message, e.InnerException)); + } + + public static object GetScriptAssembly(string assemblyName) + { + Type tEditorCompilationInterface = Type.GetType("UnityEditor.Scripting.ScriptCompilation.EditorCompilationInterface, UnityEditor"); + Type tCSharpLanguage = Type.GetType("UnityEditor.Scripting.Compilers.CSharpLanguage, UnityEditor"); + return tEditorCompilationInterface.Call(new[] { tCSharpLanguage }, "GetScriptAssemblyForLanguage", assemblyName); + } + + public static string[] ModifyDefines(IEnumerable defines, bool ignoreAccessChecks, string modifySymbols) + { + var symbols = modifySymbols.Split(';', ','); + var add = symbols.Where(x => 0 < x.Length && !x.StartsWith("!")); + var remove = symbols.Where(x => 1 < x.Length && x.StartsWith("!")).Select(x => x.Substring(1)); + return defines + .Union(add ?? Enumerable.Empty()) + .Except(remove ?? Enumerable.Empty()) + .Union(ignoreAccessChecks ? new[] { "IGNORE_ACCESS_CHECKS" } : Enumerable.Empty()) + .Distinct() + .ToArray(); + } + + public static void ModifyFiles(IEnumerable files, bool ignoreAccessChecks) + { + const string s_If = "#if IGNORE_ACCESS_CHECKS // [ASMDEFEX] DO NOT REMOVE THIS LINE MANUALLY."; + const string s_EndIf = "#endif // [ASMDEFEX] DO NOT REMOVE THIS LINE MANUALLY."; + + // Add #if and #endif to all source files. + foreach (var file in files) + { + var text = File.ReadAllText(file); + Log("ModifyFiles: {0} {1} {2}", file, ignoreAccessChecks, text.Contains(s_If)); + if (text.Contains(s_If) == ignoreAccessChecks) + continue; + + var m = Regex.Match(text, "[\r\n]+"); + if (!m.Success) + continue; + + var nl = m.Value; + if (ignoreAccessChecks) + { + text = s_If + nl + text + nl + s_EndIf; + } + else + { + text = text.Replace(s_If + nl, ""); + text = text.Replace(nl + s_EndIf, ""); + } + Log("ModifyFiles: Write {0} {1} {2}", file, ignoreAccessChecks, text.Contains(s_If)); + File.WriteAllText(file, text); + } + } + + public static void ChangeCompilerProcess(object compiler, Settings setting) + { + Type tProgram = Type.GetType("UnityEditor.Utils.Program, UnityEditor"); + Type tScriptCompilerBase = Type.GetType("UnityEditor.Scripting.Compilers.ScriptCompilerBase, UnityEditor"); + FieldInfo fiProcess = tScriptCompilerBase.GetField("process", BindingFlags.NonPublic | BindingFlags.Instance); + + Log("Kill previous compiler process"); + var psi = compiler.Get("process", fiProcess).Call("GetProcessStartInfo") as ProcessStartInfo; + compiler.Call("Dispose"); + + // Convert response file for Mono to .Net. + // - Add preferreduilang option (en-US) + // - Change language version to 'latest' + // - Change 'debug' to 'debug:portable' + // - Change compiler switch prefix '-' to '/' + string responseFile = Regex.Replace(psi.Arguments, "^.*@(.+)$", "$1"); + bool isMono = compiler.GetType().Name == "MonoCSharpCompiler"; + var text = File.ReadAllText(responseFile); + text = Regex.Replace(text, "[\r\n]+", "\n"); + text = Regex.Replace(text, "^-", "/", RegexOptions.Multiline); + + // Modify scripting define symbols. + if (setting.SholdModifyDefines) + { + Log("Modify scripting define symbols: {0}", responseFile); + var defines = Regex.Matches(text, "^/define:(.*)$", RegexOptions.Multiline) + .Cast() + .Select(x => x.Groups[1].Value); + + text = Regex.Replace(text, "[\r\n]+/define:[^\r\n]+", ""); + foreach (var d in ModifyDefines(defines, setting.IgnoreAccessChecks, setting.ModifySymbols)) + { + text += "\n/define:" + d; + } + } + + // Add/remove '#if IGNORE_ACCESS_CHECKS' and '#endif' preprocessor. + var files = Regex.Matches(text, "^\"(.*)\"$", RegexOptions.Multiline) + .Cast() + .Select(x => x.Groups[1].Value) + .Where(x => Path.GetExtension(x) == ".cs") + .Where(x => Path.GetFileName(x) != "AsmdefEx.cs"); + ModifyFiles(files, setting.IgnoreAccessChecks); + + // To access to non-publics in other assemblies, use OpenSesameCompiler instead of default csc. + if (setting.IgnoreAccessChecks) + { + text = Regex.Replace(text, "^/langversion:\\d+$", "/langversion:latest", RegexOptions.Multiline); + text = Regex.Replace(text, "^/debug$", "/debug:portable", RegexOptions.Multiline); + text += "\n/preferreduilang:en-US"; + + // Change exe file path. + var cscToolExe = OpenSesameCompiler.GetInstalledPath(); + Log("Change csc tool exe to {0}", cscToolExe); + if (Application.platform == RuntimePlatform.WindowsEditor) + { + psi.FileName = Path.GetFullPath(cscToolExe); + psi.Arguments = "/shared /noconfig @" + responseFile; + } + else + { + psi.FileName = Path.Combine(EditorApplication.applicationContentsPath, "MonoBleedingEdge/bin/mono"); + psi.Arguments = cscToolExe + " /noconfig @" + responseFile; + } + } + // Revert prefix symbols for mono compiler + else if (isMono) + { + text = Regex.Replace(text, "^/", "-", RegexOptions.Multiline); + } + + text = Regex.Replace(text, "\n", System.Environment.NewLine); + File.WriteAllText(responseFile, text); + + Log("Restart compiler process: {0} {1}", psi.FileName, psi.Arguments); + var program = tProgram.New(psi); + program.Call("Start"); + compiler.Set("process", program, fiProcess); + } + + static void OnAssemblyCompilationStarted(string name) + { + try + { + string assemblyName = Path.GetFileNameWithoutExtension(name); + string assemblyFilename = assemblyName + ".dll"; + + if (assemblyName != typeof(Core).Assembly.GetName().Name) + return; + + Type tEditorCompilationInterface = Type.GetType("UnityEditor.Scripting.ScriptCompilation.EditorCompilationInterface, UnityEditor"); + var compilerTasks = tEditorCompilationInterface.Get("Instance").Get("compilationTask").Get("compilerTasks") as IDictionary; + var scriptAssembly = compilerTasks.Keys.Cast().FirstOrDefault(x => (x.Get("Filename") as string) == assemblyFilename); + + // Should change compiler process for the assembly? + var asmdefPath = CompilationPipeline.GetAssemblyDefinitionFilePathFromAssemblyName(assemblyName); + var setting = Settings.GetAtPath(asmdefPath); + if (!setting.SholdChangeCompilerProcess) + return; + + // Create new compiler to recompile. + Log("Assembly compilation started: {0} should be recompiled.", assemblyName); + Core.ChangeCompilerProcess(compilerTasks[scriptAssembly], setting); + } + catch (Exception e) + { + UnityEngine.Debug.LogException(new Exception(k_LogHeader + e.Message, e.InnerException)); + } + } + + static Core() + { + var assemblyName = typeof(Core).Assembly.GetName().Name; + if (assemblyName == "Coffee.AsmdefEx") + return; + + k_LogHeader = string.Format("[AsmdefEx ({0})] ", assemblyName); + LogEnabled = PlayerSettings.GetScriptingDefineSymbolsForGroup(EditorUserBuildSettings.selectedBuildTargetGroup) + .Split(';', ',') + .Any(x => x == "ASMDEF_EX_LOG"); + + Log("Start watching assembly '{0}' compilation.", typeof(Core).Assembly.GetName().Name); + CompilationPipeline.assemblyCompilationStarted += OnAssemblyCompilationStarted; + } + } + +#if !IGNORE_ACCESS_CHECKS + [InitializeOnLoad] + internal class RecompileRequest + { + static RecompileRequest() + { + var assemblyName = typeof(RecompileRequest).Assembly.GetName().Name; + if (assemblyName == "Coffee.AsmdefEx") + return; + + var asmdefPath = CompilationPipeline.GetAssemblyDefinitionFilePathFromAssemblyName(assemblyName); + if (Core.LogEnabled) + UnityEngine.Debug.LogFormat("Request to recompile: {0} ({1})", assemblyName, asmdefPath); + AssetDatabase.ImportAsset(asmdefPath); + } + } +#endif +} \ No newline at end of file diff --git a/Scripts/Editor/OpenSesamePortable.cs.meta b/Scripts/Editor/AsmdefEx.cs.meta similarity index 83% rename from Scripts/Editor/OpenSesamePortable.cs.meta rename to Scripts/Editor/AsmdefEx.cs.meta index 0cb5303..3e8920f 100644 --- a/Scripts/Editor/OpenSesamePortable.cs.meta +++ b/Scripts/Editor/AsmdefEx.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 1945fcd655ed94bfd80e8f918453c865 +guid: 0defeb6d13f61475eacce2b101cb2248 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Scripts/Editor/Coffee.UIParticle.Editor.asmdef b/Scripts/Editor/Coffee.UIParticle.Editor.asmdef index bcedd90..80a575b 100644 --- a/Scripts/Editor/Coffee.UIParticle.Editor.asmdef +++ b/Scripts/Editor/Coffee.UIParticle.Editor.asmdef @@ -8,5 +8,9 @@ "Editor" ], "excludePlatforms": [], - "allowUnsafeCode": false + "allowUnsafeCode": false, + "overrideReferences": true, + "precompiledReferences": [], + "autoReferenced": false, + "defineConstraints": [] } \ No newline at end of file diff --git a/Scripts/Editor/Coffee.UIParticle.Editor.asmdef.meta b/Scripts/Editor/Coffee.UIParticle.Editor.asmdef.meta index b96bd2c..63d621d 100644 --- a/Scripts/Editor/Coffee.UIParticle.Editor.asmdef.meta +++ b/Scripts/Editor/Coffee.UIParticle.Editor.asmdef.meta @@ -2,6 +2,6 @@ fileFormatVersion: 2 guid: 69deabfe8eed7495886c9daa69c9826a AssemblyDefinitionImporter: externalObjects: {} - userData: '{"OpenSesame":true,"ModifySymbols":""}' + userData: '{"IgnoreAccessChecks":true,"ModifySymbols":""}' assetBundleName: assetBundleVariant: diff --git a/Scripts/Editor/OpenSesamePortable.Coffee.UIParticle.Editor.dll b/Scripts/Editor/OpenSesamePortable.Coffee.UIParticle.Editor.dll deleted file mode 100755 index 1ca8d67..0000000 Binary files a/Scripts/Editor/OpenSesamePortable.Coffee.UIParticle.Editor.dll and /dev/null differ diff --git a/Scripts/Editor/OpenSesamePortable.Coffee.UIParticle.Editor.dll.meta b/Scripts/Editor/OpenSesamePortable.Coffee.UIParticle.Editor.dll.meta deleted file mode 100644 index a21ddae..0000000 --- a/Scripts/Editor/OpenSesamePortable.Coffee.UIParticle.Editor.dll.meta +++ /dev/null @@ -1,90 +0,0 @@ -fileFormatVersion: 2 -guid: 7c7d9e45bc2e5d043940f9241153edd5 -PluginImporter: - externalObjects: {} - serializedVersion: 2 - iconMap: {} - executionOrder: {} - defineConstraints: - - '!OPEN_SESAME_DEV' - isPreloaded: 0 - isOverridable: 1 - isExplicitlyReferenced: 1 - validateReferences: 0 - platformData: - - first: - '': Any - second: - enabled: 0 - settings: - Exclude Editor: 0 - Exclude Linux: 1 - Exclude Linux64: 1 - Exclude LinuxUniversal: 1 - Exclude OSXUniversal: 1 - Exclude Win: 1 - Exclude Win64: 1 - - first: - Any: - second: - enabled: 0 - settings: {} - - first: - Editor: Editor - second: - enabled: 1 - settings: - CPU: AnyCPU - DefaultValueInitialized: true - OS: AnyOS - - first: - Facebook: Win - second: - enabled: 0 - settings: - CPU: AnyCPU - - first: - Facebook: Win64 - second: - enabled: 0 - settings: - CPU: AnyCPU - - first: - Standalone: Linux - second: - enabled: 0 - settings: - CPU: x86 - - first: - Standalone: Linux64 - second: - enabled: 0 - settings: - CPU: x86_64 - - first: - Standalone: OSXUniversal - second: - enabled: 0 - settings: - CPU: AnyCPU - - first: - Standalone: Win - second: - enabled: 0 - settings: - CPU: AnyCPU - - first: - Standalone: Win64 - second: - enabled: 0 - settings: - CPU: AnyCPU - - first: - Windows Store Apps: WindowsStoreApps - second: - enabled: 0 - settings: - CPU: AnyCPU - userData: - assetBundleName: - assetBundleVariant: diff --git a/Scripts/Editor/OpenSesamePortable.cs b/Scripts/Editor/OpenSesamePortable.cs deleted file mode 100644 index ff15a62..0000000 --- a/Scripts/Editor/OpenSesamePortable.cs +++ /dev/null @@ -1,19 +0,0 @@ -#if !OPEN_SESAME && UNITY_EDITOR -using UnityEditor; -using UnityEditor.Compilation; - -namespace Coffee.OpenSesame -{ - [InitializeOnLoad] - internal class Portable - { - static Portable() - { - var assemblyName = typeof(Portable).Assembly.GetName().Name; - var asmdefPath = CompilationPipeline.GetAssemblyDefinitionFilePathFromAssemblyName(assemblyName); - UnityEngine.Debug.LogFormat("Request to recompile: {0} ({1})", assemblyName, asmdefPath); - AssetDatabase.ImportAsset(asmdefPath); - } - } -} -#endif diff --git a/Scripts/Editor/UIParticleEditor.cs b/Scripts/Editor/UIParticleEditor.cs index 8a2abd9..9eb02b3 100644 --- a/Scripts/Editor/UIParticleEditor.cs +++ b/Scripts/Editor/UIParticleEditor.cs @@ -1,4 +1,4 @@ -#if OPEN_SESAME +#if IGNORE_ACCESS_CHECKS // [ASMDEFEX] DO NOT REMOVE THIS LINE MANUALLY. using UnityEditor; using UnityEditor.UI; using UnityEngine; @@ -58,10 +58,10 @@ namespace Coffee.UIExtensions { GenericMenu gm = new GenericMenu(); gm.AddItem(new GUIContent("Nothing"), s_ActiveNames.Count == 0, () => - { - sp.ClearArray(); - sp.serializedObject.ApplyModifiedProperties(); - }); + { + sp.ClearArray(); + sp.serializedObject.ApplyModifiedProperties(); + }); for (int i = 0; i < sp.arraySize; i++) @@ -279,4 +279,4 @@ namespace Coffee.UIExtensions } } } -#endif +#endif // [ASMDEFEX] DO NOT REMOVE THIS LINE MANUALLY. \ No newline at end of file diff --git a/Scripts/Editor/UIParticleMenu.cs b/Scripts/Editor/UIParticleMenu.cs index f46d6ca..8b12fbb 100644 --- a/Scripts/Editor/UIParticleMenu.cs +++ b/Scripts/Editor/UIParticleMenu.cs @@ -1,4 +1,4 @@ -#if OPEN_SESAME +#if IGNORE_ACCESS_CHECKS // [ASMDEFEX] DO NOT REMOVE THIS LINE MANUALLY. #if !UNITY_2019_1_OR_NEWER using System.Collections; using System.Collections.Generic; @@ -24,4 +24,4 @@ namespace Coffee.UIExtensions } } #endif -#endif \ No newline at end of file +#endif // [ASMDEFEX] DO NOT REMOVE THIS LINE MANUALLY. \ No newline at end of file diff --git a/package.json b/package.json index 8b7c2bc..6bd36e9 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "com.coffee.ui-particle", "displayName": "UI Particle", "description": "This plugin provide a component to render particle effect for uGUI.\nThe particle rendering is maskable and sortable, without Camera, RenderTexture or Canvas.", - "version": "3.0.0-preview.3", + "version": "3.0.0-preview.4", "unity": "2018.2", "license": "MIT", "repository": {