Unity-AnimatorTransitionCopier icon indicating copy to clipboard operation
Unity-AnimatorTransitionCopier copied to clipboard

Add Feature to Copy StateMechineBehavior

Open fawad0dev opened this issue 1 year ago • 2 comments

if I just copy and Paste the State in the animator the scripts in the State are somehow linked when i change a value the pervious state script value also Changed.

ezgif-6-2e83101585

fawad0dev avatar Jul 15 '24 08:07 fawad0dev

I didn't get it. You are copying and pasting the state, which is Unity's built-in feature not the purpose of this repo. This repo is only used to copy the transition of states.

qwe321qwe321qwe321 avatar Jul 15 '24 08:07 qwe321qwe321qwe321

by the way I have created this function

 void ShowAnimatorStateDublicator()
    {
        GUILayout.BeginHorizontal();
        var selectedStates = Selection.GetFiltered<AnimatorState>(SelectionMode.Editable);
        if (selectedStates != null && selectedStates.Length > 0)
        {
            if (GUILayout.Button("CopyBehaviors"))
            {
                Debug.Log(Selection.activeObject);
                stateBehaviors = selectedStates[0].behaviours;
            }
            if (stateBehaviors != null && stateBehaviors.Length > 0)
            {
                if (GUILayout.Button("PasteBehaviors"))
                {
                    foreach (var selectedState in selectedStates)
                    {
                        Undo.RecordObject(selectedState, "Paste Behaviors");
                        EditorUtility.SetDirty(selectedState);
                        foreach (var smb in stateBehaviors)
                        {
                            Debug.Log("Adding: " + smb.GetType());
                            var newSmb = selectedState.AddStateMachineBehaviour(smb.GetType());
                            EditorUtility.CopySerialized(smb, newSmb);
                        }
                        EditorUtility.SetDirty(selectedState);
                    }
                }
            }
        }
        GUILayout.EndHorizontal();
    }

fawad0dev avatar Jul 15 '24 11:07 fawad0dev