// Start is called before the first frame update public void OnEnable() { m_RootElement = new VisualElement(); m_ModulesVisualTree = AssetDatabase.LoadAssetAtPath <VisualTreeAsset>( "Assets/Plugins/GameplayAbilitySystem/Attributes/CharacterAttributesScriptableObject/Editor/CharacterAttributesScriptableObjectEditor.uxml" ); var stylesheet = AssetDatabase.LoadAssetAtPath <StyleSheet>( "Assets/Plugins/GameplayAbilitySystem/Attributes/CharacterAttributesScriptableObject/Editor/CharacterAttributesScriptableObjectEditor.uss" ); m_RootElement.styleSheets.Add(stylesheet); // Cleanup any strings which correspond to types that no longer exist. var allTypes = new AttributeCollector().GetAllAttributeClasses(System.AppDomain.CurrentDomain); var serializedTypeStrings = new List <string>(); var attributesSerialized = serializedObject.FindProperty("Attributes"); var count = attributesSerialized.arraySize; for (var i = count - 1; i >= 0; i--) { var type = attributesSerialized.GetArrayElementAtIndex(i).stringValue; if (!allTypes.Any(x => x.AssemblyQualifiedName == type)) { attributesSerialized.DeleteArrayElementAtIndex(i); } } serializedObject.ApplyModifiedProperties(); // Go through each item in list and check if it in allTypes. If it isn't, delete. }
public override VisualElement CreateInspectorGUI() { var container = m_RootElement; container.Clear(); m_ModulesVisualTree.CloneTree(container); var allTypes = new AttributeCollector().GetAllAttributeClasses(System.AppDomain.CurrentDomain); var attributesSerialized = serializedObject.FindProperty("Attributes"); var serializedTypeStrings = new List <string>(); var count = attributesSerialized.arraySize; for (var i = 0; i < count; i++) { serializedTypeStrings.Add(attributesSerialized.GetArrayElementAtIndex(i).stringValue); } foreach (var type in allTypes) { var button = new Button(() => { var existingIndex = serializedTypeStrings.FindIndex(x => x == type.AssemblyQualifiedName); // if this already exists in the list, delete it if (existingIndex >= 0) { attributesSerialized.DeleteArrayElementAtIndex(existingIndex); serializedObject.ApplyModifiedProperties(); } else { // Add it to list attributesSerialized.InsertArrayElementAtIndex(0); attributesSerialized.GetArrayElementAtIndex(0).stringValue = type.AssemblyQualifiedName; serializedObject.ApplyModifiedProperties(); } CreateInspectorGUI(); }) { text = type.Name }; // If this type is in the list of selected attributes, mark it enabled if (serializedTypeStrings.Any(x => x == type.AssemblyQualifiedName)) { button.AddToClassList("enabled-button"); } container.Add(button); } return(container); }
public void Parse() { Logger.Info($"Start to parse '{this.FilePath}'"); this.Text = File.ReadAllText(this.FilePath); var tree = CSharpSyntaxTree.ParseText(this.Text); this.Root = (CompilationUnitSyntax)tree.GetRoot(); //reference var refCollector = new ReferenceDirectiveTriviaCollector(); refCollector.Visit(Root); Logger.Info($"{refCollector.Reference.Count} references found. {string.Join(',', refCollector.Reference)}"); var compilation = CSharpCompilation.Create("temp") .AddReferences( MetadataReference.CreateFromFile( typeof(object).Assembly.Location)) .AddReferences( refCollector.Reference.Select(x => normalize(this.FilePath, x)).Select(x => MetadataReference.CreateFromFile(x)) ) .AddSyntaxTrees(tree); this.Model = compilation.GetSemanticModel(tree); Logger.Info("Success to construct semantic model."); var attributeCollector = new AttributeCollector(); attributeCollector.Visit(Root); Logger.Info($"{attributeCollector.Attributes.Count} attributes found. {string.Join(',', attributeCollector.Attributes)}"); this.DependendClasses = attributeCollector.Attributes .Where(x => nameof(VerifyTypeAttribute).Contains(x.Name.ToString())) .Select(analyze) .SelectMany(x => x) .Distinct().ToList().AsReadOnly(); Logger.Info($"{this.DependendClasses.Count} dependend classes found. {string.Join(',', this.DependendClasses)}"); }