Пример #1
0
        public void ConvertToSpringBone(bool fillCollidersGap = true, bool attacheToSecondary = true)
        {
            var fileName = $"{gameObject.name}_DBtoSB{DateTime.Now:yyyyMMddHHmmss}";
            var path     = EditorUtility.SaveFilePanel("Convert DynamicBones to SpringBones as JSON", string.Empty, fileName, "json");

            if (string.IsNullOrEmpty(path))
            {
                return;
            }

            try
            {
                Debug.Log("Converting DynamicBones to SpringBones");
                var dyConfig         = ExtractDynamicBones();
                var spColliderGroups = ConvertColliders(dyConfig.DynamicBoneColliders, fillCollidersGap);
                var spBones          = ConvertBones(dyConfig.DynamicBones, attacheToSecondary);

                var spConfig = new SpringBoneConfiguration();
                spConfig.SpringBones = spBones;
                spConfig.SpringBoneColliderGroups = spColliderGroups;
                var configJson = JsonConvert.SerializeObject(spConfig);

                Debug.Log("Writing SpringBones to JSON");
                File.WriteAllText(path, configJson);
            }
            catch (Exception ex)
            {
                Debug.LogError($"Error occurs in converting DynamicBones to SpringBones: {ex.Message}\n{ex.StackTrace}");
            }

            Debug.Log("Convert DynamicBones to SpringBones completed");
        }
Пример #2
0
        public static void QuickSave(SpringBoneConfiguration config, string path)
        {
            var assetData = CreateInstance <SpringBoneQSaveData>();

            assetData.Parse(config);

            AssetDatabase.CreateAsset(assetData, path);
        }
Пример #3
0
 public void Parse(SpringBoneConfiguration configuration)
 {
     Bones          = configuration.SpringBones.ToArray();
     ColliderGroups = configuration.SpringBoneColliderGroups.ToArray();
 }