Skip to content

Commit

Permalink
initial checkin
Browse files Browse the repository at this point in the history
  • Loading branch information
bdunderscore committed Aug 5, 2023
1 parent 11de242 commit d828521
Show file tree
Hide file tree
Showing 43 changed files with 969 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,9 @@ crashlytics-build.properties
Assets/PackageMakerWindowData.asset*
.idea
.vscode

Assets/*/
Assets/*
!Assets/UnitTests/
!Assets/UnitTests.meta
Packages/nadena.dev.modular-avatar
8 changes: 8 additions & 0 deletions Editor.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Editor/API.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Editor/API/Attributes.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions Editor/API/Attributes/DefineAvatarBuildPlugin.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System;

namespace nadena.dev.Av3BuildFramework
{
[System.AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true, Inherited = false)]
public class DefineAvatarBuildPlugin : System.Attribute
{
private readonly string _qualifiedName;
private readonly Type _type;

public DefineAvatarBuildPlugin(string _qualifiedName, Type type)
{
this._qualifiedName = _qualifiedName;
this._type = type;
}

public string QualifiedName => _qualifiedName;
public Type Type => _type;
}
}
3 changes: 3 additions & 0 deletions Editor/API/Attributes/DefineAvatarBuildPlugin.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions Editor/API/Attributes/PluginOrdering.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System;
using System.ComponentModel;

namespace nadena.dev.Av3BuildFramework
{
/*public enum ConstraintType
{
RunsBefore,
RunsAfter
}
[AttributeUsage(AttributeTargets.Class, AllowMultiple = true, Inherited = false)]
public class PluginOrdering : System.Attribute
{
private string _qualifiedName;
private Type _pluginType;
private ConstraintType _constraintType;
private bool _required;
public PluginOrdering
}*/
}
3 changes: 3 additions & 0 deletions Editor/API/Attributes/PluginOrdering.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 25 additions & 0 deletions Editor/API/Attributes/PluginPhase.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System;

namespace nadena.dev.Av3BuildFramework
{
public enum Phase
{
Check,
Generate,
Transform,
Optimize
}

[AttributeUsage(AttributeTargets.Class)]
public class PluginPhase : System.Attribute
{
private readonly Phase _phase;

public PluginPhase(Phase phase)
{
_phase = phase;
}

public Phase Phase => _phase;
}
}
3 changes: 3 additions & 0 deletions Editor/API/Attributes/PluginPhase.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

48 changes: 48 additions & 0 deletions Editor/API/AvatarBuildPlugin.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;

namespace nadena.dev.build_framework
{
[System.AttributeUsage(System.AttributeTargets.Assembly)]
public class ExportsPlugin : System.Attribute
{
public Type PluginType;

public ExportsPlugin(Type pluginType)
{
PluginType = pluginType;
}
}

public abstract class Plugin
{
public abstract string QualifiedName { get; }
public virtual bool EnableByDefault => true;

public abstract ImmutableList<PluginPass> Passes {
get;
}

public virtual ImmutableList<string> RunsBefore => ImmutableList<string>.Empty;
public virtual ImmutableList<string> RunsAfter => ImmutableList<string>.Empty;
public virtual ImmutableList<string> RequiredPlugins => ImmutableList<string>.Empty;
public virtual ImmutableList<string> RequiredPasses => ImmutableList<string>.Empty;
}

public abstract class PluginPass
{
public virtual string DisplayName => GetType().Name;

public virtual ImmutableList<string> RunsBefore => ImmutableList<string>.Empty;
public virtual ImmutableList<string> RunsAfter => ImmutableList<string>.Empty;

// Type or string
public virtual IImmutableSet<object> CompatibleContexts => ImmutableHashSet<object>.Empty;
public virtual IImmutableSet<Type> RequiredContexts => ImmutableHashSet<Type>.Empty;

public abstract void Process(BuildContext context);
}

}
11 changes: 11 additions & 0 deletions Editor/API/AvatarBuildPlugin.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

65 changes: 65 additions & 0 deletions Editor/API/BuildContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
using System;
using System.Collections.Generic;
using nadena.dev.build_framework.util;
using UnityEditor;
using UnityEngine;
using VRC.SDK3.Avatars.Components;

namespace nadena.dev.build_framework
{
public class BuildContext
{
private readonly VRCAvatarDescriptor _avatarDescriptor;
private readonly GameObject _avatarRootObject;
private readonly Transform _avatarRootTransform;

public VRCAvatarDescriptor AvatarDescriptor => _avatarDescriptor;
public GameObject AvatarRootObject => _avatarRootObject;
public Transform AvatarRootTransform => _avatarRootTransform;
public UnityEngine.Object AssetContainer { get; private set; }

private Dictionary<Type, object> _contextData = new Dictionary<Type, object>();

public T Get<T>() where T : new()
{
if (_contextData.TryGetValue(typeof(T), out var value))
{
return (T) value;
}

value = new T();
_contextData[typeof(T)] = value;
return (T) value;
}

public BuildContext(GameObject obj, string assetRootPath)
: this(obj.GetComponent<VRCAvatarDescriptor>(), assetRootPath)
{
}

public BuildContext(VRCAvatarDescriptor avatarDescriptor, string assetRootPath)
{
_avatarDescriptor = avatarDescriptor;
_avatarRootObject = avatarDescriptor.gameObject;
_avatarRootTransform = avatarDescriptor.transform;

// Ensure the target directory exists
System.IO.Directory.CreateDirectory(assetRootPath);

var avatarName = _avatarRootObject.name;
var avatarPath = System.IO.Path.Combine(assetRootPath, avatarName) + ".asset";

AssetDatabase.GenerateUniqueAssetPath(avatarPath);
AssetContainer = ScriptableObject.CreateInstance<GeneratedAssets>();
AssetDatabase.CreateAsset(AssetContainer, avatarPath);
}

public void Serialize()
{
foreach (var asset in _avatarRootObject.ReferencedAssets(traverseSaved: false, includeScene: false))
{
AssetDatabase.AddObjectToAsset(asset, AssetContainer);
}
}
}
}
11 changes: 11 additions & 0 deletions Editor/API/BuildContext.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Editor/API/Model.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit d828521

Please sign in to comment.