Merge pull request #2 from croakfang/master
Add FacialMorph Physics LiveSound Support.
This commit is contained in:
@@ -61,3 +61,4 @@ sysinfo.txt
|
||||
# Crashlytics generated file
|
||||
crashlytics-build.properties
|
||||
|
||||
/Assets/Plugins/RootMotion/PuppetMaster/_Integration
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2be36e9c0fdfcca44a4ae5dea045b62c
|
||||
guid: 41f1ed3680373bc4d9f545af7285c5dd
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 667e8e9da20031342bb8ca7bfd025c32
|
||||
guid: f6ac1c54436d2b544a475c918885ed8f
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
@@ -0,0 +1,85 @@
|
||||
%YAML 1.1
|
||||
%TAG !u! tag:unity3d.com,2011:
|
||||
--- !u!114 &11400000
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 0}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: bdb0b816a0bf0284282bd91a06a57a05, type: 3}
|
||||
m_Name: CriAtomEditorSettings
|
||||
m_EditorClassIdentifier:
|
||||
trySceneSettings: 0
|
||||
atomConfig:
|
||||
acfFileName:
|
||||
maxVirtualVoices: 32
|
||||
maxVoiceLimitGroups: 32
|
||||
maxCategories: 32
|
||||
maxAisacs: 8
|
||||
maxBusSends: 8
|
||||
maxSequenceEventsPerFrame: 2
|
||||
maxBeatSyncCallbacksPerFrame: 1
|
||||
maxCueLinkCallbacksPerFrame: 1
|
||||
standardVoicePoolConfig:
|
||||
memoryVoices: 16
|
||||
streamingVoices: 8
|
||||
hcaMxVoicePoolConfig:
|
||||
memoryVoices: 0
|
||||
streamingVoices: 0
|
||||
outputSamplingRate: 0
|
||||
usesInGamePreview: 0
|
||||
inGamePreviewMode: 3
|
||||
switchInitializeSocket: 0
|
||||
inGamePreviewConfig:
|
||||
maxPreviewObjects: 200
|
||||
communicationBufferSize: 2048
|
||||
playbackPositionUpdateInterval: 8
|
||||
serverFrequency: 60
|
||||
asrOutputChannels: 0
|
||||
useRandomSeedWithTime: 1
|
||||
categoriesPerPlayback: 4
|
||||
maxFaders: 4
|
||||
maxBuses: 8
|
||||
maxParameterBlocks: 1024
|
||||
vrMode: 0
|
||||
keepPlayingSoundOnPause: 1
|
||||
editorPcmOutputConfig:
|
||||
enable: 0
|
||||
bufferLength: 4096
|
||||
pcBufferingTime: 0
|
||||
linuxOutput: 0
|
||||
linuxPulseLatencyUsec: 60000
|
||||
iosEnableSonicSync: 1
|
||||
iosBufferingTime: 50
|
||||
iosOverrideIPodMusic: 0
|
||||
androidEnableSonicSync: 1
|
||||
androidBufferingTime: 133
|
||||
androidStartBufferingTime: 100
|
||||
androidLowLatencyStandardVoicePoolConfig:
|
||||
memoryVoices: 0
|
||||
streamingVoices: 0
|
||||
androidUsesAndroidFastMixer: 1
|
||||
androidForceToUseAsrForDefaultPlayback: 1
|
||||
androidUsesAAudio: 0
|
||||
vitaManaVoicePoolConfig:
|
||||
numberOfManaDecoders: 8
|
||||
vitaAtrac9VoicePoolConfig:
|
||||
memoryVoices: 0
|
||||
streamingVoices: 0
|
||||
ps4Atrac9VoicePoolConfig:
|
||||
memoryVoices: 0
|
||||
streamingVoices: 0
|
||||
switchEnableSonicSync: 1
|
||||
switchOpusVoicePoolConfig:
|
||||
memoryVoices: 0
|
||||
streamingVoices: 0
|
||||
ps4Audio3dConfig:
|
||||
useAudio3D: 0
|
||||
voicePoolConfig:
|
||||
memoryVoices: 0
|
||||
streamingVoices: 0
|
||||
webglWebAudioVoicePoolConfig:
|
||||
voices: 16
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cb7519de6d9d6414aa654607e19f59bb
|
||||
NativeFormatImporter:
|
||||
externalObjects: {}
|
||||
mainObjectFileID: 11400000
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a65fa8501f4646c47a73145499fedea6
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,43 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using System.IO;
|
||||
#if UNITY_EDITOR
|
||||
using UnityEditor;
|
||||
|
||||
public class ScriptableObjectTest
|
||||
{
|
||||
//Asset文件保存路径
|
||||
private const string assetPath = "Assets/Resources/Asset/";
|
||||
|
||||
[MenuItem("MyTools/ScriptableObjectTest")]
|
||||
public static void CreateTestAsset()
|
||||
{
|
||||
//创建数据
|
||||
TestData testData = ScriptableObject.CreateInstance<TestData>();
|
||||
//赋值
|
||||
testData.testName = "name";
|
||||
testData.level = 1;
|
||||
|
||||
//检查保存路径
|
||||
if (!Directory.Exists(assetPath))
|
||||
Directory.CreateDirectory(assetPath);
|
||||
|
||||
//删除原有文件,生成新文件
|
||||
string fullPath = assetPath + "/" + "TestData.asset";
|
||||
UnityEditor.AssetDatabase.DeleteAsset(fullPath);
|
||||
UnityEditor.AssetDatabase.CreateAsset(testData, fullPath);
|
||||
UnityEditor.AssetDatabase.Refresh();
|
||||
}
|
||||
}
|
||||
|
||||
//测试数据类
|
||||
[CreateAssetMenu(fileName = "TestData", menuName = "Create ScriptableObject : TestData", order = 1)]
|
||||
//类名与C#文件名一直
|
||||
public class TestData : ScriptableObject
|
||||
{
|
||||
public string testName;
|
||||
public int level;
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e478c6dd3bdb1774db21ae629a85226f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,180 @@
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
public class GlobalValue : EditorWindow
|
||||
{
|
||||
float _Global_MaxDensity = 1.0f;
|
||||
float _Global_MaxHeight = 10.0f;
|
||||
float _GlobalOutlineOffest = 0.0f;
|
||||
float _GlobalOutlineWidth = 1.0f;
|
||||
float _GlobalCameraFov = 0.0f;
|
||||
float _CylinderBlend = 0.0f;
|
||||
Color _GlobalToonColor = new Color(1, 1, 1, 0);
|
||||
Color _Global_FogColor;
|
||||
Color _GlobalDirtRimSpecularColor;
|
||||
Color _GlobalDirtToonColor;
|
||||
Color _GlobalRimColor = new Color(1, 1, 1, 0);
|
||||
Color _GlobalDirtColor;
|
||||
Color _RimColor2;
|
||||
List<Vector4> _MainParam = new List<Vector4>();
|
||||
Vector4 _MainParam_0;
|
||||
Vector4 _MainParam_1;
|
||||
List<Vector4> _HighParam1 = new List<Vector4>();
|
||||
Vector4 _HighParam1_0 = new Vector4(0, 0, 0, 1);
|
||||
Vector4 _HighParam1_1 = new Vector4(0, 0, 0, 1);
|
||||
Vector4 _HighParam1_2;
|
||||
List<Vector4> _HighParam2 = new List<Vector4>();
|
||||
Vector4 _HighParam2_0 = new Vector4(0, 0, 0, 1);
|
||||
Vector4 _HighParam2_1 = new Vector4(0, 0, 0, 1);
|
||||
|
||||
List<Vector4> _ColorArray = new List<Vector4>();
|
||||
Vector4 _ColorArray_0;
|
||||
Vector4 _ColorArray_1;
|
||||
Vector4 _ColorArray_2;
|
||||
Vector4 _ColorArray_3;
|
||||
Vector4 _ColorArray_4;
|
||||
Vector4 _ColorArray_5;
|
||||
Vector4 _ColorArray_6;
|
||||
Vector4 _ColorArray_7;
|
||||
Vector4 _ColorArray_8;
|
||||
Vector4 _ColorArray_9;
|
||||
|
||||
List<float> _DirtRate = new List<float>();
|
||||
float _DirtRate_0;
|
||||
float _DirtRate_1;
|
||||
float _DirtRate_2;
|
||||
|
||||
|
||||
Vector4 _Global_FogMinDistance;
|
||||
Vector4 _Global_FogLength;
|
||||
|
||||
float _RimHorizonOffset;
|
||||
|
||||
Color _AmbientColor;
|
||||
|
||||
Vector2 scrollPosition = Vector2.zero;
|
||||
|
||||
[MenuItem("Global/Value Set")]
|
||||
public static void ValueWindow()
|
||||
{
|
||||
EditorWindow.GetWindow<GlobalValue>("SetValue");
|
||||
}
|
||||
|
||||
void OnGUI()
|
||||
{
|
||||
scrollPosition = GUILayout.BeginScrollView(scrollPosition, true, true);
|
||||
GUILayout.Label("Set Your Global Value!", EditorStyles.boldLabel);
|
||||
//Vector
|
||||
_Global_FogMinDistance = EditorGUILayout.Vector4Field("雾气出现距离", _Global_FogMinDistance);
|
||||
_Global_FogLength = EditorGUILayout.Vector4Field("雾气长度", _Global_FogLength);
|
||||
//Float
|
||||
_Global_MaxDensity = EditorGUILayout.Slider("最低能见度", _Global_MaxDensity, 0, 1);
|
||||
_Global_MaxHeight = EditorGUILayout.Slider("最高可见高度", _Global_MaxHeight, 0, 10);
|
||||
_GlobalOutlineOffest = EditorGUILayout.Slider("_GlobalOutlineOffest", _GlobalOutlineOffest, 0, 100);
|
||||
_GlobalOutlineWidth = EditorGUILayout.Slider("全局轮廓线宽度", _GlobalOutlineWidth, 0, 100);
|
||||
_GlobalCameraFov = EditorGUILayout.Slider("_GlobalCameraFov", _GlobalCameraFov, 0, 100);
|
||||
_CylinderBlend = EditorGUILayout.Slider("_CylinderBlend", _CylinderBlend, 0, 100);
|
||||
_RimHorizonOffset = EditorGUILayout.Slider("_RimHorizonOffset", _RimHorizonOffset, 0, 1);
|
||||
//Color
|
||||
_GlobalToonColor = EditorGUILayout.ColorField("阴影颜色", _GlobalToonColor);
|
||||
_Global_FogColor = EditorGUILayout.ColorField("_Global_FogColor", _Global_FogColor);
|
||||
_GlobalDirtRimSpecularColor = EditorGUILayout.ColorField("_GlobalDirtRimSpecularColor", _GlobalDirtRimSpecularColor);
|
||||
_GlobalDirtToonColor = EditorGUILayout.ColorField("_GlobalDirtToonColor", _GlobalDirtToonColor);
|
||||
_GlobalRimColor = EditorGUILayout.ColorField("边缘光颜色", _GlobalRimColor);
|
||||
_GlobalDirtColor = EditorGUILayout.ColorField("_GlobalDirtColor", _GlobalDirtColor);
|
||||
_RimColor2 = EditorGUILayout.ColorField("_RimColor2", _RimColor2);
|
||||
|
||||
_AmbientColor = EditorGUILayout.ColorField("_AmbientColor", _AmbientColor);
|
||||
//Vector Array
|
||||
_MainParam_0 = EditorGUILayout.Vector4Field("左眼偏移", _MainParam_0);
|
||||
_MainParam_1 = EditorGUILayout.Vector4Field("右眼偏移", _MainParam_1);
|
||||
|
||||
_HighParam1_0 = EditorGUILayout.Vector4Field("左眼上高光(w值为强度)", _HighParam1_0);
|
||||
_HighParam1_1 = EditorGUILayout.Vector4Field("左眼下高光", _HighParam1_1);
|
||||
_HighParam1_2 = EditorGUILayout.Vector4Field("双眼闪烁效果", _HighParam1_2);
|
||||
|
||||
_HighParam2_0 = EditorGUILayout.Vector4Field("右眼上高光", _HighParam2_0);
|
||||
_HighParam2_1 = EditorGUILayout.Vector4Field("右眼下高光", _HighParam2_1);
|
||||
|
||||
_ColorArray_0 = EditorGUILayout.ColorField("_ColorArray_0", _ColorArray_0);
|
||||
_ColorArray_1 = EditorGUILayout.ColorField("_ColorArray_1", _ColorArray_1);
|
||||
_ColorArray_2 = EditorGUILayout.ColorField("_ColorArray_2", _ColorArray_2);
|
||||
_ColorArray_3 = EditorGUILayout.ColorField("_ColorArray_3", _ColorArray_3);
|
||||
_ColorArray_4 = EditorGUILayout.ColorField("_ColorArray_4", _ColorArray_4);
|
||||
_ColorArray_5 = EditorGUILayout.ColorField("_ColorArray_5", _ColorArray_5);
|
||||
_ColorArray_6 = EditorGUILayout.ColorField("_ColorArray_6", _ColorArray_6);
|
||||
_ColorArray_7 = EditorGUILayout.ColorField("_ColorArray_7", _ColorArray_7);
|
||||
_ColorArray_8 = EditorGUILayout.ColorField("_ColorArray_8", _ColorArray_8);
|
||||
_ColorArray_9 = EditorGUILayout.ColorField("_ColorArray_9", _ColorArray_9);
|
||||
|
||||
|
||||
|
||||
//Float Array
|
||||
_DirtRate_0 = EditorGUILayout.Slider("_DirtRate_0", _DirtRate_0, 0, 1);
|
||||
_DirtRate_1 = EditorGUILayout.Slider("_DirtRate_1", _DirtRate_1, 0, 1);
|
||||
_DirtRate_2 = EditorGUILayout.Slider("_DirtRate_2", _DirtRate_2, 0, 1);
|
||||
GUILayout.EndScrollView();
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
//Color
|
||||
Shader.SetGlobalColor("_GlobalToonColor", _GlobalToonColor);
|
||||
Shader.SetGlobalColor("_Global_FogColor", _Global_FogColor);
|
||||
Shader.SetGlobalColor("_GlobalDirtRimSpecularColor", _GlobalDirtRimSpecularColor);
|
||||
Shader.SetGlobalColor("_GlobalDirtToonColor", _GlobalDirtToonColor);
|
||||
Shader.SetGlobalColor("_GlobalRimColor", _GlobalRimColor);
|
||||
Shader.SetGlobalColor("_GlobalDirtColor", _GlobalDirtColor);
|
||||
Shader.SetGlobalColor("_RimColor2", _RimColor2);
|
||||
//Float
|
||||
Shader.SetGlobalFloat("_Global_MaxDensity", _Global_MaxDensity);
|
||||
Shader.SetGlobalFloat("_Global_MaxHeight", _Global_MaxHeight);
|
||||
Shader.SetGlobalFloat("_GlobalOutlineOffest", _GlobalOutlineOffest);
|
||||
Shader.SetGlobalFloat("_GlobalOutlineWidth", _GlobalOutlineWidth);
|
||||
Shader.SetGlobalFloat("_GlobalCameraFov", _GlobalCameraFov);
|
||||
Shader.SetGlobalFloat("_CylinderBlend", _CylinderBlend);
|
||||
Shader.SetGlobalFloat("_RimHorizonOffset", _RimHorizonOffset);
|
||||
//Vector Array
|
||||
_MainParam.Clear();
|
||||
_MainParam.Add(_MainParam_0);
|
||||
_MainParam.Add(_MainParam_1);
|
||||
Shader.SetGlobalVectorArray("_MainParam", _MainParam);
|
||||
|
||||
_HighParam1.Clear();
|
||||
_HighParam1.Add(_HighParam1_0);
|
||||
_HighParam1.Add(_HighParam1_1);
|
||||
_HighParam1.Add(_HighParam1_2);
|
||||
Shader.SetGlobalVectorArray("_HighParam1", _HighParam1);
|
||||
|
||||
_HighParam2.Clear();
|
||||
_HighParam2.Add(_HighParam2_0);
|
||||
_HighParam2.Add(_HighParam2_1);
|
||||
Shader.SetGlobalVectorArray("_HighParam2", _HighParam2);
|
||||
|
||||
_ColorArray.Clear();
|
||||
_ColorArray.Add(_ColorArray_0);
|
||||
_ColorArray.Add(_ColorArray_1);
|
||||
_ColorArray.Add(_ColorArray_2);
|
||||
_ColorArray.Add(_ColorArray_3);
|
||||
_ColorArray.Add(_ColorArray_4);
|
||||
_ColorArray.Add(_ColorArray_5);
|
||||
_ColorArray.Add(_ColorArray_6);
|
||||
_ColorArray.Add(_ColorArray_7);
|
||||
_ColorArray.Add(_ColorArray_8);
|
||||
_ColorArray.Add(_ColorArray_9);
|
||||
Shader.SetGlobalVectorArray("_ColorArray", _ColorArray);
|
||||
|
||||
Shader.SetGlobalVector("_Global_FogMinDistance", _Global_FogMinDistance);
|
||||
Shader.SetGlobalVector("_Global_FogLength", _Global_FogLength);
|
||||
|
||||
_DirtRate.Clear();
|
||||
_DirtRate.Add(_DirtRate_0);
|
||||
_DirtRate.Add(_DirtRate_1);
|
||||
_DirtRate.Add(_DirtRate_2);
|
||||
Shader.SetGlobalFloatArray("_DirtRate", _DirtRate);
|
||||
|
||||
Shader.SetGlobalColor("_AmbientColor", _AmbientColor);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cb10cdeeb4bac8744a4d83ecf2657977
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 10875975faa2a3c4f815508f7f376c21
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fe88a087b0795174f9c8ec2369f4ccb2
|
||||
folderAsset: yes
|
||||
timeCreated: 1516620937
|
||||
licenseType: Store
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,176 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using UnityEditor;
|
||||
using UnityEngine.Playables;
|
||||
using System;
|
||||
|
||||
namespace RootMotion
|
||||
{
|
||||
public class BakerInspector : Editor
|
||||
{
|
||||
|
||||
protected void DrawKeyframeSettings(Baker script)
|
||||
{
|
||||
if (script.isBaking) return;
|
||||
EditorGUILayout.Space();
|
||||
|
||||
EditorGUILayout.PropertyField(serializedObject.FindProperty("frameRate"));
|
||||
EditorGUILayout.PropertyField(serializedObject.FindProperty("keyReductionError"));
|
||||
}
|
||||
|
||||
protected void DrawModeSettings(Baker script)
|
||||
{
|
||||
if (script.isBaking) return;
|
||||
|
||||
EditorGUILayout.Space();
|
||||
|
||||
EditorGUILayout.PropertyField(serializedObject.FindProperty("mode"));
|
||||
|
||||
switch (script.mode)
|
||||
{
|
||||
case Baker.Mode.AnimationClips:
|
||||
EditorGUILayout.PropertyField(serializedObject.FindProperty("animationClips"), true);
|
||||
EditorGUILayout.PropertyField(serializedObject.FindProperty("appendName"));
|
||||
break;
|
||||
case Baker.Mode.AnimationStates:
|
||||
EditorGUILayout.PropertyField(serializedObject.FindProperty("loop"));
|
||||
EditorGUILayout.PropertyField(serializedObject.FindProperty("animationStates"), true);
|
||||
EditorGUILayout.PropertyField(serializedObject.FindProperty("appendName"));
|
||||
break;
|
||||
case Baker.Mode.PlayableDirector:
|
||||
EditorGUILayout.PropertyField(serializedObject.FindProperty("loop"));
|
||||
EditorGUILayout.PropertyField(serializedObject.FindProperty("saveName"));
|
||||
break;
|
||||
default:
|
||||
EditorGUILayout.PropertyField(serializedObject.FindProperty("saveName"));
|
||||
break;
|
||||
}
|
||||
|
||||
//EditorGUILayout.BeginHorizontal();
|
||||
EditorGUILayout.Space();
|
||||
EditorGUILayout.LabelField(new GUIContent("Save To Folder"));
|
||||
|
||||
if (EditorGUILayout.DropdownButton(new GUIContent(serializedObject.FindProperty("saveToFolder").stringValue, "The folder to save the baked AnimationClips to."), FocusType.Passive, GUILayout.MaxWidth(400)))
|
||||
{
|
||||
serializedObject.FindProperty("saveToFolder").stringValue = SaveClipFolderPanel.Apply(serializedObject.FindProperty("saveToFolder").stringValue);
|
||||
}
|
||||
//EditorGUILayout.EndHorizontal();
|
||||
}
|
||||
|
||||
private void TryBake(Baker script)
|
||||
{
|
||||
switch (script.mode)
|
||||
{
|
||||
case Baker.Mode.AnimationClips:
|
||||
if (script.animator == null)
|
||||
{
|
||||
EditorGUILayout.LabelField("No Animator found on Baker GameObject", EditorStyles.helpBox);
|
||||
return;
|
||||
}
|
||||
|
||||
if (script.animator.isHuman && script.animator.runtimeAnimatorController == null)
|
||||
{
|
||||
EditorGUILayout.LabelField("Humanoid Animator needs to have a valid Controller assigned for clip baking (Unity crash bug)", EditorStyles.helpBox);
|
||||
return;
|
||||
}
|
||||
|
||||
if (script.animationClips.Length == 0)
|
||||
{
|
||||
EditorGUILayout.LabelField("Please add AnimationClips to bake", EditorStyles.helpBox);
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (AnimationClip clip in script.animationClips)
|
||||
{
|
||||
if (clip == null)
|
||||
{
|
||||
EditorGUILayout.LabelField("One of the AnimationClips is null, can not bake.", EditorStyles.helpBox);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (GUILayout.Button("Bake Animation Clips")) script.BakeClip();
|
||||
return;
|
||||
case Baker.Mode.AnimationStates:
|
||||
if (script.animator == null)
|
||||
{
|
||||
EditorGUILayout.LabelField("No Animator found on Baker GameObject", EditorStyles.helpBox);
|
||||
return;
|
||||
}
|
||||
|
||||
if (script.animationStates.Length == 0)
|
||||
{
|
||||
EditorGUILayout.LabelField("Please add Animation State names to bake. The Animator must contain AnimationStates with matching names. If AnimationState names match with clip names used in them, you can have the Baker fill the names in automatically by right-clicking on the component header and selecting 'Find Animation States'.", EditorStyles.helpBox);
|
||||
return;
|
||||
}
|
||||
|
||||
for (int i = 0; i < script.animationStates.Length; i++)
|
||||
{
|
||||
if (script.animationStates[i] == string.Empty || script.animationStates[i] == "")
|
||||
{
|
||||
EditorGUILayout.LabelField("One of the animation state names in 'Animation States' is empty, can not bake.", EditorStyles.helpBox);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (GUILayout.Button("Bake Animation States")) script.BakeClip();
|
||||
return;
|
||||
case Baker.Mode.PlayableDirector:
|
||||
if (script.director == null)
|
||||
{
|
||||
EditorGUILayout.LabelField("No PlayableDirector found on Baker GameObject", EditorStyles.helpBox);
|
||||
return;
|
||||
}
|
||||
|
||||
if (GUILayout.Button("Bake Timeline")) script.BakeClip();
|
||||
break;
|
||||
case Baker.Mode.Realtime:
|
||||
if (GUILayout.Button("Start Baking")) script.StartBaking();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
protected void DrawButtons(Baker script)
|
||||
{
|
||||
if (!script.enabled) return;
|
||||
|
||||
if (script.animator == null)
|
||||
{
|
||||
serializedObject.FindProperty("animator").objectReferenceValue = script.GetComponent<Animator>();
|
||||
}
|
||||
|
||||
if (script.director == null)
|
||||
{
|
||||
serializedObject.FindProperty("director").objectReferenceValue = script.GetComponent<PlayableDirector>();
|
||||
}
|
||||
|
||||
if (!Application.isPlaying)
|
||||
{
|
||||
EditorGUILayout.LabelField("Enter Play Mode to bake.", EditorStyles.helpBox);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!script.isBaking)
|
||||
{
|
||||
TryBake(script);
|
||||
}
|
||||
else
|
||||
{
|
||||
GUI.color = Color.red;
|
||||
|
||||
switch (script.mode)
|
||||
{
|
||||
case Baker.Mode.Realtime:
|
||||
if (GUILayout.Button("Stop Baking")) script.StopBaking();
|
||||
break;
|
||||
default:
|
||||
GUILayout.Label("Baking Progress: " + System.Math.Round(script.bakingProgress, 2));
|
||||
break;
|
||||
}
|
||||
|
||||
GUI.color = Color.white;
|
||||
EditorUtility.SetDirty(script);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: dcf5801ad3ff7fa43b06824f09d82160
|
||||
timeCreated: 1516619065
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,52 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using UnityEditor;
|
||||
|
||||
namespace RootMotion
|
||||
{
|
||||
[CustomEditor(typeof(GenericBaker))]
|
||||
public class GenericBakerInspector : BakerInspector
|
||||
{
|
||||
private GenericBaker script { get { return target as GenericBaker; } }
|
||||
|
||||
private MonoScript monoScript;
|
||||
|
||||
void OnEnable()
|
||||
{
|
||||
// Changing the script execution order
|
||||
if (!Application.isPlaying)
|
||||
{
|
||||
monoScript = MonoScript.FromMonoBehaviour(script);
|
||||
int currentExecutionOrder = MonoImporter.GetExecutionOrder(monoScript);
|
||||
if (currentExecutionOrder != 15001) MonoImporter.SetExecutionOrder(monoScript, 15001);
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
serializedObject.Update();
|
||||
|
||||
DrawKeyframeSettings(script as Baker);
|
||||
DrawGenericKeyframeSettings(script);
|
||||
DrawModeSettings(script as Baker);
|
||||
DrawButtons(script as Baker);
|
||||
|
||||
if (serializedObject.ApplyModifiedProperties())
|
||||
{
|
||||
EditorUtility.SetDirty(script);
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawGenericKeyframeSettings(GenericBaker script)
|
||||
{
|
||||
if (script.isBaking) return;
|
||||
|
||||
EditorGUILayout.PropertyField(serializedObject.FindProperty("markAsLegacy"));
|
||||
EditorGUILayout.PropertyField(serializedObject.FindProperty("root"));
|
||||
EditorGUILayout.PropertyField(serializedObject.FindProperty("rootNode"));
|
||||
EditorGUILayout.PropertyField(serializedObject.FindProperty("ignoreList"), true);
|
||||
EditorGUILayout.PropertyField(serializedObject.FindProperty("bakePositionList"), true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8f544a5bc87054e74ac2e415889ba75a
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 73b96cf8495867d429c9c5b31ff6d6da
|
||||
folderAsset: yes
|
||||
timeCreated: 1516621014
|
||||
licenseType: Store
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,38 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using UnityEditor;
|
||||
|
||||
namespace RootMotion
|
||||
{
|
||||
public static class AnimationUtilityExtended
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Copies the curves with the specified property names from clipFrom to clipTo.
|
||||
/// </summary>
|
||||
/// <param name="fromClip">copy from clip.</param>
|
||||
/// <param name="toClip">paste to clip</param>
|
||||
/// <param name="propertyNames">Property names ("Root.T", "Root.Q", "LeftFoot.T"...).</param>
|
||||
public static void CopyCurves(AnimationClip fromClip, AnimationClip toClip, string[] propertyNames)
|
||||
{
|
||||
EditorCurveBinding[] bindings = AnimationUtility.GetCurveBindings(fromClip);
|
||||
|
||||
for (int i = 0; i < bindings.Length; i++)
|
||||
{
|
||||
for (int n = 0; n < propertyNames.Length; n++)
|
||||
{
|
||||
if (bindings[i].propertyName == propertyNames[n])
|
||||
{
|
||||
CopyCurve(fromClip, toClip, bindings[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void CopyCurve(AnimationClip fromClip, AnimationClip toClip, EditorCurveBinding binding)
|
||||
{
|
||||
AnimationCurve curve = AnimationUtility.GetEditorCurve(fromClip, binding);
|
||||
toClip.SetCurve(string.Empty, typeof(Animator), binding.propertyName, curve);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 054c55a0c5c10dc4fafcfd81aeaaec56
|
||||
timeCreated: 1516620625
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,22 @@
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using System.IO;
|
||||
using System;
|
||||
|
||||
namespace RootMotion
|
||||
{
|
||||
public class SaveClipFolderPanel : EditorWindow
|
||||
{
|
||||
public static string Apply(string currentPath)
|
||||
{
|
||||
string path = EditorUtility.SaveFolderPanel("Save clip(s) to folder", currentPath, "");
|
||||
|
||||
if (path.Length != 0)
|
||||
{
|
||||
return path.Substring(path.IndexOf("Assets/"));
|
||||
}
|
||||
|
||||
return currentPath;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7edb6cbf0a3b9924d8f631c4c00fd38a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,52 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using UnityEditor;
|
||||
|
||||
namespace RootMotion
|
||||
{
|
||||
[CustomEditor(typeof(HumanoidBaker))]
|
||||
public class HumanoidBakerInspector : BakerInspector
|
||||
{
|
||||
|
||||
private HumanoidBaker script { get { return target as HumanoidBaker; } }
|
||||
|
||||
private MonoScript monoScript;
|
||||
|
||||
void OnEnable()
|
||||
{
|
||||
// Changing the script execution order
|
||||
if (!Application.isPlaying)
|
||||
{
|
||||
monoScript = MonoScript.FromMonoBehaviour(script);
|
||||
int currentExecutionOrder = MonoImporter.GetExecutionOrder(monoScript);
|
||||
if (currentExecutionOrder != 15000) MonoImporter.SetExecutionOrder(monoScript, 15000);
|
||||
}
|
||||
}
|
||||
|
||||
// TODO Move this to BakerInspector.cs
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
serializedObject.Update();
|
||||
|
||||
DrawKeyframeSettings(script as Baker);
|
||||
DrawHumanoidKeyframeSettings(script);
|
||||
DrawModeSettings(script as Baker);
|
||||
DrawButtons(script as Baker);
|
||||
|
||||
if (serializedObject.ApplyModifiedProperties())
|
||||
{
|
||||
EditorUtility.SetDirty(script);
|
||||
}
|
||||
}
|
||||
|
||||
protected void DrawHumanoidKeyframeSettings(HumanoidBaker script)
|
||||
{
|
||||
if (script.isBaking) return;
|
||||
|
||||
EditorGUILayout.PropertyField(serializedObject.FindProperty("IKKeyReductionError"));
|
||||
EditorGUILayout.PropertyField(serializedObject.FindProperty("muscleFrameRateDiv"));
|
||||
EditorGUILayout.PropertyField(serializedObject.FindProperty("bakeHandIK"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f8139af98945e154885b65eedbb102cc
|
||||
timeCreated: 1516265598
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 100c77ad1e0b943c5b6e6e67b5649801
|
||||
folderAsset: yes
|
||||
timeCreated: 1436186340
|
||||
licenseType: Store
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,63 @@
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace RootMotion.Dynamics {
|
||||
|
||||
// Custom drawer for BehaviourPuppet MasterProps.
|
||||
[CustomPropertyDrawer (typeof (BehaviourPuppet.MasterProps))]
|
||||
public class BehaviourPuppetMasterPropsDrawer : PropertyDrawer {
|
||||
|
||||
private float lineHeight = 22f;
|
||||
|
||||
public override float GetPropertyHeight(SerializedProperty prop, GUIContent label) {
|
||||
lineHeight = base.GetPropertyHeight(prop, label);
|
||||
|
||||
int enumValueIndex = prop.FindPropertyRelative("normalMode").enumValueIndex;
|
||||
|
||||
switch(enumValueIndex) {
|
||||
case 1: return lineHeight * 2;
|
||||
case 2: return lineHeight * 3;
|
||||
default: return lineHeight;
|
||||
}
|
||||
}
|
||||
|
||||
private void NextLine(ref Rect pos) {
|
||||
pos = EditorGUI.IndentedRect(pos);
|
||||
pos.width -= pos.x - pos.x;
|
||||
pos.x = pos.x;
|
||||
pos.y += lineHeight;
|
||||
pos.height = lineHeight;
|
||||
|
||||
}
|
||||
|
||||
public override void OnGUI (Rect pos, SerializedProperty prop, GUIContent label) {
|
||||
int indent = EditorGUI.indentLevel;
|
||||
EditorGUI.indentLevel = 0;
|
||||
EditorGUI.BeginChangeCheck();
|
||||
|
||||
EditorGUI.PropertyField (new Rect(pos.x, pos.y, pos.width, lineHeight), prop.FindPropertyRelative ("normalMode"), new GUIContent("Normal Mode", "Active mode keeps the puppet and it's mapping active at all times. " +
|
||||
"Unmapped mode blends in mapping only if the puppet becomes in contact with something and blends out again later to maintain 100% animation accuracy while not in contact. " +
|
||||
"If Kinematic, will set the PuppetMaster.mode to Active when any of the muscles collides with something (static colliders are ignored if 'Activate On Static Collisions' is false) or is hit. PuppetMaster.mode will be set to Kinematic when all muscles are pinned and the puppet is in normal Puppet state. This will increase performance and enable you to have full animation accuracy when PuppetMaster is not needed. Note that collision events are only broadcasted if one of the Rigidbodies is not kinematic, so if you need 2 characters to wake up each other, one has to be active."));
|
||||
|
||||
int enumValueIndex = prop.FindPropertyRelative("normalMode").enumValueIndex;
|
||||
|
||||
switch(enumValueIndex) {
|
||||
case 1:
|
||||
NextLine(ref pos);
|
||||
EditorGUI.PropertyField (pos, prop.FindPropertyRelative ("mappingBlendSpeed"), new GUIContent("Mapping Blend Speed", "The speed of blending in mapping in case of contact."));
|
||||
break;
|
||||
case 2:
|
||||
NextLine(ref pos);
|
||||
EditorGUI.PropertyField (pos, prop.FindPropertyRelative ("activateOnStaticCollisions"), new GUIContent("Activate On Static Collisions", "The speed of blending in mapping in case of contact."));
|
||||
|
||||
NextLine(ref pos);
|
||||
EditorGUI.PropertyField (pos, prop.FindPropertyRelative ("activateOnImpulse"), new GUIContent("Activate On Impulse", "Minimum collision impulse for activating the puppet."));
|
||||
break;
|
||||
default: break;
|
||||
}
|
||||
|
||||
EditorGUI.EndChangeCheck();
|
||||
EditorGUI.indentLevel = indent;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 78a5ae1e71291429f8916d4c02a498b7
|
||||
timeCreated: 1452015016
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,254 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using UnityEditor;
|
||||
|
||||
namespace RootMotion.Dynamics
|
||||
{
|
||||
[CustomEditor(typeof(PropMuscle))]
|
||||
public class PropMuscleInspector : Editor
|
||||
{
|
||||
|
||||
private PropMuscle script { get { return target as PropMuscle; } }
|
||||
|
||||
private GUIStyle style = new GUIStyle();
|
||||
private GUIStyle miniLabelStyle = new GUIStyle();
|
||||
private static Color pro = new Color(0.5f, 0.7f, 0.3f, 1f);
|
||||
private static Color free = new Color(0.2f, 0.3f, 0.1f, 1f);
|
||||
private static Color sceneColor = new Color(0.2f, 0.7f, 1f);
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
if (script == null) return;
|
||||
serializedObject.Update();
|
||||
|
||||
style.wordWrap = true;
|
||||
style.normal.textColor = EditorGUIUtility.isProSkin ? pro : free;
|
||||
|
||||
miniLabelStyle.wordWrap = true;
|
||||
miniLabelStyle.fontSize = 10;
|
||||
miniLabelStyle.normal.textColor = EditorStyles.miniLabel.normal.textColor;
|
||||
|
||||
if (!Application.isPlaying)
|
||||
{
|
||||
if (GUILayout.Button("Remove This Prop Muscle"))
|
||||
{
|
||||
//int index = script.muscle.index;
|
||||
//Debug.Log(index);
|
||||
var puppetMasterS = new SerializedObject(script.puppetMaster);
|
||||
SerializedProperty muscles = puppetMasterS.FindProperty("muscles");
|
||||
|
||||
int index = 0;
|
||||
ConfigurableJoint joint = script.GetComponent<ConfigurableJoint>();
|
||||
for (int i = 0; i < puppetMasterS.FindProperty("muscles").arraySize; i++)
|
||||
{
|
||||
muscles.GetArrayElementAtIndex(i).FindPropertyRelative("index").intValue = i;
|
||||
if (muscles.GetArrayElementAtIndex(i).FindPropertyRelative("joint").objectReferenceValue == joint) index = i;
|
||||
}
|
||||
|
||||
/*
|
||||
if (script.muscle.additionalPin != null)
|
||||
{
|
||||
script.muscle.additionalPin.gameObject.hideFlags = HideFlags.None;
|
||||
script.muscle.additionalPinTarget.gameObject.hideFlags = HideFlags.None;
|
||||
}
|
||||
|
||||
script.muscle.target.gameObject.hideFlags = HideFlags.None;
|
||||
*/
|
||||
|
||||
var target = script.muscle.target;
|
||||
|
||||
|
||||
muscles.DeleteArrayElementAtIndex(index);
|
||||
|
||||
for (int i = 0; i < puppetMasterS.FindProperty("muscles").arraySize; i++)
|
||||
{
|
||||
muscles.GetArrayElementAtIndex(i).FindPropertyRelative("index").intValue = i;
|
||||
}
|
||||
|
||||
puppetMasterS.ApplyModifiedProperties();
|
||||
|
||||
PuppetMasterInspector.DestroyImmediateSafe(target.gameObject);
|
||||
PuppetMasterInspector.DestroyImmediateSafe(script.gameObject);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
DrawDefaultInspector();
|
||||
|
||||
//GUILayout.Space(10);
|
||||
|
||||
if (!Application.isPlaying)
|
||||
{
|
||||
if (script.muscle.additionalPin == null)
|
||||
{
|
||||
if (GUILayout.Button("Add Additional Pin"))
|
||||
{
|
||||
AddAdditionalPin();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (GUILayout.Button("Remove Additional Pin"))
|
||||
{
|
||||
RemoveAdditionalPin();
|
||||
}
|
||||
}
|
||||
|
||||
EditorGUILayout.LabelField("Additional Pins help to pin this prop muscle to animation from another point. Without it, the prop muscle would be actuated by Muscle Spring only, which is likely not enough to follow fast swinging animations. Move the additional pin by 'Additional Pin Offset' towards the end of the prop (tip of the sword).", miniLabelStyle);
|
||||
}
|
||||
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
|
||||
}
|
||||
|
||||
private bool AddAdditionalPin()
|
||||
{
|
||||
if (script.muscle.additionalPin != null) return false;
|
||||
|
||||
ConfigurableJoint additionalJoint = null;
|
||||
Transform additionalTarget = null;
|
||||
AddAdditionalPinUnserialized(script, out additionalJoint, out additionalTarget);
|
||||
|
||||
var puppetMasterS = new SerializedObject(script.puppetMaster);
|
||||
puppetMasterS.FindProperty("muscles").GetArrayElementAtIndex(script.muscle.index).FindPropertyRelative("additionalPin").objectReferenceValue = additionalJoint;
|
||||
puppetMasterS.FindProperty("muscles").GetArrayElementAtIndex(script.muscle.index).FindPropertyRelative("additionalPinTarget").objectReferenceValue = additionalTarget;
|
||||
puppetMasterS.ApplyModifiedProperties();
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
|
||||
//muscle.additionalPin.gameObject.hideFlags = HideFlags.HideInHierarchy;
|
||||
//muscle.additionalPinTarget.gameObject.hideFlags = HideFlags.HideInHierarchy;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static void AddAdditionalPinUnserialized(PropMuscle script, out ConfigurableJoint joint, out Transform target)
|
||||
{
|
||||
var addGO = new GameObject("Additional Pin");
|
||||
addGO.gameObject.layer = script.gameObject.layer;
|
||||
addGO.transform.parent = script.transform;
|
||||
addGO.transform.localPosition = script.additionalPinOffset;
|
||||
addGO.transform.localRotation = Quaternion.identity;
|
||||
//script.lastAdditionalPinOffset = additionalPinOffset;
|
||||
|
||||
addGO.AddComponent<Rigidbody>();
|
||||
|
||||
joint = addGO.AddComponent<ConfigurableJoint>();
|
||||
joint.connectedBody = script.muscle.joint.GetComponent<Rigidbody>();
|
||||
joint.autoConfigureConnectedAnchor = false;
|
||||
joint.connectedAnchor = script.additionalPinOffset;
|
||||
joint.xMotion = ConfigurableJointMotion.Locked;
|
||||
joint.yMotion = ConfigurableJointMotion.Locked;
|
||||
joint.zMotion = ConfigurableJointMotion.Locked;
|
||||
joint.angularXMotion = ConfigurableJointMotion.Locked;
|
||||
joint.angularYMotion = ConfigurableJointMotion.Locked;
|
||||
joint.angularZMotion = ConfigurableJointMotion.Locked;
|
||||
|
||||
var addTargetGO = new GameObject("Additional Pin Target");
|
||||
addTargetGO.layer = script.muscle.target.gameObject.layer;
|
||||
addTargetGO.transform.parent = script.muscle.target;
|
||||
addTargetGO.transform.position = addGO.transform.position;
|
||||
addTargetGO.transform.rotation = addGO.transform.rotation;
|
||||
target = addTargetGO.transform;
|
||||
}
|
||||
|
||||
private bool RemoveAdditionalPin()
|
||||
{
|
||||
if (script.muscle.additionalPin == null) return false;
|
||||
|
||||
//script.muscle.additionalPin.gameObject.hideFlags = HideFlags.None;
|
||||
//script.muscle.additionalPinTarget.gameObject.hideFlags = HideFlags.None;
|
||||
|
||||
PuppetMasterInspector.DestroyImmediateSafe(script.muscle.additionalPin.gameObject);
|
||||
PuppetMasterInspector.DestroyImmediateSafe(script.muscle.additionalPinTarget.gameObject);
|
||||
|
||||
var puppetMasterS = new SerializedObject(script.puppetMaster);
|
||||
puppetMasterS.FindProperty("muscles").GetArrayElementAtIndex(script.muscle.index).FindPropertyRelative("additionalPin").objectReferenceValue = null;
|
||||
puppetMasterS.FindProperty("muscles").GetArrayElementAtIndex(script.muscle.index).FindPropertyRelative("additionalPinTarget").objectReferenceValue = null;
|
||||
puppetMasterS.ApplyModifiedProperties();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private static float GetHandleSize(Vector3 position)
|
||||
{
|
||||
float s = HandleUtility.GetHandleSize(position) * 0.1f;
|
||||
return Mathf.Lerp(s, 0.025f, 0.2f);
|
||||
}
|
||||
|
||||
void OnSceneGUI() {
|
||||
DrawScene(script);
|
||||
}
|
||||
|
||||
private static void CubeCapSafe(Vector3 position, Quaternion rotation, float size)
|
||||
{
|
||||
#if UNITY_5_6_OR_NEWER
|
||||
Handles.CubeHandleCap(0, position, rotation, size, EventType.Repaint);
|
||||
#else
|
||||
Handles.CubeCap(0, position, rotation, size);
|
||||
#endif
|
||||
}
|
||||
|
||||
private static void SphereCapSafe(Vector3 position, Quaternion rotation, float size)
|
||||
{
|
||||
#if UNITY_5_6_OR_NEWER
|
||||
Handles.SphereHandleCap(0, position, rotation, size, EventType.Repaint);
|
||||
#else
|
||||
Handles.SphereCap(0, position, rotation, size);
|
||||
#endif
|
||||
}
|
||||
|
||||
public static void DrawScene(PropMuscle script)
|
||||
{
|
||||
if (script == null) return;
|
||||
if (Application.isPlaying) return;
|
||||
|
||||
GUIStyle sceneLabelStyle = new GUIStyle();
|
||||
sceneLabelStyle.wordWrap = false;
|
||||
sceneLabelStyle.normal.textColor = sceneColor;
|
||||
|
||||
Handles.color = sceneColor;
|
||||
float size = GetHandleSize(script.transform.position);
|
||||
|
||||
if (Selection.activeGameObject == script.gameObject)
|
||||
{
|
||||
Handles.Label(script.transform.position + script.transform.forward * size * 2f, new GUIContent(script.transform.name), sceneLabelStyle);
|
||||
} else
|
||||
{
|
||||
Handles.Label(script.transform.position + script.transform.forward * size * 2f, new GUIContent("Click to select Prop Muscle"), sceneLabelStyle);
|
||||
}
|
||||
|
||||
if (Selection.activeGameObject == script.gameObject)
|
||||
{
|
||||
CubeCapSafe(script.transform.position, script.transform.rotation, size * 2f);
|
||||
} else
|
||||
{
|
||||
if (DotButton(script.transform.position, script.transform.rotation, size, size))
|
||||
{
|
||||
Selection.activeGameObject = script.gameObject;
|
||||
}
|
||||
}
|
||||
|
||||
if (script.muscle.additionalPin != null)
|
||||
{
|
||||
Handles.DrawLine(script.transform.position, script.muscle.additionalPin.transform.position);
|
||||
SphereCapSafe(script.muscle.additionalPin.transform.position, script.muscle.additionalPin.transform.rotation, size);
|
||||
|
||||
if (Selection.activeGameObject == script.gameObject)
|
||||
{
|
||||
Handles.Label(script.muscle.additionalPin.transform.position + script.transform.forward * size * 2f, new GUIContent("Additional Pin"), sceneLabelStyle);
|
||||
}
|
||||
}
|
||||
|
||||
Handles.color = Color.white;
|
||||
}
|
||||
|
||||
public static bool DotButton(Vector3 position, Quaternion direction, float size, float pickSize)
|
||||
{
|
||||
#if UNITY_5_6_OR_NEWER
|
||||
return Handles.Button(position, direction, size, pickSize, Handles.DotHandleCap);
|
||||
#else
|
||||
return Handles.Button(position, direction, size, pickSize, Handles.DotCap);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2d0583daa68217f49b271ee02c9374f5
|
||||
timeCreated: 1550562021
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,21 @@
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace RootMotion.Dynamics {
|
||||
|
||||
[CustomEditor(typeof(PuppetMasterHumanoidConfig))]
|
||||
public class PuppetMasterHumanoidConfigInspector : Editor {
|
||||
|
||||
private PuppetMasterHumanoidConfig script { get { return target as PuppetMasterHumanoidConfig; } }
|
||||
|
||||
public override void OnInspectorGUI() {
|
||||
foreach (PuppetMasterHumanoidConfig.HumanoidMuscle m in script.muscles) {
|
||||
m.name = m.bone.ToString();
|
||||
}
|
||||
|
||||
DrawDefaultInspector ();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f97a5dd098e6d624caf82f29ed6896d2
|
||||
timeCreated: 1485252527
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,437 @@
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using System.Collections;
|
||||
using System;
|
||||
|
||||
namespace RootMotion.Dynamics
|
||||
{
|
||||
|
||||
[CustomEditor(typeof(PuppetMaster))]
|
||||
public class PuppetMasterInspector : Editor
|
||||
{
|
||||
|
||||
private PuppetMaster script { get { return target as PuppetMaster; } }
|
||||
private Transform animatedCharacter;
|
||||
private bool isValid;
|
||||
private int characterControllerLayer = 8;
|
||||
private int ragdollLayer = 9;
|
||||
private ConfigurableJoint addPropMuscleTo;
|
||||
private MonoScript monoScript;
|
||||
private Animator targetAnimator;
|
||||
private SkinnedMeshRenderer[] skinnedMeshRenderers = new SkinnedMeshRenderer[0];
|
||||
|
||||
// Colors
|
||||
private GUIStyle style = new GUIStyle();
|
||||
private GUIStyle miniLabelStyle = new GUIStyle();
|
||||
private static Color pro = new Color(0.5f, 0.7f, 0.3f, 1f);
|
||||
private static Color free = new Color(0.2f, 0.3f, 0.1f, 1f);
|
||||
|
||||
#region Inspector
|
||||
|
||||
void OnEnable()
|
||||
{
|
||||
if (!Application.isPlaying)
|
||||
{
|
||||
monoScript = MonoScript.FromMonoBehaviour(script);
|
||||
int currentExecutionOrder = MonoImporter.GetExecutionOrder(monoScript);
|
||||
if (currentExecutionOrder != 10100) MonoImporter.SetExecutionOrder(monoScript, 10100);
|
||||
|
||||
// Fix negative collider sizes for ragdolls created before PuppetMaster 0.3
|
||||
BoxCollider[] boxColliders = script.GetComponentsInChildren<BoxCollider>();
|
||||
foreach (BoxCollider box in boxColliders)
|
||||
{
|
||||
box.size = new Vector3(Mathf.Abs(box.size.x), Mathf.Abs(box.size.y), Mathf.Abs(box.size.z));
|
||||
}
|
||||
|
||||
CapsuleCollider[] capsuleColliders = script.GetComponentsInChildren<CapsuleCollider>();
|
||||
foreach (CapsuleCollider capsule in capsuleColliders)
|
||||
{
|
||||
capsule.height = Mathf.Abs(capsule.height);
|
||||
capsule.radius = Mathf.Abs(capsule.radius);
|
||||
}
|
||||
|
||||
if (script.transform.parent != null)
|
||||
{
|
||||
targetAnimator = script.transform.parent.GetComponentInChildren<Animator>();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (script.initiated) targetAnimator = script.targetAnimator;
|
||||
}
|
||||
|
||||
if (script.transform.parent != null)
|
||||
{
|
||||
skinnedMeshRenderers = script.transform.parent.GetComponentsInChildren<SkinnedMeshRenderer>();
|
||||
}
|
||||
|
||||
isValid = IsValid();
|
||||
}
|
||||
|
||||
private bool IsValid()
|
||||
{
|
||||
if (script.muscles.Length > 0) return true;
|
||||
|
||||
ConfigurableJoint[] joints = script.gameObject.GetComponentsInChildren<ConfigurableJoint>();
|
||||
|
||||
if (joints == null || joints.Length == 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (animatedCharacter == null) animatedCharacter = script.transform;
|
||||
return true;
|
||||
}
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
if (script == null) return;
|
||||
serializedObject.Update();
|
||||
|
||||
if (script.muscles.Length > 0 && script.muscles[0].target != null && script.targetRoot == null) script.targetRoot = script.FindTargetRootRecursive(script.muscles[0].target);
|
||||
|
||||
style.wordWrap = true;
|
||||
style.normal.textColor = EditorGUIUtility.isProSkin ? pro : free;
|
||||
|
||||
miniLabelStyle.wordWrap = true;
|
||||
miniLabelStyle.fontSize = 10;
|
||||
miniLabelStyle.normal.textColor = EditorStyles.miniLabel.normal.textColor;
|
||||
|
||||
if (!isValid)
|
||||
{
|
||||
EditorGUILayout.Space();
|
||||
EditorGUILayout.LabelField(
|
||||
"To set up PuppetMaster, add the component to a ragdoll character that is built with ConfigurableJoints. " +
|
||||
"If your ragdoll uses other types of joints, you can easily convert them by selecting the character and clicking on GameObject/Convert To ConfigurableJoints."
|
||||
, style);
|
||||
EditorGUILayout.Space();
|
||||
return;
|
||||
}
|
||||
|
||||
if (!Application.isPlaying)
|
||||
{
|
||||
for (int i = 0; i < script.muscles.Length; i++)
|
||||
{
|
||||
script.muscles[i].index = i;
|
||||
}
|
||||
}
|
||||
|
||||
foreach (Muscle m in script.muscles)
|
||||
{
|
||||
if (m.joint == null)
|
||||
{
|
||||
m.name = "Missing Joint Reference!";
|
||||
}
|
||||
else if (m.target == null)
|
||||
{
|
||||
m.name = "Missing Target Reference!";
|
||||
}
|
||||
else m.name = m.joint.name;
|
||||
}
|
||||
|
||||
if (script.muscles.Length == 0)
|
||||
{
|
||||
GUILayout.Space(5);
|
||||
|
||||
animatedCharacter = (Transform)EditorGUILayout.ObjectField(new GUIContent("Animated Target", "If it is assigned to the same GameObject, it will be duplicated and cleaned up of all the ragdoll components. It can also be an instance of the character or even another character as long as the positions of the bones match. The rotations of the bones don't need to be identical. That makes it possible to share ragdoll structures and is also most useful when the feet bones are not aligned to the ground (like Mixamo characters). In that case you can simply rotate the ragdoll's feet to align, keeping the target's feet where they are."), animatedCharacter, typeof(Transform), true);
|
||||
|
||||
GUILayout.Space(5);
|
||||
characterControllerLayer = EditorGUILayout.IntField(new GUIContent("Character Controller Layer", "The layer to assign the character controller to. Collisions between this layer and the 'Ragdoll Layer' will be ignored, or else the ragdoll would collide with the character controller."), characterControllerLayer);
|
||||
ragdollLayer = EditorGUILayout.IntField(new GUIContent("Ragdoll Layer", "The layer to assign the PuppetMaster and all it's muscles to. Collisions between this layer and the 'Character Controller Layer' will be ignored, or else the ragdoll would collide with the character controller."), ragdollLayer);
|
||||
|
||||
if (characterControllerLayer == ragdollLayer)
|
||||
{
|
||||
GUILayout.Space(5);
|
||||
EditorGUILayout.LabelField(
|
||||
"The 'Character Controller Layer' must not be the same as the 'Ragdoll Layer', your ragdoll bones would collide with the character controller."
|
||||
, style);
|
||||
EditorGUILayout.Space();
|
||||
}
|
||||
|
||||
if (animatedCharacter != null && characterControllerLayer != ragdollLayer)
|
||||
{
|
||||
GUILayout.Space(5);
|
||||
|
||||
if (GUILayout.Button("Set Up PuppetMaster", GUILayout.MaxWidth(140)))
|
||||
{
|
||||
#if UNITY_2018_3_OR_NEWER
|
||||
if (animatedCharacter == script.transform)
|
||||
{
|
||||
if (PrefabUtility.IsPartOfPrefabInstance(animatedCharacter.gameObject)) PrefabUtility.UnpackPrefabInstance(PrefabUtility.GetNearestPrefabInstanceRoot(animatedCharacter.gameObject), PrefabUnpackMode.Completely, InteractionMode.UserAction);
|
||||
} else
|
||||
{
|
||||
if (PrefabUtility.IsPartOfPrefabInstance(script.gameObject)) PrefabUtility.UnpackPrefabInstance(PrefabUtility.GetNearestPrefabInstanceRoot(script.gameObject), PrefabUnpackMode.Completely, InteractionMode.UserAction);
|
||||
}
|
||||
#endif
|
||||
script.SetUpTo(animatedCharacter, characterControllerLayer, ragdollLayer);
|
||||
|
||||
animatedCharacter = null;
|
||||
}
|
||||
|
||||
EditorGUILayout.LabelField("Setting up PuppetMaster is not undoable. Make sure to make a backup duplicate of the character before you do that.", miniLabelStyle);
|
||||
|
||||
if (animatedCharacter == script.transform)
|
||||
{
|
||||
GUILayout.Space(5);
|
||||
EditorGUILayout.BeginVertical("Box");
|
||||
GUILayout.Label("NB! 'Animated Target' is set to the same GameObject as this. PuppetMaster will make a duplicate of this GameObject and break the prefab to remove ragdoll components. It is recommended to set up the ragdoll on a new model instance, add PuppetMater to that and assign the original character as it's 'Animated Target'.", miniLabelStyle);
|
||||
EditorGUILayout.EndVertical();
|
||||
}
|
||||
}
|
||||
|
||||
GUILayout.Space(5);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Fix muscle positions and rotations to their targets
|
||||
if (!Application.isPlaying && script.targetRoot != null)
|
||||
{
|
||||
if (script.transform.parent == script.targetRoot.parent)
|
||||
{
|
||||
script.transform.localPosition = Vector3.zero;
|
||||
script.transform.localRotation = Quaternion.identity;
|
||||
script.targetRoot.localPosition = Vector3.zero;
|
||||
script.targetRoot.localRotation = Quaternion.identity;
|
||||
}
|
||||
|
||||
foreach (Muscle m in script.muscles)
|
||||
{
|
||||
if (m.joint != null && m.target != null && !m.isPropMuscle)
|
||||
{
|
||||
m.joint.transform.position = m.target.position;
|
||||
|
||||
var r = m.joint.GetComponent<Rigidbody>();
|
||||
|
||||
bool hasChild = false;
|
||||
foreach (Muscle otherMuscle in script.muscles)
|
||||
{
|
||||
if (otherMuscle != m && otherMuscle.joint != null && otherMuscle.joint.connectedBody != null)
|
||||
{
|
||||
if (otherMuscle.joint.connectedBody == r)
|
||||
{
|
||||
hasChild = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (hasChild)
|
||||
{
|
||||
m.joint.transform.rotation = m.target.rotation;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!Application.isPlaying && script.humanoidConfig != null && script.targetRoot != null && script.targetAnimator != null && script.targetAnimator.isHuman)
|
||||
{
|
||||
script.humanoidConfig.ApplyTo(script);
|
||||
|
||||
GUILayout.Space(5);
|
||||
EditorGUILayout.BeginVertical("Box");
|
||||
GUILayout.Label("Properties of this PuppetMaster are locked to the Humanoid Config file.", miniLabelStyle);
|
||||
EditorGUILayout.EndVertical();
|
||||
GUILayout.Space(5);
|
||||
}
|
||||
|
||||
script.muscleSpring = Mathf.Clamp(script.muscleSpring, 0f, script.muscleSpring);
|
||||
script.muscleDamper = Mathf.Clamp(script.muscleDamper, 0f, script.muscleDamper);
|
||||
|
||||
DrawDefaultInspector();
|
||||
|
||||
GUILayout.Space(10);
|
||||
|
||||
// Prop Muscles
|
||||
GUIStyle largeHeaderStyle = new GUIStyle(GUI.skin.label);
|
||||
largeHeaderStyle.fontSize = 16;
|
||||
largeHeaderStyle.fontStyle = FontStyle.Normal;
|
||||
//largeHeaderStyle.alignment = TextAnchor.LowerLeft;
|
||||
largeHeaderStyle.alignment = TextAnchor.MiddleLeft;
|
||||
|
||||
GUI.color = Color.grey * 0.7f;
|
||||
|
||||
EditorGUILayout.LabelField("Prop Muscles", largeHeaderStyle);
|
||||
|
||||
GUI.color = Color.white;
|
||||
|
||||
EditorGUILayout.BeginHorizontal("Box");
|
||||
|
||||
addPropMuscleTo = (ConfigurableJoint)EditorGUILayout.ObjectField(GUIContent.none, addPropMuscleTo, typeof(ConfigurableJoint), true);
|
||||
|
||||
if (GUILayout.Button("Add Prop Muscle"))
|
||||
{
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
AddPropMuscle(script, addPropMuscleTo, addPropMuscleTo.transform.position, addPropMuscleTo.transform.rotation, Vector3.forward * 0.5f);
|
||||
serializedObject.Update();
|
||||
}
|
||||
EditorGUILayout.EndHorizontal();
|
||||
|
||||
EditorGUILayout.LabelField("Prop Muscles are muscles that props (PuppetMasterProp) can be attached to. For example, to put a sword in the right hand, assign the right hand muscle above, click on 'Add Prop Muscle', then move the added muscle to where you would want the sword to be held. To pick up the sword, just assign it as 'Current Prop' in the PropMuscle component on the prop muscle.", miniLabelStyle);
|
||||
GUILayout.Space(5);
|
||||
}
|
||||
|
||||
bool animatorWarning = targetAnimator != null && targetAnimator.cullingMode != AnimatorCullingMode.AlwaysAnimate;
|
||||
if (animatorWarning)
|
||||
{
|
||||
GUILayout.Space(5);
|
||||
EditorGUILayout.BeginVertical("Box");
|
||||
GUILayout.Label("If Animator 'Culling Mode' is not set to 'Always Animate', animation might pause and cause glitches when the ragdoll is out of SkinnedMeshRenderer.bounds.", miniLabelStyle);
|
||||
EditorGUILayout.EndVertical();
|
||||
}
|
||||
|
||||
bool rendererWarning = false;
|
||||
foreach (SkinnedMeshRenderer s in skinnedMeshRenderers)
|
||||
{
|
||||
if (!s.updateWhenOffscreen)
|
||||
{
|
||||
rendererWarning = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (rendererWarning)
|
||||
{
|
||||
if (!animatorWarning) GUILayout.Space(5);
|
||||
EditorGUILayout.BeginVertical("Box");
|
||||
GUILayout.Label("One of the SkinnedMeshRenderers in the animated character hierarchy has 'Update When Offscreen' set to false. This might cause it to disappear from view when the ragdoll is out of the renderer's bounds.", miniLabelStyle);
|
||||
EditorGUILayout.EndVertical();
|
||||
}
|
||||
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
}
|
||||
|
||||
public static void DestroyImmediateSafe(GameObject go)
|
||||
{
|
||||
#if UNITY_2018_3_OR_NEWER
|
||||
if (PrefabUtility.IsPartOfPrefabInstance(go)) PrefabUtility.UnpackPrefabInstance(PrefabUtility.GetNearestPrefabInstanceRoot(go), PrefabUnpackMode.Completely, InteractionMode.UserAction);
|
||||
#endif
|
||||
DestroyImmediate(go);
|
||||
}
|
||||
|
||||
public static bool AddPropMuscle(PuppetMaster script, ConfigurableJoint addPropMuscleTo, Vector3 position, Quaternion rotation, Vector3 additionalPinOffset, Transform targetParent = null)
|
||||
{
|
||||
var serializedObject = new SerializedObject(script);
|
||||
|
||||
if (addPropMuscleTo != null)
|
||||
{
|
||||
bool isFlat = script.HierarchyIsFlat();
|
||||
|
||||
var addToMuscle = script.GetMuscle(addPropMuscleTo);
|
||||
if (addToMuscle != null)
|
||||
{
|
||||
|
||||
GameObject go = new GameObject("Prop Muscle " + addPropMuscleTo.name);
|
||||
go.layer = addPropMuscleTo.gameObject.layer;
|
||||
go.transform.parent = isFlat ? script.transform : addPropMuscleTo.transform;
|
||||
go.transform.position = position;
|
||||
go.transform.rotation = rotation;
|
||||
|
||||
var r = go.AddComponent<Rigidbody>();
|
||||
|
||||
GameObject target = new GameObject("Prop Muscle Target " + addPropMuscleTo.name);
|
||||
target.gameObject.layer = addToMuscle.target.gameObject.layer;
|
||||
target.transform.parent = targetParent == null ? addToMuscle.target : targetParent;
|
||||
target.transform.position = go.transform.position;
|
||||
target.transform.rotation = go.transform.rotation;
|
||||
|
||||
var joint = go.AddComponent<ConfigurableJoint>();
|
||||
joint.connectedBody = addToMuscle.joint.gameObject.GetComponent<Rigidbody>();
|
||||
joint.xMotion = ConfigurableJointMotion.Locked;
|
||||
joint.yMotion = ConfigurableJointMotion.Locked;
|
||||
joint.zMotion = ConfigurableJointMotion.Locked;
|
||||
joint.angularXMotion = ConfigurableJointMotion.Locked;
|
||||
joint.angularYMotion = ConfigurableJointMotion.Locked;
|
||||
joint.angularZMotion = ConfigurableJointMotion.Locked;
|
||||
|
||||
r.interpolation = joint.connectedBody.interpolation;
|
||||
|
||||
int newLength = script.muscles.Length + 1;
|
||||
int newMuscleIndex = newLength - 1;
|
||||
|
||||
SerializedProperty muscles = serializedObject.FindProperty("muscles");
|
||||
muscles.InsertArrayElementAtIndex(newMuscleIndex);
|
||||
|
||||
muscles.GetArrayElementAtIndex(newMuscleIndex).FindPropertyRelative("index").intValue = newMuscleIndex;
|
||||
muscles.GetArrayElementAtIndex(newMuscleIndex).FindPropertyRelative("joint").objectReferenceValue = joint;
|
||||
muscles.GetArrayElementAtIndex(newMuscleIndex).FindPropertyRelative("target").objectReferenceValue = target.transform;
|
||||
muscles.GetArrayElementAtIndex(newMuscleIndex).FindPropertyRelative("props").FindPropertyRelative("group").intValue = 8;
|
||||
muscles.GetArrayElementAtIndex(newMuscleIndex).FindPropertyRelative("isPropMuscle").boolValue = true;
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
|
||||
var propMuscle = joint.gameObject.AddComponent<PropMuscle>();
|
||||
var propMuscleS = new SerializedObject(propMuscle);
|
||||
propMuscleS.FindProperty("puppetMaster").objectReferenceValue = script;
|
||||
propMuscleS.FindProperty("additionalPinOffset").vector3Value = additionalPinOffset;
|
||||
|
||||
propMuscleS.ApplyModifiedProperties();
|
||||
|
||||
if (additionalPinOffset != Vector3.zero)
|
||||
{
|
||||
propMuscleS.Update();
|
||||
ConfigurableJoint additionalJoint = null;
|
||||
Transform additionalTarget = null;
|
||||
PropMuscleInspector.AddAdditionalPinUnserialized(propMuscle, out additionalJoint, out additionalTarget);
|
||||
|
||||
muscles.GetArrayElementAtIndex(newMuscleIndex).FindPropertyRelative("additionalPin").objectReferenceValue = additionalJoint;
|
||||
muscles.GetArrayElementAtIndex(newMuscleIndex).FindPropertyRelative("additionalPinTarget").objectReferenceValue = additionalTarget;
|
||||
|
||||
propMuscleS.ApplyModifiedProperties();
|
||||
}
|
||||
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
// TODO Do not add if addPropMuscleTo already has a PropMuscle
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError("Can't add Prop Muscle to a ConfigurableJoint that is not in the list of PuppetMaster.muscles.", script.transform);
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError("Please assign the ConfigurableJoint of the muscle you wish to add the Prop Muscle to.", script.transform);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private bool IsRagdoll()
|
||||
{
|
||||
Rigidbody[] rigidbodies = (Rigidbody[])script.gameObject.GetComponentsInChildren<Rigidbody>();
|
||||
foreach (Rigidbody r in rigidbodies)
|
||||
{
|
||||
if (r != script.GetComponent<Rigidbody>()) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
#endregion Inspector
|
||||
|
||||
#region Scene
|
||||
|
||||
|
||||
void OnSceneGUI()
|
||||
{
|
||||
if (script == null) return;
|
||||
if (Application.isPlaying) return;
|
||||
|
||||
foreach (Muscle m in script.muscles)
|
||||
{
|
||||
if (m.joint != null)
|
||||
{
|
||||
var propMuscle = m.joint.GetComponent<PropMuscle>();
|
||||
if (propMuscle != null)
|
||||
{
|
||||
PropMuscleInspector.DrawScene(propMuscle);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Handles.color = Color.white;
|
||||
}
|
||||
|
||||
|
||||
#endregion Scene
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d63c5bd59fb5541eeb1098d1f4a6d01c
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
@@ -0,0 +1,37 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using UnityEditor;
|
||||
|
||||
namespace RootMotion.Dynamics
|
||||
{
|
||||
[CustomEditor(typeof(PuppetMasterProp))]
|
||||
public class PuppetMasterPropInspector : Editor
|
||||
{
|
||||
|
||||
private PuppetMasterProp script { get { return target as PuppetMasterProp; } }
|
||||
|
||||
private GUIStyle style = new GUIStyle();
|
||||
private GUIStyle miniLabelStyle = new GUIStyle();
|
||||
private static Color pro = new Color(0.5f, 0.7f, 0.3f, 1f);
|
||||
private static Color free = new Color(0.2f, 0.3f, 0.1f, 1f);
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
if (script == null) return;
|
||||
serializedObject.Update();
|
||||
|
||||
style.wordWrap = true;
|
||||
style.normal.textColor = EditorGUIUtility.isProSkin ? pro : free;
|
||||
|
||||
miniLabelStyle.wordWrap = true;
|
||||
miniLabelStyle.fontSize = 10;
|
||||
miniLabelStyle.normal.textColor = EditorStyles.miniLabel.normal.textColor;
|
||||
|
||||
DrawDefaultInspector();
|
||||
|
||||
script.muscleProps.group = Muscle.Group.Prop;
|
||||
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a7f9c20921f4b1942b1f7b410dd66836
|
||||
timeCreated: 1550561801
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,46 @@
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
|
||||
namespace RootMotion.Dynamics {
|
||||
|
||||
[CustomPropertyDrawer (typeof (Weight))]
|
||||
public class WeightDrawer : PropertyDrawer {
|
||||
|
||||
const int valueWidth = 30;
|
||||
const int gap = 20;
|
||||
const float min = 0;
|
||||
const float max = 1;
|
||||
|
||||
public override void OnGUI (Rect pos, SerializedProperty prop, GUIContent label) {
|
||||
|
||||
SerializedProperty mode = prop.FindPropertyRelative("mode");
|
||||
SerializedProperty floatValue = prop.FindPropertyRelative ("floatValue");
|
||||
SerializedProperty curve = prop.FindPropertyRelative ("curve");
|
||||
SerializedProperty tooltip = prop.FindPropertyRelative("tooltip");
|
||||
label.tooltip = tooltip.stringValue;
|
||||
|
||||
Rect left = new Rect(pos.x, pos.y, pos.width - valueWidth - gap, pos.height);
|
||||
Rect right = new Rect (pos.width - valueWidth, pos.y, valueWidth, pos.height);
|
||||
|
||||
Weight.Mode m = (Weight.Mode)mode.enumValueIndex;
|
||||
|
||||
if (m == Weight.Mode.Float) {
|
||||
floatValue.floatValue = EditorGUI.FloatField(left, label, floatValue.floatValue);
|
||||
} else {
|
||||
// Draw curve
|
||||
int indent = EditorGUI.indentLevel;
|
||||
|
||||
EditorGUI.PropertyField (left, curve, label);
|
||||
EditorGUI.indentLevel = indent;
|
||||
}
|
||||
|
||||
int i = EditorGUI.indentLevel;
|
||||
EditorGUI.indentLevel = 0;
|
||||
|
||||
m = (Weight.Mode)EditorGUI.EnumPopup(right, GUIContent.none, ( Weight.Mode)mode.enumValueIndex, EditorStyles.miniBoldLabel);
|
||||
mode.enumValueIndex = (int)m;
|
||||
|
||||
EditorGUI.indentLevel = i;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f882d03cc62ed40c7b8febce6ef4a0de
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 98d02ab32f6fa4551b1983c76cea4586
|
||||
folderAsset: yes
|
||||
timeCreated: 1452250914
|
||||
licenseType: Store
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,75 @@
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using System.Collections;
|
||||
using RootMotion.Dynamics;
|
||||
|
||||
namespace RootMotion.Demos {
|
||||
|
||||
[CustomEditor(typeof(CharacterMeleeDemo))]
|
||||
public class CharacterMeleeDemoInspector : Editor {
|
||||
|
||||
private CharacterMeleeDemo script { get { return target as CharacterMeleeDemo; }}
|
||||
|
||||
private GameObject replace;
|
||||
|
||||
private static Color pro = new Color(0.7f, 0.9f, 0.5f, 1f);
|
||||
private static Color free = new Color(0.4f, 0.5f, 0.3f, 1f);
|
||||
|
||||
public override void OnInspectorGUI() {
|
||||
GUI.changed = false;
|
||||
|
||||
if (!Application.isPlaying) {
|
||||
GUI.color = EditorGUIUtility.isProSkin? pro: free;
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
|
||||
replace = (GameObject)EditorGUILayout.ObjectField("Replace Character Model", replace, typeof(GameObject), true);
|
||||
|
||||
if (replace != null) {
|
||||
if (GUILayout.Button("Replace")) {
|
||||
Debug.Log("PropMuscle needs to be set up manually and assigned as 'Prop Muscle' in the CharacterMeleeDemo component on the character.");
|
||||
|
||||
/* TODO Update to PropMuscle
|
||||
PropRoot propRoot = script.propRoot;
|
||||
Vector3 localPosition = propRoot.transform.localPosition;
|
||||
Quaternion localRotation = propRoot.transform.localRotation;
|
||||
propRoot.transform.parent = null;
|
||||
|
||||
CharacterPuppetInspector.ReplacePuppetModel(script as CharacterThirdPerson, replace);
|
||||
|
||||
Animator animator = script.characterAnimation.GetComponent<Animator>();
|
||||
PuppetMaster puppetMaster = script.transform.parent.GetComponentInChildren<PuppetMaster>();
|
||||
|
||||
propRoot.transform.parent = animator.GetBoneTransform(HumanBodyBones.RightHand);
|
||||
propRoot.transform.localPosition = localPosition;
|
||||
propRoot.transform.localRotation = localRotation;
|
||||
propRoot.puppetMaster = puppetMaster;
|
||||
propRoot.connectTo = GetRigidbody(puppetMaster, animator.GetBoneTransform(HumanBodyBones.RightLowerArm));
|
||||
|
||||
Debug.Log("You probably need to adjust the localPosition and localRotation of the Prop Root to match this character's hand.");
|
||||
*/
|
||||
UserControlAI[] userControls = (UserControlAI[])GameObject.FindObjectsOfType<UserControlAI>();
|
||||
foreach (UserControlAI ai in userControls) {
|
||||
if (ai.moveTarget == null) {
|
||||
ai.moveTarget = script.transform.parent.GetComponentInChildren<PuppetMaster>().muscles[0].joint.transform;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
EditorGUILayout.EndHorizontal();
|
||||
GUI.color = Color.white;
|
||||
}
|
||||
|
||||
DrawDefaultInspector();
|
||||
|
||||
if (GUI.changed) EditorUtility.SetDirty(script);
|
||||
}
|
||||
|
||||
private Rigidbody GetRigidbody(PuppetMaster puppetMaster, Transform target) {
|
||||
foreach (Muscle m in puppetMaster.muscles) {
|
||||
if (m.target == target) return m.joint.GetComponent<Rigidbody>();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5c5c74fcc11b441abb014b8119cb9e5f
|
||||
timeCreated: 1452255675
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,176 @@
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using System.Collections;
|
||||
using RootMotion.Dynamics;
|
||||
|
||||
namespace RootMotion.Demos {
|
||||
|
||||
[CustomEditor(typeof(CharacterPuppet))]
|
||||
public class CharacterPuppetInspector : Editor {
|
||||
|
||||
private CharacterPuppet script { get { return target as CharacterPuppet; }}
|
||||
|
||||
private GameObject replace;
|
||||
|
||||
private static Color pro = new Color(0.7f, 0.9f, 0.5f, 1f);
|
||||
private static Color free = new Color(0.4f, 0.5f, 0.3f, 1f);
|
||||
|
||||
public override void OnInspectorGUI() {
|
||||
GUI.changed = false;
|
||||
|
||||
if (!Application.isPlaying) {
|
||||
GUI.color = EditorGUIUtility.isProSkin? pro: free;
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
|
||||
replace = (GameObject)EditorGUILayout.ObjectField("Replace Character Model", replace, typeof(GameObject), true);
|
||||
|
||||
if (replace != null) {
|
||||
if (GUILayout.Button("Replace")) {
|
||||
ReplacePuppetModel(script as CharacterThirdPerson, replace);
|
||||
replace = null;
|
||||
}
|
||||
}
|
||||
GUI.color = Color.white;
|
||||
EditorGUILayout.EndHorizontal();
|
||||
}
|
||||
|
||||
DrawDefaultInspector();
|
||||
if (GUI.changed) EditorUtility.SetDirty(script);
|
||||
}
|
||||
|
||||
public static void ReplacePuppetModel(CharacterThirdPerson script, GameObject replace) {
|
||||
// Drag your Humanoid character to the scene, parent it to the "Animation Controller" just where the Pilot is
|
||||
GameObject find = GameObject.Find(replace.name);
|
||||
bool isSceneObject = find != null && find == replace;
|
||||
|
||||
GameObject instance = isSceneObject? replace: (GameObject)GameObject.Instantiate(replace, script.transform.position, script.transform.rotation);
|
||||
instance.transform.parent = script.characterAnimation.transform;
|
||||
instance.name = replace.name;
|
||||
instance.transform.position = script.transform.position;
|
||||
instance.transform.rotation = script.transform.rotation;
|
||||
|
||||
Animator animator = instance.GetComponentInChildren<Animator>();
|
||||
bool isAnimator = animator != null;
|
||||
if (!isAnimator || !animator.isHuman) {
|
||||
Debug.LogWarning("The demo character controller requires a Humanoid character.");
|
||||
return;
|
||||
}
|
||||
|
||||
SkinnedMeshRenderer[] skinnedMeshRenders = instance.GetComponentsInChildren<SkinnedMeshRenderer>();
|
||||
foreach (SkinnedMeshRenderer s in skinnedMeshRenders) s.updateWhenOffscreen = true;
|
||||
|
||||
// Unparent "Character Controller" from the "ThirdPersonPuppet"
|
||||
Transform oldRoot = script.transform.parent;
|
||||
PuppetMaster oldPM = script.transform.parent.GetComponentInChildren<PuppetMaster>();
|
||||
RigidbodyInterpolation oldInterpolation = oldPM.muscles[0].joint.GetComponent<Rigidbody>().interpolation;
|
||||
BehaviourBase[] behaviours = script.transform.parent.GetComponentsInChildren<BehaviourBase>();
|
||||
Camera camera = script.transform.parent.GetComponentInChildren<Camera>();
|
||||
CameraController cameraController = null;
|
||||
if (camera != null) cameraController = camera.gameObject.GetComponent<CameraController>();
|
||||
LayerSetup layerSetup = oldPM.GetComponent<LayerSetup>();
|
||||
|
||||
script.transform.parent = null;
|
||||
|
||||
// Delete the "Pilot"
|
||||
DestroyImmediate(script.characterAnimation.transform.GetChild(0).gameObject);
|
||||
|
||||
// Replace the Avatar in the Animator component of the "Animation Controller" gameobject.
|
||||
Animator characterAnimator = script.characterAnimation.GetComponent<Animator>();
|
||||
characterAnimator.avatar = animator.avatar;
|
||||
|
||||
// Add BipedRagdollCreator to the "Animation Controller", use it to create a ragdoll, delete the component when done
|
||||
Joint joint = instance.GetComponentInChildren<Joint>();
|
||||
bool isRagdoll = joint != null;
|
||||
bool isConfigurable = isRagdoll && joint is ConfigurableJoint;
|
||||
|
||||
if (isRagdoll && !isConfigurable) {
|
||||
JointConverter.ToConfigurable(instance);
|
||||
}
|
||||
|
||||
if (!isRagdoll) {
|
||||
BipedRagdollReferences r = BipedRagdollReferences.FromAvatar(animator);
|
||||
BipedRagdollCreator.Options options = BipedRagdollCreator.AutodetectOptions(r);
|
||||
|
||||
// Edit options here if you need to
|
||||
|
||||
BipedRagdollCreator.Create(r, options);
|
||||
}
|
||||
|
||||
// Delete the Animator from your character root (not the one on "Animation Controller")
|
||||
DestroyImmediate(animator);
|
||||
|
||||
// Add PuppetMaster to the "Character Controller", click on Set Up PuppetMaster.
|
||||
int cLayer = layerSetup != null? layerSetup.characterControllerLayer: script.gameObject.layer;
|
||||
int rLayer = layerSetup != null? layerSetup.ragdollLayer: oldPM.muscles[0].joint.gameObject.layer;
|
||||
|
||||
PuppetMaster newPuppetMaster = PuppetMaster.SetUp(script.transform, cLayer, rLayer);
|
||||
foreach (Muscle m in newPuppetMaster.muscles) {
|
||||
m.joint.GetComponent<Rigidbody>().interpolation = oldInterpolation;
|
||||
}
|
||||
|
||||
// Move the "Puppet" and "Fall" behaviours from the old rig to the new one (parent them to the "Behaviours").
|
||||
Transform behaviourRoot = newPuppetMaster.transform.parent.Find("Behaviours");
|
||||
Transform oldBehaviourRoot = behaviours.Length > 0? behaviours[0].transform.parent: FindChildNameContaining(oldRoot, "Behaviours");
|
||||
foreach (BehaviourBase behaviour in behaviours) behaviour.transform.parent = behaviourRoot;
|
||||
if (oldBehaviourRoot != null) DestroyImmediate(oldBehaviourRoot.gameObject);
|
||||
|
||||
// 9. Move the "Character Camera" to the new rig, replace the "Target" of the CharacterController component
|
||||
if (camera != null) camera.transform.parent = newPuppetMaster.transform.parent;
|
||||
if (cameraController != null) cameraController.target = newPuppetMaster.muscles[0].joint.transform;
|
||||
|
||||
// THIS IS NOT REQUIRED SINCE 0.3 Use the RagdollEditor (add it to the PuppetMaster) to multiply the mass of the ragdoll by 10
|
||||
|
||||
// 10. Copy the LayerSetup component from the old PuppetMaster to the new one if you have not set up the layers in the Layer Collision Matrix.
|
||||
if (layerSetup != null) {
|
||||
LayerSetup newLayerSetup = newPuppetMaster.gameObject.AddComponent<LayerSetup>();
|
||||
if (newLayerSetup != null) {
|
||||
newLayerSetup.characterController = layerSetup.characterController;
|
||||
newLayerSetup.characterControllerLayer = layerSetup.characterControllerLayer;
|
||||
newLayerSetup.ragdollLayer = layerSetup.ragdollLayer;
|
||||
newLayerSetup.ignoreCollisionWithCharacterController = layerSetup.ignoreCollisionWithCharacterController;
|
||||
}
|
||||
}
|
||||
|
||||
// 11. Make sure the new PuppetMaster settings match with the old one, delete the old rig
|
||||
newPuppetMaster.state = oldPM.state;
|
||||
newPuppetMaster.stateSettings = oldPM.stateSettings;
|
||||
newPuppetMaster.mode = oldPM.mode;
|
||||
newPuppetMaster.blendTime = oldPM.blendTime;
|
||||
newPuppetMaster.fixTargetTransforms = oldPM.fixTargetTransforms;
|
||||
newPuppetMaster.solverIterationCount = oldPM.solverIterationCount;
|
||||
newPuppetMaster.visualizeTargetPose = oldPM.visualizeTargetPose;
|
||||
newPuppetMaster.mappingWeight = oldPM.mappingWeight;
|
||||
newPuppetMaster.pinWeight = oldPM.pinWeight;
|
||||
newPuppetMaster.muscleWeight = oldPM.muscleWeight;
|
||||
newPuppetMaster.muscleSpring = oldPM.muscleSpring;
|
||||
newPuppetMaster.muscleDamper = oldPM.muscleDamper;
|
||||
newPuppetMaster.pinPow = oldPM.pinPow;
|
||||
newPuppetMaster.pinDistanceFalloff = oldPM.pinDistanceFalloff;
|
||||
newPuppetMaster.updateJointAnchors = oldPM.updateJointAnchors;
|
||||
newPuppetMaster.supportTranslationAnimation = oldPM.supportTranslationAnimation;
|
||||
newPuppetMaster.angularLimits = oldPM.angularLimits;
|
||||
newPuppetMaster.internalCollisions = oldPM.internalCollisions;
|
||||
|
||||
// 12 Parent this CharacterPuppet to the new puppet root
|
||||
script.transform.parent = newPuppetMaster.transform.parent;
|
||||
|
||||
// 13. Delete the old root
|
||||
script.transform.parent.name = oldRoot.name;
|
||||
|
||||
for (int i = 0; i < oldRoot.childCount; i++) {
|
||||
var child = oldRoot.GetChild(i);
|
||||
if (child != oldPM.transform && child != behaviourRoot) {
|
||||
child.parent = script.transform.parent;
|
||||
}
|
||||
}
|
||||
DestroyImmediate(oldRoot.gameObject);
|
||||
}
|
||||
|
||||
private static Transform FindChildNameContaining(Transform t, string name) {
|
||||
for (int i = 0; i < t.childCount; i++) {
|
||||
if (t.GetChild(i).name.Contains(name)) return t.GetChild(i);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d86142a0934834027a39b8a2e105c009
|
||||
timeCreated: 1452250930
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e216fee95a1f04dd38a1e457aed7617a
|
||||
folderAsset: yes
|
||||
timeCreated: 1436186405
|
||||
licenseType: Store
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,168 @@
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using System.Collections;
|
||||
using RootMotion;
|
||||
|
||||
namespace RootMotion.Dynamics {
|
||||
|
||||
[CustomEditor(typeof(BipedRagdollCreator))]
|
||||
public class BipedRagdollCreatorInspector : Editor {
|
||||
|
||||
public BipedRagdollCreator script { get { return target as BipedRagdollCreator; }}
|
||||
|
||||
private GUIStyle miniLabelStyle = new GUIStyle();
|
||||
|
||||
void OnEnable() {
|
||||
if (script == null) return;
|
||||
//if (Application.isPlaying) return;
|
||||
|
||||
// Autodetection
|
||||
if (script.references.IsEmpty(false)) {
|
||||
Animator animator = script.gameObject.GetComponent<Animator>();
|
||||
|
||||
if (animator == null && script.references.root != null) {
|
||||
animator = script.references.root.GetComponentInChildren<Animator>();
|
||||
if (animator == null) animator = GetAnimatorInParents(script.references.root);
|
||||
}
|
||||
|
||||
if (animator != null) {
|
||||
script.references = BipedRagdollReferences.FromAvatar(animator);
|
||||
|
||||
} else {
|
||||
|
||||
BipedReferences r = new BipedReferences();
|
||||
BipedReferences.AutoDetectReferences(ref r, script.transform, BipedReferences.AutoDetectParams.Default);
|
||||
if (r.isFilled) script.references = BipedRagdollReferences.FromBipedReferences(r);
|
||||
}
|
||||
|
||||
if (!OnRoot()) {
|
||||
Debug.LogWarning("BipedRagdollCreator must be added to the root of the character. Destroying the component.");
|
||||
DestroyImmediate(script);
|
||||
return;
|
||||
}
|
||||
|
||||
string msg = string.Empty;
|
||||
if (script.references.IsValid(ref msg)) {
|
||||
script.options = BipedRagdollCreator.AutodetectOptions(script.references);
|
||||
//BipedRagdollCreator.Create(script.references, script.options);
|
||||
|
||||
//if (animator != null) DestroyImmediate(animator);
|
||||
//if (script.GetComponent<Animation>() != null) DestroyImmediate(script.GetComponent<Animation>());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private bool OnRoot() {
|
||||
if (script.references.Contains(script.transform, true)) return false;
|
||||
if (script.references.root != null) {
|
||||
var bipedRagdollCreatorOnChild = script.references.root.GetComponentInChildren<BipedRagdollCreator>();
|
||||
if (bipedRagdollCreatorOnChild != null && bipedRagdollCreatorOnChild.transform != script.references.root) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public override void OnInspectorGUI() {
|
||||
miniLabelStyle.wordWrap = true;
|
||||
miniLabelStyle.fontSize = 9;
|
||||
miniLabelStyle.normal.textColor = EditorStyles.miniLabel.normal.textColor;
|
||||
|
||||
serializedObject.Update();
|
||||
|
||||
//if (Application.isPlaying) {
|
||||
// GUILayout.BeginVertical("Box");
|
||||
// GUILayout.Label("Can not edit ragdolls in play mode.");
|
||||
// GUILayout.EndVertical();
|
||||
// return;
|
||||
//}
|
||||
|
||||
GUI.changed = false;
|
||||
GUILayout.Space(10);
|
||||
EditorGUILayout.BeginVertical("Box");
|
||||
int indent = EditorGUI.indentLevel;
|
||||
EditorGUI.indentLevel = 1;
|
||||
|
||||
EditorGUILayout.PropertyField(serializedObject.FindProperty("references"), new GUIContent("References", "Definition of the biped ragdoll."), true);
|
||||
|
||||
if (GUI.changed) {
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
EditorUtility.SetDirty(script);
|
||||
}
|
||||
|
||||
string msg = string.Empty;
|
||||
bool referencesValid = script.references.IsValid(ref msg);
|
||||
if (serializedObject.FindProperty("references").isExpanded) GUILayout.Space(5);
|
||||
EditorGUILayout.EndVertical();
|
||||
|
||||
if (referencesValid) {
|
||||
|
||||
if (!script.canBuild) {
|
||||
UnityEditor.EditorApplication.isPaused = true;
|
||||
GUILayout.Space(5);
|
||||
|
||||
if (GUILayout.Button("Create a Ragdoll")) {
|
||||
|
||||
script.canBuild = true;
|
||||
}
|
||||
GUILayout.Label("Clears all existing physics components, creates a new ragdoll and starts live-updating. NB! THIS CAN NOT BE UNDONE!", miniLabelStyle);
|
||||
GUILayout.Space(5);
|
||||
}
|
||||
|
||||
if (script.canBuild) {
|
||||
GUI.changed = false;
|
||||
//GUILayout.Space(5);
|
||||
EditorGUILayout.BeginVertical("Box");
|
||||
EditorGUILayout.PropertyField(serializedObject.FindProperty("options"), new GUIContent("Options", "Options for automatic ragdoll generation."), true);
|
||||
|
||||
if (GUI.changed) {
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
EditorUtility.SetDirty(script);
|
||||
}
|
||||
if (serializedObject.FindProperty("options").isExpanded) GUILayout.Space(5);
|
||||
EditorGUILayout.EndVertical();
|
||||
|
||||
BipedRagdollCreator.Create(script.references, script.options);
|
||||
|
||||
GUILayout.Space(10);
|
||||
|
||||
if (GUILayout.Button("Done")) {
|
||||
UnityEditor.EditorApplication.isPaused = false;
|
||||
EditorGUI.indentLevel = indent;
|
||||
DestroyImmediate(script);
|
||||
return;
|
||||
}
|
||||
|
||||
GUILayout.Label("Removes this component.", miniLabelStyle);
|
||||
|
||||
if (GUILayout.Button("Start Editing Manually")) {
|
||||
script.gameObject.AddComponent<RagdollEditor>();
|
||||
EditorGUI.indentLevel = indent;
|
||||
DestroyImmediate(script);
|
||||
return;
|
||||
}
|
||||
|
||||
GUILayout.Label("Replaces this component with the RagdollEditor.", miniLabelStyle);
|
||||
|
||||
GUILayout.Space(10);
|
||||
|
||||
}
|
||||
} else {
|
||||
GUILayout.Space(10);
|
||||
GUILayout.BeginVertical("Box");
|
||||
GUILayout.Label(msg);
|
||||
GUILayout.EndVertical();
|
||||
GUILayout.Space(10);
|
||||
|
||||
if (script.canBuild) RagdollCreator.ClearAll(script.transform);
|
||||
}
|
||||
|
||||
EditorGUI.indentLevel = indent;
|
||||
}
|
||||
|
||||
private static Animator GetAnimatorInParents(Transform transform) {
|
||||
if (transform.GetComponent<Animator>() != null) return transform.GetComponent<Animator>();
|
||||
if (transform.parent == null) return null;
|
||||
return GetAnimatorInParents(transform.parent);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3b4d10c84c3764847812025f2e5986e6
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
@@ -0,0 +1,48 @@
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
|
||||
namespace RootMotion.Dynamics {
|
||||
|
||||
[CustomEditor(typeof(CharacterJoint))]
|
||||
public class CharacterJointInspector : JointInspector {
|
||||
|
||||
private static Color
|
||||
highTwistColor = new Color(1, 0.75f, 0, 0.3f),
|
||||
lowTwistColor = new Color(0.8f, 0.65f, 0, 0.3f),
|
||||
swing1Color = new Color(0, 1, 0, 0.3f),
|
||||
swing2Color = new Color(0, 0, 1, 0.3f);
|
||||
|
||||
public static void DrawJoint(CharacterJoint joint, bool modifiable = true, float alphaMlp = 1f) {
|
||||
if (joint == null) return;
|
||||
|
||||
Vector3 axis = Vector3.zero;
|
||||
if (joint.axis != Vector3.zero) axis = joint.axis.normalized;
|
||||
Vector3 swingAxis = Vector3.zero;
|
||||
if (joint.swingAxis != Vector3.zero) swingAxis = joint.swingAxis.normalized;
|
||||
Vector3 crossAxis = swingAxis;
|
||||
if (swingAxis != axis) crossAxis = Vector3.Cross(swingAxis, axis);
|
||||
|
||||
float newLowTwistLimit = DrawJointLimit(joint as Joint, "Low Twist Limit", axis, joint.lowTwistLimit.limit, MlpAlpha(lowTwistColor, alphaMlp), -25, modifiable);
|
||||
joint.lowTwistLimit = NewJointLimit(newLowTwistLimit, joint.lowTwistLimit, -180, 180);
|
||||
|
||||
float newHighTwistLimit = joint.highTwistLimit.limit;
|
||||
if (newLowTwistLimit != 0 || (newLowTwistLimit == 0 && newHighTwistLimit != 0)) newHighTwistLimit = DrawJointLimit(joint as Joint, "High Twist Limit", axis, joint.highTwistLimit.limit, MlpAlpha(highTwistColor, alphaMlp), 25, modifiable);
|
||||
joint.highTwistLimit = NewJointLimit(newHighTwistLimit, joint.highTwistLimit, -180, 180);
|
||||
|
||||
float newSwing1Limit = DrawJointLimit(joint as Joint, "Swing1 Limit", swingAxis, -joint.swing1Limit.limit, MlpAlpha(swing1Color, alphaMlp), 25, false);
|
||||
newSwing1Limit = DrawJointLimit(joint as Joint, "Swing1 Limit", swingAxis, -newSwing1Limit, MlpAlpha(swing1Color, alphaMlp), 25, modifiable);
|
||||
joint.swing1Limit = NewJointLimit(newSwing1Limit, joint.swing1Limit, 0, 180);
|
||||
|
||||
float newSwing2Limit = DrawJointLimit(joint as Joint, "Swing2 Limit", crossAxis, -joint.swing2Limit.limit, MlpAlpha(swing2Color, alphaMlp), 25, false);
|
||||
newSwing2Limit = DrawJointLimit(joint as Joint, "Swing2 Limit", crossAxis, -newSwing2Limit, MlpAlpha(swing2Color, alphaMlp), 25, modifiable);
|
||||
joint.swing2Limit = NewJointLimit(newSwing2Limit, joint.swing2Limit, 0, 180);
|
||||
}
|
||||
|
||||
public void OnSceneGUI() {
|
||||
DrawJoint(target as CharacterJoint);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: df75c9b4717ec4cf996ae3055c26373e
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
@@ -0,0 +1,250 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using UnityEditor;
|
||||
|
||||
namespace RootMotion.Dynamics {
|
||||
|
||||
// Tools for editing Colliders.
|
||||
public class ColliderTools: Editor {
|
||||
|
||||
public static void ConvertToSphereCollider(CapsuleCollider capsule) {
|
||||
SphereCollider sphere = Undo.AddComponent(capsule.gameObject, typeof(SphereCollider)) as SphereCollider;
|
||||
|
||||
sphere.center = capsule.center;
|
||||
sphere.radius = capsule.radius;
|
||||
|
||||
Undo.DestroyObjectImmediate(capsule);
|
||||
}
|
||||
|
||||
public static void ConvertToSphereCollider(BoxCollider box) {
|
||||
SphereCollider sphere = Undo.AddComponent(box.gameObject, typeof(SphereCollider)) as SphereCollider;
|
||||
|
||||
sphere.center = box.center;
|
||||
sphere.radius = Mathf.Max(new float[3] { box.size.x, box.size.y, box.size.z }) * 0.5f;
|
||||
|
||||
Undo.DestroyObjectImmediate(box);
|
||||
}
|
||||
|
||||
public static void ConvertToBoxCollider(SphereCollider sphere) {
|
||||
BoxCollider box = Undo.AddComponent(sphere.gameObject, typeof(BoxCollider)) as BoxCollider;
|
||||
|
||||
box.center = sphere.center;
|
||||
box.size = Vector3.one * sphere.radius * 2f;
|
||||
|
||||
Undo.DestroyObjectImmediate(sphere);
|
||||
}
|
||||
|
||||
public static void ConvertToCapsuleCollider(SphereCollider sphere) {
|
||||
CapsuleCollider capsule = Undo.AddComponent(sphere.gameObject, typeof(CapsuleCollider)) as CapsuleCollider;
|
||||
|
||||
capsule.center = sphere.center;
|
||||
capsule.radius = sphere.radius;
|
||||
capsule.height = sphere.radius;
|
||||
|
||||
Undo.DestroyObjectImmediate(sphere);
|
||||
}
|
||||
|
||||
public static void ConvertToBoxCollider(CapsuleCollider capsule) {
|
||||
BoxCollider box = Undo.AddComponent(capsule.gameObject, typeof(BoxCollider)) as BoxCollider;
|
||||
|
||||
box.center = capsule.center;
|
||||
|
||||
float diameter = capsule.radius * 2f;
|
||||
float height = Mathf.Max(diameter, capsule.height);
|
||||
|
||||
if (capsule.direction == 0) box.size = new Vector3(height, diameter, diameter);
|
||||
else if (capsule.direction == 1) box.size = new Vector3(diameter, height, diameter);
|
||||
else if (capsule.direction == 2) box.size = new Vector3(diameter, diameter, height);
|
||||
|
||||
Undo.DestroyObjectImmediate(capsule);
|
||||
}
|
||||
|
||||
public static void ConvertToCapsuleCollider(BoxCollider box) {
|
||||
float absX = Mathf.Abs(box.size.x);
|
||||
float absY = Mathf.Abs(box.size.y);
|
||||
float absZ = Mathf.Abs(box.size.z);
|
||||
|
||||
CapsuleCollider capsule = Undo.AddComponent(box.gameObject, typeof(CapsuleCollider)) as CapsuleCollider;
|
||||
|
||||
capsule.center = box.center;
|
||||
|
||||
capsule.direction = 0;
|
||||
if (absY > absX && absY > absZ) capsule.direction = 1;
|
||||
if (absZ > absX && absZ > absY) capsule.direction = 2;
|
||||
|
||||
if (capsule.direction == 0) {
|
||||
capsule.height = absX;
|
||||
capsule.radius = Mathf.Max(absY, absZ) * 0.5f;
|
||||
} else if (capsule.direction == 1) {
|
||||
capsule.height = absY;
|
||||
capsule.radius = Mathf.Max(absX, absZ) * 0.5f;
|
||||
} else if (capsule.direction == 2) {
|
||||
capsule.height = absZ;
|
||||
capsule.radius = Mathf.Max(absX, absY) * 0.5f;
|
||||
}
|
||||
|
||||
Undo.DestroyObjectImmediate(box);
|
||||
}
|
||||
|
||||
public static void SetColliderCenterWorld(Collider r, Collider s, Vector3 value, Transform root) {
|
||||
Vector3 newCenter = r.transform.InverseTransformPoint(value);
|
||||
Vector3 centerWorld = Vector3.zero;
|
||||
Vector3 deltaWorld = Vector3.zero;
|
||||
|
||||
if (r is BoxCollider) {
|
||||
var box = r as BoxCollider;
|
||||
centerWorld = r.transform.TransformPoint(box.center);
|
||||
deltaWorld = value - centerWorld;
|
||||
box.center = newCenter;
|
||||
|
||||
if (s != null && s is BoxCollider) s.transform.GetComponent<BoxCollider>().center += s.transform.InverseTransformVector(SymmetryTools.Mirror(deltaWorld, root));
|
||||
return;
|
||||
}
|
||||
|
||||
if (r is CapsuleCollider) {
|
||||
var capsule = r as CapsuleCollider;
|
||||
centerWorld = r.transform.TransformPoint(capsule.center);
|
||||
deltaWorld = value - centerWorld;
|
||||
capsule.center = newCenter;
|
||||
|
||||
if (s != null && s is CapsuleCollider) s.transform.GetComponent<CapsuleCollider>().center += s.transform.InverseTransformVector(SymmetryTools.Mirror(deltaWorld, root));
|
||||
return;
|
||||
}
|
||||
|
||||
if (r is SphereCollider) {
|
||||
var sphere = r as SphereCollider;
|
||||
centerWorld = r.transform.TransformPoint(sphere.center);
|
||||
deltaWorld = value - centerWorld;
|
||||
sphere.center = newCenter;
|
||||
|
||||
if (s != null && s is SphereCollider) s.transform.GetComponent<SphereCollider>().center += s.transform.InverseTransformVector(SymmetryTools.Mirror(deltaWorld, root));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
public static Vector3 GetColliderCenterWorld(Collider r) {
|
||||
if (r == null) return Vector3.zero;
|
||||
|
||||
if (r is BoxCollider) {
|
||||
return r.transform.TransformPoint((r as BoxCollider).center);
|
||||
}
|
||||
|
||||
if (r is CapsuleCollider) {
|
||||
return r.transform.TransformPoint((r as CapsuleCollider).center);
|
||||
}
|
||||
|
||||
if (r is SphereCollider) {
|
||||
return r.transform.TransformPoint((r as SphereCollider).center);
|
||||
}
|
||||
|
||||
return r.transform.position;
|
||||
}
|
||||
|
||||
public static void SetColliderSize(Collider r, Collider s, Vector3 value, Vector3 lastValue, Vector3 lastValueS, Transform root) {
|
||||
Vector3 delta = Vector3.zero;
|
||||
Vector3 deltaM = Vector3.zero;
|
||||
|
||||
if (r is BoxCollider) {
|
||||
var box = r as BoxCollider;
|
||||
delta = value - box.size;
|
||||
box.size = value;
|
||||
|
||||
if (s != null && s is BoxCollider) {
|
||||
var boxS = s as BoxCollider;
|
||||
|
||||
deltaM = SymmetryTools.MirrorDelta(r.transform, s.transform, root, delta);
|
||||
boxS.size += deltaM;
|
||||
}
|
||||
}
|
||||
|
||||
if (r is CapsuleCollider) {
|
||||
var capsule = r as CapsuleCollider;
|
||||
|
||||
delta = value - GetCapsuleSize(capsule);
|
||||
SetCapsuleSize(capsule, value, lastValue);
|
||||
|
||||
if (s != null && s is CapsuleCollider) {
|
||||
var capsuleS = s as CapsuleCollider;
|
||||
|
||||
if (capsuleS != null) {
|
||||
deltaM = SymmetryTools.MirrorDelta(r.transform, s.transform, root, delta);
|
||||
Vector3 capsuleSSize = GetCapsuleSize(capsuleS);
|
||||
capsuleSSize += deltaM;
|
||||
|
||||
SetCapsuleSize(capsuleS, capsuleSSize, lastValueS);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (r is SphereCollider) {
|
||||
var sphere = r as SphereCollider;
|
||||
|
||||
delta = value - GetColliderSize(r);
|
||||
SetSphereSize(sphere, value, lastValue);
|
||||
|
||||
if (s != null && s is SphereCollider) {
|
||||
var sphereS = s as SphereCollider;
|
||||
Vector3 sphereSSize = GetColliderSize(s);
|
||||
sphereSSize += delta;
|
||||
|
||||
if (sphereS != null) {
|
||||
SetSphereSize(sphereS, sphereSSize, lastValueS);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static Vector3 GetColliderSize(Collider r) {
|
||||
if (r == null) return Vector3.zero;
|
||||
|
||||
if (r is BoxCollider) return (r as BoxCollider).size;
|
||||
if (r is CapsuleCollider) return GetCapsuleSize(r as CapsuleCollider);
|
||||
if (r is SphereCollider) return Vector3.one * (r as SphereCollider).radius;
|
||||
|
||||
return r.transform.localScale;
|
||||
}
|
||||
|
||||
public static void SetCapsuleSize(CapsuleCollider capsule, Vector3 size, Vector3 lastSize) {
|
||||
if (capsule.direction == 0) {
|
||||
capsule.height = size.x;
|
||||
|
||||
float absY = Mathf.Abs(size.y - lastSize.y);
|
||||
float absZ = Mathf.Abs(size.z - lastSize.z);
|
||||
capsule.radius = absY > absZ? size.y: size.z;
|
||||
}
|
||||
|
||||
if (capsule.direction == 1) {
|
||||
capsule.height = size.y;
|
||||
|
||||
float absX = Mathf.Abs(size.x - lastSize.x);
|
||||
float absZ = Mathf.Abs(size.z - lastSize.z);
|
||||
capsule.radius = absX > absZ? size.x: size.z;
|
||||
}
|
||||
|
||||
if (capsule.direction == 2) {
|
||||
capsule.height = size.z;
|
||||
|
||||
float absX = Mathf.Abs(size.x - lastSize.x);
|
||||
float absY = Mathf.Abs(size.y - lastSize.y);
|
||||
capsule.radius = absX > absY? size.x: size.y;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static void SetSphereSize(SphereCollider sphere, Vector3 size, Vector3 lastSize) {
|
||||
if (size.x != lastSize.z) {
|
||||
sphere.radius += size.x - lastSize.x;
|
||||
} else if (size.y != lastSize.y) {
|
||||
sphere.radius += size.y - lastSize.y;
|
||||
} else if (size.z != lastSize.z) {
|
||||
sphere.radius += size.z - lastSize.z;
|
||||
}
|
||||
}
|
||||
|
||||
public static Vector3 GetCapsuleSize(CapsuleCollider capsule) {
|
||||
if (capsule.direction == 0) return new Vector3(capsule.height, capsule.radius, capsule.radius);
|
||||
if (capsule.direction == 1) return new Vector3(capsule.radius, capsule.height, capsule.radius);
|
||||
return new Vector3(capsule.radius, capsule.radius, capsule.height);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9ed7bfe787e81435c8b76e75353a45fb
|
||||
timeCreated: 1444653054
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,56 @@
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
|
||||
namespace RootMotion.Dynamics {
|
||||
|
||||
[CustomEditor(typeof(ConfigurableJoint))]
|
||||
public class ConfigurableJointInspector : JointInspector {
|
||||
|
||||
private static Color
|
||||
highAngularXColor = new Color(1, 0.75f, 0, 0.3f),
|
||||
lowAngularXColor = new Color(0.8f, 0.65f, 0, 0.3f),
|
||||
angularYColor = new Color(0, 1, 0, 0.3f),
|
||||
angularZColor = new Color(0, 0, 1, 0.3f);
|
||||
|
||||
private const string lowX = "Low X", highX = "High X", y = "Y", z = "Z";
|
||||
|
||||
public static void DrawJoint(ConfigurableJoint joint, bool modifiable = true, float alphaMlp = 1f) {
|
||||
if (joint == null) return;
|
||||
|
||||
Vector3 axis = Vector3.zero;
|
||||
if (joint.axis != Vector3.zero) axis = joint.axis.normalized;
|
||||
Vector3 secondaryAxis = Vector3.zero;
|
||||
if (joint.secondaryAxis != Vector3.zero) secondaryAxis = joint.secondaryAxis.normalized;
|
||||
Vector3 crossAxis = secondaryAxis;
|
||||
if (secondaryAxis != axis) crossAxis = Vector3.Cross(secondaryAxis, axis);
|
||||
|
||||
if (joint.angularXMotion == ConfigurableJointMotion.Limited) {
|
||||
float newLowAngularXLimit = DrawJointLimit(joint as Joint, lowX, axis, joint.lowAngularXLimit.limit, MlpAlpha(lowAngularXColor, alphaMlp), -25, modifiable);
|
||||
joint.lowAngularXLimit = NewJointLimit(newLowAngularXLimit, joint.lowAngularXLimit, -180, 180);
|
||||
|
||||
float newHighAngularXLimit = joint.highAngularXLimit.limit;
|
||||
if (newLowAngularXLimit != 0 || (newLowAngularXLimit == 0 && newHighAngularXLimit != 0)) newHighAngularXLimit = DrawJointLimit(joint as Joint, highX, axis, joint.highAngularXLimit.limit, MlpAlpha(highAngularXColor, alphaMlp), 25, modifiable);
|
||||
joint.highAngularXLimit = NewJointLimit(newHighAngularXLimit, joint.highAngularXLimit, -180, 180);
|
||||
}
|
||||
|
||||
if (joint.angularYMotion == ConfigurableJointMotion.Limited) {
|
||||
float newAngularYLimit = DrawJointLimit(joint as Joint, y, secondaryAxis, -joint.angularYLimit.limit, MlpAlpha(angularYColor, alphaMlp), 25, false);
|
||||
newAngularYLimit = DrawJointLimit(joint as Joint, y, secondaryAxis, -newAngularYLimit, MlpAlpha(angularYColor, alphaMlp), 25, modifiable);
|
||||
joint.angularYLimit = NewJointLimit(newAngularYLimit, joint.angularYLimit, 0, 180);
|
||||
}
|
||||
|
||||
if (joint.angularZMotion == ConfigurableJointMotion.Limited) {
|
||||
float newAngularZLimit = DrawJointLimit(joint as Joint, z, crossAxis, -joint.angularZLimit.limit, MlpAlpha(angularZColor, alphaMlp), 25, false);
|
||||
newAngularZLimit = DrawJointLimit(joint as Joint, z, crossAxis, -newAngularZLimit, MlpAlpha(angularZColor, alphaMlp), 25, modifiable);
|
||||
joint.angularZLimit = NewJointLimit(newAngularZLimit, joint.angularZLimit, 0, 180);
|
||||
}
|
||||
}
|
||||
|
||||
public void OnSceneGUI() {
|
||||
DrawJoint(target as ConfigurableJoint);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 79e48320bea5b4a49a128eabdb1b39b2
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
@@ -0,0 +1,27 @@
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
|
||||
namespace RootMotion.Dynamics {
|
||||
|
||||
/// <summary>
|
||||
/// Converting 3D joints to ConfigurableJoints
|
||||
/// </summary>
|
||||
public class ConvertToConfigurableJoints: Editor {
|
||||
|
||||
/// <summary>
|
||||
/// Converts any 3D joints on the selected Transform and it's children to ConfigurableJoints
|
||||
/// </summary>
|
||||
//[MenuItem ("Component/Physics/Convert to ConfigurableJoints")]
|
||||
[MenuItem ("GameObject/Convert to ConfigurableJoints")]
|
||||
public static void ConvertSelected() {
|
||||
if (Selection.activeGameObject == null) {
|
||||
Debug.Log("Please select the root of the ragdoll that you wish to convert to use ConfigurableJoints.");
|
||||
return;
|
||||
}
|
||||
|
||||
// @todo undo
|
||||
|
||||
JointConverter.ToConfigurable(Selection.activeGameObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5c49a237763c444bda35d3387fed6c35
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
@@ -0,0 +1,25 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
|
||||
namespace RootMotion.Dynamics
|
||||
{
|
||||
public class DragRig : MonoBehaviour
|
||||
{
|
||||
|
||||
private Rigidbody rig;
|
||||
private void Start()
|
||||
{
|
||||
rig = transform.GetComponent<Rigidbody>();
|
||||
}
|
||||
private void OnMouseDrag()
|
||||
{
|
||||
Vector3 cursorPos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
|
||||
rig.AddForce(0.01f * Time.deltaTime * (cursorPos-transform.position).normalized,ForceMode.Force);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b32271905ed4afe44b53328a916f382a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,139 @@
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace RootMotion.Dynamics {
|
||||
|
||||
public class JointInspector : Editor {
|
||||
|
||||
#region Public methods
|
||||
|
||||
private static bool isDragging;
|
||||
|
||||
public static float DrawJointLimit(Joint joint, string label, Vector3 axis, float limit, Color color, float openValue, bool drawHandles) {
|
||||
if (Event.current.type == EventType.MouseDown) isDragging = false;
|
||||
if (Event.current.type == EventType.MouseUp) isDragging = false;
|
||||
|
||||
float radius = HandleUtility.GetHandleSize(joint.transform.position);
|
||||
Vector3 center = joint.transform.TransformPoint(joint.anchor);
|
||||
|
||||
Quaternion axisOffset = Quaternion.AngleAxis(GetViewOffset(joint, axis), axis);
|
||||
Vector3 limitAxis = joint.transform.TransformDirection(axisOffset * axis).normalized;
|
||||
Vector3 limitAxisOrtho = joint.transform.TransformDirection(axisOffset * new Vector3(axis.z, axis.x, axis.y)).normalized;
|
||||
Vector3 limitAxisCross = Vector3.Cross(limitAxis, limitAxisOrtho);
|
||||
|
||||
Handles.color = color;
|
||||
Handles.DrawSolidArc(center, limitAxis, limitAxisCross, -limit, radius);
|
||||
|
||||
Handles.color = new Color(color.r, color.g, color.b, 1f);
|
||||
GUI.color = new Color(color.r, color.g, color.b, 1f);
|
||||
|
||||
//if (limitAxis != Vector3.zero) Handles.CircleCap(0, center, Quaternion.LookRotation(limitAxis), radius);
|
||||
|
||||
Quaternion angleAxis = Quaternion.AngleAxis(-limit, limitAxis);
|
||||
Vector3 handleVector = angleAxis * limitAxisCross;
|
||||
|
||||
Quaternion handleRotation = Quaternion.AngleAxis(-limit, limitAxis);
|
||||
if (limitAxisCross != Vector3.zero && limitAxisOrtho != Vector3.zero) {
|
||||
handleRotation = Quaternion.AngleAxis(-limit, limitAxis) * Quaternion.LookRotation(limitAxisCross) * Quaternion.LookRotation(limitAxisOrtho);
|
||||
}
|
||||
|
||||
if (!drawHandles) return limit;
|
||||
|
||||
float newLimit = Inspector.ScaleValueHandleSphere(limit, center + handleVector * radius, Quaternion.identity, radius, 1);
|
||||
//float newLimit = Handles.han(handleRotation, center + handleVector * radius, limit);
|
||||
|
||||
string labelInfo = label;
|
||||
|
||||
if (newLimit == 0) {
|
||||
labelInfo = "Open " + label;
|
||||
if (Inspector.SphereButton(center + handleVector * radius, handleRotation, radius * 0.2f, radius * 0.07f)) {
|
||||
newLimit = openValue;
|
||||
}
|
||||
}
|
||||
|
||||
Handles.Label(center + handleVector * radius * 1.2f, labelInfo);
|
||||
|
||||
if (newLimit != limit) {
|
||||
if (!isDragging) {
|
||||
Undo.RecordObject(joint, "Change Joint Limits");
|
||||
isDragging = true;
|
||||
}
|
||||
}
|
||||
|
||||
GUI.color = Color.white;
|
||||
return newLimit;
|
||||
}
|
||||
|
||||
public static SoftJointLimit NewJointLimit(float limit, SoftJointLimit referenceJointLimit, float min, float max) {
|
||||
SoftJointLimit newJointLimit = new SoftJointLimit();
|
||||
newJointLimit.limit = Mathf.Clamp(limit, min, max);
|
||||
newJointLimit.bounciness = referenceJointLimit.bounciness;
|
||||
return newJointLimit;
|
||||
}
|
||||
|
||||
public static Color MlpAlpha(Color color, float alphaMlp) {
|
||||
return new Color(color.r, color.g, color.b, color.a * alphaMlp);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private static float GetViewOffset(Joint joint, Vector3 axis) {
|
||||
if (joint.connectedBody == null) return 0;
|
||||
|
||||
Vector3 directionAxis = joint.transform.right;
|
||||
Axis viewAxis = GetViewAxis(joint);
|
||||
|
||||
switch(viewAxis) {
|
||||
case Axis.Y: directionAxis = joint.transform.up; break;
|
||||
case Axis.Z: directionAxis = joint.transform.forward; break;
|
||||
}
|
||||
|
||||
if (FlipAxis(joint, viewAxis)) directionAxis = -directionAxis;
|
||||
|
||||
Vector3 axisWorld = joint.transform.TransformDirection(axis).normalized;
|
||||
Vector3 axisWorldOrtho = joint.transform.TransformDirection(new Vector3(axis.z, axis.x, axis.y)).normalized;
|
||||
|
||||
float dot = Vector3.Dot(axisWorldOrtho, directionAxis);
|
||||
float dot2 = Vector3.Dot(axisWorldOrtho, Vector3.Cross(directionAxis, axisWorld));
|
||||
|
||||
if (dot >= 0.5f) return -90;
|
||||
if (dot2 >= 0.5f) return 0;
|
||||
if (dot < -0.5f) return 90;
|
||||
if (dot2 < -0.5f) return 180;
|
||||
return 0;
|
||||
}
|
||||
|
||||
private static Axis GetViewAxis(Joint joint) {
|
||||
if (joint.connectedBody == null) return Axis.Z;
|
||||
|
||||
CapsuleCollider capsule = joint.GetComponent<CapsuleCollider>();
|
||||
if (capsule != null && capsule.center != Vector3.zero) return AxisTools.ToAxis(capsule.center);
|
||||
else {
|
||||
BoxCollider box = joint.GetComponent<BoxCollider>();
|
||||
if (box != null && box.center != Vector3.zero) return AxisTools.ToAxis(box.center);
|
||||
}
|
||||
|
||||
return AxisTools.GetAxisToPoint(joint.transform, joint.connectedBody.worldCenterOfMass);
|
||||
}
|
||||
|
||||
private static bool FlipAxis(Joint joint, Axis axis) {
|
||||
Vector3 direction = Vector3.Normalize(joint.transform.position - joint.connectedBody.worldCenterOfMass);
|
||||
|
||||
CapsuleCollider capsuleCollider = joint.GetComponent<CapsuleCollider>();
|
||||
if (capsuleCollider != null) {
|
||||
direction = Vector3.Normalize(joint.transform.position - (joint.transform.position - (joint.transform.rotation * capsuleCollider.center)));
|
||||
}
|
||||
|
||||
switch(axis) {
|
||||
case Axis.X:
|
||||
return Vector3.Dot(joint.transform.right, direction) < 0;
|
||||
case Axis.Y:
|
||||
return Vector3.Dot(joint.transform.up, direction) < 0;
|
||||
default: return Vector3.Dot(joint.transform.forward, direction) < 0;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2c166e20a769d4ec3a0f504c4fa3ffe7
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
@@ -0,0 +1,276 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using UnityEditor;
|
||||
|
||||
namespace RootMotion.Dynamics {
|
||||
|
||||
public enum JointAxis {
|
||||
Primary,
|
||||
Secondary,
|
||||
Tertiary
|
||||
}
|
||||
|
||||
// Tools for editing Joints.
|
||||
public class JointTools: Editor {
|
||||
|
||||
public static Quaternion LocalToJointSpace(ConfigurableJoint joint) {
|
||||
Vector3 forward = Vector3.Cross (joint.axis, joint.secondaryAxis).normalized;
|
||||
Vector3 up = Vector3.Cross(forward, joint.axis).normalized;
|
||||
|
||||
if (forward == up) {
|
||||
Debug.LogWarning("Joint " + joint.name + " secondaryAxis is in the exact same direction as it's axis. Please make sure they are not aligned.");
|
||||
}
|
||||
|
||||
return Quaternion.LookRotation(forward, up);
|
||||
}
|
||||
|
||||
public static Quaternion LocalToJointSpace(CharacterJoint joint) {
|
||||
Vector3 forward = Vector3.Cross (joint.axis, joint.swingAxis).normalized;
|
||||
Vector3 up = Vector3.Cross(forward, joint.axis).normalized;
|
||||
|
||||
if (forward == up) {
|
||||
Debug.LogWarning("Joint " + joint.name + " swingAxis is in the exact same direction as it's axis. Please make sure they are not aligned.");
|
||||
}
|
||||
|
||||
return Quaternion.LookRotation(forward, up);
|
||||
}
|
||||
|
||||
public static Quaternion JointToLocalSpace(ConfigurableJoint joint) {
|
||||
return Quaternion.Inverse(LocalToJointSpace(joint));
|
||||
}
|
||||
|
||||
public static Quaternion JointToLocalSpace(CharacterJoint joint) {
|
||||
return Quaternion.Inverse(LocalToJointSpace(joint));
|
||||
}
|
||||
|
||||
public static JointAxis GetJointAxis(ConfigurableJoint joint, Vector3 vLocal) {
|
||||
return GetJointAxis(joint.axis, joint.secondaryAxis, vLocal);
|
||||
}
|
||||
|
||||
public static JointAxis GetJointAxis(CharacterJoint joint, Vector3 vLocal) {
|
||||
return GetJointAxis(joint.axis, joint.swingAxis, vLocal);
|
||||
}
|
||||
|
||||
public static JointAxis GetJointAxis(Vector3 axis, Vector3 secondaryAxis, Vector3 vLocal) {
|
||||
vLocal = vLocal.normalized;
|
||||
|
||||
float axisDot = Mathf.Abs(Vector3.Dot(axis, vLocal));
|
||||
float secondaryAxisDot = Mathf.Abs(Vector3.Dot(secondaryAxis, vLocal));
|
||||
float tertiaryAxisDot = Mathf.Abs(Vector3.Dot(Vector3.Cross(axis, secondaryAxis), vLocal));
|
||||
|
||||
if (axisDot > secondaryAxisDot && axisDot > tertiaryAxisDot) return JointAxis.Primary;
|
||||
if (secondaryAxisDot > axisDot && secondaryAxisDot > tertiaryAxisDot) return JointAxis.Secondary;
|
||||
return JointAxis.Tertiary;
|
||||
}
|
||||
|
||||
public static JointAxis GetSymmetricJointAxis(ConfigurableJoint joint, JointAxis jointAxis, ConfigurableJoint symmetricJoint, Transform root) {
|
||||
return GetSymmetricJointAxis(joint.transform, joint.axis, joint.secondaryAxis, jointAxis, symmetricJoint.transform, symmetricJoint.axis, symmetricJoint.secondaryAxis, root);
|
||||
}
|
||||
|
||||
public static JointAxis GetSymmetricJointAxis(CharacterJoint joint, JointAxis jointAxis, CharacterJoint symmetricJoint, Transform root) {
|
||||
return GetSymmetricJointAxis(joint.transform, joint.axis, joint.swingAxis, jointAxis, symmetricJoint.transform, symmetricJoint.axis, symmetricJoint.swingAxis, root);
|
||||
}
|
||||
|
||||
public static JointAxis GetSymmetricJointAxis(Transform jointTransform, Vector3 axis, Vector3 secondaryAxis, JointAxis jointAxis, Transform symmetricTransform, Vector3 symmetricAxis, Vector3 symmetricSecondaryAxis, Transform root) {
|
||||
Vector3 a = JointAxisToVector3(axis, secondaryAxis, jointAxis);
|
||||
Vector3 aWorld = jointTransform.rotation * a;
|
||||
|
||||
Vector3 aWorldMirror = SymmetryTools.Mirror(aWorld, root);
|
||||
Vector3 aLocalMirror = Quaternion.Inverse(symmetricTransform.rotation) * aWorldMirror;
|
||||
|
||||
Vector3 sAVector = AxisTools.GetAxisVectorToDirection(symmetricTransform, aWorldMirror);
|
||||
Vector3 sA = Vector3.Project(aLocalMirror, sAVector);
|
||||
|
||||
return GetJointAxis(symmetricAxis, symmetricSecondaryAxis, sA);
|
||||
}
|
||||
|
||||
public static Vector3 JointAxisToVector3(ConfigurableJoint joint, JointAxis jointAxis) {
|
||||
return JointAxisToVector3(joint.axis, joint.secondaryAxis, jointAxis);
|
||||
}
|
||||
|
||||
public static Vector3 JointAxisToVector3(CharacterJoint joint, JointAxis jointAxis) {
|
||||
return JointAxisToVector3(joint.axis, joint.swingAxis, jointAxis);
|
||||
}
|
||||
|
||||
public static Vector3 JointAxisToVector3(Vector3 axis, Vector3 secondaryAxis, JointAxis jointAxis) {
|
||||
switch(jointAxis) {
|
||||
case JointAxis.Primary: return axis;
|
||||
case JointAxis.Secondary: return secondaryAxis;
|
||||
default: return Vector3.Cross(axis, secondaryAxis);
|
||||
}
|
||||
}
|
||||
|
||||
public static void ApplyXDeltaToJointLimit(ref ConfigurableJoint joint, float delta, JointAxis jointAxis, bool low) {
|
||||
switch(jointAxis) {
|
||||
case JointAxis.Primary:
|
||||
if (low) {
|
||||
SoftJointLimit lowX = joint.lowAngularXLimit;
|
||||
lowX.limit += delta;
|
||||
joint.lowAngularXLimit = lowX;
|
||||
} else {
|
||||
SoftJointLimit highX = joint.highAngularXLimit;
|
||||
highX.limit -= delta;
|
||||
joint.highAngularXLimit = highX;
|
||||
}
|
||||
break;
|
||||
case JointAxis.Secondary:
|
||||
SoftJointLimit y = joint.angularYLimit;
|
||||
y.limit += delta * 0.5f;
|
||||
joint.angularYLimit = y;
|
||||
break;
|
||||
case JointAxis.Tertiary:
|
||||
SoftJointLimit z = joint.angularZLimit;
|
||||
z.limit += delta * 0.5f;
|
||||
joint.angularZLimit = z;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public static void ApplyXDeltaToJointLimit(ref CharacterJoint joint, float delta, JointAxis jointAxis, bool low) {
|
||||
switch(jointAxis) {
|
||||
case JointAxis.Primary:
|
||||
if (low) {
|
||||
SoftJointLimit lowX = joint.lowTwistLimit;
|
||||
lowX.limit += delta;
|
||||
joint.lowTwistLimit = lowX;
|
||||
} else {
|
||||
SoftJointLimit highX = joint.highTwistLimit;
|
||||
highX.limit -= delta;
|
||||
joint.highTwistLimit = highX;
|
||||
}
|
||||
break;
|
||||
case JointAxis.Secondary:
|
||||
SoftJointLimit y = joint.swing1Limit;
|
||||
y.limit += delta * 0.5f;
|
||||
joint.swing1Limit = y;
|
||||
break;
|
||||
case JointAxis.Tertiary:
|
||||
SoftJointLimit z = joint.swing2Limit;
|
||||
z.limit += delta * 0.5f;
|
||||
joint.swing2Limit = z;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public static void ApplyDeltaToJointLimit(ref ConfigurableJoint joint, float delta, JointAxis jointAxis) {
|
||||
switch(jointAxis) {
|
||||
case JointAxis.Primary:
|
||||
SoftJointLimit lowX = joint.lowAngularXLimit;
|
||||
lowX.limit += delta;
|
||||
joint.lowAngularXLimit = lowX;
|
||||
|
||||
SoftJointLimit highX = joint.highAngularXLimit;
|
||||
highX.limit += delta;
|
||||
joint.highAngularXLimit = highX;
|
||||
break;
|
||||
case JointAxis.Secondary:
|
||||
SoftJointLimit y = joint.angularYLimit;
|
||||
y.limit += delta;
|
||||
joint.angularYLimit = y;
|
||||
break;
|
||||
case JointAxis.Tertiary:
|
||||
SoftJointLimit z = joint.angularZLimit;
|
||||
z.limit += delta;
|
||||
joint.angularZLimit = z;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public static void ApplyDeltaToJointLimit(ref CharacterJoint joint, float delta, JointAxis jointAxis) {
|
||||
switch(jointAxis) {
|
||||
case JointAxis.Primary:
|
||||
SoftJointLimit lowX = joint.lowTwistLimit;
|
||||
lowX.limit += delta;
|
||||
joint.lowTwistLimit = lowX;
|
||||
|
||||
SoftJointLimit highX = joint.highTwistLimit;
|
||||
highX.limit += delta;
|
||||
joint.highTwistLimit = highX;
|
||||
break;
|
||||
case JointAxis.Secondary:
|
||||
SoftJointLimit y = joint.swing1Limit;
|
||||
y.limit += delta;
|
||||
joint.swing1Limit = y;
|
||||
break;
|
||||
case JointAxis.Tertiary:
|
||||
SoftJointLimit z = joint.swing2Limit;
|
||||
z.limit += delta;
|
||||
joint.swing2Limit = z;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public static Vector3 GetLowXAxisWorld(Joint joint) {
|
||||
return joint.transform.rotation * joint.axis;
|
||||
}
|
||||
|
||||
public static Vector3 GetHighXAxisWorld(Joint joint) {
|
||||
return joint.transform.rotation * -joint.axis;
|
||||
}
|
||||
|
||||
public static void SwitchXY(ref ConfigurableJoint joint) {
|
||||
Undo.RecordObject(joint, "Switch Yellow/Green Joint Axis");
|
||||
|
||||
Vector3 axis = joint.axis;
|
||||
joint.axis = joint.secondaryAxis;
|
||||
joint.secondaryAxis = axis;
|
||||
}
|
||||
|
||||
public static void SwitchXZ(ref ConfigurableJoint joint) {
|
||||
Undo.RecordObject(joint, "Switch Yellow/Blue Joint Axis");
|
||||
|
||||
Vector3 cross = Vector3.Cross(joint.axis, joint.secondaryAxis).normalized;
|
||||
joint.axis = cross;
|
||||
}
|
||||
|
||||
public static void SwitchYZ(ref ConfigurableJoint joint) {
|
||||
Undo.RecordObject(joint, "Switch Green/Blue Joint Axis");
|
||||
|
||||
Vector3 cross = Vector3.Cross(joint.axis, joint.secondaryAxis).normalized;
|
||||
joint.secondaryAxis = cross;
|
||||
}
|
||||
|
||||
public static void SwitchXY(ref CharacterJoint joint) {
|
||||
Undo.RecordObject(joint, "Switch Yellow/Green Joint Axis");
|
||||
|
||||
Vector3 axis = joint.axis;
|
||||
joint.axis = joint.swingAxis;
|
||||
joint.swingAxis = axis;
|
||||
}
|
||||
|
||||
public static void SwitchXZ(ref CharacterJoint joint) {
|
||||
Undo.RecordObject(joint, "Switch Yellow/Blue Joint Axis");
|
||||
|
||||
Vector3 cross = Vector3.Cross(joint.axis, joint.swingAxis).normalized;
|
||||
joint.axis = cross;
|
||||
}
|
||||
|
||||
public static void SwitchYZ(ref CharacterJoint joint) {
|
||||
Undo.RecordObject(joint, "Switch Green/Blue Joint Axis");
|
||||
|
||||
Vector3 cross = Vector3.Cross(joint.axis, joint.swingAxis).normalized;
|
||||
joint.swingAxis = cross;
|
||||
}
|
||||
|
||||
public static void InvertAxis(ref Joint joint) {
|
||||
Undo.RecordObject(joint, "Invert Axis");
|
||||
|
||||
joint.axis = -joint.axis;
|
||||
}
|
||||
|
||||
public static void InvertSecondaryAxis(ref Joint joint) {
|
||||
if (joint is ConfigurableJoint) {
|
||||
var j = joint as ConfigurableJoint;
|
||||
Undo.RecordObject(j, "Invert Secondary Axis");
|
||||
j.secondaryAxis = -j.secondaryAxis;
|
||||
}
|
||||
|
||||
if (joint is CharacterJoint) {
|
||||
var j = joint as CharacterJoint;
|
||||
Undo.RecordObject(j, "Invert Swing Axis");
|
||||
j.swingAxis = -j.swingAxis;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7d88fb763cb86436197038e855690500
|
||||
timeCreated: 1444653109
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,566 @@
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using System.Collections;
|
||||
using RootMotion;
|
||||
|
||||
namespace RootMotion.Dynamics {
|
||||
|
||||
[CustomEditor(typeof(RagdollEditor))]
|
||||
public class RagdollEditorInspector : Editor {
|
||||
|
||||
public RagdollEditor script { get { return target as RagdollEditor; }}
|
||||
|
||||
private float massMlp = 1f;
|
||||
private Transform t;
|
||||
private bool isDragging;
|
||||
|
||||
public override void OnInspectorGUI() {
|
||||
DrawDefaultInspector();
|
||||
GUILayout.Space(10);
|
||||
|
||||
EditorGUILayout.LabelField("Rigidbodies", EditorStyles.boldLabel);
|
||||
|
||||
GUILayout.BeginHorizontal();
|
||||
massMlp = EditorGUILayout.FloatField("Mass Multiplier", massMlp);
|
||||
if (massMlp <= 0f) massMlp = 0.00001f;
|
||||
|
||||
if (GUILayout.Button(new GUIContent("Multiply", "Multiplies the mass of all child Rigidbodies."))) {
|
||||
Rigidbody[] rigidbodies = GetRigidbodies();
|
||||
Undo.RecordObjects(rigidbodies, "Multiply Mass");
|
||||
|
||||
float totalMass = 0f;
|
||||
foreach (Rigidbody r in rigidbodies) {
|
||||
r.mass *= massMlp;
|
||||
totalMass += r.mass;
|
||||
}
|
||||
Debug.Log("Character mass: " + totalMass);
|
||||
}
|
||||
GUILayout.EndHorizontal();
|
||||
|
||||
GUILayout.BeginHorizontal();
|
||||
if (GUILayout.Button(new GUIContent("Set All Kinematic", "Enables 'Is Kinematic' on all child Rigidbodies."))) {
|
||||
Rigidbody[] rigidbodies = GetRigidbodies();
|
||||
Undo.RecordObjects(rigidbodies, "Set All Kinematic");
|
||||
|
||||
foreach (Rigidbody r in rigidbodies) {
|
||||
r.isKinematic = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (GUILayout.Button(new GUIContent("Set All Non-Kinematic", "Disables 'Is Kinematic' on all child Rigidbodies."))) {
|
||||
Rigidbody[] rigidbodies = GetRigidbodies();
|
||||
Undo.RecordObjects(rigidbodies, "Set All Non-Kinematic");
|
||||
|
||||
foreach (Rigidbody r in rigidbodies) {
|
||||
r.isKinematic = false;
|
||||
}
|
||||
}
|
||||
GUILayout.EndHorizontal();
|
||||
|
||||
GUILayout.Space(10);
|
||||
|
||||
EditorGUILayout.LabelField("Joints", EditorStyles.boldLabel);
|
||||
|
||||
GUILayout.BeginHorizontal();
|
||||
if (GUILayout.Button(new GUIContent("Disable Preprocessing", "Unchecks 'Enable Preprocessing' on all joints. This can make ragdolls more stable."))) {
|
||||
Joint[] joints = GetJoints();
|
||||
Undo.RecordObjects(joints, "Disable Preprocessing");
|
||||
|
||||
foreach (Joint j in joints) {
|
||||
j.enablePreprocessing = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (GUILayout.Button(new GUIContent("Enable Preprocessing", "Checks 'Enable Preprocessing' on all joints."))) {
|
||||
Joint[] joints = GetJoints();
|
||||
Undo.RecordObjects(joints, "Enable Preprocessing");
|
||||
|
||||
foreach (Joint j in joints) {
|
||||
j.enablePreprocessing = true;
|
||||
}
|
||||
}
|
||||
GUILayout.EndHorizontal();
|
||||
|
||||
GUILayout.Space(10);
|
||||
|
||||
|
||||
GUILayout.Label("Use the Scene View gizmos to edit Colliders and Joint limits", EditorStyles.miniLabel);
|
||||
}
|
||||
|
||||
private Rigidbody[] GetRigidbodies() {
|
||||
return (Rigidbody[])script.GetComponentsInChildren<Rigidbody>();
|
||||
}
|
||||
|
||||
private Joint[] GetJoints() {
|
||||
return (Joint[])script.GetComponentsInChildren<Joint>();
|
||||
}
|
||||
|
||||
void OnEnable() {
|
||||
t = script.transform;
|
||||
}
|
||||
|
||||
void OnDisable() {
|
||||
if (script == null) return;
|
||||
|
||||
Collider[] colliders = script.transform.GetComponentsInChildren<Collider>();
|
||||
foreach (Collider collider in colliders) collider.enabled = true;
|
||||
}
|
||||
|
||||
void OnDestroy() {
|
||||
if (t == null) return;
|
||||
|
||||
Collider[] colliders = t.GetComponentsInChildren<Collider>();
|
||||
foreach (Collider collider in colliders) collider.enabled = true;
|
||||
}
|
||||
|
||||
void OnSceneGUI() {
|
||||
Rigidbody[] rigidbodies = script.transform.GetComponentsInChildren<Rigidbody>();
|
||||
if (rigidbodies.Length == 0) return;
|
||||
|
||||
Collider[] colliders = script.transform.GetComponentsInChildren<Collider>();
|
||||
|
||||
if (script.selectedRigidbody == null) script.selectedRigidbody = rigidbodies[0];
|
||||
if (script.selectedCollider == null && colliders.Length > 0) script.selectedCollider = colliders[0];
|
||||
|
||||
Rigidbody symmetricRigidbody = script.symmetry && script.selectedRigidbody != null? SymmetryTools.GetSymmetric(script.selectedRigidbody, rigidbodies, script.transform): null;
|
||||
Collider symmetricCollider = script.symmetry && script.selectedCollider != null? SymmetryTools.GetSymmetric(script.selectedCollider, colliders, script.transform): null;
|
||||
|
||||
Joint joint = script.selectedRigidbody != null? script.selectedRigidbody.GetComponent<Joint>(): null;
|
||||
Joint symmetricJoint = joint != null && symmetricRigidbody != null? symmetricRigidbody.GetComponent<Joint>(): null;
|
||||
|
||||
// Selected
|
||||
Transform selected = script.mode == RootMotion.Dynamics.RagdollEditor.Mode.Colliders? (script.selectedCollider != null? script.selectedCollider.transform: null): (script.selectedRigidbody != null? script.selectedRigidbody.transform: null);
|
||||
|
||||
if (selected != null) {
|
||||
Handles.BeginGUI();
|
||||
GUILayout.BeginVertical(new GUIContent("Ragdoll Editor", string.Empty), "Window", GUILayout.Width(200), GUILayout.Height(20));
|
||||
GUILayout.BeginHorizontal();
|
||||
GUILayout.Label(selected.name);
|
||||
if (GUILayout.Button("Select GameObject", EditorStyles.miniButton)) {
|
||||
Selection.activeGameObject = selected.gameObject;
|
||||
}
|
||||
GUILayout.EndHorizontal();
|
||||
|
||||
GUILayout.Space(10);
|
||||
|
||||
//GUILayout.BeginVertical("Box");
|
||||
|
||||
GUILayout.BeginHorizontal();
|
||||
GUILayout.Label("Edit Mode", GUILayout.Width(86));
|
||||
script.mode = (RagdollEditor.Mode)EditorGUILayout.EnumPopup(string.Empty, script.mode, GUILayout.Width(100));
|
||||
GUILayout.EndHorizontal();
|
||||
|
||||
|
||||
GUILayout.BeginHorizontal();
|
||||
GUILayout.Label("Symmetry", GUILayout.Width(86));
|
||||
script.symmetry = GUILayout.Toggle(script.symmetry, string.Empty);
|
||||
GUILayout.EndHorizontal();
|
||||
|
||||
GUILayout.Space(10);
|
||||
|
||||
// COLLIDERS
|
||||
if (script.mode == RagdollEditor.Mode.Colliders && selected != null) {
|
||||
|
||||
if (script.selectedCollider is CapsuleCollider) {
|
||||
var capsule = script.selectedCollider as CapsuleCollider;
|
||||
var capsuleS = symmetricCollider != null? symmetricCollider.transform.GetComponent<CapsuleCollider>(): null;
|
||||
|
||||
if (GUILayout.Button("Convert To Box Collider")) {
|
||||
ColliderTools.ConvertToBoxCollider(capsule);
|
||||
script.selectedCollider = selected.GetComponent<Collider>();
|
||||
if (capsuleS != null) ColliderTools.ConvertToBoxCollider(capsuleS);
|
||||
return;
|
||||
}
|
||||
|
||||
if (GUILayout.Button("Convert To Sphere Collider")) {
|
||||
ColliderTools.ConvertToSphereCollider(capsule);
|
||||
script.selectedCollider = selected.GetComponent<Collider>();
|
||||
if (capsuleS != null) ColliderTools.ConvertToSphereCollider(capsuleS);
|
||||
return;
|
||||
}
|
||||
|
||||
string capsuleDir = capsule.direction == 0? "X": (capsule.direction == 1? "Y": "Z");
|
||||
|
||||
if (GUILayout.Button("Direction: " + capsuleDir)) {
|
||||
if (capsuleS == null) {
|
||||
Undo.RecordObject(capsule, "Change Capsule Direction");
|
||||
} else {
|
||||
Undo.RecordObjects(new Object[2] { capsule, capsuleS }, "Change Capsule Direction");
|
||||
}
|
||||
|
||||
capsule.direction ++;
|
||||
if (capsule.direction > 2) capsule.direction = 0;
|
||||
if (capsuleS != null) capsuleS.direction = capsule.direction;
|
||||
}
|
||||
} else if (script.selectedCollider is BoxCollider) {
|
||||
var box = script.selectedCollider as BoxCollider;
|
||||
var boxS = symmetricCollider != null? symmetricCollider.transform.GetComponent<BoxCollider>(): null;
|
||||
|
||||
if (GUILayout.Button("Convert To Capsule Collider")) {
|
||||
ColliderTools.ConvertToCapsuleCollider(box);
|
||||
script.selectedCollider = selected.GetComponent<Collider>();
|
||||
if (boxS != null) ColliderTools.ConvertToCapsuleCollider(boxS);
|
||||
return;
|
||||
}
|
||||
|
||||
if (GUILayout.Button("Convert To Sphere Collider")) {
|
||||
ColliderTools.ConvertToSphereCollider(box);
|
||||
script.selectedCollider = selected.GetComponent<Collider>();
|
||||
if (boxS != null) ColliderTools.ConvertToSphereCollider(boxS);
|
||||
return;
|
||||
}
|
||||
|
||||
if (GUILayout.Button("Rotate Collider")) {
|
||||
if (boxS == null) {
|
||||
Undo.RecordObject(box, "Rotate Collider");
|
||||
} else {
|
||||
Undo.RecordObjects(new Object[2] { box, boxS }, "Rotate Collider");
|
||||
}
|
||||
|
||||
box.size = new Vector3(box.size.y, box.size.z, box.size.x);
|
||||
if (boxS != null) boxS.size = box.size;
|
||||
}
|
||||
} else if (script.selectedCollider is SphereCollider) {
|
||||
var sphere = script.selectedCollider as SphereCollider;
|
||||
var sphereS = symmetricCollider != null? symmetricCollider.transform.GetComponent<SphereCollider>(): null;
|
||||
|
||||
if (GUILayout.Button("Convert To Capsule Collider")) {
|
||||
ColliderTools.ConvertToCapsuleCollider(sphere);
|
||||
script.selectedCollider = selected.GetComponent<Collider>();
|
||||
if (sphereS != null) ColliderTools.ConvertToCapsuleCollider(sphereS);
|
||||
return;
|
||||
}
|
||||
|
||||
if (GUILayout.Button("Convert To Box Collider")) {
|
||||
ColliderTools.ConvertToBoxCollider(sphere);
|
||||
script.selectedCollider = selected.GetComponent<Collider>();
|
||||
if (sphereS != null) ColliderTools.ConvertToBoxCollider(sphereS);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// JOINTS
|
||||
if (script.mode == RagdollEditor.Mode.Joints) {
|
||||
if (joint != null && (joint is CharacterJoint || joint is ConfigurableJoint)) {
|
||||
|
||||
GUILayout.BeginHorizontal();
|
||||
GUILayout.Label("Connected Body");
|
||||
|
||||
var lastConnectedBody = joint.connectedBody;
|
||||
var newConnectedBody = (Rigidbody)EditorGUILayout.ObjectField(joint.connectedBody, typeof(Rigidbody), true);
|
||||
if (newConnectedBody != lastConnectedBody) {
|
||||
Undo.RecordObject(joint, "Changing Joint ConnectedBody");
|
||||
joint.connectedBody = newConnectedBody;
|
||||
}
|
||||
|
||||
GUILayout.EndHorizontal();
|
||||
|
||||
if (joint is CharacterJoint) {
|
||||
var j = joint as CharacterJoint;
|
||||
var sJ = symmetricJoint != null && symmetricJoint is CharacterJoint? symmetricJoint as CharacterJoint: null;
|
||||
|
||||
if (GUILayout.Button("Convert to Configurable")) {
|
||||
JointConverter.CharacterToConfigurable(j);
|
||||
|
||||
if (sJ != null) {
|
||||
JointConverter.CharacterToConfigurable(sJ);
|
||||
}
|
||||
}
|
||||
|
||||
if (GUILayout.Button("Switch Yellow/Green")) {
|
||||
JointTools.SwitchXY(ref j);
|
||||
if (sJ != null) JointTools.SwitchXY(ref sJ);
|
||||
}
|
||||
|
||||
if (GUILayout.Button("Switch Yellow/Blue")) {
|
||||
JointTools.SwitchXZ(ref j);
|
||||
if (sJ != null) JointTools.SwitchXZ(ref sJ);
|
||||
}
|
||||
|
||||
if (GUILayout.Button("Switch Green/Blue")) {
|
||||
JointTools.SwitchYZ(ref j);
|
||||
if (sJ != null) JointTools.SwitchYZ(ref sJ);
|
||||
}
|
||||
|
||||
if (GUILayout.Button("Invert Yellow")) {
|
||||
JointTools.InvertAxis(ref joint);
|
||||
if (sJ != null) JointTools.InvertAxis(ref symmetricJoint);
|
||||
}
|
||||
}
|
||||
|
||||
if (joint is ConfigurableJoint) {
|
||||
var j = joint as ConfigurableJoint;
|
||||
var sJ = symmetricJoint != null && symmetricJoint is ConfigurableJoint? symmetricJoint as ConfigurableJoint: null;
|
||||
|
||||
if (GUILayout.Button("Switch Yellow/Green")) {
|
||||
JointTools.SwitchXY(ref j);
|
||||
if (sJ != null) JointTools.SwitchXY(ref sJ);
|
||||
}
|
||||
|
||||
if (GUILayout.Button("Switch Yellow/Blue")) {
|
||||
JointTools.SwitchXZ(ref j);
|
||||
if (sJ != null) JointTools.SwitchXZ(ref sJ);
|
||||
}
|
||||
|
||||
if (GUILayout.Button("Switch Green/Blue")) {
|
||||
JointTools.SwitchYZ(ref j);
|
||||
if (sJ != null) JointTools.SwitchYZ(ref sJ);
|
||||
}
|
||||
|
||||
if (GUILayout.Button("Invert Yellow")) {
|
||||
JointTools.InvertAxis(ref joint);
|
||||
if (sJ != null) JointTools.InvertAxis(ref symmetricJoint);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
GUILayout.EndVertical();
|
||||
//GUILayout.EndArea();
|
||||
Handles.EndGUI();
|
||||
|
||||
if (script.mode == RagdollEditor.Mode.Joints && joint != null) {
|
||||
if (joint is CharacterJoint) {
|
||||
var j = joint as CharacterJoint;
|
||||
|
||||
SoftJointLimit lowTwistLimit = j.lowTwistLimit;
|
||||
SoftJointLimit highTwistLimit = j.highTwistLimit;
|
||||
SoftJointLimit swing1Limit = j.swing1Limit;
|
||||
SoftJointLimit swing2Limit = j.swing2Limit;
|
||||
|
||||
CharacterJointInspector.DrawJoint(j);
|
||||
|
||||
if (symmetricJoint != null && symmetricJoint is CharacterJoint) {
|
||||
var sJ = symmetricJoint as CharacterJoint;
|
||||
|
||||
CharacterJointInspector.DrawJoint(sJ, false, 0.5f);
|
||||
|
||||
// Low Twist
|
||||
if (lowTwistLimit.limit != j.lowTwistLimit.limit) {
|
||||
Undo.RecordObject(sJ, "Change Joint Limits");
|
||||
|
||||
Vector3 lowXAxisWorld = JointTools.GetLowXAxisWorld(j);
|
||||
Vector3 lowXAxisWorldS = JointTools.GetLowXAxisWorld(sJ);
|
||||
Vector3 lowXAxisWorldMirror = SymmetryTools.Mirror(lowXAxisWorld, script.transform);
|
||||
bool low = Vector3.Dot(lowXAxisWorldMirror, lowXAxisWorldS) < 0f;
|
||||
|
||||
JointAxis sJointAxis = JointTools.GetSymmetricJointAxis(j, JointAxis.Primary, sJ, script.transform);
|
||||
float delta = j.lowTwistLimit.limit - lowTwistLimit.limit;
|
||||
|
||||
JointTools.ApplyXDeltaToJointLimit(ref sJ, delta, sJointAxis, low);
|
||||
}
|
||||
|
||||
// High Twist
|
||||
if (highTwistLimit.limit != j.highTwistLimit.limit) {
|
||||
Undo.RecordObject(sJ, "Change Joint Limits");
|
||||
|
||||
Vector3 highXAxisWorld = JointTools.GetHighXAxisWorld(j);
|
||||
Vector3 highXAxisWorldS = JointTools.GetHighXAxisWorld(sJ);
|
||||
Vector3 highXAxisWorldMirror = SymmetryTools.Mirror(highXAxisWorld, script.transform);
|
||||
bool low = Vector3.Dot(highXAxisWorldMirror, highXAxisWorldS) > 0f;
|
||||
|
||||
JointAxis sJointAxis = JointTools.GetSymmetricJointAxis(j, JointAxis.Primary, sJ, script.transform);
|
||||
float delta = j.highTwistLimit.limit - highTwistLimit.limit;
|
||||
|
||||
JointTools.ApplyXDeltaToJointLimit(ref sJ, -delta, sJointAxis, low);
|
||||
}
|
||||
|
||||
// Swing 1
|
||||
if (swing1Limit.limit != j.swing1Limit.limit) {
|
||||
Undo.RecordObject(sJ, "Change Joint Limits");
|
||||
JointAxis sJointAxis = JointTools.GetSymmetricJointAxis(j, JointAxis.Secondary, sJ, script.transform);
|
||||
float delta = j.swing1Limit.limit - swing1Limit.limit;
|
||||
|
||||
JointTools.ApplyDeltaToJointLimit(ref sJ, delta, sJointAxis);
|
||||
}
|
||||
|
||||
// Swing 2
|
||||
if (swing2Limit.limit != j.swing2Limit.limit) {
|
||||
Undo.RecordObject(sJ, "Change Joint Limits");
|
||||
JointAxis sJointAxis = JointTools.GetSymmetricJointAxis(j, JointAxis.Tertiary, sJ, script.transform);
|
||||
float delta = j.swing2Limit.limit - swing2Limit.limit;
|
||||
|
||||
JointTools.ApplyDeltaToJointLimit(ref sJ, delta, sJointAxis);
|
||||
}
|
||||
}
|
||||
|
||||
} else if (joint is ConfigurableJoint) {
|
||||
|
||||
var j = joint as ConfigurableJoint;
|
||||
|
||||
SoftJointLimit lowAngularXLimit = j.lowAngularXLimit;
|
||||
SoftJointLimit highAngularXLimit = j.highAngularXLimit;
|
||||
SoftJointLimit angularYLimit = j.angularYLimit;
|
||||
SoftJointLimit angularZLimit = j.angularZLimit;
|
||||
|
||||
ConfigurableJointInspector.DrawJoint(j);
|
||||
|
||||
if (symmetricJoint != null && symmetricJoint is ConfigurableJoint) {
|
||||
var sJ = symmetricJoint as ConfigurableJoint;
|
||||
|
||||
ConfigurableJointInspector.DrawJoint(sJ, false, 0.5f);
|
||||
|
||||
// Low X
|
||||
if (lowAngularXLimit.limit != j.lowAngularXLimit.limit) {
|
||||
Undo.RecordObject(sJ, "Change Joint Limits");
|
||||
|
||||
Vector3 lowXAxisWorld = JointTools.GetLowXAxisWorld(j);
|
||||
Vector3 lowXAxisWorldS = JointTools.GetLowXAxisWorld(sJ);
|
||||
Vector3 lowXAxisWorldMirror = SymmetryTools.Mirror(lowXAxisWorld, script.transform);
|
||||
bool low = Vector3.Dot(lowXAxisWorldMirror, lowXAxisWorldS) < 0f;
|
||||
|
||||
JointAxis sJointAxis = JointTools.GetSymmetricJointAxis(j, JointAxis.Primary, sJ, script.transform);
|
||||
float delta = j.lowAngularXLimit.limit - lowAngularXLimit.limit;
|
||||
|
||||
JointTools.ApplyXDeltaToJointLimit(ref sJ, delta, sJointAxis, low);
|
||||
}
|
||||
|
||||
// High X
|
||||
if (highAngularXLimit.limit != j.highAngularXLimit.limit) {
|
||||
Undo.RecordObject(sJ, "Change Joint Limits");
|
||||
|
||||
Vector3 highXAxisWorld = JointTools.GetHighXAxisWorld(j);
|
||||
Vector3 highXAxisWorldS = JointTools.GetHighXAxisWorld(sJ);
|
||||
Vector3 highXAxisWorldMirror = SymmetryTools.Mirror(highXAxisWorld, script.transform);
|
||||
bool low = Vector3.Dot(highXAxisWorldMirror, highXAxisWorldS) > 0f;
|
||||
|
||||
JointAxis sJointAxis = JointTools.GetSymmetricJointAxis(j, JointAxis.Primary, sJ, script.transform);
|
||||
float delta = j.highAngularXLimit.limit - highAngularXLimit.limit;
|
||||
|
||||
JointTools.ApplyXDeltaToJointLimit(ref sJ, -delta, sJointAxis, low);
|
||||
}
|
||||
|
||||
// Y
|
||||
if (angularYLimit.limit != j.angularYLimit.limit) {
|
||||
Undo.RecordObject(sJ, "Change Joint Limits");
|
||||
JointAxis sJointAxis = JointTools.GetSymmetricJointAxis(j, JointAxis.Secondary, sJ, script.transform);
|
||||
float delta = j.angularYLimit.limit - angularYLimit.limit;
|
||||
|
||||
JointTools.ApplyDeltaToJointLimit(ref sJ, delta, sJointAxis);
|
||||
}
|
||||
|
||||
// Z
|
||||
if (angularZLimit.limit != j.angularZLimit.limit) {
|
||||
Undo.RecordObject(sJ, "Change Joint Limits");
|
||||
JointAxis sJointAxis = JointTools.GetSymmetricJointAxis(j, JointAxis.Tertiary, sJ, script.transform);
|
||||
float delta = j.angularZLimit.limit - angularZLimit.limit;
|
||||
|
||||
JointTools.ApplyDeltaToJointLimit(ref sJ, delta, sJointAxis);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!Application.isPlaying) {
|
||||
foreach (Collider c in colliders) {
|
||||
c.enabled = script.mode == RagdollEditor.Mode.Colliders;
|
||||
}
|
||||
}
|
||||
|
||||
// HANDLES
|
||||
Color color = new Color(0.2f, 0.9f, 0.5f);
|
||||
Handles.color = color;
|
||||
|
||||
if (Event.current.type == EventType.MouseUp) isDragging = false;
|
||||
if (Event.current.type == EventType.MouseDown) isDragging = false;
|
||||
|
||||
if (script.mode == RagdollEditor.Mode.Colliders) {
|
||||
|
||||
// Select/move scale colliders
|
||||
for (int i = 0; i < colliders.Length; i++) {
|
||||
|
||||
if (colliders[i] == script.selectedCollider) {
|
||||
|
||||
// Moving and scaling selected colliders
|
||||
switch(Tools.current) {
|
||||
case Tool.Move:
|
||||
Vector3 oldPosition = ColliderTools.GetColliderCenterWorld(colliders[i]);
|
||||
Vector3 newPosition = Handles.PositionHandle(oldPosition, colliders[i].transform.rotation);
|
||||
if (newPosition != oldPosition) {
|
||||
if (!isDragging) {
|
||||
Undo.RecordObjects(SymmetryTools.GetColliderPair(colliders[i], symmetricCollider), "Move Colliders");
|
||||
|
||||
isDragging = true;
|
||||
}
|
||||
|
||||
ColliderTools.SetColliderCenterWorld(colliders[i], symmetricCollider, newPosition, script.transform);
|
||||
}
|
||||
break;
|
||||
case Tool.Scale:
|
||||
Vector3 position = ColliderTools.GetColliderCenterWorld(colliders[i]);
|
||||
Vector3 oldSize = ColliderTools.GetColliderSize(colliders[i]);
|
||||
Vector3 oldSizeS = ColliderTools.GetColliderSize(symmetricCollider);
|
||||
Vector3 newSize = Handles.ScaleHandle(oldSize, position, colliders[i].transform.rotation, HandleUtility.GetHandleSize(position));
|
||||
if (newSize != oldSize) {
|
||||
if (!isDragging) {
|
||||
Undo.RecordObjects(SymmetryTools.GetColliderPair(colliders[i], symmetricCollider), "Scale Colliders");
|
||||
|
||||
isDragging = true;
|
||||
}
|
||||
|
||||
ColliderTools.SetColliderSize(colliders[i], symmetricCollider, newSize, oldSize, oldSizeS, script.transform);
|
||||
}
|
||||
|
||||
Handles.color = color;
|
||||
break;
|
||||
}
|
||||
|
||||
// Dot on selected collider
|
||||
if (Tools.current != Tool.Scale) {
|
||||
Handles.color = new Color(0.8f, 0.8f, 0.8f);
|
||||
Vector3 center = ColliderTools.GetColliderCenterWorld(colliders[i]);
|
||||
float size = GetHandleSize(center);
|
||||
Inspector.CubeCap(0, center, colliders[i].transform.rotation, size);
|
||||
Handles.color = color;
|
||||
}
|
||||
|
||||
} else {
|
||||
// Selecting colliders
|
||||
Vector3 center = ColliderTools.GetColliderCenterWorld(colliders[i]);
|
||||
float size = GetHandleSize(center);
|
||||
|
||||
if (Inspector.DotButton(center, Quaternion.identity, size * 0.5f, size * 0.5f)) {
|
||||
Undo.RecordObject(script, "Change RagdollEditor Selection");
|
||||
|
||||
script.selectedCollider = colliders[i];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
} else {
|
||||
// Select joints
|
||||
for (int i = 0; i < rigidbodies.Length; i++) {
|
||||
|
||||
if (rigidbodies[i] == script.selectedRigidbody) {
|
||||
// Dots on selected joints
|
||||
Handles.color = new Color(0.8f, 0.8f, 0.8f);
|
||||
Vector3 center = rigidbodies[i].transform.position;
|
||||
float size = GetHandleSize(center);
|
||||
Inspector.CubeCap(0, center, rigidbodies[i].transform.rotation, size);
|
||||
Handles.color = color;
|
||||
} else {
|
||||
// Selecting joints
|
||||
Vector3 center = rigidbodies[i].transform.position;
|
||||
float size = GetHandleSize(center);
|
||||
|
||||
if (Inspector.DotButton(center, Quaternion.identity, size * 0.5f, size * 0.5f)) {
|
||||
Undo.RecordObject(script, "Change RagdollEditor Selection");
|
||||
|
||||
script.selectedRigidbody = rigidbodies[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Handles.color = Color.white;
|
||||
}
|
||||
|
||||
private static float GetHandleSize(Vector3 position) {
|
||||
float s = HandleUtility.GetHandleSize(position) * 0.1f;
|
||||
return Mathf.Lerp(s, 0.025f, 0.2f);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1f61264d173e24310b255e76adcfff81
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
@@ -0,0 +1,94 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using UnityEditor;
|
||||
|
||||
namespace RootMotion.Dynamics {
|
||||
|
||||
// Tools for symmetric operations
|
||||
public class SymmetryTools: Editor {
|
||||
|
||||
public static Rigidbody GetSymmetric(Rigidbody r, Rigidbody[] R, Transform root) {
|
||||
Vector3 localPos = root.InverseTransformPoint(r.position);
|
||||
|
||||
Rigidbody closest = null;
|
||||
float closestDistance = 0.01f;
|
||||
|
||||
foreach (Rigidbody r2 in R) {
|
||||
if (r != r2) {
|
||||
Vector3 localPos2 = root.InverseTransformPoint(r2.position);
|
||||
localPos2.x = -localPos2.x;
|
||||
|
||||
float dist = Vector3.Distance(localPos, localPos2);
|
||||
if (dist < closestDistance) {
|
||||
closest = r2;
|
||||
closestDistance = dist;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return closest;
|
||||
}
|
||||
|
||||
public static Collider GetSymmetric(Collider c, Collider[] C, Transform root) {
|
||||
Vector3 localPos = root.InverseTransformPoint(c.transform.position);
|
||||
|
||||
Collider closest = null;
|
||||
float closestDistance = 0.01f;
|
||||
|
||||
foreach (Collider c2 in C) {
|
||||
if (c != c2) {
|
||||
Vector3 localPos2 = root.InverseTransformPoint(c2.transform.position);
|
||||
localPos2.x = -localPos2.x;
|
||||
|
||||
float dist = Vector3.Distance(localPos, localPos2);
|
||||
if (dist < closestDistance) {
|
||||
closest = c2;
|
||||
closestDistance = dist;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return closest;
|
||||
}
|
||||
|
||||
public static Vector3 MirrorDelta(Transform r, Transform s, Transform root, Vector3 delta) {
|
||||
Vector3 dXW = r.right * delta.x;
|
||||
Vector3 dYW = r.up * delta.y;
|
||||
Vector3 dZW = r.forward * delta.z;
|
||||
|
||||
Vector3 dXWM = Mirror(dXW, root);
|
||||
Vector3 dYWM = Mirror(dYW, root);
|
||||
Vector3 dZWM = Mirror(dZW, root);
|
||||
|
||||
Vector3 deltaS = Vector3.zero;
|
||||
deltaS = DeltaSize(deltaS, s, dXWM, delta.x);
|
||||
deltaS = DeltaSize(deltaS, s, dYWM, delta.y);
|
||||
deltaS = DeltaSize(deltaS, s, dZWM, delta.z);
|
||||
|
||||
return deltaS;
|
||||
}
|
||||
|
||||
public static Vector3 Mirror(Vector3 v, Transform root) {
|
||||
Vector3 local = root.InverseTransformVector(v);
|
||||
return root.TransformVector(-local.x, local.y, local.z);
|
||||
}
|
||||
|
||||
public static Vector3 DeltaSize(Vector3 size, Transform t, Vector3 direction, float delta) {
|
||||
Axis axis = AxisTools.GetAxisToDirection(t, direction);
|
||||
|
||||
switch(axis) {
|
||||
case Axis.X: size.x += delta; break;
|
||||
case Axis.Y: size.y += delta; break;
|
||||
case Axis.Z: size.z += delta; break;
|
||||
}
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
public static Collider[] GetColliderPair(Collider r, Collider s) {
|
||||
if (s == null) return new Collider[1] {r};
|
||||
return new Collider[2] {r, s};
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: dd9c3cde48ab14fb2991ac46cf73af84
|
||||
timeCreated: 1444653494
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: dab395325550b7642aab381552be816e
|
||||
folderAsset: yes
|
||||
timeCreated: 1478090994
|
||||
licenseType: Store
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,22 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using UnityEditor;
|
||||
|
||||
namespace RootMotion {
|
||||
|
||||
// Just making sure the camera controller updates last
|
||||
[CustomEditor(typeof(CameraController))]
|
||||
public class CameraControllerInspector : Editor {
|
||||
|
||||
private CameraController script { get { return target as CameraController; }}
|
||||
private MonoScript monoScript;
|
||||
|
||||
void OnEnable() {
|
||||
if (!Application.isPlaying) {
|
||||
monoScript = MonoScript.FromMonoBehaviour(script);
|
||||
int currentExecutionOrder = MonoImporter.GetExecutionOrder(monoScript);
|
||||
if (currentExecutionOrder != 10200) MonoImporter.SetExecutionOrder(monoScript, 10200);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b4af31e5f2e82444d80e3b3020689f59
|
||||
timeCreated: 1444227100
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2ecaf76b180974576a00c022bf77d0b6
|
||||
folderAsset: yes
|
||||
timeCreated: 1436260609
|
||||
licenseType: Store
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,26 @@
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using System.Collections;
|
||||
|
||||
namespace RootMotion {
|
||||
|
||||
/*
|
||||
* Custom inspector for BipedReferences
|
||||
* */
|
||||
public class BipedReferencesInspector: Inspector {
|
||||
|
||||
/*
|
||||
* Draws the default property, returns true if modified
|
||||
* */
|
||||
public static bool AddModifiedInspector(SerializedProperty prop) {
|
||||
EditorGUILayout.PropertyField(prop, true);
|
||||
|
||||
if (prop.isExpanded) EditorGUILayout.Space();
|
||||
|
||||
// If references have changed reinitiate the bipedIK.
|
||||
if (prop.serializedObject.ApplyModifiedProperties()) return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5880965ffd5754534ac6d4c1fce8bb73
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,41 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using UnityEditor;
|
||||
|
||||
namespace RootMotion {
|
||||
|
||||
[CustomEditor(typeof(Comments))]
|
||||
public class CommentsInspector : Editor {
|
||||
|
||||
private Comments script { get { return target as Comments; }}
|
||||
private GUIStyle style = new GUIStyle();
|
||||
|
||||
// Black and white
|
||||
//private static Color pro = new Color(0.7f, 0.7f, 0.7f, 1f);
|
||||
//private static Color free = new Color(0, 0, 0, 1);
|
||||
|
||||
// Colors
|
||||
private static Color pro = new Color(0.5f, 0.7f, 0.3f, 1f);
|
||||
private static Color free = new Color(0.2f, 0.3f, 0.1f, 1f);
|
||||
|
||||
public override void OnInspectorGUI() {
|
||||
if (serializedObject == null) return;
|
||||
|
||||
style.wordWrap = true;
|
||||
style.normal.textColor = EditorGUIUtility.isProSkin? pro: free;
|
||||
|
||||
serializedObject.Update();
|
||||
EditorGUILayout.Space();
|
||||
|
||||
string text = EditorGUILayout.TextArea(script.text, style);
|
||||
if (text != script.text) {
|
||||
Undo.RecordObject(script, "Edit Comments");
|
||||
script.text = text;
|
||||
}
|
||||
|
||||
EditorGUILayout.Space();
|
||||
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c93e61235cb3cad45aec1688c1990eff
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,323 @@
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using System.Collections;
|
||||
|
||||
namespace RootMotion {
|
||||
|
||||
/*
|
||||
* Inspector contains helper methods for creating undoable custom inspectors with enforced layout, tooltips and styling
|
||||
* */
|
||||
public class Inspector {
|
||||
|
||||
#region InspectorGUI tools
|
||||
|
||||
public const int indent = 16;
|
||||
|
||||
public delegate void DrawArrayElement(SerializedProperty prop, bool editHierarchy);
|
||||
public delegate void DrawArrayElementLabel(SerializedProperty prop, bool editHierarchy);
|
||||
public delegate void OnAddToArray(SerializedProperty prop);
|
||||
|
||||
private static string arrayName;
|
||||
private static SerializedProperty property;
|
||||
private static SerializedProperty element;
|
||||
|
||||
public static string GetArrayName(SerializedProperty array, string emptyName, string propertyName = "") {
|
||||
if (array.arraySize < 1) return emptyName;
|
||||
property = propertyName == ""? array.GetArrayElementAtIndex(0): array.GetArrayElementAtIndex(0).FindPropertyRelative(propertyName);
|
||||
return GetObjectReferenceName(property, emptyName);
|
||||
}
|
||||
|
||||
public static string GetObjectReferenceName(SerializedProperty prop, string emptyName) {
|
||||
if (prop.objectReferenceValue == null) return emptyName;
|
||||
return prop.objectReferenceValue.name;
|
||||
}
|
||||
|
||||
public static void AddArray(SerializedProperty prop, GUIContent guiContent, bool editHierarchy, bool changeOrder, DrawArrayElement drawArrayElement = null, OnAddToArray onAddToArray = null, DrawArrayElementLabel drawArrayElementLabel = null, bool showHeading = true) {
|
||||
int resetIndent = EditorGUI.indentLevel;
|
||||
|
||||
// Array heading
|
||||
if (showHeading) {
|
||||
GUILayout.BeginHorizontal();
|
||||
GUILayout.Space(EditorGUI.indentLevel * indent);
|
||||
|
||||
if (drawArrayElement == null) {
|
||||
GUILayout.Label(guiContent.text + " (" + prop.arraySize.ToString() + ")", GUILayout.Width(150));
|
||||
} else {
|
||||
EditorGUILayout.PropertyField(prop, new GUIContent(guiContent.text + " (" + prop.arraySize.ToString() + ")", string.Empty), false, GUILayout.Width(150));
|
||||
}
|
||||
|
||||
GUILayout.EndHorizontal();
|
||||
}
|
||||
|
||||
int deleteIndex = -1;
|
||||
|
||||
if (drawArrayElement == null || !showHeading) prop.isExpanded = true;
|
||||
|
||||
// Draw Array elements
|
||||
if (prop.isExpanded) {
|
||||
for(int i = 0; i < prop.arraySize; i++) {
|
||||
GUILayout.BeginHorizontal(); // Main
|
||||
GUILayout.Space(((EditorGUI.indentLevel + 1) * indent));
|
||||
GUILayout.BeginVertical();
|
||||
|
||||
element = prop.GetArrayElementAtIndex(i);
|
||||
|
||||
// Label
|
||||
GUILayout.BeginHorizontal();
|
||||
|
||||
if (editHierarchy && GUILayout.Button(new GUIContent("-", "Remove"), changeOrder? EditorStyles.miniButtonLeft: EditorStyles.miniButton, GUILayout.Width(20))){
|
||||
deleteIndex = i;
|
||||
}
|
||||
|
||||
if (changeOrder) {
|
||||
if (GUILayout.Button(new GUIContent("<", "Move up"), editHierarchy? EditorStyles.miniButtonMid: EditorStyles.miniButtonLeft, GUILayout.Width(20))) {
|
||||
int moveTo = i == 0? prop.arraySize - 1: i - 1;
|
||||
prop.MoveArrayElement(i, moveTo);
|
||||
prop.isExpanded = true;
|
||||
}
|
||||
|
||||
if (GUILayout.Button(new GUIContent(">", "Move down"), EditorStyles.miniButtonRight, GUILayout.Width(20))) {
|
||||
int moveTo = i == prop.arraySize - 1? 0: i + 1;
|
||||
prop.MoveArrayElement(i, moveTo);
|
||||
prop.isExpanded = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Calling the DrawArrayElementLabel delegate
|
||||
if (drawArrayElementLabel != null) {
|
||||
drawArrayElementLabel(element, editHierarchy);
|
||||
}
|
||||
|
||||
GUILayout.EndHorizontal(); // End Label
|
||||
|
||||
// Array Element
|
||||
GUILayout.BeginVertical();
|
||||
if (element.isExpanded && drawArrayElement != null) {
|
||||
drawArrayElement(element, editHierarchy);
|
||||
}
|
||||
GUILayout.EndVertical();
|
||||
|
||||
GUILayout.Space(5);
|
||||
|
||||
GUILayout.EndVertical(); // End Style
|
||||
GUILayout.EndHorizontal(); // End Main
|
||||
}
|
||||
|
||||
// Deleting array elements
|
||||
if (deleteIndex != -1) prop.DeleteArrayElementAtIndex(deleteIndex);
|
||||
|
||||
// Adding array elements
|
||||
GUILayout.BeginHorizontal();
|
||||
GUILayout.Space(((EditorGUI.indentLevel + 1) * indent) + 4);
|
||||
GUILayout.BeginVertical();
|
||||
|
||||
if (editHierarchy && GUILayout.Button(new GUIContent("+", "Add"), EditorStyles.miniButton, GUILayout.Width(20))) {
|
||||
prop.arraySize ++;
|
||||
|
||||
if (onAddToArray != null) onAddToArray(prop.GetArrayElementAtIndex(prop.arraySize - 1));
|
||||
}
|
||||
|
||||
GUILayout.EndVertical();
|
||||
GUILayout.EndHorizontal();
|
||||
}
|
||||
|
||||
EditorGUI.indentLevel = resetIndent;
|
||||
}
|
||||
|
||||
public static void AddContent(SerializedContent content, bool addChildren = false, params GUILayoutOption[] options) {
|
||||
EditorGUILayout.PropertyField(content.prop, content.guiContent, addChildren, options);
|
||||
}
|
||||
|
||||
public static void AddClampedFloat(SerializedContent content, float min = 0f, float max = 1f, params GUILayoutOption[] options) {
|
||||
AddClampedFloat(content.prop, content.guiContent, min, max, options);
|
||||
}
|
||||
|
||||
public static void AddClampedInt(SerializedContent content, int min = int.MinValue, int max = int.MaxValue, params GUILayoutOption[] options) {
|
||||
AddClampedInt(content.prop, content.guiContent, min, max, options);
|
||||
}
|
||||
|
||||
public static void AddClampedFloat(SerializedProperty prop, GUIContent guiContent, float min = 0f, float max = 1f, params GUILayoutOption[] options) {
|
||||
EditorGUILayout.PropertyField(prop, guiContent, options);
|
||||
prop.floatValue = Mathf.Clamp(prop.floatValue, min, max);
|
||||
}
|
||||
|
||||
public static void AddClampedInt(SerializedProperty prop, GUIContent guiContent, int min = int.MinValue, int max = int.MaxValue, params GUILayoutOption[] options) {
|
||||
EditorGUILayout.PropertyField(prop, guiContent, options);
|
||||
prop.intValue = Mathf.Clamp(prop.intValue, min, max);
|
||||
}
|
||||
|
||||
public static void AddObjectReference(SerializedProperty prop, GUIContent guiContent, bool editHierarchy, int labelWidth, bool alignToEdge = true) {
|
||||
if (alignToEdge) GUILayout.BeginHorizontal();
|
||||
EditorGUILayout.LabelField(guiContent, GUILayout.MinWidth(labelWidth));
|
||||
if (editHierarchy) {
|
||||
EditorGUILayout.PropertyField(prop, GUIContent.none);
|
||||
} else {
|
||||
UnityEngine.Object obj = prop.objectReferenceValue;
|
||||
EditorGUILayout.LabelField(new GUIContent(obj != null? obj.name: "None"));
|
||||
}
|
||||
if (alignToEdge) GUILayout.EndHorizontal();
|
||||
}
|
||||
|
||||
public static void AddObjectReference(SerializedProperty prop, GUIContent guiContent, bool editHierarchy, int labelWidth, int propWidth, bool alignToEdge = true) {
|
||||
//if (alignToEdge) GUILayout.BeginHorizontal();
|
||||
EditorGUILayout.LabelField(guiContent, GUILayout.Width(labelWidth));
|
||||
if (editHierarchy) {
|
||||
EditorGUILayout.PropertyField(prop, GUIContent.none, GUILayout.Width(propWidth));
|
||||
} else {
|
||||
UnityEngine.Object obj = prop.objectReferenceValue;
|
||||
EditorGUILayout.LabelField(new GUIContent(obj != null? obj.name: "None"), GUILayout.Width(propWidth));
|
||||
}
|
||||
//if (alignToEdge) GUILayout.EndHorizontal();
|
||||
}
|
||||
|
||||
#endregion InspectorGUI tools
|
||||
|
||||
#region SceneGUI tools
|
||||
|
||||
public static bool Button(string name, string toolTip, Object undoObject, params GUILayoutOption[] options) {
|
||||
bool button = GUILayout.Button(new GUIContent(name, toolTip), options);
|
||||
if (button && !Application.isPlaying) Undo.RecordObject(undoObject, name);
|
||||
return button;
|
||||
}
|
||||
|
||||
public static Object AddObject(Object input, string name, string toolTip, System.Type type, bool allowSceneObjects, Object undoObject, params GUILayoutOption[] options) {
|
||||
Object newValue = EditorGUILayout.ObjectField(new GUIContent(name, toolTip), input, type, allowSceneObjects, options);
|
||||
|
||||
return RecordObject(input, newValue, name, undoObject);
|
||||
}
|
||||
|
||||
public static System.Enum AddEnum(System.Enum input, string name, string toolTip, Object undoObject, params GUILayoutOption[] options) {
|
||||
System.Enum newValue = EditorGUILayout.EnumPopup(new GUIContent(name, toolTip), input, options);
|
||||
|
||||
if (newValue.ToString() != input.ToString() && !Application.isPlaying) Undo.RecordObject(undoObject, name);
|
||||
return newValue;
|
||||
}
|
||||
|
||||
public static void AddHorizontalSlider(ref float input, float leftValue, float rightValue, string name, string toolTip, Object undoObject, int labelWidth, int minWidth) {
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
|
||||
GUILayout.Label(new GUIContent(name, toolTip), GUILayout.Width(labelWidth));
|
||||
|
||||
input = RecordObjectFloat(input, GUILayout.HorizontalSlider(input, leftValue, rightValue, GUILayout.MinWidth(minWidth)), name, undoObject);
|
||||
input = Mathf.Clamp(RecordObjectFloat(input, EditorGUILayout.FloatField(string.Empty, input, GUILayout.Width(75)), name, undoObject), leftValue, rightValue);
|
||||
|
||||
EditorGUILayout.EndHorizontal();
|
||||
}
|
||||
|
||||
public static void AddFloat(ref float input, string name, string toolTip, Object undoObject, float min = -Mathf.Infinity, float max = Mathf.Infinity, params GUILayoutOption[] options) {
|
||||
input = Mathf.Clamp(RecordObjectFloat(input, EditorGUILayout.FloatField(new GUIContent(name, toolTip), input, options), name, undoObject), min, max);
|
||||
}
|
||||
|
||||
public static void AddInt(ref int input, string name, string toolTip, Object undoObject, int min = -int.MaxValue, int max = int.MaxValue, params GUILayoutOption[] options) {
|
||||
input = Mathf.Clamp((int)RecordObjectFloat((float)input, (float)EditorGUILayout.IntField(new GUIContent(name, toolTip), input, options), name, undoObject), min, max);
|
||||
}
|
||||
|
||||
public static void AddBool(ref bool input, string name, string toolTip, Object undoObject) {
|
||||
bool newValue = EditorGUILayout.Toggle(new GUIContent(name, toolTip), input);
|
||||
|
||||
if (newValue != input && !Application.isPlaying) {
|
||||
Undo.RecordObject(undoObject, name);
|
||||
}
|
||||
|
||||
input = newValue;
|
||||
}
|
||||
|
||||
public static void AddVector3(ref Vector3 input, string name, Object undoObject, params GUILayoutOption[] options) {
|
||||
Vector3 newValue = EditorGUILayout.Vector3Field(name, input, options);
|
||||
|
||||
if (newValue != input && !Application.isPlaying) {
|
||||
Undo.RecordObject(undoObject, name);
|
||||
}
|
||||
|
||||
input = newValue;
|
||||
}
|
||||
|
||||
private static float RecordObjectFloat(float input, float newValue, string name, Object undoObject) {
|
||||
if (newValue != input && !Application.isPlaying) Undo.RecordObject(undoObject, name);
|
||||
return newValue;
|
||||
}
|
||||
|
||||
private static Object RecordObject(Object input, Object newValue, string name, Object undoObject) {
|
||||
if (newValue != input && !Application.isPlaying) Undo.RecordObject(undoObject, name);
|
||||
return newValue;
|
||||
}
|
||||
|
||||
#endregion SceneGUI tools
|
||||
|
||||
#region Platform dependent
|
||||
|
||||
public static void SphereCap(int controlID, Vector3 position, Quaternion rotation, float size) {
|
||||
#if UNITY_5_6_OR_NEWER
|
||||
Handles.SphereHandleCap(controlID, position, rotation, size, EventType.Repaint);
|
||||
#else
|
||||
Handles.SphereCap(controlID, position, rotation, size);
|
||||
#endif
|
||||
}
|
||||
|
||||
public static void CubeCap(int controlID, Vector3 position, Quaternion rotation, float size) {
|
||||
#if UNITY_5_6_OR_NEWER
|
||||
Handles.CubeHandleCap(controlID, position, rotation, size, EventType.Repaint);
|
||||
#else
|
||||
Handles.CubeCap(controlID, position, rotation, size);
|
||||
#endif
|
||||
}
|
||||
|
||||
public static void ConeCap(int controlID, Vector3 position, Quaternion rotation, float size) {
|
||||
#if UNITY_5_6_OR_NEWER
|
||||
Handles.ConeHandleCap(controlID, position, rotation, size, EventType.Repaint);
|
||||
#else
|
||||
Handles.ConeCap(controlID, position, rotation, size);
|
||||
#endif
|
||||
}
|
||||
|
||||
public static void ArrowCap(int controlID, Vector3 position, Quaternion rotation, float size) {
|
||||
#if UNITY_5_6_OR_NEWER
|
||||
Handles.ArrowHandleCap(controlID, position, rotation, size, EventType.Repaint);
|
||||
#else
|
||||
Handles.ArrowCap(controlID, position, rotation, size);
|
||||
#endif
|
||||
}
|
||||
|
||||
public static void CircleCap(int controlID, Vector3 position, Quaternion rotation, float size) {
|
||||
#if UNITY_5_6_OR_NEWER
|
||||
Handles.CircleHandleCap(controlID, position, rotation, size, EventType.Repaint);
|
||||
#else
|
||||
Handles.CircleCap(controlID, position, rotation, size);
|
||||
#endif
|
||||
}
|
||||
|
||||
public static void DotCap(int controlID, Vector3 position, Quaternion rotation, float size) {
|
||||
#if UNITY_5_6_OR_NEWER
|
||||
Handles.DotHandleCap(controlID, position, rotation, size, EventType.Repaint);
|
||||
#else
|
||||
Handles.DotCap(controlID, position, rotation, size);
|
||||
#endif
|
||||
}
|
||||
|
||||
public static bool DotButton(Vector3 position, Quaternion direction, float size, float pickSize) {
|
||||
#if UNITY_5_6_OR_NEWER
|
||||
return Handles.Button(position, direction, size, pickSize, Handles.DotHandleCap);
|
||||
#else
|
||||
return Handles.Button(position, direction, size, pickSize, Handles.DotCap);
|
||||
#endif
|
||||
}
|
||||
|
||||
public static bool SphereButton(Vector3 position, Quaternion direction, float size, float pickSize) {
|
||||
#if UNITY_5_6_OR_NEWER
|
||||
return Handles.Button(position, direction, size, pickSize, Handles.SphereHandleCap);
|
||||
#else
|
||||
return Handles.Button(position, direction, size, pickSize, Handles.SphereCap);
|
||||
#endif
|
||||
}
|
||||
|
||||
public static float ScaleValueHandleSphere(float value, Vector3 position, Quaternion rotation, float size, float snap) {
|
||||
#if UNITY_5_6_OR_NEWER
|
||||
return Handles.ScaleValueHandle(value, position, rotation, size, Handles.SphereHandleCap, snap);
|
||||
#else
|
||||
return Handles.ScaleValueHandle(value, position, rotation, size, Handles.SphereCap, snap);
|
||||
#endif
|
||||
}
|
||||
|
||||
#endregion Platform dependent
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c18519ac3faf848ca878cd0509c4ce8c
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,65 @@
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace RootMotion
|
||||
{
|
||||
|
||||
// Custom drawer for the LargeHeader attribute
|
||||
[CustomPropertyDrawer(typeof(InspectorComment))]
|
||||
public class InspectorCommentDrawer : DecoratorDrawer
|
||||
{
|
||||
// Used to calculate the height of the box
|
||||
public static Texture2D lineTex = null;
|
||||
private GUIStyle style;
|
||||
|
||||
InspectorComment comment { get { return ((InspectorComment)attribute); } }
|
||||
|
||||
// Get the height of the element
|
||||
public override float GetHeight()
|
||||
{
|
||||
style = GetStyle();
|
||||
return style.CalcHeight(new GUIContent(comment.name), EditorGUIUtility.currentViewWidth) + 10f;
|
||||
|
||||
//return base.GetHeight() * 1.5f;
|
||||
}
|
||||
|
||||
// Override the GUI drawing for this attribute
|
||||
public override void OnGUI(Rect pos)
|
||||
{
|
||||
// Get the color the line should be
|
||||
Color color = Color.white;
|
||||
switch (comment.color.ToString().ToLower())
|
||||
{
|
||||
case "white": color = Color.white; break;
|
||||
case "red": color = Color.red; break;
|
||||
case "blue": color = Color.blue; break;
|
||||
case "green": color = Color.green; break;
|
||||
case "gray": color = Color.gray; break;
|
||||
case "grey": color = Color.grey; break;
|
||||
case "black": color = Color.black; break;
|
||||
}
|
||||
|
||||
color *= 0.5f;
|
||||
|
||||
style = GetStyle();
|
||||
|
||||
GUI.color = color;
|
||||
|
||||
Rect labelRect = pos;
|
||||
//labelRect.y += 10;
|
||||
EditorGUI.LabelField(labelRect, new GUIContent(comment.name), style);
|
||||
|
||||
GUI.color = Color.white;
|
||||
}
|
||||
|
||||
private GUIStyle GetStyle()
|
||||
{
|
||||
var style = new GUIStyle(GUI.skin.label);
|
||||
style.fontSize = 10;
|
||||
style.fontStyle = FontStyle.Normal;
|
||||
style.wordWrap = true;
|
||||
style.alignment = TextAnchor.LowerLeft;
|
||||
return style;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c87de0c0b96012c43b2684edd36e3289
|
||||
timeCreated: 1533045048
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,54 @@
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace RootMotion {
|
||||
|
||||
// Custom drawer for the LargeHeader attribute
|
||||
[CustomPropertyDrawer (typeof (LargeHeader))]
|
||||
public class LargeHeaderDrawer : DecoratorDrawer
|
||||
{
|
||||
// Used to calculate the height of the box
|
||||
public static Texture2D lineTex = null;
|
||||
private GUIStyle style;
|
||||
|
||||
LargeHeader largeHeader { get { return ((LargeHeader) attribute); } }
|
||||
|
||||
// Get the height of the element
|
||||
public override float GetHeight ()
|
||||
{
|
||||
return base.GetHeight () * 2f;
|
||||
}
|
||||
|
||||
|
||||
// Override the GUI drawing for this attribute
|
||||
public override void OnGUI (Rect pos)
|
||||
{
|
||||
// Get the color the line should be
|
||||
Color color = Color.white;
|
||||
switch (largeHeader.color.ToString().ToLower())
|
||||
{
|
||||
case "white": color = Color.white; break;
|
||||
case "red": color = Color.red; break;
|
||||
case "blue": color = Color.blue; break;
|
||||
case "green": color = Color.green; break;
|
||||
case "gray": color = Color.gray; break;
|
||||
case "grey": color = Color.grey; break;
|
||||
case "black": color = Color.black; break;
|
||||
}
|
||||
|
||||
color *= 0.7f;
|
||||
|
||||
style = new GUIStyle(GUI.skin.label);
|
||||
style.fontSize = 16;
|
||||
style.fontStyle = FontStyle.Normal;
|
||||
style.alignment = TextAnchor.LowerLeft;
|
||||
GUI.color = color;
|
||||
|
||||
Rect labelRect = pos;
|
||||
//labelRect.y += 10;
|
||||
EditorGUI.LabelField(labelRect, largeHeader.name, style);
|
||||
|
||||
GUI.color = Color.white;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 070e28ee88d2b41128ff9e7520f48015
|
||||
timeCreated: 1452022291
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,19 @@
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using System.Collections;
|
||||
|
||||
namespace RootMotion {
|
||||
|
||||
/*
|
||||
* Serialized content is used for caching serialized properties and their respective GUIContent and enforcing unified GUI layout.
|
||||
* */
|
||||
public struct SerializedContent {
|
||||
public SerializedProperty prop;
|
||||
public GUIContent guiContent;
|
||||
|
||||
public SerializedContent(SerializedProperty prop, GUIContent guiContent) {
|
||||
this.prop = prop;
|
||||
this.guiContent = guiContent;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fa9bdb02a53b1450c8f474d42de57950
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,265 @@
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using System.Collections;
|
||||
using System.IO;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
|
||||
|
||||
class SelectAllOfTag : ScriptableWizard
|
||||
{
|
||||
//此函数可将无法读写的Tex克隆成一份可读写的Tex,用于提取图片至png
|
||||
Texture2D duplicateTexture(Texture2D source)
|
||||
{
|
||||
RenderTexture renderTex = RenderTexture.GetTemporary(
|
||||
source.width,
|
||||
source.height,
|
||||
0,
|
||||
RenderTextureFormat.Default,
|
||||
RenderTextureReadWrite.Linear);
|
||||
|
||||
Graphics.Blit(source, renderTex);
|
||||
RenderTexture previous = RenderTexture.active;
|
||||
RenderTexture.active = renderTex;
|
||||
Texture2D readableText = new Texture2D(source.width, source.height);
|
||||
readableText.ReadPixels(new Rect(0, 0, renderTex.width, renderTex.height), 0, 0);
|
||||
readableText.Apply();
|
||||
RenderTexture.active = previous;
|
||||
RenderTexture.ReleaseTemporary(renderTex);
|
||||
return readableText;
|
||||
}
|
||||
|
||||
[MenuItem("Model/Get Select Model")]
|
||||
static void CreateWindow()
|
||||
{
|
||||
ScriptableWizard.DisplayWizard(
|
||||
"Get Select Model",
|
||||
typeof(SelectAllOfTag),
|
||||
"Start!");
|
||||
}
|
||||
|
||||
void OnWizardCreate()
|
||||
{
|
||||
|
||||
Debug.Log(Selection.objects[0]);
|
||||
|
||||
GameObject gameobj = (GameObject)Selection.objects[0];
|
||||
|
||||
if (!AssetDatabase.IsValidFolder("Assets/Model"))
|
||||
{
|
||||
AssetDatabase.CreateFolder("Assets", "Model");
|
||||
}
|
||||
|
||||
string folder_name = "Assets/Model/" + gameobj.name;
|
||||
|
||||
if (!AssetDatabase.IsValidFolder(folder_name))
|
||||
{
|
||||
AssetDatabase.CreateFolder("Assets/Model", gameobj.name);
|
||||
}
|
||||
|
||||
foreach (SkinnedMeshRenderer skin_mesh in gameobj.transform.GetComponentsInChildren<SkinnedMeshRenderer>())
|
||||
{
|
||||
//提取所有Mesh至文件夹
|
||||
Mesh m = skin_mesh.sharedMesh;
|
||||
|
||||
string m_parent = folder_name + "/Mesh";
|
||||
string m_path = folder_name + "/Mesh/" + m.name + ".mesh";
|
||||
if (!AssetDatabase.IsValidFolder(m_parent))
|
||||
{
|
||||
AssetDatabase.CreateFolder(folder_name, "Mesh");
|
||||
}
|
||||
|
||||
Debug.Log(m.name);
|
||||
Debug.Log(AssetDatabase.IsValidFolder(m_parent));
|
||||
AssetDatabase.RemoveObjectFromAsset(m);
|
||||
AssetDatabase.CreateAsset(m, folder_name + "/Mesh/" + m.name + ".mesh");
|
||||
|
||||
//创建Texture2D文件夹
|
||||
string tex_parent = folder_name + "/Texture2D";
|
||||
|
||||
if (!AssetDatabase.IsValidFolder(tex_parent))
|
||||
{
|
||||
AssetDatabase.CreateFolder(folder_name, "Texture2D");
|
||||
}
|
||||
|
||||
//创建Material文件夹
|
||||
string mat_parent = folder_name + "/Material";
|
||||
|
||||
if (!AssetDatabase.IsValidFolder(mat_parent))
|
||||
{
|
||||
AssetDatabase.CreateFolder(folder_name, "Material");
|
||||
}
|
||||
|
||||
foreach (Material mat in skin_mesh.sharedMaterials)
|
||||
{
|
||||
|
||||
JArray p_name_list = new JArray();
|
||||
JArray tex_name_list = new JArray();
|
||||
|
||||
//获得材质的所有属性名,如果改属性名对应的是贴图,提取该贴图
|
||||
Shader mat_shader = mat.shader;
|
||||
int p_num = mat_shader.GetPropertyCount();
|
||||
Debug.Log(p_num);
|
||||
for (int i = 0; i < p_num; i++)
|
||||
{
|
||||
//Debug.Log(mat_shader.GetPropertyName(i));
|
||||
//Debug.Log(mat_shader.GetPropertyType(i));
|
||||
string p_name = mat_shader.GetPropertyName(i);
|
||||
if (mat_shader.GetPropertyType(i) == UnityEngine.Rendering.ShaderPropertyType.Texture)
|
||||
{
|
||||
//Debug.Log("Hello!");
|
||||
Debug.Log(p_name);
|
||||
Texture2D mat_texture = (Texture2D)mat.GetTexture(p_name);
|
||||
if (mat_texture)
|
||||
{
|
||||
//Debug.Log("There is a Name!");
|
||||
string tex_name = mat_texture.name;
|
||||
string tex_path = folder_name + "/Texture2D/" + tex_name + ".png";
|
||||
if (!File.Exists(tex_path))
|
||||
{
|
||||
mat_texture = duplicateTexture(mat_texture);
|
||||
byte[] bytes = mat_texture.EncodeToPNG();
|
||||
File.WriteAllBytes(tex_path, bytes);
|
||||
}
|
||||
//记忆图片与属性名之间的关联
|
||||
p_name_list.Add(new JValue(p_name));
|
||||
tex_name_list.Add(new JValue(tex_path));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//提取材质
|
||||
AssetDatabase.RemoveObjectFromAsset(mat);
|
||||
AssetDatabase.CreateAsset(mat, folder_name + "/Material/" + mat.name + ".mat");
|
||||
|
||||
//刷新资源,将所有提取出来的图片载入Assets
|
||||
AssetDatabase.Refresh();
|
||||
|
||||
//将图片附加进材质
|
||||
for (int i = 0; i < p_name_list.Count; i++)
|
||||
{
|
||||
Debug.Log(p_name_list[i]);
|
||||
Debug.Log(tex_name_list[i]);
|
||||
mat.SetTexture(p_name_list[i].ToString(), (Texture2D)AssetDatabase.LoadAssetAtPath(tex_name_list[i].ToString(), typeof(Texture2D)));
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
foreach (MeshFilter mf in gameobj.transform.GetComponentsInChildren<MeshFilter>())
|
||||
{
|
||||
//提取所有Mesh至文件夹
|
||||
Mesh m = mf.sharedMesh;
|
||||
|
||||
string m_parent = folder_name + "/Mesh";
|
||||
string m_path = folder_name + "/Mesh/" + m.name + ".mesh";
|
||||
if (!AssetDatabase.IsValidFolder(m_parent))
|
||||
{
|
||||
AssetDatabase.CreateFolder(folder_name, "Mesh");
|
||||
}
|
||||
|
||||
Debug.Log(m.name);
|
||||
Debug.Log(AssetDatabase.IsValidFolder(m_parent));
|
||||
AssetDatabase.RemoveObjectFromAsset(m);
|
||||
AssetDatabase.CreateAsset(m, folder_name + "/Mesh/" + m.name + ".mesh");
|
||||
}
|
||||
|
||||
foreach (MeshRenderer mr in gameobj.transform.GetComponentsInChildren<MeshRenderer>())
|
||||
{
|
||||
//创建Texture2D文件夹
|
||||
string tex_parent = folder_name + "/Texture2D";
|
||||
|
||||
if (!AssetDatabase.IsValidFolder(tex_parent))
|
||||
{
|
||||
AssetDatabase.CreateFolder(folder_name, "Texture2D");
|
||||
}
|
||||
|
||||
//创建Material文件夹
|
||||
string mat_parent = folder_name + "/Material";
|
||||
|
||||
if (!AssetDatabase.IsValidFolder(mat_parent))
|
||||
{
|
||||
AssetDatabase.CreateFolder(folder_name, "Material");
|
||||
}
|
||||
|
||||
foreach (Material mat in mr.sharedMaterials)
|
||||
{
|
||||
|
||||
JArray p_name_list = new JArray();
|
||||
JArray tex_name_list = new JArray();
|
||||
|
||||
//获得材质的所有属性名,如果改属性名对应的是贴图,提取该贴图
|
||||
Shader mat_shader = mat.shader;
|
||||
int p_num = mat_shader.GetPropertyCount();
|
||||
Debug.Log(p_num);
|
||||
for (int i = 0; i < p_num; i++)
|
||||
{
|
||||
//Debug.Log(mat_shader.GetPropertyName(i));
|
||||
//Debug.Log(mat_shader.GetPropertyType(i));
|
||||
string p_name = mat_shader.GetPropertyName(i);
|
||||
if (mat_shader.GetPropertyType(i) == UnityEngine.Rendering.ShaderPropertyType.Texture)
|
||||
{
|
||||
//Debug.Log("Hello!");
|
||||
Debug.Log(p_name);
|
||||
Texture2D mat_texture = (Texture2D)mat.GetTexture(p_name);
|
||||
if (mat_texture)
|
||||
{
|
||||
//Debug.Log("There is a Name!");
|
||||
string tex_name = mat_texture.name;
|
||||
string tex_path = folder_name + "/Texture2D/" + tex_name + ".png";
|
||||
if (!File.Exists(tex_path))
|
||||
{
|
||||
mat_texture = duplicateTexture(mat_texture);
|
||||
byte[] bytes = mat_texture.EncodeToPNG();
|
||||
File.WriteAllBytes(tex_path, bytes);
|
||||
}
|
||||
//记忆图片与属性名之间的关联
|
||||
p_name_list.Add(new JValue(p_name));
|
||||
tex_name_list.Add(new JValue(tex_path));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//提取材质
|
||||
AssetDatabase.RemoveObjectFromAsset(mat);
|
||||
AssetDatabase.CreateAsset(mat, folder_name + "/Material/" + mat.name + ".mat");
|
||||
|
||||
//刷新资源,将所有提取出来的图片载入Assets
|
||||
AssetDatabase.Refresh();
|
||||
|
||||
//将图片附加进材质
|
||||
for (int i = 0; i < p_name_list.Count; i++)
|
||||
{
|
||||
Debug.Log(p_name_list[i]);
|
||||
Debug.Log(tex_name_list[i]);
|
||||
mat.SetTexture(p_name_list[i].ToString(), (Texture2D)AssetDatabase.LoadAssetAtPath(tex_name_list[i].ToString(), typeof(Texture2D)));
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
foreach (Animator anim in gameobj.transform.GetComponentsInChildren<Animator>())
|
||||
{
|
||||
//提取所有Avatar至文件夹
|
||||
Avatar av = anim.avatar;
|
||||
|
||||
string av_parent = folder_name + "/Avatar";
|
||||
string av_path = folder_name + "/Avatar/" + av.name + ".asset";
|
||||
if (!AssetDatabase.IsValidFolder(av_parent))
|
||||
{
|
||||
AssetDatabase.CreateFolder(folder_name, "Avatar");
|
||||
}
|
||||
|
||||
Debug.Log(av.name);
|
||||
Debug.Log(AssetDatabase.IsValidFolder(av_parent));
|
||||
AssetDatabase.RemoveObjectFromAsset(av);
|
||||
|
||||
AssetDatabase.CreateAsset(av, folder_name + "/Avatar/" + av.name + ".asset");
|
||||
}
|
||||
|
||||
//提取预制体
|
||||
PrefabUtility.SaveAsPrefabAsset(gameobj, folder_name + "/" + gameobj.name + ".prefab");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f45bcbff6c596104888b02292eba909a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,24 @@
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
|
||||
class SelectAllOfTagSingle : ScriptableWizard
|
||||
{
|
||||
|
||||
string tagName = "ExampleTag";
|
||||
|
||||
|
||||
[MenuItem("Example/Get")]
|
||||
static void SelectAllOfTagSingleWizard()
|
||||
{
|
||||
ScriptableWizard.DisplayWizard(
|
||||
"Example/Get",
|
||||
typeof(SelectAllOfTagSingle),
|
||||
"Make Selection");
|
||||
}
|
||||
|
||||
void OnWizardCreate()
|
||||
{
|
||||
AssetDatabase.RemoveObjectFromAsset(Selection.objects[0]);
|
||||
AssetDatabase.CreateAsset(Selection.objects[0], "Assets/"+ Selection.objects[0].name + ".asset");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c2e3dbce9401c5e41bf9415e33a79207
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1fdd4de1668fa554d87e5651110ab090
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 577d9725f58264943855b8ac185531fe
|
||||
folderAsset: yes
|
||||
timeCreated: 1466788344
|
||||
licenseType: Store
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 14f21d7a1e53a8c4e87b25526a7eb63c
|
||||
folderAsset: yes
|
||||
timeCreated: 1466788345
|
||||
licenseType: Store
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: aadad8ac54f29e44583510294ac5c312
|
||||
timeCreated: 1466788355
|
||||
licenseType: Store
|
||||
TextScriptImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Binary file not shown.
@@ -0,0 +1,76 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6a3c684705042f345975d924f6983e36
|
||||
timeCreated: 1466788352
|
||||
licenseType: Store
|
||||
PluginImporter:
|
||||
serializedVersion: 1
|
||||
iconMap: {}
|
||||
executionOrder: {}
|
||||
isPreloaded: 0
|
||||
platformData:
|
||||
Android:
|
||||
enabled: 1
|
||||
settings:
|
||||
CPU: AnyCPU
|
||||
Any:
|
||||
enabled: 0
|
||||
settings: {}
|
||||
Editor:
|
||||
enabled: 0
|
||||
settings:
|
||||
CPU: AnyCPU
|
||||
DefaultValueInitialized: true
|
||||
OS: AnyOS
|
||||
Linux:
|
||||
enabled: 0
|
||||
settings:
|
||||
CPU: x86
|
||||
Linux64:
|
||||
enabled: 0
|
||||
settings:
|
||||
CPU: x86_64
|
||||
OSXIntel:
|
||||
enabled: 0
|
||||
settings:
|
||||
CPU: AnyCPU
|
||||
OSXIntel64:
|
||||
enabled: 0
|
||||
settings:
|
||||
CPU: AnyCPU
|
||||
SamsungTV:
|
||||
enabled: 1
|
||||
settings:
|
||||
STV_MODEL: STANDARD_13
|
||||
Tizen:
|
||||
enabled: 1
|
||||
settings: {}
|
||||
WebGL:
|
||||
enabled: 1
|
||||
settings: {}
|
||||
Win:
|
||||
enabled: 0
|
||||
settings:
|
||||
CPU: AnyCPU
|
||||
Win64:
|
||||
enabled: 0
|
||||
settings:
|
||||
CPU: AnyCPU
|
||||
WindowsStoreApps:
|
||||
enabled: 1
|
||||
settings:
|
||||
CPU: AnyCPU
|
||||
DontProcess: False
|
||||
PlaceholderPath: Assets/JsonDotNet/Assemblies/Standalone/Newtonsoft.Json.dll
|
||||
SDK: AnySDK
|
||||
ScriptingBackend: Il2Cpp
|
||||
iOS:
|
||||
enabled: 1
|
||||
settings:
|
||||
CompileFlags:
|
||||
FrameworkDependencies:
|
||||
tvOS:
|
||||
enabled: 1
|
||||
settings: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 01ef782d02bb1994dbe418b69432552b
|
||||
folderAsset: yes
|
||||
timeCreated: 1466788344
|
||||
licenseType: Store
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d6807fedb8dcaf04682d2c84f0ab753f
|
||||
timeCreated: 1466788355
|
||||
licenseType: Store
|
||||
TextScriptImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Binary file not shown.
@@ -0,0 +1,75 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 17aef65a15b471f468b5fbeb4ff0c6a1
|
||||
timeCreated: 1466788349
|
||||
licenseType: Store
|
||||
PluginImporter:
|
||||
serializedVersion: 1
|
||||
iconMap: {}
|
||||
executionOrder: {}
|
||||
isPreloaded: 0
|
||||
platformData:
|
||||
Android:
|
||||
enabled: 0
|
||||
settings:
|
||||
CPU: AnyCPU
|
||||
Any:
|
||||
enabled: 0
|
||||
settings: {}
|
||||
Editor:
|
||||
enabled: 1
|
||||
settings:
|
||||
CPU: AnyCPU
|
||||
DefaultValueInitialized: true
|
||||
OS: AnyOS
|
||||
Linux:
|
||||
enabled: 1
|
||||
settings:
|
||||
CPU: x86
|
||||
Linux64:
|
||||
enabled: 1
|
||||
settings:
|
||||
CPU: x86_64
|
||||
LinuxUniversal:
|
||||
enabled: 1
|
||||
settings:
|
||||
CPU: AnyCPU
|
||||
OSXIntel:
|
||||
enabled: 1
|
||||
settings:
|
||||
CPU: AnyCPU
|
||||
OSXIntel64:
|
||||
enabled: 1
|
||||
settings:
|
||||
CPU: AnyCPU
|
||||
OSXUniversal:
|
||||
enabled: 1
|
||||
settings:
|
||||
CPU: AnyCPU
|
||||
SamsungTV:
|
||||
enabled: 0
|
||||
settings:
|
||||
STV_MODEL: STANDARD_13
|
||||
Win:
|
||||
enabled: 1
|
||||
settings:
|
||||
CPU: AnyCPU
|
||||
Win64:
|
||||
enabled: 1
|
||||
settings:
|
||||
CPU: AnyCPU
|
||||
WindowsStoreApps:
|
||||
enabled: 0
|
||||
settings:
|
||||
CPU: AnyCPU
|
||||
DontProcess: False
|
||||
PlaceholderPath:
|
||||
SDK: AnySDK
|
||||
ScriptingBackend: Il2Cpp
|
||||
iOS:
|
||||
enabled: 0
|
||||
settings:
|
||||
CompileFlags:
|
||||
FrameworkDependencies:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1418141139a6ac443b18cb05c0643a29
|
||||
folderAsset: yes
|
||||
timeCreated: 1466788345
|
||||
licenseType: Store
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 36f7323c55864364d8bb88c736e4bca6
|
||||
timeCreated: 1466788355
|
||||
licenseType: Store
|
||||
TextScriptImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Binary file not shown.
@@ -0,0 +1,67 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9b6ba260dada0ea4a871a42011f8b87d
|
||||
timeCreated: 1466788355
|
||||
licenseType: Store
|
||||
PluginImporter:
|
||||
serializedVersion: 1
|
||||
iconMap: {}
|
||||
executionOrder: {}
|
||||
isPreloaded: 0
|
||||
platformData:
|
||||
Android:
|
||||
enabled: 0
|
||||
settings:
|
||||
CPU: AnyCPU
|
||||
Any:
|
||||
enabled: 0
|
||||
settings: {}
|
||||
Editor:
|
||||
enabled: 0
|
||||
settings:
|
||||
CPU: AnyCPU
|
||||
DefaultValueInitialized: true
|
||||
OS: AnyOS
|
||||
Linux:
|
||||
enabled: 0
|
||||
settings:
|
||||
CPU: x86
|
||||
Linux64:
|
||||
enabled: 0
|
||||
settings:
|
||||
CPU: x86_64
|
||||
OSXIntel:
|
||||
enabled: 0
|
||||
settings:
|
||||
CPU: AnyCPU
|
||||
OSXIntel64:
|
||||
enabled: 0
|
||||
settings:
|
||||
CPU: AnyCPU
|
||||
SamsungTV:
|
||||
enabled: 0
|
||||
settings:
|
||||
STV_MODEL: STANDARD_13
|
||||
Win:
|
||||
enabled: 0
|
||||
settings:
|
||||
CPU: AnyCPU
|
||||
Win64:
|
||||
enabled: 0
|
||||
settings:
|
||||
CPU: AnyCPU
|
||||
WindowsStoreApps:
|
||||
enabled: 1
|
||||
settings:
|
||||
CPU: AnyCPU
|
||||
DontProcess: False
|
||||
PlaceholderPath: Assets/JsonDotNet/Assemblies/Standalone/Newtonsoft.Json.dll
|
||||
SDK: AnySDK
|
||||
ScriptingBackend: DotNet
|
||||
iOS:
|
||||
enabled: 0
|
||||
settings:
|
||||
CompileFlags:
|
||||
FrameworkDependencies:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user