Skip to content

Commit

Permalink
1.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
rurre committed Dec 8, 2023
1 parent d601463 commit 1c6c51c
Show file tree
Hide file tree
Showing 47 changed files with 4,869 additions and 6,020 deletions.
12 changes: 0 additions & 12 deletions .github/FUNDING.yml

This file was deleted.

1 change: 0 additions & 1 deletion .gitignore

This file was deleted.

74 changes: 74 additions & 0 deletions Editor/Copiers/DynamicCopierTypeCategory.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Pumkin.HelperFunctions;
using UnityEngine.Serialization;

namespace Pumkin.AvatarTools.Copiers
{
[Serializable]
internal class DynamicCopierTypesWrapper
{
public List<DynamicCopierTypeCategory> extraCopierTypes = new List<DynamicCopierTypeCategory>();
public bool HasValidTypes { get; private set; }

internal void Initialize()
{
foreach(var extraType in extraCopierTypes)
extraType.Initialize();

extraCopierTypes = extraCopierTypes.Where(t => t.types.Count > 0).ToList();
HasValidTypes = extraCopierTypes.Count > 0;
}

public void AddTypeNamesFromWrapper(DynamicCopierTypesWrapper newWrapper)
{
// Look for matching category by name, if found add it's types to the template, if not add the whole category
foreach(var newCategory in newWrapper.extraCopierTypes)
{
var foundCategory = extraCopierTypes.FirstOrDefault(t => t.categoryName.Equals(newCategory.categoryName, StringComparison.OrdinalIgnoreCase));
if(foundCategory != null)
{
foundCategory.typeFullNames.AddRange(newCategory.typeFullNames);
foundCategory.typeFullNames = foundCategory.typeFullNames.Distinct().ToList();
}
else
{
extraCopierTypes.Add(newCategory);
}
}
}
}

[Serializable]
internal class DynamicCopierTypeCategory
{
public string categoryName;
[FormerlySerializedAs("typeNames")] public List<string> typeFullNames;

[NonSerialized] public List<Type> types;
[NonSerialized] public List<bool> enableStates;
[NonSerialized] public List<string> names;

internal void Initialize()
{
types = new List<Type>();
enableStates = new List<bool>();
names = new List<string>();

if(typeFullNames == null)
return;

foreach(var name in typeFullNames)
{
var type = TypeHelpers.GetTypeAnywhere(name);
if(type == null)
continue;

types.Add(type);
names.Add(type.Name);
enableStates.Add(false);
}
}
}
}
3 changes: 3 additions & 0 deletions Editor/Copiers/DynamicCopierTypeCategory.cs.meta

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

57 changes: 8 additions & 49 deletions Editor/Data/PumkinsDataStructures.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public enum Tab { Common, All } //All needs to be last
{
{
Tab.Common,
new string[] //Initially lowercase to avoid having to cast them every time
new [] //Initially lowercase to avoid having to cast them every time
{
"prefab",
"physbone",
Expand All @@ -35,6 +35,13 @@ public enum Tab { Common, All } //All needs to be last
"light",
"contactreceiver",
"contactsender",
"parentconstraint",
"positionconstraint",
"rotationconstraint",
"scaleconstraint",
"aimconstraint",
"lookatconstraint",
"other"
}
}
};
Expand Down Expand Up @@ -746,54 +753,6 @@ public static string[] RightFingers
}
}

[Serializable]
class ThryModuleRequirement
{
public string type = "VRC_SDK_VERSION";
public string data = ">=0.0";
}

[Serializable]
class ThryModuleManifest
{
public string name;
public string description;
public string classname;
public double version;
public ThryModuleRequirement requirement;
public string[] files;

ThryModuleManifest()
{
name = Strings.Main.title;
description = "A set of tools to help you setup avatars easier.\nIncludes a component copier and tools to make thumbnails.\nTo launch the tools go to Tools > Pumkin > Avatar Tools.";
classname = typeof(PumkinsAvatarTools).FullName.ToString();
requirement = new ThryModuleRequirement();
version = Strings.toolsVersion;

var fileArray = Directory.GetFiles(PumkinsAvatarTools.MainFolderPath, "*", SearchOption.AllDirectories);
var finalFileList = new List<string>();
for(int i = 0; i < fileArray.Length; i++)
{
var file = fileArray[i].Substring(PumkinsAvatarTools.MainFolderPath.Length + 1);
if(file.EndsWith(".meta") || file.EndsWith("thry_module_manifest.json") || file.StartsWith(".git"))
continue;

file = file.Replace('\\', '/');
finalFileList.Add(file);
}
files = finalFileList.ToArray();
}

static public void Generate()
{
ThryModuleManifest m = new ThryModuleManifest();
string json = EditorJsonUtility.ToJson(m, true);
string path = PumkinsAvatarTools.MainFolderPath + "/thry_module_manifest.json";
File.WriteAllText(path, json);
}
}

class TexturePackerData
{
public enum PumkinsTextureChannel { RGBA, Red, Green, Blue, Alpha }
Expand Down
30 changes: 25 additions & 5 deletions Editor/Data/PumkinsStrings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEditor;
using UnityEngine;

Expand All @@ -11,14 +12,15 @@ namespace Pumkin.DataStructures
[ExecuteInEditMode, InitializeOnLoad] //needed for string singleton
public class Strings : SingletonScriptableObject<Strings>
{
public const string TOOLS_VERSION_STRING = "1.3.9";
public const double toolsVersion = 1.39;
public static string TOOLS_VERSION_STRING = "0.0.0";

public const string POSE_EDITOR_VERSION_NUMBER = "0.1.3b - Work in Progress";
public const string LINK_GITHUB = "https://github.com/rurre/PumkinsAvatarTools/";
public const string LINK_DONATION = "https://ko-fi.com/notpumkin";
public const string LINK_DISCORD = "https://discord.gg/7vyekJv";

static readonly string packagePath = $"{PumkinsAvatarTools.MainFolderPath}/package.json";

static PumkinsTranslation _translationHolder;
public static PumkinsTranslation Translation
{
Expand Down Expand Up @@ -85,11 +87,25 @@ static Main()
Reload();
}

class PackageJson
{
public string version;
}

public static void Reload()
{
if(Translation is null)
return;

// Get version from package.json
if(File.Exists(packagePath))
{
string json = File.ReadAllText(packagePath);
var jsonInstance = JsonUtility.FromJson<PackageJson>(json);
if(jsonInstance != null)
TOOLS_VERSION_STRING = jsonInstance.version;
}

avatar = Translation.main.avatar;
title = Translation.main.title;
version = Translation.main.version;
Expand Down Expand Up @@ -194,6 +210,8 @@ public static class Tools
public static string autoViewpoint = "_Auto Viewpoint";
public static string setTPose = "_Force TPose";
public static string setMeshRendererAnchors = "_Set Mesh Renderer Anchors";
public static string setParticleSystemAnchors = "_Set Particle System Anchors";
public static string setTrailRendererAnchors = "_Set Trail Renderer Anchors";
public static string setSkinnedMeshRendererAnchors = "_Set Skinned Mesh Renderer Anchors";
public static string viewpointZDepth = "_Z Depth";
public static string revertScale = "_Revert Scale";
Expand Down Expand Up @@ -234,6 +252,8 @@ public static void Reload()
setTPose = Translation.tools.setTPose;
viewpointZDepth = Translation.tools.viewpointZDepth;
setMeshRendererAnchors = Translation.tools.setRendererAnchors;
setParticleSystemAnchors = Translation.tools.setParticleSystemAnchors;
setTrailRendererAnchors = Translation.tools.setTrailRendererAnchors;
setSkinnedMeshRendererAnchors = Translation.tools.setSkinnedMeshRendererAnchors;
revertScale = Translation.tools.revertScale;
editScaleMoveViewpoint = Translation.tools.editScaleMoveViewpoint;
Expand Down Expand Up @@ -439,7 +459,7 @@ public static class Copier
public static string animators_inChildren = "_Child Animators";
public static string audioSources = "_Audio Sources";
public static string joints = "_Joints";
public static string other = "_Other";
public static string other = "_External";
public static string other_emptyScripts = "_Empty Scripts";
public static string other_vrmSpringBones = "_VRM Spring Bones";
public static string vrc_station = "_VRC Station (Chair)";
Expand Down Expand Up @@ -477,7 +497,7 @@ public static class Copier
public static string prefabs_copyPropertyOverrides = "_Copy Property Overrides";
public static string prefabs_ignorePrefabByOtherCopiers = "_Ignore Prefab By Other Copiers";

public static string adjustScale = "_Adjust Scale";
public static string adjustScale = "_Adjust Scale (might not work correctly)";
public static string fixReferences = "_Fix References";

public static string exclusions = "_Exclusions";
Expand Down Expand Up @@ -776,7 +796,7 @@ public static void Reload()
if(Translation is null)
return;

version = (Translation.credits.version + " " + TOOLS_VERSION_STRING) ?? ("_Version" + " " + TOOLS_VERSION_STRING);
version = $"{Translation.credits.version} {TOOLS_VERSION_STRING}";
redundantStrings = Translation.credits.redundantStrings;
addMoreStuff = Translation.credits.addMoreStuff;
pokeOnDiscord = Translation.credits.pokeOnDiscord;
Expand Down
99 changes: 99 additions & 0 deletions Editor/Data/PumkinsTypeCache.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
using System;
using System.Collections.Generic;
using Pumkin.AvatarTools;
using Pumkin.HelperFunctions;
using System.IO;
using System.Linq;
using Pumkin.AvatarTools.Copiers;
using UnityEditor;
using UnityEngine;

namespace Pumkin.DataStructures
{
Expand Down Expand Up @@ -36,6 +43,98 @@ internal static class PumkinsTypeCache
public static readonly Type FullBodyBipedIK = TypeHelpers.GetTypeAnywhere("RootMotion.FinalIK.FullBodyBipedIK");
public static readonly Type VRIK = TypeHelpers.GetTypeAnywhere("RootMotion.FinalIK.VRIK");
public static readonly Type Grounder = TypeHelpers.GetTypeAnywhere("RootMotion.FinalIK.Grounder");
public static readonly Type IKExecutionOrder = TypeHelpers.GetTypeAnywhere("RootMotion.FinalIK.IKExecutionOrder");

public static readonly Type VRMSpringBone = TypeHelpers.GetTypeAnywhere("VRM.VRMSpringBone");

static readonly string extraTypesTemplatePath = $"{PumkinsAvatarTools.MainFolderPath}/extra_copier_types_template.json";
const string extraTypesFilename = "extra_copier_types.json";
const string extraTypesStatesFilename = "extra_copier_types_states.json";

public static void OpenExtraTypesJson()
{
PumkinsSettingsUtility.OpenSettingsFile(extraTypesFilename, CopierTypesTemplate);
}

public static List<DynamicCopierTypeCategory> ExtraTypes { get; private set; }

public static bool HasExtraTypes
{
get => hasValidTypes != null && (bool)hasValidTypes;
}

static bool? hasValidTypes;

static DynamicCopierTypesWrapper CopierTypesTemplate
{
get
{
if(_copierTypesTemplate == null)
{
if(File.Exists(extraTypesTemplatePath))
{
string exampleJson = File.ReadAllText(extraTypesTemplatePath);
_copierTypesTemplate = JsonUtility.FromJson<DynamicCopierTypesWrapper>(exampleJson);
return _copierTypesTemplate;
}
PumkinsAvatarTools.Log("_Couldn't find example file for extra copier types inside PumkinsAvatarTools folder.", LogType.Warning);
}
return _copierTypesTemplate;
}
}

class DynamicCopierStatesWrapper
{
public string[] enabledTypeNames;
}

static DynamicCopierTypesWrapper _copierTypesTemplate;

internal static void LoadExtraTypes()
{
bool wasCreated = PumkinsSettingsUtility.EnsureSettingsFileExists(extraTypesFilename, CopierTypesTemplate);
if(PumkinsSettingsUtility.TryLoadSettings<DynamicCopierTypesWrapper>(extraTypesFilename, out var typesWrapper))
{
if(!wasCreated)
typesWrapper.AddTypeNamesFromWrapper(CopierTypesTemplate);

typesWrapper.Initialize();
hasValidTypes = typesWrapper.HasValidTypes;
ExtraTypes = typesWrapper.extraCopierTypes;

if(PumkinsSettingsUtility.TryLoadSettings<DynamicCopierStatesWrapper>(extraTypesStatesFilename, out var enabledTypeNames))
{
// Get names of all enabled types from json then compare it to a list of valid types and if found, set it's state to enabled.
var enabledNames = enabledTypeNames.enabledTypeNames.Select(n => n.ToLower());
foreach(var typeCategory in ExtraTypes)
{
var validTypeNames = typeCategory.types.Select(t => t.FullName.ToLower()).ToList();
for(int i = 0; i < validTypeNames.Count; i++)
{
if(enabledNames.Contains(validTypeNames[i]))
typeCategory.enableStates[i] = true;
}
}
}
}
}

internal static void SaveExtraTypeEnableStates()
{
List<string> enabledTypes = new List<string>();

// Get names of all enabled types across any category
foreach(var typeCategory in ExtraTypes)
{
for(int i = 0; i < typeCategory.enableStates.Count; i++)
{
if(typeCategory.enableStates[i])
enabledTypes.Add(typeCategory.types[i].FullName);
}
}

var statesWrapper = new DynamicCopierStatesWrapper { enabledTypeNames = enabledTypes.ToArray() };
PumkinsSettingsUtility.SaveSettings(extraTypesStatesFilename, statesWrapper, true);
}
}
}
2 changes: 1 addition & 1 deletion Editor/Destroyers/LegacyDestroyer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ internal static void DestroyEmptyGameObjects(GameObject from)
}
if(c <= 0 && (t.name.ToLower() != (t.parent.name.ToLower() + "_end")))
{
if(PrefabUtility.GetPrefabInstanceStatus(t) == PrefabInstanceStatus.NotAPrefab || PrefabUtility.GetPrefabInstanceStatus(t) == PrefabInstanceStatus.Disconnected)
if(PrefabUtility.GetPrefabInstanceStatus(t) == PrefabInstanceStatus.NotAPrefab)
{
PumkinsAvatarTools.Log(Strings.Log.hasNoComponentsOrChildrenDestroying, LogType.Log, t.name);
GameObject.DestroyImmediate(t.gameObject);
Expand Down
Loading

0 comments on commit 1c6c51c

Please sign in to comment.