Skip to content

UnioGame/unigame.linkxml.generator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Link XML Generator for Unity

An advanced link.xml file generator for Unity projects with support for multiple resource types and automated section management.

Link XML Generator Editor

Overview

LinkXmlGenerator is a Unity Editor utility that automatically generates and updates the link.xml file required for proper IL2CPP builds. The generator supports various resource types and preserves existing manual rules in the file. It also includes LinkXmlGeneratorAsset - a ScriptableObject-based solution for easy configuration through Unity Inspector.

Features

  • Multiple Resource Types: Support for namespaces, types, assemblies, regex patterns, and base types
  • ScriptableObject Asset: Easy configuration through Unity Inspector with LinkXmlGeneratorAsset

Installation

add into your manifest.json dependencies section:

"com.unigame.linkxml.generator": "https://github.com/UnioGame/linkxml.generator"

Usage

Method 1: Using LinkXmlGeneratorAsset with Custom UI Toolkit Editor (Recommended)

  1. Create Asset:
    • Right-click in Project window → Create → UniGame/Tools/Link Xml Generator Asset
  2. Configure Resources: The modern UI Toolkit editor provides an enhanced interface:
    • Search & Filter: Real-time search by value to quickly find resources
    • Add Buttons: Convenient "Add [Type]" buttons for all resource types
  3. Generate: Click the prominent "Generate Link XML" button or use context menu

Adding Resources in Inspector:

  • Namespace Resources: Enter namespace name (e.g., "MyProject.Core")
  • Base Type Resources: Enter full type name (e.g., "UnityEngine.MonoBehaviour") to include the type + all inheritors
  • Concrete Type Resources: Enter exact type name (e.g., "MySpecificClass")
  • Regex Pattern Resources: Enter regex pattern (e.g., ".*Controller$")
  • Assembly Resources: Enter assembly name (e.g., "MyProject.Runtime")

Method 2: Using Code API

using System;
using UnityEngine;
            LinkXmlResource.FromRegex(@".*Controller$"), // all classes ending with "Controller"
            LinkXmlResource.FromRegex(@"^MyProject\.Data\..*"), // all types in MyProject.Data
            
            // Include entire assembly
            LinkXmlResource.FromAssembly("MyProject.Runtime"),
        };

        LinkXmlGenerator.GenerateFromResources(resources);
    }
}

Resource Types

1. Namespace

Includes all types in the specified namespace and its sub-namespaces:

LinkXmlResource.FromNamespace("MyProject.Core")
// Will include: MyProject.Core.*, MyProject.Core.Utils.*, etc.

2. Base Type

Includes the base type itself and all its inheritors:

LinkXmlResource.FromBaseType(typeof(UIWindow))
LinkXmlResource.FromBaseType("MyProject.UI.UIWindow") // Using string type name
// Will include: UIWindow + all classes inheriting from UIWindow

3. Concrete Type

Includes only the specified type:

LinkXmlResource.FromConcreteType("MySpecificClass")
LinkXmlResource.FromConcreteType(typeof(MyClass))

4. Regex Pattern

Includes types whose names match the regex pattern:

LinkXmlResource.FromRegex(@".*Manager$")     // all classes ending with "Manager"
LinkXmlResource.FromRegex(@"^UI\..*")        // all types starting with "UI."
LinkXmlResource.FromRegex(@"Controller|Service|Handler") // multiple patterns

5. Entire Assembly

Includes all types in the specified assembly:

LinkXmlResource.FromAssembly("MyProject.Runtime")
// Creates: <assembly fullname="MyProject.Runtime" preserve="all"/>

Generated link.xml Structure

<linker>
  <!-- You can keep your manual rules here -->
  
  <!-- BEGIN-AUTO-GENERATED-BY-LinkXmlNamespaceGenerator -->
  <!-- DO NOT EDIT MANUALLY: this section is regenerated by LinkXmlGenerator -->
  
  <!-- Entire assemblies -->
  <assembly fullname="MyProject.Runtime" preserve="all"/>
  
  <!-- Partial assemblies -->
  <assembly fullname="Assembly-CSharp">
    <namespace fullname="MyProject.Core" preserve="all"/>
    <namespace fullname="MyProject.Gameplay" preserve="all"/>
    <type fullname="MySpecificClass" preserve="all"/>
    <type fullname="SomeController" preserve="all"/>
  </assembly>
  
  <!-- END-AUTO-GENERATED-BY-LinkXmlNamespaceGenerator -->
  
  <!-- Your manual rules continue to work here -->
</linker>

LinkXmlGeneratorAsset Configuration

Creating and Using the Asset

  1. Create: Right-click in Project window → Create → UniGame/Tools/Link Xml Generator Asset
  2. Configure:
    • Add resources to the "Resources" list
    • Set resource type and values
    • Enable/disable individual resources
    • Use legacy "Namespaces" and "Types" arrays for backward compatibility
  3. Generate: Click "Generate Link Xml" button or use context menu

Inspector Helper Buttons

The custom UI Toolkit editor provides convenient buttons:

  • Add Namespace Resource: Quickly add a namespace resource
  • Add Base Type Resource: Add a base type resource with MonoBehaviour as default
  • Add Regex Resource: Add a regex pattern resource
  • Add Assembly Resource: Add an entire assembly resource
  • Add Concrete Type Resource: Add a specific type resource

The LinkXmlGeneratorAsset also maintains backward compatibility with legacy Namespaces and Types arrays.

Exclusion Logic

The generator automatically excludes:

  • Editor assemblies: *.Editor, *.EditorTests, UnityEditor
  • Editor types: Types from UnityEditor.* namespace
  • Generic definitions: Open generic types (only concrete types are included)
  • Dynamic assemblies: Assemblies created at runtime

License

Use freely in your Unity projects.

About

create link.xml records by rules

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages