导入角色动画,和增加角色控制
This commit is contained in:
88
Assets/KINEMATION/MagicBlend/Editor/MagicBlendContextMenu.cs
Normal file
88
Assets/KINEMATION/MagicBlend/Editor/MagicBlendContextMenu.cs
Normal file
@@ -0,0 +1,88 @@
|
||||
// Designed by KINEMATION, 2025.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using KINEMATION.KAnimationCore.Editor;
|
||||
using KINEMATION.KAnimationCore.Runtime.Rig;
|
||||
using KINEMATION.MagicBlend.Runtime;
|
||||
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace KINEMATION.MagicBlend.Editor
|
||||
{
|
||||
public class MagicBlendContextMenu
|
||||
{
|
||||
private const string ItemName = "Assets/Create Magic Blend";
|
||||
|
||||
public static KRigElementChain[] GetMatchingChains(KRig rig, string[] queries)
|
||||
{
|
||||
List<KRigElementChain> chains = new List<KRigElementChain>();
|
||||
|
||||
foreach (var elementChain in rig.rigElementChains)
|
||||
{
|
||||
foreach (var query in queries)
|
||||
{
|
||||
if (!elementChain.chainName.ToLower().Contains(query.ToLower())) continue;
|
||||
|
||||
chains.Add(elementChain);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return chains.ToArray();
|
||||
}
|
||||
|
||||
public static KRigElementChain MergeChains(string name, in KRigElementChain[] chains)
|
||||
{
|
||||
KRigElementChain mergedChain = new KRigElementChain();
|
||||
mergedChain.chainName = name;
|
||||
|
||||
foreach (var chain in chains)
|
||||
{
|
||||
if(chain == null) continue;
|
||||
foreach (var element in chain.elementChain) mergedChain.elementChain.Add(element);
|
||||
}
|
||||
|
||||
return mergedChain;
|
||||
}
|
||||
|
||||
public static void AddCompositeChain(MagicBlendAsset blendAsset, string name, string[] queries)
|
||||
{
|
||||
blendAsset.layeredBlends.Add(new LayeredBlend()
|
||||
{
|
||||
layer = MergeChains(name, GetMatchingChains(blendAsset.rigAsset, queries))
|
||||
});
|
||||
}
|
||||
|
||||
[MenuItem(ItemName, true)]
|
||||
private static bool ValidateCreateRigMapping()
|
||||
{
|
||||
return Selection.activeObject is KRig;
|
||||
}
|
||||
|
||||
[MenuItem(ItemName)]
|
||||
private static void CreateRigMapping()
|
||||
{
|
||||
KRig rig = Selection.activeObject as KRig;
|
||||
if (rig == null) return;
|
||||
|
||||
MagicBlendAsset blendAsset = ScriptableObject.CreateInstance<MagicBlendAsset>();
|
||||
blendAsset.rigAsset = rig;
|
||||
|
||||
AddCompositeChain(blendAsset, "LowerBody", new[] {"pelvis", "hip", "leg", "thigh"});
|
||||
AddCompositeChain(blendAsset, "Spine", new[] {"spine"});
|
||||
AddCompositeChain(blendAsset, "Head", new[] {"neck", "head"});
|
||||
AddCompositeChain(blendAsset, "Arms", new[] {"arm", "clavicle", "shoulder"});
|
||||
AddCompositeChain(blendAsset, "Fingers", new[]
|
||||
{
|
||||
"finger", "index", "thumb", "pinky", "ring", "middle"
|
||||
});
|
||||
|
||||
string assetName = rig.name.Replace("Rig_", "");
|
||||
assetName = assetName.Replace("Rig", "");
|
||||
|
||||
KEditorUtility.SaveAsset(blendAsset, KEditorUtility.GetProjectActiveFolder(),
|
||||
$"MagicBlend_{assetName}.asset");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b4d0f5047e1d4badb94456da709f642f
|
||||
timeCreated: 1723535203
|
||||
63
Assets/KINEMATION/MagicBlend/Editor/MagicDragAndDrop.cs
Normal file
63
Assets/KINEMATION/MagicBlend/Editor/MagicDragAndDrop.cs
Normal file
@@ -0,0 +1,63 @@
|
||||
// Designed by KINEMATION, 2025.
|
||||
|
||||
using KINEMATION.MagicBlend.Runtime;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace KINEMATION.MagicBlend.Editor
|
||||
{
|
||||
public class MagicDragAndDrop
|
||||
{
|
||||
private static DragAndDropVisualMode OnHierarchyDrop(int dropTargetInstanceID, HierarchyDropFlags dropMode,
|
||||
Transform parentForDraggedObjects, bool perform)
|
||||
{
|
||||
var asset = DragAndDrop.objectReferences[0] as MagicBlendAsset;
|
||||
if (asset == null)
|
||||
{
|
||||
return DragAndDropVisualMode.None;
|
||||
}
|
||||
|
||||
if (perform)
|
||||
{
|
||||
var selection = Selection.activeGameObject;
|
||||
if (selection != null)
|
||||
{
|
||||
var component = selection.GetComponent<MagicBlending>();
|
||||
if (component == null) component = selection.AddComponent<MagicBlending>();
|
||||
component.SetMagicBlendAsset(asset);
|
||||
}
|
||||
}
|
||||
|
||||
return DragAndDropVisualMode.Copy;
|
||||
}
|
||||
|
||||
private static DragAndDropVisualMode OnInspectorDrop(UnityEngine.Object[] targets, bool perform)
|
||||
{
|
||||
var asset = DragAndDrop.objectReferences[0] as MagicBlendAsset;
|
||||
if (asset == null)
|
||||
{
|
||||
return DragAndDropVisualMode.None;
|
||||
}
|
||||
|
||||
if (perform)
|
||||
{
|
||||
var selection = Selection.activeGameObject;
|
||||
if (selection != null)
|
||||
{
|
||||
var component = selection.GetComponent<MagicBlending>();
|
||||
if (component == null) component = selection.AddComponent<MagicBlending>();
|
||||
component.SetMagicBlendAsset(asset);
|
||||
}
|
||||
}
|
||||
|
||||
return DragAndDropVisualMode.Copy;
|
||||
}
|
||||
|
||||
[InitializeOnLoadMethod]
|
||||
private static void OnLoad()
|
||||
{
|
||||
DragAndDrop.AddDropHandler(OnInspectorDrop);
|
||||
DragAndDrop.AddDropHandler(OnHierarchyDrop);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0b975fde8b324849b0ea1eed6f492101
|
||||
timeCreated: 1734451661
|
||||
Reference in New Issue
Block a user