Ejemplo n.º 1
0
        public static void SwapVector2Labels(BGCurve.Mode2DEnum mode2D, Action action)
        {
            var needToSwap = mode2D != BGCurve.Mode2DEnum.Off && mode2D != BGCurve.Mode2DEnum.XY;

            GUIContent[] oldLabels = null;
            if (needToSwap)
            {
                oldLabels = BGPrivateField.Get <GUIContent[]>(typeof(EditorGUI), "s_XYLabels");
                GUIContent[] newLabels;
                switch (mode2D)
                {
                case BGCurve.Mode2DEnum.XZ:
                    newLabels = XZLabels;
                    break;

                case BGCurve.Mode2DEnum.YZ:
                    newLabels = YZLabels;
                    break;

                default:
                    throw new ArgumentOutOfRangeException("mode2D", mode2D, null);
                }
                BGPrivateField.Set(typeof(EditorGUI), "s_XYLabels", newLabels);
            }

            try
            {
                action();
            }
            finally
            {
                if (needToSwap)
                {
                    BGPrivateField.Set(typeof(EditorGUI), "s_XYLabels", oldLabels);
                }
            }
        }