Ejemplo n.º 1
0
        public static void CopyLayer(StateLayer layer, StateLayer layerToCopy, bool copyStates, bool copySublayers)
        {
#if UNITY_EDITOR
            if (layerToCopy == null)
            {
                return;
            }

            var layerSerialized       = new UnityEditor.SerializedObject(layer);
            var parentReference       = layerSerialized.FindProperty("parentReference").GetValue <UnityEngine.Object>();
            var machineReference      = layerSerialized.FindProperty("machineReference").GetValue <UnityEngine.Object>();
            var stateReferences       = layerSerialized.FindProperty("stateReferences").GetValues <UnityEngine.Object>();
            var activeStateReferences = layerSerialized.FindProperty("activeStateReferences").GetValues <UnityEngine.Object>();

            UnityEditorInternal.ComponentUtility.CopyComponent(layerToCopy);
            UnityEditorInternal.ComponentUtility.PasteComponentValues(layer);

            layerSerialized = new UnityEditor.SerializedObject(layer);
            layerSerialized.FindProperty("parentReference").SetValue(parentReference);
            layerSerialized.FindProperty("machineReference").SetValue(machineReference);
            layerSerialized.FindProperty("stateReferences").SetValues(stateReferences);
            layerSerialized.FindProperty("activeStateReferences").SetValues(activeStateReferences);

            for (int i = 0; i < stateReferences.Length; i++)
            {
                var stateReference = stateReferences[i];
                var state          = stateReference as State;
                var sublayer       = stateReference as StateLayer;

                if (copyStates && state != null)
                {
                    var stateToCopy = layerToCopy.GetState(state.GetType()) as State;

                    if (stateToCopy != null)
                    {
                        CopyState(state, stateToCopy);
                    }
                }

                if (copySublayers && sublayer != null)
                {
                    var sublayerToCopy = layerToCopy.GetState(sublayer.GetType()) as StateLayer;

                    if (sublayerToCopy != null)
                    {
                        CopyLayer(sublayer, sublayerToCopy, copyStates, copySublayers);
                    }
                }
            }
#endif
        }
Ejemplo n.º 2
0
 public static List <State> GetState()
 {
     return(StateLayer.GetState());
 }
        public static void CopyLayer(StateLayer layer, StateLayer layerToCopy, bool copyStates, bool copySublayers)
        {
            #if UNITY_EDITOR
            if (layerToCopy == null)
                return;

            var layerSerialized = new UnityEditor.SerializedObject(layer);
            var parentReference = layerSerialized.FindProperty("parentReference").GetValue<UnityEngine.Object>();
            var machineReference = layerSerialized.FindProperty("machineReference").GetValue<UnityEngine.Object>();
            var stateReferences = layerSerialized.FindProperty("stateReferences").GetValues<UnityEngine.Object>();
            var activeStateReferences = layerSerialized.FindProperty("activeStateReferences").GetValues<UnityEngine.Object>();

            UnityEditorInternal.ComponentUtility.CopyComponent(layerToCopy);
            UnityEditorInternal.ComponentUtility.PasteComponentValues(layer);

            layerSerialized = new UnityEditor.SerializedObject(layer);
            layerSerialized.FindProperty("parentReference").SetValue(parentReference);
            layerSerialized.FindProperty("machineReference").SetValue(machineReference);
            layerSerialized.FindProperty("stateReferences").SetValues(stateReferences);
            layerSerialized.FindProperty("activeStateReferences").SetValues(activeStateReferences);

            for (int i = 0; i < stateReferences.Length; i++)
            {
                var stateReference = stateReferences[i];
                var state = stateReference as State;
                var sublayer = stateReference as StateLayer;

                if (copyStates && state != null)
                {
                    var stateToCopy = layerToCopy.GetState(state.GetType()) as State;

                    if (stateToCopy != null)
                        CopyState(state, stateToCopy);
                }

                if (copySublayers && sublayer != null)
                {
                    var sublayerToCopy = layerToCopy.GetState(sublayer.GetType()) as StateLayer;

                    if (sublayerToCopy != null)
                        CopyLayer(sublayer, sublayerToCopy, copyStates, copySublayers);
                }
            }
            #endif
        }