人物骨骼的引用绑定,如果是要一个个手动设置,大概是相当让人头痛的事情吧。

using UnityEngine;
using System.Collections;
using UnityEditor;
using System.Reflection;
using System.IO;
using System;public class SetRagdoll : EditorWindow{private GUIStyle m_HeaderLabelStyle;//  public Animator animator;public static GameObject Character;[MenuItem("Tool/SetRagdoll", false, 11)]public static void SetRagdollWindow(){var window = EditorWindow.GetWindow<SetRagdoll>(true, "SetRagdoll");window.minSize = new Vector2(500, 100);}private void OnEnable(){if(m_HeaderLabelStyle == null){m_HeaderLabelStyle = new GUIStyle(EditorStyles.label);m_HeaderLabelStyle.wordWrap = true;}}private void OnGUI(){var description = "This is set Ragdoll for a character";EditorGUILayout.LabelField(description, m_HeaderLabelStyle);GUILayout.Space(5);Character = EditorGUILayout.ObjectField("character", Character, typeof(GameObject), true) as GameObject;GUILayout.Space(20);if (GUILayout.Button("Build")) {AddRagdoll();Close();}}private  void AddRagdoll(){//  AddAbility(controller, typeof(Opsive.ThirdPersonController.Wrappers.Abilities.Die), string.Empty, Abilities.Ability.AbilityStartType.Manual, Abilities.Ability.AbilityStopType.Manual);var ragdollBuilderType = Type.GetType("UnityEditor.RagdollBuilder, UnityEditor");var windows = Resources.FindObjectsOfTypeAll(ragdollBuilderType);// Open the Ragdoll Builder if it isn't already opened.if(windows == null || windows.Length == 0){EditorApplication.ExecuteMenuItem("GameObject/3D Object/Ragdoll...");windows = Resources.FindObjectsOfTypeAll(ragdollBuilderType);}if(windows != null && windows.Length > 0){var ragdollWindow = windows[0] as ScriptableWizard;var animator = Character.GetComponentInChildren<Animator>();
#if UNITY_4_6 || UNITY_4_7SetFieldValue(ragdollWindow, "root", animator.GetBoneTransform(HumanBodyBones.Hips));
#elseSetFieldValue(ragdollWindow, "pelvis", animator.GetBoneTransform(HumanBodyBones.Hips));
#endifSetFieldValue(ragdollWindow, "leftHips", animator.GetBoneTransform(HumanBodyBones.LeftUpperLeg));SetFieldValue(ragdollWindow, "leftKnee", animator.GetBoneTransform(HumanBodyBones.LeftLowerLeg));SetFieldValue(ragdollWindow, "leftFoot",  animator.GetBoneTransform(HumanBodyBones.LeftFoot));SetFieldValue(ragdollWindow, "rightHips", animator.GetBoneTransform(HumanBodyBones.RightUpperLeg));SetFieldValue(ragdollWindow, "rightKnee", animator.GetBoneTransform(HumanBodyBones.RightLowerLeg));SetFieldValue(ragdollWindow, "rightFoot", animator.GetBoneTransform(HumanBodyBones.RightFoot));SetFieldValue(ragdollWindow, "leftArm",   animator.GetBoneTransform(HumanBodyBones.LeftUpperArm));SetFieldValue(ragdollWindow, "leftElbow", animator.GetBoneTransform(HumanBodyBones.LeftLowerArm));SetFieldValue(ragdollWindow, "rightArm",   animator.GetBoneTransform(HumanBodyBones.RightUpperArm));SetFieldValue(ragdollWindow, "rightElbow", animator.GetBoneTransform(HumanBodyBones.RightLowerArm));SetFieldValue(ragdollWindow, "middleSpine", animator.GetBoneTransform(HumanBodyBones.Spine));SetFieldValue(ragdollWindow, "head", animator.GetBoneTransform(HumanBodyBones.Head));var method = ragdollWindow.GetType().GetMethod("CheckConsistency", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);if(method != null){ragdollWindow.errorString = (string)method.Invoke(ragdollWindow, null);ragdollWindow.isValid = string.IsNullOrEmpty(ragdollWindow.errorString);}}}/// <summary>/// Use reflection to set the value of the field./// </summary>private  void SetFieldValue(ScriptableWizard obj, string name, object value){if(value == null){return;}var field = obj.GetType().GetField(name);if(field != null){field.SetValue(obj, value);}}
}

Ragdoll 自动配置相关推荐

  1. 自动配置IPv4问题

    对于 Windows , 配置 IP,如: 192.168.1.101, 如果这个 IP 已经在局域网内存在,那么将会提示局域网内已经存在该 IP. 而这个时候,Windows 7 将产生一个 &qu ...

  2. SpringBoot自动配置的原理及实现

    SpringBoot的核心就是自动配置,自动配置是基于条件判断配置Bean 自动配置的源码在spring-boot-autoconfigure-2.2.13.RELEASE SpringBoot运行原 ...

  3. Spring Boot 面试杀手锏:自动配置原理

    欢迎关注方志朋的博客,回复"666"获面试宝典 不论在工作中,亦或是求职面试,Spring Boot已经成为我们必知必会的技能项.除了某些老旧的政府项目或金融项目持有观望态度外,如 ...

  4. SpringBoot面试杀手锏——自动配置原理

    欢迎关注方志朋的博客,回复"666"获面试宝典 来源:blog.csdn.net/u014745069/ article/details/83820511 引言 不论在工作中,亦或 ...

  5. 这样讲 SpringBoot 自动配置原理,你应该能明白了吧

    点击上方"方志朋",选择"设为星标" 回复"666"获取新整理的面试资料 作者:你在我家门口 juejin.im/post/5ce5effb ...

  6. Spring Boot之自动配置

    1.原理 (1).SpringBoot启动的时候会加载主配置类,主配置类中已经开启了自动配置功能**@SpringBootApplication注解中包含了@EnableAutoConfigurati ...

  7. win10未开启没有运行无线服务器,win10系统提示共享无线自动配置服务没有自动运行的解决办法...

    win10系统提示共享无线自动配置服务没有自动运行的解决办法? win10系统有很多人都喜欢使用,我们操作的过程中常常会碰到win10系统提示共享无线自动配置服务没有自动运行的问题.如果遇到win10 ...

  8. Pod Preset玩转K8S容器时区自动配置

    摘要: 通过Pod Preset自动配置容器的时区 缘由 默认的情况,在K8S里启动一个容器,该容器的设置的时区是UTC0,但是对于很多客户而言,其主机环境并不在UTC0.例如中国客户在UTC8.如果 ...

  9. Spring Boot 基于注解驱动源码分析--自动配置

    Spring作为Java开发最常用的容器管理框架,使用注解为我们提供很多便捷,下面通过源码分析Spring基于注解驱动自动配置的原理 首先介绍两个关键类: ConfigurationClassPost ...

最新文章

  1. Linux shell 脚本中, $@ 和$# 分别是什么意思?
  2. treegrid修改css
  3. 凯立德地图导航2020年最新版_曾是导航领域“领头羊”的凯立德,如今为何岌岌可危?...
  4. php电子备课系统,电子备课-华思信息-智慧校园-智慧班牌-智慧课堂-智慧教育整体解决方案...
  5. 安装 Maxwell
  6. AI CC呼叫中心源码
  7. ZeroMQ模式介绍
  8. 如何用计算机算标准偏差,标准差计算器怎样安装使用?标准差计算器使用教程介绍...
  9. 大数据开发之Hive篇14-Hive归档(Archiving)
  10. iOS 画图context/QuartzCore(相关函数的解释)
  11. 【JS】JSON.stringify( )
  12. php 关键词生成,全自动无限生成关键词页面(黑帽SEO优化终极方法)
  13. 电视显示正在接入或无法接入认证服务器,长虹网络电视无法连接服务器,怎么回事?-长虹电视接入网络障碍...
  14. 2022-2027年中国医学影像设备市场竞争态势及行业投资前景预测报告
  15. ISC2022 HackingClub白帽峰会倒计时1天!最全议程正式公布!元宇宙集结,精彩绝伦!
  16. c++调用偏僻数据库db2
  17. 文本情感分析-机器学习实验三
  18. 公司组装服务器无法识别硬盘问题
  19. 成语——》如果蜗牛有爱情
  20. tim-db工具包-dao层查询工具

热门文章

  1. php 随机播放音乐,听音乐时随机播放真的是随机的吗?
  2. 思科路由器-配置RIPv2
  3. 计算机上排名代表的字母,电脑新手必须懂的英文字母缩写
  4. the content must be served over HTTPS报错
  5. 商城项目笔记一:搭建Maven工程,利用Dubbo实现SOA面向服务框架,部署zookeeper注册中心,FastDFS框架实现图片上传,部署nginx服务器。
  6. 在服务器上关闭smtp协议,SMTP 协议入门教程
  7. 详解通讯录(静态版、动态增长版、文件存储版)
  8. php中如何使用smtp,PHP使用SMTP协议发送邮件
  9. 历史上的今天:Google 之母出生;同一天诞生的两位图灵奖先驱
  10. 从后验概率到逻辑回归,从逻辑回归到神经网络