mirror of
https://github.com/AssetRipper/AssetRipper.git
synced 2025-12-11 20:15:29 +01:00
Source generate methods for AssetCreator
This commit is contained in:
parent
81adf771e1
commit
0cda960407
@ -162,6 +162,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AssetRipper.Processing.Sour
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AssetRipper.GUI.Licensing.SourceGenerator", "Source\AssetRipper.GUI.Licensing.SourceGenerator\AssetRipper.GUI.Licensing.SourceGenerator.csproj", "{6B3DD564-FD57-4EAA-8696-A15A5A6FFF29}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AssetRipper.SourceGenerated.Extensions.SourceGenerator", "Source\AssetRipper.SourceGenerated.Extensions.SourceGenerator\AssetRipper.SourceGenerated.Extensions.SourceGenerator.csproj", "{C10F7EBE-4898-44F9-9934-0727A20169BE}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
@ -340,6 +342,10 @@ Global
|
||||
{6B3DD564-FD57-4EAA-8696-A15A5A6FFF29}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{6B3DD564-FD57-4EAA-8696-A15A5A6FFF29}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{6B3DD564-FD57-4EAA-8696-A15A5A6FFF29}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{C10F7EBE-4898-44F9-9934-0727A20169BE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{C10F7EBE-4898-44F9-9934-0727A20169BE}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{C10F7EBE-4898-44F9-9934-0727A20169BE}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{C10F7EBE-4898-44F9-9934-0727A20169BE}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
||||
@ -13,8 +13,8 @@ internal class AssetEqualityTests
|
||||
[Test]
|
||||
public void DefaultGameObjectEqualityTest()
|
||||
{
|
||||
IGameObject gameObject1 = AssetCreator.Create<IGameObject>(ClassIDType.GameObject, new UnityVersion(2017));
|
||||
IGameObject gameObject2 = AssetCreator.Create<IGameObject>(ClassIDType.GameObject, new UnityVersion(2017));
|
||||
IGameObject gameObject1 = AssetCreator.CreateGameObject(new UnityVersion(2017));
|
||||
IGameObject gameObject2 = AssetCreator.CreateGameObject(new UnityVersion(2017));
|
||||
AssetEqualityComparer comparer = new();
|
||||
Assert.That(comparer.Equals(gameObject1, gameObject2));
|
||||
}
|
||||
@ -30,8 +30,8 @@ internal class AssetEqualityTests
|
||||
static IGameObject CreateGameObject()
|
||||
{
|
||||
ProcessedAssetCollection collection = AssetCreator.CreateCollection(new UnityVersion(2017));
|
||||
IGameObject gameObject = collection.CreateAsset<IGameObject>(ClassIDType.GameObject);
|
||||
ITransform transform = collection.CreateAsset<ITransform>(ClassIDType.Transform);
|
||||
IGameObject gameObject = collection.CreateGameObject();
|
||||
ITransform transform = collection.CreateTransform();
|
||||
gameObject.AddComponent(ClassIDType.Transform, transform);
|
||||
transform.GameObject_C4P = gameObject;
|
||||
return gameObject;
|
||||
@ -49,8 +49,8 @@ internal class AssetEqualityTests
|
||||
static IGameObject CreateGameObject(float x, float y, float z)
|
||||
{
|
||||
ProcessedAssetCollection collection = AssetCreator.CreateCollection(new UnityVersion(2017));
|
||||
IGameObject gameObject = collection.CreateAsset<IGameObject>(ClassIDType.GameObject);
|
||||
ITransform transform = collection.CreateAsset<ITransform>(ClassIDType.Transform);
|
||||
IGameObject gameObject = collection.CreateGameObject();
|
||||
ITransform transform = collection.CreateTransform();
|
||||
transform.LocalPosition_C4.SetValues(x, y, z);
|
||||
gameObject.AddComponent(ClassIDType.Transform, transform);
|
||||
transform.GameObject_C4P = gameObject;
|
||||
|
||||
@ -79,7 +79,7 @@ namespace AssetRipper.Processing.AnimatorControllers
|
||||
|
||||
private static IBlendTree CreateBlendTree(ProcessedAssetCollection virtualFile, IAnimatorController controller, IStateConstant state, int nodeIndex)
|
||||
{
|
||||
IBlendTree blendTree = virtualFile.CreateAsset((int)ClassIDType.BlendTree, BlendTree.Create);
|
||||
IBlendTree blendTree = virtualFile.CreateBlendTree();
|
||||
blendTree.HideFlagsE = HideFlags.HideInHierarchy;
|
||||
|
||||
IBlendTreeNodeConstant node = state.GetBlendTree().NodeArray[nodeIndex].Data;
|
||||
@ -169,7 +169,7 @@ namespace AssetRipper.Processing.AnimatorControllers
|
||||
|
||||
public static IAnimatorStateMachine CreateStateMachine(ProcessedAssetCollection virtualFile, IAnimatorController controller, int layerIndex, uint fullPathID = 0)
|
||||
{
|
||||
IAnimatorStateMachine stateMachine = virtualFile.CreateAsset((int)ClassIDType.AnimatorStateMachine, AnimatorStateMachine.Create);
|
||||
IAnimatorStateMachine stateMachine = virtualFile.CreateAnimatorStateMachine();
|
||||
stateMachine.HideFlagsE = HideFlags.HideInHierarchy;
|
||||
|
||||
// can add StateMachineBehaviours now
|
||||
@ -191,7 +191,7 @@ namespace AssetRipper.Processing.AnimatorControllers
|
||||
|
||||
public static IAnimatorState CreateAnimatorState(ProcessedAssetCollection virtualFile, IAnimatorController controller, AssetDictionary<uint, Utf8String> tos, int layerIndex, IStateConstant stateConstant)
|
||||
{
|
||||
IAnimatorState animatorState = virtualFile.CreateAsset((int)ClassIDType.AnimatorState, AnimatorState.Create);
|
||||
IAnimatorState animatorState = virtualFile.CreateAnimatorState();
|
||||
animatorState.HideFlagsE = HideFlags.HideInHierarchy;
|
||||
|
||||
animatorState.Name = stateConstant.GetName(tos);
|
||||
@ -234,7 +234,7 @@ namespace AssetRipper.Processing.AnimatorControllers
|
||||
|
||||
public static IAnimatorState CreateDefaultAnimatorState(ProcessedAssetCollection virtualFile)
|
||||
{
|
||||
IAnimatorState animatorState = virtualFile.CreateAsset((int)ClassIDType.AnimatorState, AnimatorState.Create);
|
||||
IAnimatorState animatorState = virtualFile.CreateAnimatorState();
|
||||
animatorState.HideFlagsE = HideFlags.HideInHierarchy;
|
||||
|
||||
animatorState.Name = AnimatorStateName;
|
||||
@ -246,7 +246,7 @@ namespace AssetRipper.Processing.AnimatorControllers
|
||||
|
||||
public static IAnimatorStateTransition CreateAnimatorStateTransition(ProcessedAssetCollection virtualFile, AssetDictionary<uint, Utf8String> TOS, ITransitionConstant Transition)
|
||||
{
|
||||
IAnimatorStateTransition animatorStateTransition = virtualFile.CreateAsset((int)ClassIDType.AnimatorStateTransition, AnimatorStateTransition.Create);
|
||||
IAnimatorStateTransition animatorStateTransition = virtualFile.CreateAnimatorStateTransition();
|
||||
animatorStateTransition.HideFlags = (uint)HideFlags.HideInHierarchy;
|
||||
|
||||
animatorStateTransition.Conditions.Capacity = Transition.ConditionConstantArray.Count;
|
||||
@ -280,7 +280,7 @@ namespace AssetRipper.Processing.AnimatorControllers
|
||||
|
||||
public static IAnimatorTransition CreateAnimatorTransition(ProcessedAssetCollection virtualFile, AssetDictionary<uint, Utf8String> TOS, SelectorTransitionConstant transition)
|
||||
{
|
||||
IAnimatorTransition animatorTransition = virtualFile.CreateAsset((int)ClassIDType.AnimatorTransition, AnimatorTransition.Create);
|
||||
IAnimatorTransition animatorTransition = virtualFile.CreateAnimatorTransition();
|
||||
animatorTransition.HideFlagsE = HideFlags.HideInHierarchy;
|
||||
|
||||
animatorTransition.Conditions.Capacity = transition.ConditionConstantArray.Count;
|
||||
|
||||
@ -115,7 +115,7 @@ namespace AssetRipper.Processing.AudioMixers
|
||||
|
||||
for (int i = 0; i < effects.Length; i++)
|
||||
{
|
||||
IAudioMixerEffectController effect = virtualFile.CreateAsset((int)ClassIDType.AudioMixerEffectController, AudioMixerEffectController.Create);
|
||||
IAudioMixerEffectController effect = virtualFile.CreateAudioMixerEffectController();
|
||||
effect.HideFlagsE = HideFlags.HideInHierarchy | HideFlags.HideInInspector;
|
||||
effects[i] = effect;
|
||||
effect.MainAsset = mixer;
|
||||
@ -175,7 +175,7 @@ namespace AssetRipper.Processing.AudioMixers
|
||||
{
|
||||
if (!groupsWithAttenuation.Contains(group))
|
||||
{
|
||||
IAudioMixerEffectController effect = virtualFile.CreateAsset((int)ClassIDType.AudioMixerEffectController, AudioMixerEffectController.Create);
|
||||
IAudioMixerEffectController effect = virtualFile.CreateAudioMixerEffectController();
|
||||
effect.HideFlagsE = HideFlags.HideInHierarchy | HideFlags.HideInInspector;
|
||||
effect.EffectID.CopyValues(UnityGuid.NewGuid());
|
||||
effect.EffectName = "Attenuation";
|
||||
|
||||
@ -76,7 +76,7 @@ namespace AssetRipper.Processing
|
||||
continue;
|
||||
}
|
||||
|
||||
ILightingDataAsset lightingDataAsset = CreateLightingDataAsset(processedCollection);
|
||||
ILightingDataAsset lightingDataAsset = processedCollection.CreateLightingDataAsset();
|
||||
|
||||
lightmapSettings.LightingDataAssetP = lightingDataAsset;
|
||||
|
||||
@ -378,19 +378,9 @@ namespace AssetRipper.Processing
|
||||
lightingDataAsset.EnlightenDataVersion = 112;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create a new, empty <see cref="ILightingDataAsset"/>.
|
||||
/// </summary>
|
||||
/// <param name="collection"></param>
|
||||
/// <returns></returns>
|
||||
private static ILightingDataAsset CreateLightingDataAsset(ProcessedAssetCollection collection)
|
||||
{
|
||||
return collection.CreateAsset((int)ClassIDType.LightingDataAsset, LightingDataAsset.Create);
|
||||
}
|
||||
|
||||
private static ISceneAsset CreateSceneAsset(ProcessedAssetCollection collection, SceneDefinition targetScene)
|
||||
{
|
||||
ISceneAsset asset = collection.CreateAsset((int)ClassIDType.SceneAsset, SceneAsset.Create);
|
||||
ISceneAsset asset = collection.CreateSceneAsset();
|
||||
asset.TargetScene = targetScene;
|
||||
return asset;
|
||||
}
|
||||
|
||||
@ -96,7 +96,7 @@ public sealed class PrefabProcessor : IAssetProcessor
|
||||
collection = missingPrefabTransformCollection;
|
||||
}
|
||||
|
||||
ITransform transform = collection.CreateAsset((int)ClassIDType.Transform, Transform.Create);
|
||||
ITransform transform = collection.CreateTransform();
|
||||
|
||||
transform.InitializeDefault();
|
||||
|
||||
|
||||
@ -134,7 +134,7 @@ namespace AssetRipper.Processing.Scenes
|
||||
|
||||
if (buildSettings is not null)
|
||||
{
|
||||
IEditorBuildSettings editorBuildSettings = processedCollection.CreateAsset((int)ClassIDType.EditorBuildSettings, EditorBuildSettings.Create);
|
||||
IEditorBuildSettings editorBuildSettings = processedCollection.CreateEditorBuildSettings();
|
||||
{
|
||||
int numScenes = buildSettings.Scenes.Count;
|
||||
editorBuildSettings.Scenes.Capacity = numScenes;
|
||||
@ -150,7 +150,7 @@ namespace AssetRipper.Processing.Scenes
|
||||
|
||||
//EditorSettings
|
||||
//Is this the best place to create this? It doesn't have anything to do with scenes.
|
||||
processedCollection.CreateAsset((int)ClassIDType.EditorSettings, EditorSettings.Create)
|
||||
processedCollection.CreateEditorSettings()
|
||||
.SetToDefaults();
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,29 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netstandard2.0</TargetFramework>
|
||||
<IsAotCompatible>false</IsAotCompatible>
|
||||
<AppendTargetFrameworkToOutputPath>true</AppendTargetFrameworkToOutputPath>
|
||||
<EnforceExtendedAnalyzerRules>true</EnforceExtendedAnalyzerRules>
|
||||
<PolySharpExcludeGeneratedTypes>System.Runtime.CompilerServices.ModuleInitializerAttribute</PolySharpExcludeGeneratedTypes>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="4.14.0">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.14.0" />
|
||||
<PackageReference Include="PolySharp" Version="1.15.0">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="SourceGenerator.Foundations" Version="2.0.13" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<!-- Generator dependencies -->
|
||||
<PackageReference Include="AssetRipper.Text.SourceGeneration" Version="1.2.2" PrivateAssets="all" GeneratePathProperty="true" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@ -0,0 +1,360 @@
|
||||
namespace AssetRipper.SourceGenerated.Extensions.SourceGenerator;
|
||||
|
||||
// Copy-pasted from decompilation and removed abstract classes
|
||||
public enum ClassIDType
|
||||
{
|
||||
GameObject = 1,
|
||||
Component = 2,
|
||||
Transform = 4,
|
||||
TimeManager = 5,
|
||||
AudioManager = 11,
|
||||
ParticleAnimator = 12,
|
||||
InputManager = 13,
|
||||
EllipsoidParticleEmitter = 15,
|
||||
Pipeline = 17,
|
||||
Physics2DSettings = 19,
|
||||
Camera = 20,
|
||||
Material = 21,
|
||||
MeshRenderer = 23,
|
||||
ParticleRenderer = 26,
|
||||
Texture2D = 28,
|
||||
OcclusionCullingSettings = 29,
|
||||
GraphicsSettings = 30,
|
||||
MeshFilter = 33,
|
||||
OcclusionPortal = 41,
|
||||
Mesh = 43,
|
||||
Skybox = 45,
|
||||
QualitySettings = 47,
|
||||
Shader = 48,
|
||||
TextAsset = 49,
|
||||
Rigidbody2D = 50,
|
||||
NotificationManager = 52,
|
||||
Rigidbody = 54,
|
||||
PhysicsManager = 55,
|
||||
CircleCollider2D = 58,
|
||||
HingeJoint = 59,
|
||||
PolygonCollider2D = 60,
|
||||
BoxCollider2D = 61,
|
||||
PhysicsMaterial2D = 62,
|
||||
MeshCollider = 64,
|
||||
BoxCollider = 65,
|
||||
CompositeCollider2D = 66,
|
||||
EdgeCollider2D = 68,
|
||||
CapsuleCollider2D = 70,
|
||||
AnimationManager = 71,
|
||||
ComputeShader = 72,
|
||||
AnimationClip = 74,
|
||||
ConstantForce = 75,
|
||||
WorldParticleCollider = 76,
|
||||
TagManager = 78,
|
||||
AudioListener = 81,
|
||||
AudioSource = 82,
|
||||
AudioClip = 83,
|
||||
RenderTexture = 84,
|
||||
CustomRenderTexture = 86,
|
||||
MeshParticleEmitter = 87,
|
||||
Cubemap = 89,
|
||||
Avatar = 90,
|
||||
AnimatorController = 91,
|
||||
GUILayer = 92,
|
||||
RuntimeAnimatorController = 93,
|
||||
ShaderNameRegistry = 94,
|
||||
Animator = 95,
|
||||
TrailRenderer = 96,
|
||||
DelayedCallManager = 98,
|
||||
TextMesh = 102,
|
||||
RenderSettings = 104,
|
||||
Light = 108,
|
||||
ShaderInclude = 109,
|
||||
Animation = 111,
|
||||
MonoBehaviour = 114,
|
||||
MonoScript = 115,
|
||||
MonoManager = 116,
|
||||
Texture3D = 117,
|
||||
NewAnimationTrack = 118,
|
||||
Projector = 119,
|
||||
LineRenderer = 120,
|
||||
Flare = 121,
|
||||
Halo = 122,
|
||||
LensFlare = 123,
|
||||
FlareLayer = 124,
|
||||
HaloLayer = 125,
|
||||
NavMeshProjectSettings = 126,
|
||||
HaloManager = 127,
|
||||
Font = 128,
|
||||
GUITexture = 131,
|
||||
GUIText = 132,
|
||||
PhysicsMaterial = 134,
|
||||
SphereCollider = 135,
|
||||
CapsuleCollider = 136,
|
||||
SkinnedMeshRenderer = 137,
|
||||
FixedJoint = 138,
|
||||
RaycastCollider = 140,
|
||||
BuildSettings = 141,
|
||||
AssetBundle = 142,
|
||||
CharacterController = 143,
|
||||
CharacterJoint = 144,
|
||||
SpringJoint = 145,
|
||||
WheelCollider = 146,
|
||||
ResourceManager = 147,
|
||||
NetworkView = 148,
|
||||
NetworkManager = 149,
|
||||
PreloadData = 150,
|
||||
MovieTexture = 152,
|
||||
ConfigurableJoint = 153,
|
||||
TerrainCollider = 154,
|
||||
MasterServerInterface = 155,
|
||||
TerrainData = 156,
|
||||
LightmapSettings = 157,
|
||||
WebCamTexture = 158,
|
||||
EditorSettings = 159,
|
||||
InteractiveCloth = 160,
|
||||
ClothRenderer = 161,
|
||||
EditorUserSettings = 162,
|
||||
SkinnedCloth = 163,
|
||||
AudioReverbFilter = 164,
|
||||
AudioHighPassFilter = 165,
|
||||
AudioChorusFilter = 166,
|
||||
AudioReverbZone = 167,
|
||||
AudioEchoFilter = 168,
|
||||
AudioLowPassFilter = 169,
|
||||
AudioDistortionFilter = 170,
|
||||
SparseTexture = 171,
|
||||
WindZone = 182,
|
||||
Cloth = 183,
|
||||
SubstanceArchive = 184,
|
||||
ProceduralMaterial = 185,
|
||||
ProceduralTexture = 186,
|
||||
Texture2DArray = 187,
|
||||
CubemapArray = 188,
|
||||
OffMeshLink = 191,
|
||||
OcclusionArea = 192,
|
||||
Tree = 193,
|
||||
NavMeshData_194 = 194,
|
||||
NavMeshAgent = 195,
|
||||
NavMeshSettings = 196,
|
||||
LightProbes_197 = 197,
|
||||
ParticleSystem = 198,
|
||||
ParticleSystemRenderer = 199,
|
||||
ShaderVariantCollection = 200,
|
||||
LODGroup = 205,
|
||||
BlendTree = 206,
|
||||
NavMeshObstacle = 208,
|
||||
SortingGroup = 210,
|
||||
SpriteRenderer = 212,
|
||||
Sprite = 213,
|
||||
CachedSpriteAtlas = 214,
|
||||
ReflectionProbe = 215,
|
||||
Terrain = 218,
|
||||
LightProbeGroup = 220,
|
||||
AnimatorOverrideController = 221,
|
||||
CanvasRenderer = 222,
|
||||
Canvas = 223,
|
||||
RectTransform = 224,
|
||||
CanvasGroup = 225,
|
||||
BillboardAsset = 226,
|
||||
BillboardRenderer = 227,
|
||||
SpeedTreeWindAsset = 228,
|
||||
SpringJoint2D = 231,
|
||||
DistanceJoint2D = 232,
|
||||
HingeJoint2D = 233,
|
||||
SliderJoint2D = 234,
|
||||
WheelJoint2D = 235,
|
||||
ClusterInputManager = 236,
|
||||
NavMeshData_238 = 238,
|
||||
AudioMixer = 240,
|
||||
AudioMixerController = 241,
|
||||
AudioMixerGroupController = 243,
|
||||
AudioMixerEffectController = 244,
|
||||
AudioMixerSnapshotController = 245,
|
||||
ConstantForce2D = 247,
|
||||
AreaEffector2D = 249,
|
||||
PointEffector2D = 250,
|
||||
PlatformEffector2D = 251,
|
||||
SurfaceEffector2D = 252,
|
||||
BuoyancyEffector2D = 253,
|
||||
RelativeJoint2D = 254,
|
||||
FixedJoint2D = 255,
|
||||
FrictionJoint2D = 256,
|
||||
TargetJoint2D = 257,
|
||||
LightProbes_258 = 258,
|
||||
LightProbeProxyVolume = 259,
|
||||
SampleClip = 271,
|
||||
AudioMixerSnapshot = 272,
|
||||
AudioMixerGroup = 273,
|
||||
NScreenBridge = 280,
|
||||
AssetBundleManifest = 290,
|
||||
UnityAdsManager = 292,
|
||||
RuntimeInitializeOnLoadManager = 300,
|
||||
CloudWebServicesManager = 301,
|
||||
CloudServiceHandlerBehaviour = 302,
|
||||
UnityAnalyticsManager = 303,
|
||||
CrashReportManager = 304,
|
||||
PerformanceReportingManager = 305,
|
||||
UnityConnectSettings = 310,
|
||||
AvatarMask_319 = 319,
|
||||
PlayableDirector = 320,
|
||||
VideoClip_327 = 327,
|
||||
VideoPlayer = 328,
|
||||
VideoClip_329 = 329,
|
||||
ParticleSystemForceField = 330,
|
||||
SpriteMask = 331,
|
||||
WorldAnchor = 362,
|
||||
OcclusionCullingData = 363,
|
||||
MarshallingTestObject = 900,
|
||||
PrefabInstance = 1001,
|
||||
EditorExtensionImpl = 1002,
|
||||
AssetDatabaseV1 = 1004,
|
||||
Mesh3DSImporter = 1005,
|
||||
TextureImporter = 1006,
|
||||
ShaderImporter = 1007,
|
||||
ComputeShaderImporter = 1008,
|
||||
AvatarMask_1011 = 1011,
|
||||
AvatarSkeletonMask = 1012,
|
||||
AudioImporter = 1020,
|
||||
HierarchyState = 1026,
|
||||
GUIDSerializer = 1027,
|
||||
AssetMetaData = 1028,
|
||||
DefaultAsset = 1029,
|
||||
DefaultImporter = 1030,
|
||||
TextScriptImporter = 1031,
|
||||
SceneAsset = 1032,
|
||||
NativeFormatImporter = 1034,
|
||||
MonoImporter = 1035,
|
||||
AssetServerCache = 1037,
|
||||
LibraryAssetImporter = 1038,
|
||||
FBXImporter = 1041,
|
||||
TrueTypeFontImporter = 1042,
|
||||
MovieImporter = 1044,
|
||||
EditorBuildSettings = 1045,
|
||||
DDSImporter = 1046,
|
||||
InspectorExpandedState = 1048,
|
||||
AnnotationManager = 1049,
|
||||
PluginImporter = 1050,
|
||||
EditorUserBuildSettings = 1051,
|
||||
PVRImporter = 1052,
|
||||
ASTCImporter = 1053,
|
||||
KTXImporter = 1054,
|
||||
IHVImageFormatImporter = 1055,
|
||||
AnimatorStateTransition = 1101,
|
||||
AnimatorState = 1102,
|
||||
HumanTemplate = 1105,
|
||||
AnimatorStateMachine = 1107,
|
||||
PreviewAnimationClip = 1108,
|
||||
AnimatorTransition = 1109,
|
||||
SpeedTreeImporter = 1110,
|
||||
AnimatorTransitionBase = 1111,
|
||||
SubstanceImporter = 1112,
|
||||
LightmapParameters = 1113,
|
||||
LightingDataAsset = 1120,
|
||||
SketchUpImporter = 1124,
|
||||
BuildReport = 1125,
|
||||
PackedAssets = 1126,
|
||||
VideoClipImporter = 1127,
|
||||
StyleSheetImporter = 1128,
|
||||
TilemapCollider2D = 19719996,
|
||||
ImportLog = 41386430,
|
||||
GraphicsStateCollection = 55640938,
|
||||
VFXRenderer = 73398921,
|
||||
SerializableManagedRefTestClass = 76251197,
|
||||
Grid = 156049354,
|
||||
ScenesUsingAssets = 156483287,
|
||||
ArticulationBody = 171741748,
|
||||
Preset = 181963792,
|
||||
EmptyObject = 277625683,
|
||||
TestObjectWithSpecialLayoutOne = 293259124,
|
||||
AssemblyDefinitionReferenceImporter = 294290339,
|
||||
SiblingDerived = 334799969,
|
||||
TestObjectWithSerializedMapStringNonAlignedStruct = 342846651,
|
||||
AudioResource = 355983997,
|
||||
SubDerived = 367388927,
|
||||
AssetImportInProgressProxy = 369655926,
|
||||
PluginBuildInfo = 382020655,
|
||||
MemorySettings = 387306366,
|
||||
BuildMetaDataImporter = 403037116,
|
||||
BuildInstructionImporter = 403037117,
|
||||
EditorProjectAccess = 426301858,
|
||||
PrefabImporter = 468431735,
|
||||
TestObjectWithSerializedArray = 478637458,
|
||||
TestObjectWithSerializedAnimationCurve = 478637459,
|
||||
TilemapRenderer = 483693784,
|
||||
ScriptableCamera = 488575907,
|
||||
SpriteAtlasAsset = 612988286,
|
||||
SpriteAtlasDatabase = 638013454,
|
||||
AudioBuildInfo = 641289076,
|
||||
CachedSpriteAtlasRuntimeData = 644342135,
|
||||
MultiplayerManager = 655991488,
|
||||
AssemblyDefinitionReferenceAsset = 662584278,
|
||||
BuiltAssetBundleInfoSet = 668709126,
|
||||
SpriteAtlas = 687078895,
|
||||
DifferentMarshallingTestObject = 702665669,
|
||||
RayTracingShaderImporter = 747330370,
|
||||
BuildArchiveImporter = 780535461,
|
||||
PreviewImporter = 815301076,
|
||||
RayTracingShader = 825902497,
|
||||
LightingSettings = 850595691,
|
||||
PlatformModuleSetup = 877146078,
|
||||
VersionControlSettings = 890905787,
|
||||
CustomCollider2D = 893571522,
|
||||
AimConstraint = 895512359,
|
||||
VFXManager = 937362698,
|
||||
RoslynAnalyzerConfigAsset = 947337230,
|
||||
RuleSetFileAsset = 954905827,
|
||||
VisualEffectSubgraphOperator = 994735403,
|
||||
VisualEffectSubgraphBlock = 994735404,
|
||||
Prefab = 1001480554,
|
||||
LocalizationImporter = 1027052791,
|
||||
Derived = 1091556383,
|
||||
PropertyModificationsTargetTestObject = 1111377672,
|
||||
ReferencesArtifactGenerator = 1114811875,
|
||||
AssemblyDefinitionAsset = 1152215463,
|
||||
SceneVisibilityState = 1154873562,
|
||||
LookAtConstraint = 1183024399,
|
||||
SpriteAtlasImporter = 1210832254,
|
||||
MultiArtifactTestImporter = 1223240404,
|
||||
AudioContainerElement = 1233149941,
|
||||
GameObjectRecorder = 1268269756,
|
||||
AudioRandomContainer = 1307931743,
|
||||
LightingDataAssetParent = 1325145578,
|
||||
PresetManager = 1386491679,
|
||||
TestObjectWithSpecialLayoutTwo = 1392443030,
|
||||
StreamingManager = 1403656975,
|
||||
LowerResBlitTexture = 1480428607,
|
||||
VideoBuildInfo = 1521398425,
|
||||
C4DImporter = 1541671625,
|
||||
StreamingController = 1542919678,
|
||||
ShaderContainer = 1557264870,
|
||||
RenderPassAttachment = 1571458007,
|
||||
RoslynAdditionalFileAsset = 1597193336,
|
||||
TestObjectVectorPairStringBool = 1628831178,
|
||||
RoslynAdditionalFileImporter = 1642787288,
|
||||
MultiplayerRolesData = 1652712579,
|
||||
SceneRoots = 1660057539,
|
||||
BrokenPrefabAsset = 1731078267,
|
||||
AndroidAssetPackImporter = 1736697216,
|
||||
VulkanDeviceFilterLists = 1740304944,
|
||||
AssemblyDefinitionImporter = 1766753193,
|
||||
ParentConstraint = 1773428102,
|
||||
RuleSetFileImporter = 1777034230,
|
||||
PositionConstraint = 1818360608,
|
||||
RotationConstraint = 1818360609,
|
||||
ScaleConstraint = 1818360610,
|
||||
Tilemap = 1839735485,
|
||||
PackageManifest = 1896753125,
|
||||
PackageManifestImporter = 1896753126,
|
||||
RoslynAnalyzerConfigImporter = 1903396204,
|
||||
UIRenderer = 1931382933,
|
||||
TerrainLayer = 1953259897,
|
||||
SpriteShapeRenderer = 1971053207,
|
||||
NativeObjectType = 1977754360,
|
||||
TestObjectWithSerializedMapStringBool = 1981279845,
|
||||
SerializableManagedHost = 1995898324,
|
||||
VisualEffectAsset = 2058629509,
|
||||
VisualEffectImporter = 2058629510,
|
||||
VisualEffectResource = 2058629511,
|
||||
VisualEffect = 2083052967,
|
||||
LocalizationAsset = 2083778819,
|
||||
ScriptedImporter = 2089858483,
|
||||
ShaderIncludeImporter = 2103361453,
|
||||
TilemapEditorUserSettings = 2126867596
|
||||
}
|
||||
@ -0,0 +1,82 @@
|
||||
using AssetRipper.Text.SourceGeneration;
|
||||
using SGF;
|
||||
using System.CodeDom.Compiler;
|
||||
|
||||
namespace AssetRipper.SourceGenerated.Extensions.SourceGenerator;
|
||||
|
||||
[IncrementalGenerator]
|
||||
public class CreateMethodGenerator() : IncrementalGenerator(nameof(CreateMethodGenerator))
|
||||
{
|
||||
public override void OnInitialize(SgfInitializationContext context)
|
||||
{
|
||||
context.RegisterPostInitializationOutput(static (context) =>
|
||||
{
|
||||
context.AddSource("AssetCreator.g.cs", GenerateCode());
|
||||
});
|
||||
}
|
||||
|
||||
private static string GenerateCode()
|
||||
{
|
||||
StringWriter stringWriter = new() { NewLine = "\n" };
|
||||
using IndentedTextWriter writer = IndentedTextWriterFactory.Create(stringWriter);
|
||||
|
||||
writer.WriteGeneratedCodeWarning();
|
||||
writer.WriteLineNoTabs();
|
||||
writer.WriteUsing("AssetRipper.Assets.Collections");
|
||||
writer.WriteUsing("AssetRipper.Primitives");
|
||||
foreach (ClassIDType classId in GetValues())
|
||||
{
|
||||
writer.WriteUsing($"AssetRipper.SourceGenerated.Classes.ClassID_{(int)classId}");
|
||||
}
|
||||
writer.WriteLineNoTabs();
|
||||
writer.WriteFileScopedNamespace("AssetRipper.SourceGenerated.Extensions");
|
||||
writer.WriteLineNoTabs();
|
||||
writer.WriteLine("public static partial class AssetCreator");
|
||||
using (new CurlyBrackets(writer))
|
||||
{
|
||||
writer.WriteLine("extension(ProcessedAssetCollection collection)");
|
||||
using (new CurlyBrackets(writer))
|
||||
{
|
||||
foreach (ClassIDType classId in GetValues())
|
||||
{
|
||||
string enumValueName = classId.ToString();
|
||||
string name = GetName(enumValueName);
|
||||
writer.WriteLine($"public I{name} Create{name}() => collection.CreateAsset((int)ClassIDType.{enumValueName}, {name}.Create);");
|
||||
}
|
||||
}
|
||||
foreach (ClassIDType classId in GetValues())
|
||||
{
|
||||
string name = GetName(classId.ToString());
|
||||
writer.WriteLine($"public static I{name} Create{name}(UnityVersion version) => CreateCollection(version).Create{name}();");
|
||||
}
|
||||
}
|
||||
|
||||
return stringWriter.ToString();
|
||||
}
|
||||
|
||||
private static string GetName(string enumValueName)
|
||||
{
|
||||
int index = enumValueName.IndexOf('_');
|
||||
if (index < 0)
|
||||
{
|
||||
return enumValueName;
|
||||
}
|
||||
else
|
||||
{
|
||||
return enumValueName.Substring(0, index);
|
||||
}
|
||||
}
|
||||
|
||||
private static IEnumerable<ClassIDType> GetValues()
|
||||
{
|
||||
foreach (ClassIDType value in Enum.GetValues(typeof(ClassIDType)).Cast<ClassIDType>())
|
||||
{
|
||||
if (value is ClassIDType.NavMeshData_194 or ClassIDType.LightProbes_197 or ClassIDType.VideoClip_327 or ClassIDType.AvatarMask_1011)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
yield return value;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -9,29 +9,13 @@ namespace AssetRipper.SourceGenerated.Extensions;
|
||||
/// <summary>
|
||||
/// A helper class for creating assets, generally for unit testing.
|
||||
/// </summary>
|
||||
public static class AssetCreator
|
||||
public static partial class AssetCreator
|
||||
{
|
||||
public static T CreateAsset<T>(this ProcessedAssetCollection collection, ClassIDType classID) where T : IUnityObjectBase
|
||||
{
|
||||
return collection.CreateAsset((int)classID, (assetInfo) =>
|
||||
{
|
||||
return (T)AssetFactory.Create(assetInfo);
|
||||
});
|
||||
}
|
||||
|
||||
public static T Create<T>(ClassIDType classID, UnityVersion version, Func<AssetInfo, T> factory) where T : IUnityObjectBase
|
||||
{
|
||||
return CreateCollection(version).CreateAsset((int)classID, factory);
|
||||
}
|
||||
|
||||
public static T Create<T>(ClassIDType classID, UnityVersion version) where T : IUnityObjectBase
|
||||
{
|
||||
return CreateCollection(version).CreateAsset((int)classID, (assetInfo) =>
|
||||
{
|
||||
return (T)AssetFactory.Create(assetInfo);
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create a new asset using reflection.
|
||||
/// </summary>
|
||||
|
||||
@ -1,19 +1,20 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<IsTrimmable>true</IsTrimmable>
|
||||
<OutputPath>..\0Bins\Other\AssetRipper.SourceGenerated.Extensions\$(Configuration)\</OutputPath>
|
||||
<IntermediateOutputPath>..\0Bins\obj\AssetRipper.SourceGenerated.Extensions\$(Configuration)\</IntermediateOutputPath>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\AssetRipper.Assets\AssetRipper.Assets.csproj" />
|
||||
<ProjectReference Include="..\AssetRipper.Numerics\AssetRipper.Numerics.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="AssetRipper.Checksum" Version="1.0.0" />
|
||||
<PackageReference Include="AssetRipper.SourceGenerated" Version="1.2.3" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<IsTrimmable>true</IsTrimmable>
|
||||
<OutputPath>..\0Bins\Other\AssetRipper.SourceGenerated.Extensions\$(Configuration)\</OutputPath>
|
||||
<IntermediateOutputPath>..\0Bins\obj\AssetRipper.SourceGenerated.Extensions\$(Configuration)\</IntermediateOutputPath>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\AssetRipper.Assets\AssetRipper.Assets.csproj" />
|
||||
<ProjectReference Include="..\AssetRipper.Numerics\AssetRipper.Numerics.csproj" />
|
||||
<ProjectReference Include="..\AssetRipper.SourceGenerated.Extensions.SourceGenerator\AssetRipper.SourceGenerated.Extensions.SourceGenerator.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="AssetRipper.Checksum" Version="1.0.0" />
|
||||
<PackageReference Include="AssetRipper.SourceGenerated" Version="1.2.3" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@ -209,7 +209,7 @@ namespace AssetRipper.SourceGenerated.Extensions
|
||||
|
||||
public static IPrefabInstance CreatePrefabForRoot(this IGameObject root, ProcessedAssetCollection collection)
|
||||
{
|
||||
IPrefabInstance prefab = collection.CreateAsset((int)ClassIDType.PrefabInstance, PrefabInstance.Create);
|
||||
IPrefabInstance prefab = collection.CreatePrefabInstance();
|
||||
|
||||
prefab.HideFlagsE = HideFlags.HideInHierarchy;
|
||||
prefab.RootGameObjectP = root;
|
||||
|
||||
@ -8,6 +8,7 @@ using AssetRipper.SourceGenerated;
|
||||
using AssetRipper.SourceGenerated.Classes.ClassID_1;
|
||||
using AssetRipper.SourceGenerated.Classes.ClassID_1001;
|
||||
using AssetRipper.SourceGenerated.Classes.ClassID_114;
|
||||
using AssetRipper.SourceGenerated.Extensions;
|
||||
using AssetRipper.Yaml;
|
||||
using NUnit.Framework.Internal;
|
||||
|
||||
@ -19,8 +20,8 @@ public class StrippedAssetTests
|
||||
public void IsStrippedReturnsTrueForStrippedAsset()
|
||||
{
|
||||
ProcessedAssetCollection collection = CreateCollection(new UnityVersion(2020, 1));
|
||||
IGameObject root = collection.CreateAsset((int)ClassIDType.GameObject, GameObject.Create);
|
||||
IPrefabInstance prefab = collection.CreateAsset((int)ClassIDType.PrefabInstance, PrefabInstance.Create);
|
||||
IGameObject root = collection.CreateGameObject();
|
||||
IPrefabInstance prefab = collection.CreatePrefabInstance();
|
||||
PrefabHierarchyObject hierarchy = collection.CreateAsset(-1, (assetInfo) => new PrefabHierarchyObject(assetInfo, root, prefab));
|
||||
hierarchy.GameObjects.Add(root);
|
||||
hierarchy.SetMainAsset();
|
||||
@ -36,7 +37,7 @@ public class StrippedAssetTests
|
||||
ProcessedAssetCollection collection = CreateCollection(new UnityVersion(2020, 1));
|
||||
SceneDefinition scene = SceneDefinition.FromName("TestScene");
|
||||
scene.AddCollection(collection);
|
||||
IGameObject gameObject = collection.CreateAsset((int)ClassIDType.GameObject, GameObject.Create);
|
||||
IGameObject gameObject = collection.CreateGameObject();
|
||||
SceneHierarchyObject hierarchy = collection.CreateAsset(-1, (assetInfo) => new SceneHierarchyObject(assetInfo, scene));
|
||||
hierarchy.GameObjects.Add(gameObject);
|
||||
hierarchy.SetMainAsset();
|
||||
@ -64,7 +65,7 @@ public class StrippedAssetTests
|
||||
ProcessedAssetCollection collection = CreateCollection(new UnityVersion(2020, 1));
|
||||
SceneDefinition scene = SceneDefinition.FromName("TestScene");
|
||||
scene.AddCollection(collection);
|
||||
IMonoBehaviour monoBehaviour = collection.CreateAsset((int)ClassIDType.MonoBehaviour, MonoBehaviour.Create);
|
||||
IMonoBehaviour monoBehaviour = collection.CreateMonoBehaviour();
|
||||
SceneHierarchyObject hierarchy = collection.CreateAsset(-1, (assetInfo) => new SceneHierarchyObject(assetInfo, scene));
|
||||
hierarchy.Components.Add(monoBehaviour);
|
||||
hierarchy.SetMainAsset();
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
using AssetRipper.Primitives;
|
||||
using AssetRipper.SourceGenerated;
|
||||
using AssetRipper.SourceGenerated.Classes.ClassID_1006;
|
||||
using AssetRipper.SourceGenerated.Extensions;
|
||||
using NUnit.Framework.Internal;
|
||||
@ -96,11 +95,11 @@ internal class TextureImporterTests
|
||||
|
||||
private static ITextureImporter CreateImporterWithSwizzleField()
|
||||
{
|
||||
return AssetCreator.Create<ITextureImporter>(ClassIDType.TextureImporter, new UnityVersion(2022, 2));
|
||||
return AssetCreator.CreateTextureImporter(new UnityVersion(2022, 2));
|
||||
}
|
||||
|
||||
private static ITextureImporter CreateImporterWithoutSwizzleField()
|
||||
{
|
||||
return AssetCreator.Create<ITextureImporter>(ClassIDType.TextureImporter, new UnityVersion(2020, 1));
|
||||
return AssetCreator.CreateTextureImporter(new UnityVersion(2020, 1));
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user