private void GameObjectChanged(GUIBase sender) { GUIObjectField <GameObject> gameObjectField = sender as GUIObjectField <GameObject>; _guiSpriteSheetName.value = GetExportNameForGameObject(gameObjectField.value); if (_modelGameObject != null) { _modelGameObject.transform.parent = null; DestroyImmediate(_modelGameObject); _modelGameObject = null; } if (gameObjectField.value != null) { _modelGameObject = GameObject.Instantiate(gameObjectField.value); _modelGameObject.name = _ModelName; _modelGameObject.transform.parent = _rootGameObject.transform; _modelGameObject.transform.localPosition = Vector3.zero; Transform[] children = _modelGameObject.GetComponentsInChildren <Transform>(true); foreach (Transform child in children) { child.gameObject.hideFlags = HideFlags.HideAndDontSave; child.gameObject.layer = _PreviewLayer; } ScaleModelToFitCamera(); _guiAnimationClips.animators = _modelGameObject.GetComponentsInChildren <Animator>(true); _guiMaterials.materials = GetUniquePixelArtMaterials(_modelGameObject); } else { _guiAnimationClips.animators = null; _guiMaterials.materials = null; } _guiExport.isEnabled = gameObjectField.value != null; RenderPreview(_guiCurrentFrame.value); }
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; }