Inheritance: UnityEditor.AssetPostprocessor
示例#1
0
        private static void SetPropertyByName <T>(string propertyName, T value)
        {
            PropertyInfo propertyByName = VersionHandler.GetPropertyByName(propertyName);

            if (propertyByName == null)
            {
                return;
            }
            propertyByName.SetValue(null, value, null);
        }
示例#2
0
        private static T GetPropertyByName <T>(string propertyName, T defaultValue)
        {
            PropertyInfo propertyByName = VersionHandler.GetPropertyByName(propertyName);

            if (propertyByName == null)
            {
                return(defaultValue);
            }
            return((T)((object)propertyByName.GetValue(null, null)));
        }
        /// <summary>
        /// Unregister for beforeAssemblyReload event.
        /// Note that AssemblyReloadEvents is only availabe from Unity 2017.
        /// </summary>
        /// <param name="action">Action to unregister for.</param>
        /// <returns>True if the action is unregistered successfully.</returns>
        public static bool UnregisterBeforeAssemblyReloadEvent(Action action)
        {
            Type eventType = VersionHandler.FindClass("UnityEditor",
                                                      "UnityEditor.AssemblyReloadEvents");

            if (eventType != null)
            {
                return(InvokeStaticEventRemoveMethod(eventType, BeforeAssemblyReloadEventName, action));
            }
            return(false);
        }
示例#4
0
        public static void UpdateVersionedAssets(bool forceUpdate = false)
        {
            string methodName = "UpdateVersionedAssets";
            Dictionary <string, object> namedArgs = new Dictionary <string, object>
            {
                {
                    "forceUpdate",
                    forceUpdate
                }
            };

            VersionHandler.InvokeImplMethod(methodName, null, namedArgs, true);
        }
示例#5
0
 public static string[] SearchAssetDatabase(string assetsFilter = null, VersionHandler.FilenameFilter filter = null)
 {
     return(VersionHandler.StringArrayFromObject(VersionHandler.InvokeImplMethod("SearchAssetDatabase", null, new Dictionary <string, object>
     {
         {
             "assetsFilter",
             assetsFilter
         },
         {
             "filter",
             filter
         }
     }, false)));
 }
示例#6
0
 /// <summary>
 /// Checks out a file should Version Control be active and valid.
 /// </summary>
 /// <param name="path">Path to the file that needs checking out.</param>
 /// <param name="logger">Logger, used to log any error messages.</param>
 /// <returns>False should the checkout fail, otherwise true.</returns>
 public static bool CheckoutFile(string path, Logger logger)
 {
     try {
         if (UnityEditor.VersionControl.Provider.enabled &&
             UnityEditor.VersionControl.Provider.isActive &&
             (!UnityEditor.VersionControl.Provider.requiresNetwork ||
              UnityEditor.VersionControl.Provider.onlineState ==
              UnityEditor.VersionControl.OnlineState.Online))
         {
             // Some versions of Unity seem to have bug to convert "string path" to
             // "AssetList assets" (See #359). Generate it in advance as a workaround.
             var assetList = new UnityEditor.VersionControl.AssetList();
             assetList.Add(new UnityEditor.VersionControl.Asset(path));
             // Unity 2019.1+ broke backwards compatibility of Checkout() by adding an
             // optional argument to the method so we dynamically invoke the method to add
             // the optional
             // argument for the Unity 2019.1+ overload at runtime.
             var task = (UnityEditor.VersionControl.Task)VersionHandler.InvokeStaticMethod(
                 typeof(UnityEditor.VersionControl.Provider),
                 "Checkout",
                 new object[] { assetList, UnityEditor.VersionControl.CheckoutMode.Exact },
                 namedArgs: null);
             task.Wait();
             if (!task.success)
             {
                 var errorMessage = new List <string>();
                 errorMessage.Add(String.Format("Failed to checkout {0}.", path));
                 if (task.messages != null)
                 {
                     foreach (var message in task.messages)
                     {
                         if (message != null)
                         {
                             errorMessage.Add(message.message);
                         }
                     }
                 }
                 logger.Log(String.Join("\n", errorMessage.ToArray()),
                            level: LogLevel.Warning);
                 return(false);
             }
         }
         return(true);
     } catch (Exception ex) {
         logger.Log(String.Format("Failed to checkout {0} ({1}.", path, ex),
                    level: LogLevel.Warning);
         return(false);
     }
 }
示例#7
0
        private static object InvokeImplMethod(string methodName, object[] args = null, Dictionary <string, object> namedArgs = null, bool schedule = false)
        {
            Type bootStrappedImpl = VersionHandler.BootStrappedImpl;

            if (bootStrappedImpl == null)
            {
                if (VersionHandler.BootStrapping && schedule)
                {
                    VersionHandler.AddToBootStrappingFile(new List <string>
                    {
                        methodName
                    });
                }
                return(null);
            }
            return(VersionHandler.InvokeStaticMethod(bootStrappedImpl, methodName, args, namedArgs));
        }
示例#8
0
        public static float GetUnityVersionMajorMinor()
        {
            if (VersionHandler.unityVersionMajorMinor > 0f)
            {
                return(VersionHandler.unityVersionMajorMinor);
            }
            float result;

            try
            {
                object obj = VersionHandler.InvokeImplMethod("GetUnityVersionMajorMinor", null, null, false);
                VersionHandler.unityVersionMajorMinor = (float)obj;
                result = VersionHandler.unityVersionMajorMinor;
            }
            catch (Exception)
            {
                result = 0f;
            }
            return(result);
        }
 // Function called when the dialog window is enabled.
 void OnEnable() {
     VersionHandler.RegisterBeforeAssemblyReloadEvent(OnBeforeAssemblyReload);
 }
示例#10
0
 public static object InvokeStaticMethod(Type type, string methodName, object[] args, Dictionary <string, object> namedArgs = null)
 {
     return(VersionHandler.InvokeMethod(type, null, methodName, args, namedArgs));
 }
示例#11
0
 public static object InvokeInstanceMethod(object objectInstance, string methodName, object[] args, Dictionary <string, object> namedArgs = null)
 {
     return(VersionHandler.InvokeMethod(objectInstance.GetType(), objectInstance, methodName, args, namedArgs));
 }
示例#12
0
 public static string[] FindAllAssets()
 {
     return(VersionHandler.StringArrayFromObject(VersionHandler.InvokeImplMethod("FindAllAssets", null, null, false)));
 }
示例#13
0
 public static void UpdateNow()
 {
     VersionHandler.InvokeImplMethod("UpdateNow", null, null, true);
 }
示例#14
0
 public static void ShowSettings()
 {
     VersionHandler.InvokeImplMethod("ShowSettings", null, null, false);
 }
示例#15
0
 // Function called when the dialog window is disabled.
 void OnDisable() {
     VersionHandler.UnregisterBeforeAssemblyReloadEvent(OnBeforeAssemblyReload);
 }
        /// <summary>
        /// Enable the latest VersionHandler DLL if it's not already loaded.
        /// </summary>
        private static void BootStrap()
        {
            var bootStrapping = BootStrapping;
            var implAvailable = Impl != null;

            // If the VersionHandler assembly is already loaded or we're still bootstrapping we have
            // nothing to do.
            if (bootStrapping)
            {
                BootStrapping = !implAvailable;
                return;
            }
            EditorApplication.update -= BootStrap;
            if (implAvailable)
            {
                return;
            }

            var assemblies = new List <Match>();

            foreach (string assetGuid in AssetDatabase.FindAssets("l:gvh"))
            {
                string filename = AssetDatabase.GUIDToAssetPath(assetGuid);
                var    match    = VERSION_HANDLER_FILENAME_RE.Match(filename);
                if (match.Success)
                {
                    assemblies.Add(match);
                }
            }
            if (assemblies.Count == 0)
            {
                UnityEngine.Debug.LogWarning(String.Format("No {0} DLL found to bootstrap",
                                                           VERSION_HANDLER_ASSEMBLY_NAME));
                return;
            }
            // Sort assembly paths by version number.
            string mostRecentAssembly      = null;
            var    mostRecentVersionNumber = -1;

            foreach (var match in assemblies)
            {
                var filename = match.Groups[0].Value;
                var version  = match.Groups[2].Value;
                // Convert a multi-component version number to a string.
                var components = version.Split(new [] { '.' });
                Array.Reverse(components);
                var versionNumber              = 0;
                var componentMultiplier        = 1000;
                var currentComponentMultiplier = 1;
                foreach (var component in components)
                {
                    try {
                        versionNumber += Int32.Parse(component) * currentComponentMultiplier;
                    } catch (FormatException) {
                        // Ignore the component.
                    }
                    currentComponentMultiplier *= componentMultiplier;
                }
                if (versionNumber > mostRecentVersionNumber)
                {
                    mostRecentVersionNumber = versionNumber;
                    mostRecentAssembly      = filename;
                }
            }
            if (String.IsNullOrEmpty(mostRecentAssembly))
            {
                UnityEngine.Debug.LogWarning(String.Format("Failed to get the most recent {0} DLL.  " +
                                                           "Unable to bootstrap.",
                                                           VERSION_HANDLER_ASSEMBLY_NAME));
                return;
            }
            BootStrapping = true;
            if (VersionHandler.FindClass("UnityEditor", "UnityEditor.PluginImporter") != null)
            {
                EnableEditorPlugin(mostRecentAssembly);
            }
            else
            {
                ReimportPlugin(mostRecentAssembly);
            }
        }
示例#17
0
        private static void BootStrap()
        {
            bool bootStrapping = VersionHandler.BootStrapping;
            bool flag          = VersionHandler.Impl != null;

            if (bootStrapping)
            {
                VersionHandler.BootStrapping = !flag;
                return;
            }
            Delegate arg_44_0 = EditorApplication.update;

            if (VersionHandler.callbackFunction2 == null)
            {
                VersionHandler.callbackFunction2 = new EditorApplication.CallbackFunction(VersionHandler.BootStrap);
            }
            EditorApplication.update = (EditorApplication.CallbackFunction)Delegate.Remove(arg_44_0, VersionHandler.callbackFunction2);
            if (flag)
            {
                return;
            }
            List <Match> list = new List <Match>();

            string[] array = AssetDatabase.FindAssets("l:gvh");
            for (int i = 0; i < array.Length; i++)
            {
                string guid  = array[i];
                string input = AssetDatabase.GUIDToAssetPath(guid);
                Match  match = VersionHandler.VERSION_HANDLER_FILENAME_RE.Match(input);
                if (match.Success)
                {
                    list.Add(match);
                }
            }
            if (list.Count == 0)
            {
                Debug.LogWarning(string.Format("No {0} DLL found to bootstrap", "Google.VersionHandlerImpl"));
                return;
            }
            string text = null;
            int    num  = -1;

            foreach (Match current in list)
            {
                string   value  = current.Groups[0].Value;
                string   value2 = current.Groups[2].Value;
                string[] array2 = value2.Split(new char[]
                {
                    '.'
                });
                Array.Reverse(array2);
                int      num2   = 0;
                int      num3   = 1000;
                int      num4   = 1;
                string[] array3 = array2;
                for (int j = 0; j < array3.Length; j++)
                {
                    string s = array3[j];
                    try
                    {
                        num2 += int.Parse(s) * num4;
                    }
                    catch (FormatException)
                    {
                    }
                    num4 *= num3;
                }
                if (num2 > num)
                {
                    num  = num2;
                    text = value;
                }
            }
            if (string.IsNullOrEmpty(text))
            {
                Debug.LogWarning(string.Format("Failed to get the most recent {0} DLL.  Unable to bootstrap.", "Google.VersionHandlerImpl"));
                return;
            }
            VersionHandler.BootStrapping = true;
            if (VersionHandler.FindClass("UnityEditor", "UnityEditor.PluginImporter") != null)
            {
                VersionHandler.EnableEditorPlugin(text);
            }
            else
            {
                VersionHandler.ReimportPlugin(text);
            }
        }