protected override void OnEnable() { _target = (PreviewCamera)target; _cameraPointsList = new ReorderableList(serializedObject, serializedObject.FindProperty("cameraPoints"), true, true, true, true); _cameraPointsList.drawHeaderCallback = rect => { EditorGUI.LabelField(rect, "Camera Transition Points", EditorStyles.boldLabel); }; _cameraPointsList.drawElementCallback = (Rect rect, int index, bool isActive, bool isFocused) => { var element = _cameraPointsList.serializedProperty.GetArrayElementAtIndex(index); EditorGUI.ObjectField(new Rect(rect.x, rect.y, rect.width, EditorGUIUtility.singleLineHeight), element, GUIContent.none); }; #region Properties //Get Properties cameraPoints = serializedObject.FindProperty("cameraPoints"); moveImmediatly = serializedObject.FindProperty("moveImmediatly"); cameraMoveSpeed = serializedObject.FindProperty("cameraMoveSpeed"); cameraCloseEnough = serializedObject.FindProperty("cameraCloseEnough"); stopOnJoinRoom = serializedObject.FindProperty("stopOnJoinRoom"); targetCam = serializedObject.FindProperty("targetCam"); networkManager = serializedObject.FindProperty("networkManager"); #endregion base.OnEnable(); }
void RenderPreview() { for (int i = 0; i < sceneLights.Length; i++) { lightWasEnabled[i] = sceneLights[i].enabled; sceneLights[i].enabled = false; } RenderTexture.active = RenderTexture; instance.SetActive(true); PreviewLightA.gameObject.SetActive(true); PreviewLightB.gameObject.SetActive(true); PreviewCamera.Render(); instance.SetActive(false); PreviewLightA.gameObject.SetActive(false); PreviewLightB.gameObject.SetActive(false); for (int i = 0; i < sceneLights.Length; i++) { sceneLights[i].enabled = lightWasEnabled[i]; } }
void UpdateCamera(Scene oldScene, Scene newScene) { cam = Camera.main; if (cam == null) { //check if there's a preview camera PreviewCamera pcam = FindObjectOfType <PreviewCamera>(); if (pcam) { cam = pcam.GetComponent <Camera>(); } } }
private void ClearPreview(Card card) { if (PreviewCamera != null && CurrentCard == card) { if (PreviewCamera.Target != null) { CurrentCard.GraphicRotation = PreviewCamera.Target.transform.rotation; } this.DeferUntilNextFixedUpdate(() => Preview(card)).Then(() => { CurrentCard = null; PreviewCamera.Preview(null, null); }); } }
public static void CB_PreviewCamPoint() { if (!FindObjectOfType <PreviewCamera>()) { if (EditorUtility.DisplayDialog("Missing \"PreviewCamera\" Component!", "Unable to find the \"PreviewCamera\" component in the scene. Please run \"CB Games/Add/Camera/Preview Camera Component\" before running this.", "Okay")) { } } else { PreviewCamera cam = FindObjectOfType <PreviewCamera>(); GameObject point = new GameObject("CameraPoint"); E_Helpers.SetObjectIcon(point, E_Core.h_cameraPath); point.transform.SetParent(cam.transform); cam.cameraPoints.Add(point.transform); Debug.Log("Successfully added camera point to the scene."); } }
public override void OnInspectorGUI() { #region Core base.OnInspectorGUI(); PreviewCamera pc = (PreviewCamera)target; DrawTitleBar( "Preview Camera", "Component thats used to make a target camera follow a series of points. " + "This is designed specifically for a lobby preview camera however this does " + "contain a start/stop function for outside components to call.", E_Core.h_cameraPath ); #endregion #region Properties GUILayout.BeginHorizontal(); GUILayout.BeginVertical(); GUILayout.EndVertical(); GUILayout.EndHorizontal(); EditorGUILayout.PropertyField(moveImmediatly); EditorGUILayout.PropertyField(stopOnJoinRoom); GUILayout.BeginHorizontal(_skin.customStyles[1], GUILayout.ExpandHeight(false)); GUILayout.BeginVertical(GUILayout.ExpandHeight(false)); GUI.skin = _original; CBEditor.SetColorToEditorStyle(_originalHolder, _originalFoldout); _cameraPointsList.DoLayoutList(); GUI.skin = _skin; CBEditor.SetColorToEditorStyle(_skinHolder, _skinHolder); GUILayout.EndHorizontal(); GUILayout.EndVertical(); EditorGUILayout.PropertyField(cameraMoveSpeed); EditorGUILayout.PropertyField(cameraCloseEnough); EditorGUILayout.Space(); EditorGUILayout.LabelField("Optional Fields", _skin.textArea); EditorGUILayout.PropertyField(targetCam); EditorGUILayout.PropertyField(networkManager); #endregion #region Core EndInspectorGUI(typeof(PreviewCamera)); #endregion }
void Load(string path) { if (!File.Exists(path)) { Debug.LogError("File does not exist " + path); return; } using (BinaryReader reader = new BinaryReader(File.OpenRead(path))) { int header = reader.ReadInt32(); if (header <= 1) { hexGrid.Load(reader, header); PreviewCamera.ValidatePosition(); } else { Debug.LogWarning("Unknown map format " + header); } } }
//const float FACTOR = 0.1f; public Texture Render(Rect r, GUIStyle background, PreviewSceneManager scene, float yaw, float pitch, Vector3 position) { if (scene == null) { return(null); } using (var fog = new FogScope()) { m_previewUtility.BeginPreview(r, background); // set up the PreviewRenderUtility's mini internal scene // setup the ObjectPreview's camera scene.SetupCamera(PreviewCamera, scene.TargetPosition, yaw, pitch, position); foreach (var item in scene.EnumRenderItems) { // now, actually render out the RenderTexture //RenderMeshPreview(previewMesh, skinMeshRender.sharedMaterials); // submesh support, in case the mesh is made of multiple parts int subMeshCount = item.Mesh.subMeshCount; for (int i = 0; i < subMeshCount; i++) { m_previewUtility.DrawMesh(item.Mesh, item.Position, item.Rotation, item.Materials[i], i); } } // VERY IMPORTANT: this manually tells the camera to render and produce the render texture PreviewCamera.Render(); //m_previewUtility.Render(false, false); // reset the scene's fog from before return(m_previewUtility.EndPreview()); } }
private void Preview(Card card) { if (card != null && PreviewCamera != null) { if (card.Graphic.texture != null && !card.UseAnimatedGraphic) { return; } if (card.Graphic.texture == null) { card.UseAnimatedGraphic = true; } CurrentCard = card; var model = card.Build(); model.transform.rotation = card.GraphicRotation; PreviewCamera.PreviewOutline = card.Item.Element.PreviewOutline; PreviewCamera.PreviewDistance = card.Item.Element.PreviewDistance; PreviewCamera.Preview(model, CurrentCard.Graphic); } }
protected override void OnNavigatedTo(NavigationEventArgs e) { camera = new PreviewCamera(1280, 720); }
//################################################################################################# /// <summary> /// Constructor that create the Camera and the socket (inheritance). As for simple camera constructor, resolution could be set. /// </summary> /// <param name="width"> width frame resolution </param> /// <param name="height"> height frame resolution </param> public UdpPreviewCamera(int width, int height) { _camera = new PreviewCamera(width, height); }
/// <summary> /// Handles scenveview rendering of portal previews and related editor utilities /// </summary> private void OnWillRenderObject() { #if UNITY_EDITOR if (!(Selection.activeGameObject == gameObject)) return; if (!TargetController || !PortalMaterial || !Mask || !SKSGlobalRenderSettings.Preview || !this || Application.isPlaying) return; var previewRenderer = PreviewRoot.GetComponent<MeshRenderer>(); previewRenderer.sharedMaterial = PortalMaterial; //previewRenderer.enabled = true; var lib = PreviewCamera.GetComponent<SKSRenderLib>(); PreviewCamera.transform.localPosition = Vector3.zero; var sceneCam = SceneView.GetAllSceneCameras()[0]; var cam = PreviewCamera; GL.Clear(true, true, Color.black); Graphics.SetRenderTarget(null); var renderProps = new RenderProperties(); //renderState |= RenderState.FirstRender; renderProps |= RenderProperties.Optimize; renderProps |= SKSGlobalRenderSettings.Inverted ? RenderProperties.InvertedCached : 0; renderProps |= !SKSGlobalRenderSettings.UvFlip ? RenderProperties.UvFlipCached : 0; renderProps |= RenderProperties.ObliquePlane; renderProps |= RenderProperties.FirstRender; renderProps |= RenderProperties.RipCustomSkybox; var rend = GetComponent<MeshRenderer>(); var rend2 = TargetController.GetComponent<MeshRenderer>(); var mesh = PreviewRoot.GetComponent<MeshFilter>().sharedMesh; //TargetController.PreviewRoot.GetComponent<MeshRenderer>().enabled = false; //TargetController.GetComponent<MeshRenderer>().enabled = false; cam.transform.localPosition = Vector3.zero; TargetController.PreviewRoot.transform.localPosition = Vector3.zero; cam.transform.rotation = TargetController.PreviewRoot.transform.rotation * (Quaternion.Inverse(transform.rotation) * sceneCam.transform.rotation); TargetController.PreviewRoot.transform.localScale = Vector3.one; if (renderData == null) { renderData = new RenderData(renderProps, cam, sceneCam, sceneCam.projectionMatrix, TextureTargetEye.Right, PortalMaterial, new Vector2(Screen.currentResolution.width, Screen.currentResolution.height), previewRenderer, rend2, null, null, mesh, 1, 0, false, 0); } else { renderData.Position = sceneCam.transform.position; renderData.ProjectionMatrix = sceneCam.projectionMatrix; renderData.ScreenSize = new Vector2(Screen.currentResolution.width, Screen.currentResolution.height); renderData.RenderingCamera = PreviewCamera; renderData.SourceRenderer = previewRenderer; } try { lib.RenderCamera(renderData); } catch { //Doesn't really matter what happened here, unity editor strangeness sometimes hucks issues Graphics.SetRenderTarget(null); lib.TerminateRender(); return; } var block = new MaterialPropertyBlock(); previewRenderer.GetPropertyBlock(block); var output = (RenderTexture) block.GetTexture(TextureTargetEye.Right.Name()); if (output) previewRenderer.sharedMaterial.SetTexture(TextureTargetEye.Right.Name(), output); if (output) previewRenderer.sharedMaterial.SetTexture(TextureTargetEye.Left.Name(), output); if (output) block.SetTexture(TextureTargetEye.Left.Name(), output); Graphics.SetRenderTarget(null); lib.TerminateRender(); #endif }
void OnEnable() { instance = this; }
private void OnWillRenderObject() { #if UNITY_EDITOR if (!(Selection.activeGameObject == gameObject)) { return; } if (!TargetController || !PortalMaterial || !Mask || !SKSGlobalRenderSettings.Preview || !this || Application.isPlaying) { //CleanupTemp(); return; } MeshRenderer previewRenderer = PreviewRoot.GetComponent <MeshRenderer>(); previewRenderer.sharedMaterial = PortalMaterial; //previewRenderer.enabled = true; SKSRenderLib lib = PreviewCamera.GetComponent <SKSRenderLib>(); PreviewCamera.transform.localPosition = Vector3.zero; Camera sceneCam = SceneView.GetAllSceneCameras()[0]; Camera cam = PreviewCamera; GL.Clear(true, true, Color.black); Graphics.SetRenderTarget(null); RenderProperties renderProps = new RenderProperties(); //renderState |= RenderState.FirstRender; renderProps |= RenderProperties.Optimize; renderProps |= SKSGlobalRenderSettings.Inverted ? RenderProperties.InvertedCached : 0; renderProps |= !SKSGlobalRenderSettings.UvFlip ? RenderProperties.UvFlipCached : 0; renderProps |= RenderProperties.ObliquePlane; renderProps |= RenderProperties.FirstRender; renderProps |= RenderProperties.RipCustomSkybox; MeshRenderer rend = GetComponent <MeshRenderer>(); MeshRenderer rend2 = TargetController.GetComponent <MeshRenderer>(); Mesh mesh = PreviewRoot.GetComponent <MeshFilter>().sharedMesh; //TargetController.PreviewRoot.GetComponent<MeshRenderer>().enabled = false; //TargetController.GetComponent<MeshRenderer>().enabled = false; cam.transform.localPosition = Vector3.zero; TargetController.PreviewRoot.transform.localPosition = Vector3.zero; cam.transform.rotation = TargetController.PreviewRoot.transform.rotation * (Quaternion.Inverse(transform.rotation) * (sceneCam.transform.rotation)); TargetController.PreviewRoot.transform.localScale = Vector3.one; if (renderData == null) { renderData = new RenderData(renderProps, cam, sceneCam, sceneCam.transform.position, sceneCam.projectionMatrix, "_RightEyeTexture", PortalMaterial, new Vector2(Screen.currentResolution.width, Screen.currentResolution.height), previewRenderer, rend2, mesh, 1, 0, false, false); } else { renderData.Position = sceneCam.transform.position; renderData.ProjectionMatrix = sceneCam.projectionMatrix; renderData.ScreenSize = new Vector2(Screen.currentResolution.width, Screen.currentResolution.height); renderData.RenderingCamera = PreviewCamera; renderData.SourceRenderer = previewRenderer; } lib.RenderCamera(renderData); MaterialPropertyBlock block = new MaterialPropertyBlock(); previewRenderer.GetPropertyBlock(block); RenderTexture output = (RenderTexture)block.GetTexture("_RightEyeTexture"); //RenderTexture cachedOutput = RenderTexture.GetTemporary(output.width, output.height, output.depth, output.format); //cachedOutput.Create(); //texturesToDispose.Add(cachedOutput); //Graphics.CopyTexture(output, cachedOutput); if (output) { previewRenderer.sharedMaterial.SetTexture("_RightEyeTexture", output); } if (output) { previewRenderer.sharedMaterial.SetTexture("_LeftEyeTexture", output); } if (output) { block.SetTexture("_LeftEyeTexture", output); } //PortalController.PortalMaterial.SetVector("_LeftDrawPos", PortalController.PortalMaterial.GetVector("_RightDrawPos")); Graphics.SetRenderTarget(null); lib.TerminateRender(); #endif }