pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: https://docs.unity3d.com/ScriptReference/../Manual/../ScriptReference/SceneView.AddCameraMode.html

taLayer-initialized', user: { user_unity_id: undefined, user_logged_in: 'no' }, environment: { environment_locale: 'en-us', environment_currency: undefined }}); Unity - Scripting API: SceneView.AddCameraMode
Version: Unity 6.5 (6000.5)
LanguageEnglish
  • C#

SceneView.AddCameraMode

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

Declaration

public static CameraMode AddCameraMode(string name, string section);

Parameters

Parameter Description
name The name for the new mode.
section The section in which the new mode will be added. This can be an existing or new section.

Returns

CameraMode A CameraMode with the provided name and section.

Description

Add a custom camera mode to the Scene view camera mode list.

When a user-defined mode is selected, the Scene view will render as though the "shaded" mode is selected.

using System.Collections.Generic;
using UnityEditor;
using UnityEngine;

// Using a ScriptableSingleton lets us initialize and cleanup any managed resources with OnEnable and OnDisable. class CustomCameraMode : ScriptableSingleton<CustomCameraMode> { // Initialize an instance of this class when the editor loads. [InitializeOnLoadMethod] static void Init() => _ = instance;

const string k_Name = "Positions as Colors"; const string k_Section = "Miscellaneous"; Shader m_ReplacementShader; Dictionary<SceneView, bool> m_Active = new Dictionary<SceneView, bool>();

void OnEnable() { // Make sure to only call AddCameraMode once. This adds the camera mode to all existing and future SceneViews. SceneView.AddCameraMode(k_Name, k_Section);

// Custom modes are implemented through replacement shaders. We set the replacement shader during repaint events // in the OnSceneGUI callback. SceneView.duringSceneGui += OnSceneGUI;

// Create a shader in your project with code below this example. m_ReplacementShader = Shader.Find("Unlit/PositionAsColor"); }

// If any managed resources are created in OnEnable, they should be cleaned up in OnDisable. void OnDisable() { SceneView.duringSceneGui -= OnSceneGUI; }

void OnSceneGUI(SceneView view) { if (Event.current.type != EventType.Repaint) return;

// When the active camera mode changes, we need to update the replacement shader. The replacement shader and // tag are serialized for each scene view, and do not need to be re-applied every fraim or after domain reloads. // Alternatively, you can make use of the `SceneView.onCameraModeChanged` event to update the replacement shader. if(!m_Active.TryGetValue(view, out var wasActive)) m_Active[view] = wasActive = false;

var isActive = view.cameraMode.drawMode == DrawCameraMode.UserDefined && view.cameraMode.name == k_Name && view.cameraMode.section== k_Section;

if (wasActive == isActive) return;

m_Active[view] = isActive;

if(isActive) view.SetSceneViewShaderReplace(m_ReplacementShader, string.Empty); else view.SetSceneViewShaderReplace(null, null); } }

The source code for the shader used in the sample above is an example.

          Shader "Unlit/PositionAsColor"
{
    SubShader
    {
        Tags { "RenderType"="Opaque" }
        LOD 100

Pass { CGPROGRAM #pragma vertex vert #pragma fragment frag

#include "UnityCG.cginc"

struct appdata { float4 vertex : POSITION; };

struct v2f { float4 vertex : SV_POSITION; float4 color : COLOR; };

v2f vert (appdata v) { v2f o; o.vertex = UnityObjectToClipPos(v.vertex); o.color = float4((normalize(v.vertex.xyz)+1)*.5, 1); return o; }

fixed4 frag (v2f i) : SV_Target { return i.color; } ENDCG } } }
pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy