void OnDisable()
 {
     _gui                = null;
     _guiSide            = null;
     _guiFrameCount      = null;
     _guiFrameWidth      = null;
     _guiFrameHeight     = null;
     _guiCurrentFrame    = null;
     _guiPositionOffset  = null;
     _guiScaleOffset     = null;
     _guiAnimationClips  = null;
     _guiAnimationClips  = null;
     _guiMaterials       = null;
     _guiStartRotation   = null;
     _guiEndRotation     = null;
     _guiLoopCount       = null;
     _guiPingPong        = null;
     _guiSpriteSheetName = null;
     _guiExport          = null;
     _guiPreview         = null;
 }
        void OnEnable()
        {
            CreateExportFolderIfNeeded();

            _lastFrameTime = Time.realtimeSinceStartup;

            _gui = new GUIHorizontal();

            GUIVertical sideContainer = _gui.Add(new GUIVertical(GUILayout.MaxWidth(290.0f))) as GUIVertical;

            _guiSide = sideContainer.Add(new GUIScrollView()) as GUIScrollView;

            GUIObjectField <GameObject> guiGameObject = _guiSide.Add(new GUIObjectField <GameObject>(new GUIContent("GameObject", "GameObject to render as sprite sheet"),
                                                                                                     true, GameObjectChanged)) as GUIObjectField <GameObject>;

            _guiFrameCount = _guiSide.Add(new GUIIntSlider(new GUIContent("Frame Count", "Number of frames in the sprite sheet"),
                                                           12, 1, 64, FrameCountChanged)) as GUIIntSlider;
            _guiFrameWidth = _guiSide.Add(new GUIIntSlider(new GUIContent("Frame Width", "Width of each frame in the sprite sheet"),
                                                           100, 32, 512, ResizeFrame)) as GUIIntSlider;
            _guiFrameHeight = _guiSide.Add(new GUIIntSlider(new GUIContent("Frame Height", "Height of each frame in the sprite sheet"),
                                                            100, 32, 512, ResizeFrame)) as GUIIntSlider;
            _guiFOV = _guiSide.Add(new GUISlider(new GUIContent("FOV"), 20, 1, 179, OffsetChanged)) as GUISlider;

            _guiSide.Add(new GUISpace());
            _guiCurrentFrame = _guiSide.Add(new GUIIntSlider(new GUIContent("Current Frame"),
                                                             0, 0, _guiFrameCount.value - 1, RenderPreviewAction)) as GUIIntSlider;
            _guiDuration = _guiSide.Add(new GUISlider(new GUIContent("Duration"),
                                                      1, 0, 100, RenderPreviewAction)) as GUISlider;
            _guiPlay = _guiSide.Add(new GUIToggle(new GUIContent("Play"))) as GUIToggle;

            _guiSide.Add(new GUISpace());
            GUIFoldout offsetFoldout = _guiSide.Add(new GUIFoldout(new GUIContent("Position/Scale"))) as GUIFoldout;

            _guiPositionOffset = offsetFoldout.Add(new GUIVector3Field(new GUIContent("Position Offset"), OffsetChanged)) as GUIVector3Field;
            _guiScaleOffset    = offsetFoldout.Add(new GUISlider(new GUIContent("Scale Offset"), 0.0f, -10.0f, 10.0f, OffsetChanged)) as GUISlider;

            _guiAnimationClips = _guiSide.Add(new GUISpriteSheetClips(RenderPreviewAction)) as GUISpriteSheetClips;
            _guiMaterials      = _guiSide.Add(new GUISpriteSheetMaterials(RenderPreviewAction)) as GUISpriteSheetMaterials;

            GUIFoldout rotationFoldout = _guiSide.Add(new GUIFoldout(new GUIContent("Rotation"))) as GUIFoldout;

            _guiStartRotation = rotationFoldout.Add(new GUIVector3Field(new GUIContent("Start Rotation"), RenderPreviewAction)) as GUIVector3Field;
            _guiEndRotation   = rotationFoldout.Add(new GUIVector3Field(new GUIContent("End Rotation"), RenderPreviewAction)) as GUIVector3Field;

            GUIFoldout loopFoldout = _guiSide.Add(new GUIFoldout(new GUIContent("Rotation/Material Looping"))) as GUIFoldout;

            _guiLoopCount = loopFoldout.Add(new GUIIntSlider(new GUIContent("Loop Count"), 1, 1, 10, RenderPreviewAction)) as GUIIntSlider;
            _guiPingPong  = loopFoldout.Add(new GUIToggle(new GUIContent("Pingpong"), RenderPreviewAction)) as GUIToggle;

            GUIFoldout    outlineFoldout = _guiSide.Add(new GUIFoldout(new GUIContent("Outline Effect"))) as GUIFoldout;
            GUIColorField outlineColor   = outlineFoldout.Add(new GUIColorField(new GUIContent("Color"),
                                                                                OutlineColorChanged)) as GUIColorField;
            GUISlider outlineThreshold = outlineFoldout.Add(new GUISlider(new GUIContent("Threshold"),
                                                                          0.05f, 0.0f, 0.05f, OutlineThresholdChanged)) as GUISlider;

            _guiSide.Add(new GUISpace());
            _guiSpriteSheetName = _guiSide.Add(new GUITextField(new GUIContent("Sprite Sheet Name"))) as GUITextField;
            _guiExport          = _guiSide.Add(new GUIButton(new GUIContent("Export Sprite Sheet"), ExportSpriteSheet)) as GUIButton;

            _guiPreview = _gui.Add(new GUIVertical(GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true))) as GUIVertical;
            _guiPreview.shouldStoreLastRect = true;

            InitPreviewRenderTexture();
            InitPreviewCamera();
            InitRootGameObject();
            guiGameObject.value = _modelGameObject;
            GameObjectChanged(guiGameObject);
            RenderPreview(0);

            _guiStartRotation.vector = Vector3.zero;
            _guiEndRotation.vector   = Vector3.zero;
            outlineColor.color       = _previewOutline.outlineColor;
            outlineThreshold.value   = _previewOutline.depthThreshold;
        }