浏览代码

Added auto-setup IK script

/main
Dave Hunt 6 年前
当前提交
e8b3ec27
共有 9 个文件被更改,包括 2755 次插入316 次删除
  1. 75
      Assets/Editor/HelperMenu.cs
  2. 4
      Assets/Scenes/SampleSceneNinja.unity
  3. 968
      Assets/TestNinja/Content/Characters/Ninja/Prefabs/NinjaRig.prefab
  4. 1001
      Assets/Scenes/SampleSceneNinja2.unity
  5. 7
      Assets/Scenes/SampleSceneNinja2.unity.meta
  6. 8
      Assets/TestNinja/Content/Characters/Ninja/Prefabs/Workshop.meta
  7. 1001
      Assets/TestNinja/Content/Characters/Ninja/Prefabs/Workshop/NinjaRig_01_Start.prefab
  8. 7
      Assets/TestNinja/Content/Characters/Ninja/Prefabs/Workshop/NinjaRig_01_Start.prefab.meta

75
Assets/Editor/HelperMenu.cs


using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
using UnityEngine.Animations.Rigging;
public class MirrorTransformWindow : EditorWindow
{

private Vector4 m_Plane = new Vector4(1f, 0f, 0f, 0f);
[MenuItem("Animation Rigging/Mirror Transforms", false, 0)]
[MenuItem("Animation Rigging/Utilities/Mirror Transforms", false, 0)]
static void ShowWindow()
{
MirrorTransformWindow window = EditorWindow.GetWindow<MirrorTransformWindow>();

return reflectionMat;
}
[MenuItem("Animation Rigging/Utilities/Auto-Setup TwoBoneIK from Tip Transform", false, 0)]
public static void TwoBoneIKAutoSetup2(MenuCommand command)
{
var selection = Selection.activeObject as GameObject;
if (!selection)
{
Debug.LogWarning("Please select a TwoBoneIK before running auto setup.");
return;
}
var constraint = selection.GetComponent<TwoBoneIKConstraint>() ;// command.context as UnityEngine.Animations.Rigging.TwoBoneIKConstraint;
var tip = constraint.data.tip ;// constraint.data.tip;
var animator = constraint.GetComponentInParent<Animator>()?.transform;
if (!tip)
{
Debug.LogWarning("Please provide a tip before running auto setup.");
return;
}
if (!constraint.data.mid)
{
Undo.RecordObject(constraint, "Setup mid bone for TwoBoneIK");
constraint.data.mid = tip.parent;
}
if (!constraint.data.root)
{
Undo.RecordObject(constraint, "Setup root bone for TwoBoneIK");
constraint.data.root = tip.parent.parent;
}
if (!constraint.data.target)
{
var target = constraint.transform.Find(constraint.gameObject.name + "_target");
if (target == null)
{
var t = new GameObject();
Undo.RegisterCreatedObjectUndo(t, "Created target");
t.name = constraint.gameObject.name + "_target";
t.transform.localScale = .1f * t.transform.localScale;
Undo.SetTransformParent(t.transform, constraint.transform, "Set new parent");
target = t.transform;
}
constraint.data.target = target;
}
if (!constraint.data.hint)
{
var hint = constraint.transform.Find(constraint.gameObject.name + "_hint");
if (hint == null)
{
var t = new GameObject();
Undo.RegisterCreatedObjectUndo(t, "Created hint");
t.name = constraint.gameObject.name + "_hint";
t.transform.localScale = .1f * t.transform.localScale;
Undo.SetTransformParent(t.transform, constraint.transform, "Set new parent");
hint = t.transform;
}
constraint.data.hint = hint;
}
// align target and hint to bones
constraint.data.target.position = constraint.data.tip.position;
constraint.data.target.rotation = constraint.data.tip.rotation;
constraint.data.hint.position = constraint.data.mid.position;
constraint.data.hint.rotation = constraint.data.mid.rotation;
}
}

4
Assets/Scenes/SampleSceneNinja.unity


m_ReflectionIntensity: 1
m_CustomReflection: {fileID: 0}
m_Sun: {fileID: 2138677392}
m_IndirectSpecularColor: {r: 0.28502673, g: 0.371393, b: 0.49601054, a: 1}
m_IndirectSpecularColor: {r: 0, g: 0, b: 0, a: 1}
m_UseRadianceAmbientProbe: 0
--- !u!157 &3
LightmapSettings:

- component: {fileID: 772315690}
- component: {fileID: 772315689}
m_Layer: 0
m_Name: FullBodyRig
m_Name: ControlRig
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0

968
Assets/TestNinja/Content/Characters/Ninja/Prefabs/NinjaRig.prefab
文件差异内容过多而无法显示
查看文件

1001
Assets/Scenes/SampleSceneNinja2.unity
文件差异内容过多而无法显示
查看文件

7
Assets/Scenes/SampleSceneNinja2.unity.meta


fileFormatVersion: 2
guid: b4686011f6080b24ab3b0e6752ff79d1
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

8
Assets/TestNinja/Content/Characters/Ninja/Prefabs/Workshop.meta


fileFormatVersion: 2
guid: 5eeac501838aa88408946952586b815a
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

1001
Assets/TestNinja/Content/Characters/Ninja/Prefabs/Workshop/NinjaRig_01_Start.prefab
文件差异内容过多而无法显示
查看文件

7
Assets/TestNinja/Content/Characters/Ninja/Prefabs/Workshop/NinjaRig_01_Start.prefab.meta


fileFormatVersion: 2
guid: 678948e8d26321d449ebdf8096ff60d5
PrefabImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存