public static void ExecuteUnitRecovery(GameObject selected, ClipValidationContainer container,
                                               Action <string, float> onProgressChagned)
        {
            var childObjectsNames = GetChildObjectNames(selected);

            Recovery(container, ref childObjectsNames, onProgressChagned);
            EditorUtility.ClearProgressBar();
        }
 private void DrawOnError(ClipValidationContainer result)
 {
     DrawIconAndLabel(ErrorIcon, result.ClipName);
     DrawDetail(result.LostProperties);
     DrawButton("自動修正", () =>
     {
         AnimationValidator.ExecuteUnitRecovery(_selectedObject, result, ShowProgress);
         _window.Repaint();
         EditorApplication.RepaintAnimationWindow();
     });
 }
 private void DrawResult(ClipValidationContainer result)
 {
     if (result.HasNoError)
     {
         using (new EditorGUILayout.VerticalScope("box", GUILayout.Width(position.width - RightPadding)))
         {
             DrawOnSuccess(result);
         }
     }
     else
     {
         using (new EditorGUILayout.VerticalScope("box", GUILayout.Width(position.width - RightPadding)))
         {
             DrawOnError(result);
         }
     }
 }
        private static void Recovery(ClipValidationContainer validationContainer, ref List <PathModel> paths,
                                     Action <string, float> onUnitProgressChanged = null)
        {
            for (var i = 0; i < validationContainer.LostProperties.Count; i++)
            {
                var anim            = validationContainer.LostProperties[i];
                var pathInHierarchy = paths.Where(path => path.ObjectName == anim.ObjectName).ToList();
                var hierarchyCount  = pathInHierarchy.Count;

                if (onUnitProgressChanged != null)
                {
                    onUnitProgressChanged.Invoke(anim.ObjectName, (float)i / validationContainer.LostProperties.Count);
                }

                if (hierarchyCount == 0)
                {
                    //同名のobjectNameが存在しない
                    anim.State     = FixState.ErrorNoSameName;
                    anim.FixedPath = anim.PropPath;
                    continue;
                }

                if (hierarchyCount >= 2)
                {
                    // 複数のobjectが存在するから修正出来ない
                    anim.State = FixState.ErrorDuplicate;
                    // 後方一致で類似したパス順に並び替えて見つかったオブジェクトの相対パスを残しておく
                    anim.FindPropPaths = OrderPathByValidity(
                        pathInHierarchy.Select(x => x.RelativePath).ToList(),
                        anim.PropPath);
                    continue;
                }


                // 修復処理
                var correctPath = pathInHierarchy.First().RelativePath;
                UpdateAnimationRelativePath(anim, correctPath);
            }
        }
        private static ClipValidationContainer FindLostAnimations(AnimationClip clip, Transform root)
        {
            var lostAnimations = new List <LostProperty>();
            var serializedClip = new SerializedObject(clip);

            // clipはいくつかのカーブをもっている
            foreach (var curveName in CurveNames)
            {
                var curves     = serializedClip.FindProperty(curveName);
                var curveCount = curves.arraySize;
                for (var i = 0; i < curveCount; i++)
                {
                    var curve             = curves.GetArrayElementAtIndex(i);
                    var pathProperty      = curve.FindPropertyRelative(PathPropName);
                    var attributeProperty = curve.FindPropertyRelative(AttributePropName);
                    var attribute         = attributeProperty != null ? attributeProperty.stringValue : "Position";
                    // ルートの直下からの相対パスが入ってる
                    var path   = pathProperty.stringValue;
                    var result = root.Find(path);
                    if (result == null)
                    {
                        var lost = new LostProperty
                        {
                            ObjectName         = GetObjectName(path),
                            PropPath           = path,
                            AttributeName      = attribute,
                            SerializedProperty = pathProperty,
                            SerializedClip     = serializedClip,
                            State = FixState.Lost
                        };
                        lostAnimations.Add(lost);
                    }
                }
            }

            var clipLost = new ClipValidationContainer(lostAnimations, clip);

            return(clipLost);
        }
 private void DrawOnSuccess(ClipValidationContainer result)
 {
     DrawIconAndLabel(SuccessIcon, result.ClipName, "→正常です");
     DrawDetail(result.LostProperties);
 }