Exemple #1
0
        public UnityReferencesTracker(
            Lifetime lifetime,
            IEnumerable <IUnityReferenceChangeHandler> handlers,
            ISolution solution,
            ISolutionLoadTasksScheduler scheduler,
            ModuleReferenceResolveSync moduleReferenceResolveSync,
            ChangeManager changeManager,
            IViewableProjectsCollection projects,
            ILogger logger,
            UnityVersion unityVersion)
        {
            myAllProjectLifetimes = new Dictionary <IProject, Lifetime>();
            myUnityProjects       = new HashSet <IProject>();

            myHandlers = handlers.ToList();
            myLifetime = lifetime;
            myLogger   = logger;
            mySolution = solution;
            myModuleReferenceResolveSync = moduleReferenceResolveSync;
            myChangeManager = changeManager;
            myProjects      = projects;

            // At PreparePsiModules, we know what references we have, so we know if we're a Unity project. This is where
            // we'll initialise our custom PSI module. We have to initialise our PSI module before Done, or the
            // PersistentIndexManager will clean out the "orphaned" external (YAML) files and we'll have to reparse all
            // files on every startup
            scheduler.EnqueueTask(new SolutionLoadTask("Preparing Unity project", SolutionLoadTaskKinds.PreparePsiModules,
                                                       OnSolutionPreparePsiModules));

            HasUnityReference.WhenTrue(lifetime, lt => unityVersion.UpdateActualVersionForSolution());
        }
Exemple #2
0
        public CppDeclarationGenerator(Il2CppModel model, UnityVersion version)
        {
            this.model = model;
            if (version == null)
            {
                UnityHeader  = UnityHeader.GuessHeadersForModel(model)[0];
                UnityVersion = UnityHeader.MinVersion;
            }
            else
            {
                UnityVersion = version;
                UnityHeader  = UnityHeader.GetHeaderForVersion(version);
                if (UnityHeader.MetadataVersion != model.Package.BinaryImage.Version)
                {
                    /* this can only happen in the CLI frontend with a manually-supplied version number */
                    Console.WriteLine($"Warning: selected version {UnityVersion} (metadata version {UnityHeader.MetadataVersion})" +
                                      $" does not match metadata version {model.Package.BinaryImage.Version}.");
                }
            }

            InitializeNaming();
            InitializeConcreteImplementations();

            // Configure inheritance style based on binary type; this can be overridden by setting InheritanceStyle in the object initializer
            InheritanceStyle = CppCompiler.GuessFromImage(model.Package.BinaryImage);
        }
Exemple #3
0
        public static void ResetCustomEditors()
        {
            if (!IsValid)
            {
                return;
            }

            if (UnityVersion.IsVersionOrGreater(2018, 1))
            {
                ((IDictionary)CustomEditorAttributesType_CustomEditors.GetValue(null)).Clear();
                ((IDictionary)CustomEditorAttributesType_CustomMultiEditors.GetValue(null)).Clear();
            }
            else
            {
                if (CustomEditorAttributesType_CachedEditorForType != null)
                {
                    ((Dictionary <Type, Type>)CustomEditorAttributesType_CachedEditorForType.GetValue(null)).Clear();
                }
                if (CustomEditorAttributesType_CachedMultiEditorForType != null)
                {
                    ((Dictionary <Type, Type>)CustomEditorAttributesType_CachedMultiEditorForType.GetValue(null)).Clear();
                }
                ((IList)CustomEditorAttributesType_CustomEditors.GetValue(null)).Clear();
                ((IList)CustomEditorAttributesType_CustomMultiEditors.GetValue(null)).Clear();
            }

            CustomEditorAttributesType_Initialized.SetValue(null, false);
        }
Exemple #4
0
        public CppApplicationModel(Il2CppModel model, UnityVersion unityVersion = null, CppCompiler.Type compiler = CppCompiler.Type.BinaryFormat)
        {
            // Set key properties
            Compiler = compiler == CppCompiler.Type.BinaryFormat ? CppCompiler.GuessFromImage(model.Package.BinaryImage) : compiler;

            var unityHeader = unityVersion != null?UnityHeader.GetHeaderForVersion(unityVersion) : UnityHeader.GuessHeadersForModel(model)[0];

            UnityVersion = unityVersion ?? unityHeader.MinVersion;
            ILModel      = model;

            // Check for matching metadata and binary versions
            if (unityHeader.MetadataVersion != model.Package.BinaryImage.Version)
            {
                Console.WriteLine($"Warning: selected version {UnityVersion} (metadata version {unityHeader.MetadataVersion})" +
                                  $" does not match metadata version {model.Package.BinaryImage.Version}.");
            }

            // Get addresses of IL2CPP API function exports
            Exports = model.Package.Binary.Image.GetExports().ToList();

            // Start creation of type model by parsing all of the Unity IL2CPP headers
            Types = CppTypes.FromUnityHeaders(unityHeader, WordSize);

            // TODO: Process every type in the binary
            //var decl = new CppDeclarationGenerator(this);
        }
        public static UnityPluginParameter ParseUnityPluginParameter(
            Configs.UnityPlugins configs, Configs.UnityManagedPluginProject projectConfig)
        {
            Ensure.Argument.NotNull(configs, nameof(configs));
            Ensure.Argument.NotNull(projectConfig, nameof(projectConfig));

            StringToVersionInfo versions = null;

            if (projectConfig.ForMultipleVersions)
            {
                versions = projectConfig.Versions ?? new StringToVersionInfo();
                foreach (var kvp in configs.DefaultVersions)
                {
                    var ver  = kvp.Key;
                    var info = kvp.Value;
                    if (!versions.ContainsKey(ver))
                    {
                        versions.Add(ver, info);
                    }
                }
            }

            var parameter = new UnityPluginParameter
            {
                ForEditor = projectConfig.ForEditor,
                Versions  = versions?.ToDictionary(p => UnityVersion.Parse(p.Key), p => p.Value)
            };

            return(parameter);
        }
        private void NotifyFrontend(FrontendBackendHost host, UnityVersion unityVersion, Version version)
        {
            host.Do(rd =>
            {
                // if model is there, then ApplicationPath was already set via UnityEditorProtocol, it would be more
                // correct than any counted value
                if (myBackendUnityHost.BackendUnityModel.Value != null)
                {
                    return;
                }

                var info = UnityInstallationFinder.GetApplicationInfo(version, unityVersion);
                if (info == null)
                {
                    return;
                }

                var contentsPath = UnityInstallationFinder.GetApplicationContentsPath(info.Path);
                rd.UnityApplicationData.SetValue(new UnityApplicationData(info.Path.FullPath,
                                                                          contentsPath.FullPath,
                                                                          UnityVersion.VersionToString(info.Version),
                                                                          null, null, null));
                rd.RequiresRiderPackage.Set(UnityVersion.RequiresRiderPackage(info.Version));
            });
        }
Exemple #7
0
        private string ToVersionString(UnityVersion unityVersion)
        {
            switch (unityVersion)
            {
            case UnityVersion.Unity54: return("5.4.0");

            case UnityVersion.Unity55: return("5.5.0");

            case UnityVersion.Unity56: return("5.6.0");

            case UnityVersion.Unity2017_1: return("2017.1.0");

            case UnityVersion.Unity2017_2: return("2017.2.0");

            case UnityVersion.Unity2017_3: return("2017.3.0");

            case UnityVersion.Unity2017_4: return("2017.4.0");

            case UnityVersion.Unity2018_1: return("2018.1.0");

            case UnityVersion.Unity2018_2: return("2018.2.0");

            default:
                throw new ArgumentOutOfRangeException(nameof(unityVersion), unityVersion, null);
            }
        }
Exemple #8
0
        protected override void DrawPropertyLayout(IPropertyValueEntry <T> entry, GUIContent label)
        {
            var eventDrawer = entry.Context.Get(this, "event_drawer", (UnityEditorInternal.UnityEventDrawer)null);

            if (eventDrawer.Value == null)
            {
                eventDrawer.Value = new UnityEditorInternal.UnityEventDrawer();
                this.drawer       = eventDrawer.Value;

                if (UnityPropertyHandlerUtility.IsAvailable)
                {
                    this.propertyHandler = UnityPropertyHandlerUtility.CreatePropertyHandler(this.drawer);
                }
            }

            FieldInfo          fieldInfo;
            SerializedProperty unityProperty = entry.Property.Tree.GetUnityPropertyForPath(entry.Property.Path, out fieldInfo);

            if (unityProperty == null)
            {
                if (UnityVersion.IsVersionOrGreater(2017, 1))
                {
                    this.CallNextDrawer(entry, label);
                    return;
                }
                else if (!typeof(T).IsDefined <SerializableAttribute>())
                {
                    SirenixEditorGUI.ErrorMessageBox("You have likely forgotten to mark your custom UnityEvent class '" + typeof(T).GetNiceName() + "' with the [Serializable] attribute! Could not get a Unity SerializedProperty for the property '" + entry.Property.NiceName + "' of type '" + entry.TypeOfValue.GetNiceName() + "' at path '" + entry.Property.Path + "'.");
                    return;
                }
            }

            base.DrawPropertyLayout(entry, label);
        }
Exemple #9
0
        // this method should be very fast as it gets called a lot
        public HostProviderAvailability GetAvailability(IUnitTestElement element)
        {
            var solution = element.Id.Project.GetSolution();
            var tracker  = solution.GetComponent <UnitySolutionTracker>();

            if (tracker.IsUnityProject.HasValue() && !tracker.IsUnityProject.Value)
            {
                return(HostProviderAvailability.Available);
            }

            var frontendBackendModel = solution.GetProtocolSolution().GetFrontendBackendModel();

            switch (frontendBackendModel.UnitTestPreference.Value)
            {
            case UnitTestLaunchPreference.NUnit:
                return(HostProviderAvailability.Available);

            case UnitTestLaunchPreference.Both:
            case UnitTestLaunchPreference.PlayMode:
            case UnitTestLaunchPreference.EditMode:
            {
                var unityVersion = UnityVersion.Parse(frontendBackendModel.UnityApplicationData.Maybe.ValueOrDefault?.ApplicationVersion ?? string.Empty);

                return(unityVersion == null || unityVersion < ourMinSupportedUnityVersion
                        ? HostProviderAvailability.Nonexistent
                        : HostProviderAvailability.Available);
            }

            default:
                return(HostProviderAvailability.Nonexistent);
            }
        }
Exemple #10
0
        private static void NotifyFrontend(UnityHost host, UnityVersion unityVersion)
        {
            var version = unityVersion.GetActualVersionForSolution();
            var info    = UnityInstallationFinder.GetApplicationInfo(version);

            if (info == null)
            {
                return;
            }

            host.PerformModelAction(rd =>
            {
                // ApplicationPath may be already set via UnityEditorProtocol, which is more accurate
                if (!rd.ApplicationPath.HasValue())
                {
                    rd.ApplicationPath.SetValue(info.Path.FullPath);
                }
                if (!rd.ApplicationContentsPath.HasValue())
                {
                    var contentsPath = UnityInstallationFinder.GetApplicationContentsPath(version);
                    if (contentsPath != null)
                    {
                        rd.ApplicationContentsPath.SetValue(contentsPath.FullPath);
                    }
                }
                if (!rd.ApplicationVersion.HasValue() && info.Version != null)
                {
                    rd.ApplicationVersion.SetValue(UnityVersion.VersionToString(info.Version));
                }
            });
        }
 public VsUnityVersionPropertiesExtenderProvider(Lifetime lifetime, IShellLocks locks, UnityVersion unityVersion, UnityApi unityApi)
 {
     myLifetime     = lifetime;
     myLocks        = locks;
     myUnityVersion = unityVersion;
     myUnityApi     = unityApi;
 }
        private void NotifyFrontend(UnityHost host, UnityVersion unityVersion)
        {
            host.PerformModelAction(rd =>
            {
                // if model is there, then ApplicationPath was already set via UnityEditorProtocol, it would be more correct than any counted value
                if (myUnityEditorProtocol.UnityModel.Value != null)
                {
                    return;
                }

                var version = unityVersion.GetActualVersionForSolution();
                var info    = UnityInstallationFinder.GetApplicationInfo(version, unityVersion);
                if (info == null)
                {
                    return;
                }

                var contentsPath = UnityInstallationFinder.GetApplicationContentsPath(info.Path);
                rd.UnityApplicationData.SetValue(new UnityApplicationData(info.Path.FullPath,
                                                                          contentsPath.FullPath,
                                                                          UnityVersion.VersionToString(info.Version),
                                                                          UnityVersion.RequiresRiderPackage(info.Version)
                                                                          ));
            });
        }
 public GenerateUnityEventFunctionsProvider(UnityApi unityApi, UnityVersion unityVersion,
                                            KnownTypesCache knownTypesCache)
 {
     myUnityApi        = unityApi;
     myUnityVersion    = unityVersion;
     myKnownTypesCache = knownTypesCache;
 }
 public UnityInstallationSynchronizer(Lifetime lifetime,
                                      UnityHost host, UnityVersion unityVersion,
                                      UnityEditorProtocol unityEditorProtocol)
 {
     myUnityEditorProtocol = unityEditorProtocol;
     unityVersion.ActualVersionForSolution.Advise(lifetime, version => NotifyFrontend(host, unityVersion, version));
 }
        private async Task RefreshInternal(Lifetime lifetime, RefreshType refreshType)
        {
            var lifetimeDef = Lifetime.Define(lifetime);

            myLogger.Verbose($"myPluginProtocolController.UnityModel.Value.Refresh.StartAsTask, force = {refreshType} Started");
            mySolution.GetComponent <RiderBackgroundTaskHost>().AddNewTask(lifetimeDef.Lifetime,
                                                                           RiderBackgroundTaskBuilder.Create().WithHeader("Refreshing solution in Unity Editor...")
                                                                           .AsIndeterminate().AsNonCancelable());
            try
            {
                try
                {
                    var version = UnityVersion.Parse(myEditorProtocol.UnityModel.Value.UnityApplicationData.Value.ApplicationVersion);
                    if (version != null && version.Major < 2018)
                    {
                        using (mySolution.GetComponent <VfsListener>().PauseChanges())
                        {
                            await myEditorProtocol.UnityModel.Value.Refresh.Start(lifetimeDef.Lifetime, refreshType).AsTask();
                        }
                    }
                    else // it is a risk to pause vfs https://github.com/JetBrains/resharper-unity/issues/1601
                    {
                        await myEditorProtocol.UnityModel.Value.Refresh.Start(lifetimeDef.Lifetime, refreshType).AsTask();
                    }
                }
                catch (Exception e)
                {
                    myLogger.Warn("connection usually brakes during refresh.", e);
                }
                finally
                {
                    try
                    {
                        myLogger.Verbose(
                            $"myPluginProtocolController.UnityModel.Value.Refresh.StartAsTask, force = {refreshType} Finished");
                        var solution  = mySolution.GetProtocolSolution();
                        var solFolder = mySolution.SolutionDirectory;
                        var list      = new List <string> {
                            solFolder.FullPath
                        };
                        myLogger.Verbose($"RefreshPaths.StartAsTask Finished.");
                        await solution.GetFileSystemModel().RefreshPaths.Start(lifetimeDef.Lifetime, new RdRefreshRequest(list, true)).AsTask();
                    }
                    finally
                    {
                        myLogger.Verbose($"RefreshPaths.StartAsTask Finished.");
                        lifetimeDef.Terminate();
                    }
                }
            }
            catch (Exception e)
            {
                myLogger.LogException(e);
            }
            finally
            {
                lifetimeDef.Terminate();
            }
        }
 private static Conditions CreateCondition(ProjectConfigurationType type, UnityVersion version)
 {
     return(new Conditions(new[]
     {
         new Condition(ConditionNames.Configuration, $"{type}-{version.ToString(true)}"),
         new Condition(ConditionNames.Platform, "AnyCPU")
     }));
 }
Exemple #17
0
 /// <summary>
 /// Not yet documented.
 /// </summary>
 public AssemblyGenerator()
 {
     if (!UnityVersion.IsVersionOrGreater(5, 5))
     {
         // Make sure mscorlib is always referenced
         this.referencedAssemblies.Add(typeof(string).Assembly.Location);
     }
 }
Exemple #18
0
 public ShaderLabCppFileLocationTracker(Lifetime lifetime, ISolution solution, UnityVersion unityVersion,
                                        IPersistentIndexManager persistentIndexManager)
     : base(
         lifetime, solution, persistentIndexManager, CppInjectionInfo.Read, CppInjectionInfo.Write)
 {
     mySolution     = solution;
     myUnityVersion = unityVersion;
 }
 public UnityInstallationSynchronizer(Lifetime lifetime,
                                      FrontendBackendHost frontendBackendHost,
                                      BackendUnityHost backendUnityHost,
                                      UnityVersion unityVersion)
 {
     myBackendUnityHost = backendUnityHost;
     unityVersion.ActualVersionForSolution.Advise(lifetime,
                                                  version => NotifyFrontend(frontendBackendHost, unityVersion, version));
 }
 public InjectedHlslFileLocationTracker(Lifetime lifetime, ISolution solution, UnityVersion unityVersion,
                                        IPersistentIndexManager persistentIndexManager, CppExternalModule cppExternalModule)
     : base(
         lifetime, solution, persistentIndexManager, InjectedHlslLocationInfo.Read, InjectedHlslLocationInfo.Write)
 {
     mySolution          = solution;
     myUnityVersion      = unityVersion;
     myCppExternalModule = cppExternalModule;
 }
 public void SelectVersion(bool patched, Version version, string path, UnityVersion unityVersion)
 {
     _patchButton.interactable   = !patched;
     _unpatchButton.interactable = patched;
     m_version = version;
     _versionDropdown.value = (int)version;
     SetInputFieldValue(new[] { path });
     m_unityVersion = unityVersion;
 }
        private static UnityVersion VersionOfPath(string path)
        {
            var verStr = Path.GetFileNameWithoutExtension(path);

            if (verStr.EndsWith("+"))
            {
                verStr = verStr.RemoveTail(1);
            }
            return(UnityVersion.TryParse(verStr, out var ver) ? ver : null);
        }
Exemple #23
0
 private static void Equals(UnityVersion l, UnityVersion r, bool equals)
 {
     if (!ReferenceEquals(l, null))
     {
         Assert.AreEqual(l.Equals(r), equals);
     }
     if (!ReferenceEquals(r, null))
     {
         Assert.AreEqual(r.Equals(l), equals);
     }
 }
Exemple #24
0
 private static void CompareTo(UnityVersion l, UnityVersion r, int result)
 {
     if (!ReferenceEquals(l, null))
     {
         Assert.AreEqual(Math.Sign(l.CompareTo(r)), Math.Sign(result));
     }
     if (!ReferenceEquals(r, null))
     {
         Assert.AreEqual(Math.Sign(r.CompareTo(l)), -Math.Sign(result));
     }
 }
        internal static bool UnityVersionSatisfiesPackageUnityVersion(string unityVersionString, string packageUnityVersionString)
        {
            var unityVersion        = UnityVersion.Parse(unityVersionString);
            var packageUnityVersion = UnityVersion.Parse(packageUnityVersionString);

            // We only care about major and minor version
            var truncatedUnityVersion        = new SemVersion(unityVersion.Major, unityVersion.Minor);
            var truncatedPackageUnityVersion = new SemVersion(packageUnityVersion.Major, packageUnityVersion.Minor);

            return(truncatedUnityVersion >= truncatedPackageUnityVersion);
        }
        public UnityPluginInstaller(
            Lifetime lifetime,
            ILogger logger,
            ISolution solution,
            IShellLocks shellLocks,
            UnityPluginDetector detector,
            NotificationsModel notifications,
            ISettingsStore settingsStore,
            PluginPathsProvider pluginPathsProvider,
            UnityVersion unityVersion,
            UnityHost unityHost,
            UnitySolutionTracker unitySolutionTracker,
            UnityRefresher refresher)
        {
            myPluginInstallations = new JetHashSet <FileSystemPath>();

            myLifetime             = lifetime;
            myLogger               = logger;
            mySolution             = solution;
            myShellLocks           = shellLocks;
            myDetector             = detector;
            myNotifications        = notifications;
            myPluginPathsProvider  = pluginPathsProvider;
            myUnityVersion         = unityVersion;
            myUnitySolutionTracker = unitySolutionTracker;
            myRefresher            = refresher;

            myBoundSettingsStore = settingsStore.BindToContextLive(myLifetime, ContextRange.Smart(solution.ToDataContext()));
            myQueue = new ProcessingQueue(myShellLocks, myLifetime);

            unityHost.PerformModelAction(rdUnityModel =>
            {
                rdUnityModel.InstallEditorPlugin.AdviseNotNull(lifetime, x =>
                {
                    myShellLocks.ExecuteOrQueueReadLockEx(myLifetime, "UnityPluginInstaller.InstallEditorPlugin", () =>
                    {
                        var installationInfo = myDetector.GetInstallationInfo(myCurrentVersion);
                        QueueInstall(installationInfo, true);
                    });
                });
            });

            unitySolutionTracker.IsUnityProjectFolder.AdviseOnce(lifetime, args =>
            {
                if (!args)
                {
                    return;
                }
                myShellLocks.ExecuteOrQueueReadLockEx(myLifetime, "IsAbleToEstablishProtocolConnectionWithUnity", InstallPluginIfRequired);
                BindToInstallationSettingChange();
            });
        }
        private static Version TryGetUnityVersionFromDll(XmlElement documentElement)
        {
            var referencePathElement = documentElement.ChildElements()
                                       .Where(a => a.Name == "ItemGroup").SelectMany(b => b.ChildElements())
                                       .Where(c => c.Name == "Reference" && c.GetAttribute("Include").StartsWith("UnityEngine") || c.GetAttribute("Include").Equals("UnityEditor"))
                                       .SelectMany(d => d.ChildElements())
                                       .FirstOrDefault(c => c.Name == "HintPath");

            if (referencePathElement == null || string.IsNullOrEmpty(referencePathElement.InnerText))
            {
                return(null);
            }

            var filePath = FileSystemPath.Parse(referencePathElement.InnerText);

            if (!filePath.IsAbsolute) // RIDER-21237
            {
                return(null);
            }

            if (filePath.ExistsFile)
            {
                if (PlatformUtil.RuntimePlatform == PlatformUtil.Platform.Windows)
                {
                    var exePath = filePath.Combine("../../../Unity.exe"); // Editor\Data\Managed\UnityEngine.dll
                    if (!exePath.ExistsFile)
                    {
                        exePath = filePath.Combine("../../../../Unity.exe"); // Editor\Data\Managed\UnityEngine\UnityEngine.dll
                    }
                    if (exePath.ExistsFile)
                    {
                        return(new Version(new Version(FileVersionInfo.GetVersionInfo(exePath.FullPath).FileVersion).ToString(3)));
                    }
                }
                else if (PlatformUtil.RuntimePlatform == PlatformUtil.Platform.MacOsX)
                {
                    var infoPlistPath = filePath.Combine("../../Info.plist");
                    if (!infoPlistPath.ExistsFile)
                    {
                        infoPlistPath = filePath.Combine("../../../Info.plist");
                    }
                    if (!infoPlistPath.ExistsFile)
                    {
                        return(null);
                    }
                    var fullVersion = UnityVersion.GetVersionFromInfoPlist(infoPlistPath);
                    return(UnityVersion.Parse(fullVersion));
                }
            }

            return(null);
        }
        public UnityProjectConfigurator(string directory)
        {
            ProjectDirectory = new DirectoryInfo(directory);
            ProjectName      = ProjectDirectory.Name;
            ProjectVersion   = FindProjectVersion(ProjectDirectory);

            var slnPath = Path.Combine(ProjectDirectory.FullName, ProjectName + ".sln");

            if (File.Exists(slnPath))
            {
                SolutionFile = SolutionFile.FromFile(slnPath);
            }
        }
        public static FileSystemPath GetCgIncludeFolderPath(UnityVersion unityVersion)
        {
            var path = unityVersion.GetActualAppPathForSolution();

            if (path.IsEmpty)
            {
                return(FileSystemPath.Empty);
            }

            var contentPath = UnityInstallationFinder.GetApplicationContentsPath(path);

            return(contentPath.Combine("CGIncludes"));
        }
Exemple #30
0
 /// <summary>
 /// Get a version from the database.
 /// </summary>
 /// <remarks>
 /// If the version is incomplete, the latest version matching will be returned.
 /// </remarks>
 public VersionMetadata Find(UnityVersion version)
 {
     if (version.IsFullVersion)
     {
         // Do exact match
         foreach (var metadata in cache.versions)
         {
             if (version.MatchesVersionOrHash(metadata.version))
             {
                 return(metadata);
             }
         }
         return(default);
 public TestUnityAttribute(UnityVersion version)
 {
     myVersion = version;
 }