コード例 #1
0
        /// <summary> Sets subtitle text and tooltip for display below the main header text of MonoScript asset. </summary>
        /// <param name="subtitle"> [in,out] The subtitle GUContent to edit. This cannot be null. </param>
        /// <param name="monoScript"> The monoScript asset. </param>
        public static void GetHeaderSubtitle([NotNull] ref GUIContent subtitle, [NotNull] UnityEditor.MonoScript monoScript)
        {
            var classType = monoScript.GetClass();

            subtitle.tooltip = "A C# MonoScript asset";

            if (classType == null)
            {
                subtitle.text = "Script";
            }
            else if (Types.MonoBehaviour.IsAssignableFrom(classType))
            {
                subtitle.text = "MonoBehaviour Script";
            }
            else if (Types.ScriptableObject.IsAssignableFrom(classType))
            {
                if (Types.EditorWindow.IsAssignableFrom(classType))
                {
                    subtitle.text = "ScriptableObject Script";
                }
            }
            else if (classType.IsValueType)
            {
                if (classType.IsEnum)
                {
                    subtitle.text = "Enum Script";
                }
                else
                {
                    subtitle.text = "Struct Script";
                }
            }
            else if (classType.IsAbstract)
            {
                if (classType.IsInterface)
                {
                    subtitle.text = "Interface Script";
                }
                else if (classType.IsStatic())
                {
                    subtitle.text = "Static Script";
                }
                else
                {
                    subtitle.text = "Abstract Script";
                }
            }
            else if (classType.IsClass)
            {
                subtitle.text = "Class Script";
            }
            else
            {
                subtitle.text = "Script";
            }
        }
        ScriptData Init_Script(UnityEditor.MonoScript script)
        {
            if (script == null)
            {
                throw new System.ArgumentNullException("Init_Script: script cannot be null");
            }

            var scriptClass = script.GetClass();

            if (scriptClass == null)
            {
                throw new System.ArgumentNullException("Init_Script: must be a monoscript with a valid class");
            }

            ScriptData scriptData = null;

            if (scriptDataTable.TryGetValue(script, out scriptData))
            {
                return(scriptData);
            }
            else
            {
                scriptData        = scriptDataTable[script] = new ScriptData();
                scriptData.script = script;
            }


            var fixedOrderAttribute =
                scriptClass.GetCustomAttributes(typeof(ScriptExecutionOrderAttribute), true)
                .Cast <ScriptExecutionOrderAttribute>()
                .FirstOrDefault();

            if (fixedOrderAttribute != null)
            {
                scriptData.fixedOrderValue = fixedOrderAttribute.order;
            }

            foreach (ScriptExecuteAfterAttribute i in scriptClass.GetCustomAttributes(typeof(ScriptExecuteAfterAttribute), true))
            {
                if (!typeLookup.TryGetValue(i.ExecuteAfter, out var j))
                {
                    continue;
                }
                var dependsOnSD = Init_Script(j);
                dependsOnSD.dependedOnBy.Add(scriptData);
                scriptData.dependsOn.Add(dependsOnSD);
            }

            foreach (ScriptExecuteBeforeAttribute i in scriptClass.GetCustomAttributes(typeof(ScriptExecuteBeforeAttribute), true))
            {
                if (!typeLookup.TryGetValue(i.ExecuteBefore, out var j))
                {
                    continue;
                }
                var dependedOnBySD = Init_Script(j);
                dependedOnBySD.dependsOn.Add(scriptData);
                scriptData.dependedOnBy.Add(dependedOnBySD);
            }

            return(scriptData);
        }
コード例 #3
0
 public static string MonoToString(UnityEditor.MonoScript mono)
 {
     return(mono == null ? "" : TypeToString(mono.GetClass()));
 }