Adaug proiectul Unity

This commit is contained in:
2026-11-01 23:39:55 +02:00
parent cb14d9d37d
commit 863eac8f2c
23463 changed files with 5412601 additions and 0 deletions
@@ -0,0 +1,229 @@
namespace UnityEngine.Rendering
{
/// <summary>
/// User API to request access for an instance of the user history type.
/// Tracks the history types that were requested by the render pipeline features on this frame.
/// Requested history types are then made available for the future frames.
/// Request is active for one frame only and a new request should be made every frame.
/// Types that were not requested are eventually reset and GPU resources released.
/// </summary>
public interface IPerFrameHistoryAccessTracker
{
/// <summary>
/// Mark a certain history texture type (class) as a requirement for next frame.
/// Note: Requesting a history doesn't mean it will be actually available.
/// E.g. The first frame doesn't have any history data available at all.
/// </summary>
/// <typeparam name="Type">Type of the history instance.</typeparam>
public void RequestAccess<Type>() where Type : ContextItem;
}
/// <summary>
/// User API to get history write access for a user history type instance.
/// Write access is valid and available after the history type has been requested.
/// Otherwise a null is returned.
/// Typically called by the history type producer render pass in the render pipeline.
/// </summary>
public interface ICameraHistoryWriteAccess
{
/// <summary>
/// Check if a type has been requested and should be written this frame.
/// </summary>
/// <typeparam name="Type">Type of the history instance.</typeparam>
/// <returns>True if a type has been requested earlier. False otherwise.</returns>
public bool IsAccessRequested<Type>() where Type : ContextItem;
/// <summary>
/// Get write access to an instance of certain history type.
/// It is expected that the caller will filling the contents of the type textures.
/// Null if not requested beforehand.
/// On first get of a type, the type instance is created.
/// </summary>
/// <typeparam name="Type">Type of the history instance.</typeparam>
/// <returns>True if a type has been requested earlier. False otherwise.</returns>
public Type GetHistoryForWrite<Type>() where Type : ContextItem, new();
/// <summary>
/// Check if a type was already written this frame by some render pass.
/// </summary>
/// <typeparam name="Type">Type of the history instance.</typeparam>
/// <returns>True if a type has been written earlier. False otherwise.</returns>
public bool IsWritten<Type>() where Type : ContextItem;
}
/// <summary>
/// User API to get history read access for a user history type instance.
/// Read access is valid and available after the history type has been requested and written by a render pass.
/// Otherwise a null is returned.
/// Typically called by the history type consumer render pass in the render pipeline.
///
/// User API for external systems to register history read access callbacks.
/// </summary>
public interface ICameraHistoryReadAccess
{
/// <summary>
/// Get read access to an instance of certain history type.
/// Available only if the type instance has been requested and written earlier.
/// </summary>
/// <typeparam name="Type">Type of the history instance.</typeparam>
/// <returns>A class instance of Type. Null if not available on this frame.</returns>
// Get a certain history item from the camera or null if not available this frame.
public Type GetHistoryForRead<Type>() where Type : ContextItem;
/// <summary>
/// Callback type for requesting various history type instances for read.
/// Typically used by systems external to the pipeline.
/// For example: A MonoBehavior requesting access for MonoBehavior.LateUpdate() call.
/// </summary>
/// <param name="historyAccess">A container for history type requests.</param>
public delegate void HistoryRequestDelegate(IPerFrameHistoryAccessTracker historyAccess);
/// <summary>
/// A callback event used to register a callback for requesting history types.
/// </summary>
public event HistoryRequestDelegate OnGatherHistoryRequests;
}
/// <summary>
/// A convenience base class for camera history items/types.
/// It is recommended to derive from this class to make new history item type.
///
/// The owning camera BufferedRTHandleSystem reference is used for central storage.
/// The central storage allows the camera to track all of the history types in a single place.
/// And gives the deriving type a direct access to texture allocation services.
/// Type id is used to deconflict RTHandle ids from different types.
///
/// The user is responsible for designing the derived type to work well with the
/// producing and consuming render passes.
/// For example:
/// Add the necessary cpu-side tracking data and update logic.
/// Add methods for accessing the history data and design a suitable API for the type.
/// Handle allocation and deallocation of the history texture RTHandles etc.
/// </summary>
public abstract class CameraHistoryItem : ContextItem
{
// BufferedRTHandleSystem of the owning camera.
private BufferedRTHandleSystem m_Owner = null;
// Unique id for this type (derived) given by the owning camera.
private uint m_TypeId = uint.MaxValue;
/// <summary>
/// Called internally when a CameraHistoryItem type is created to initialize the RTHandle storage and type id.
///
/// User types can override to do additional initialization, such as creating the ids for multiple history RTHandles.
/// Deriving type should call the base.OnCreate() to correctly initialize the CameraHistoryItem first.
/// </summary>
/// <param name="owner">BufferedRTHandleSystem of the owning camera.</param>
/// <param name="typeId">Unique id given to this class type by the owning camera.</param>
public virtual void OnCreate(BufferedRTHandleSystem owner, uint typeId)
{
m_Owner = owner;
m_TypeId = typeId;
}
// The user API is protected, so that the BufferedRTHandleSystem is visible only for the custom Type implementation.
/// <summary>
/// The owning camera RTHandle storage for the history textures.
/// </summary>
protected BufferedRTHandleSystem storage => m_Owner;
/// <summary>
/// Creates unique ids for the RTHandle storage.
/// Index == 0, returns the TypeId of this CameraHistoryItem.
/// Index == N, generates new ids in case the user wants to store multiple history textures in the same CameraHistoryItem.
/// </summary>
/// <param name="index">Index of the type RTHandle, a type local Enum or a user id.</param>
/// <returns>A unique id for each type, index and camera.</returns>
protected int MakeId(uint index)
{
return (int)(((m_TypeId & 0xFFFF) << 16) | (index & 0xFFFF));
}
/// <summary>
/// Allocate a history frame RTHandle[] using a descriptor.
/// </summary>
/// <param name="id">Id for the history RTHandle storage.</param>
/// <param name="count">Number of RTHandles allocated for the id.</param>
/// <param name="desc">Texture descriptor used for each RTHandle in the allocation.</param>
/// <param name="name">User visible debug name of the texture.</param>
/// <returns>Current frame RTHandle in the allocation.</returns>
protected RTHandle AllocHistoryFrameRT(int id, int count,
ref RenderTextureDescriptor desc, string name = "")
{
// Simplified for typical history textures:
// Sampling is usually bilinear & clamp. Point sample can be a texture.Load() or done with inline samplers.
return AllocHistoryFrameRT(id, count, ref desc, FilterMode.Bilinear, name);
}
/// <summary>
/// Allocate a history frame RTHandle[] using a descriptor.
/// </summary>
/// <param name="id">Id for the history RTHandle storage.</param>
/// <param name="count">Number of RTHandles allocated for the id.</param>
/// <param name="desc">Texture descriptor used for each RTHandle in the allocation.</param>
/// <param name="filterMode">Filtering mode of the texture.</param>
/// <param name="name">User visible debug name of the texture.</param>
/// <returns>Current frame RTHandle in the allocation.</returns>
protected RTHandle AllocHistoryFrameRT(int id, int count,
ref RenderTextureDescriptor desc,
FilterMode filterMode,
string name = "")
{
RenderTextureDescriptor d = desc;
// Simplified for typical history textures:
// No shadows, no mipmaps, no aniso.
m_Owner.AllocBuffer(id, count, ref desc, filterMode, TextureWrapMode.Clamp, false, 0, 0, name);
return GetCurrentFrameRT(0);
}
/// <summary>
/// Release the RTHandles allocated for the id.
/// </summary>
/// <param name="id">Id for the history RTHandle storage.</param>
protected void ReleaseHistoryFrameRT(int id)
{
m_Owner.ReleaseBuffer(id);
}
/// <summary>
/// Returns the id RTHandle from the previous frame.
/// </summary>
/// <param name="id">Id for the history RTHandle storage.</param>
/// <returns>The RTHandle from previous frame.</returns>
protected RTHandle GetPreviousFrameRT(int id)
{
return m_Owner.GetFrameRT(id, 1);
}
/// <summary>
/// Returns the id RTHandle of the current frame.
/// </summary>
/// <param name="id">Id for the history RTHandle storage.</param>
/// <returns>The RTHandle of the current frame.</returns>
protected RTHandle GetCurrentFrameRT(int id)
{
return m_Owner.GetFrameRT(id, 0);
}
/// <summary>
/// Returns the id stable index from the previous frame.
/// </summary>
/// <param name="id">Id for the history RTHandle storage.</param>
/// <returns>The stable index from previous frame.</returns>
protected int GetPreviousFrameRTStableIndex(int id)
{
return m_Owner.GetFrameRTStableIndex(id, 1);
}
/// <summary>
/// Returns the id stable index of the current frame.
/// </summary>
/// <param name="id">Id for the history RTHandle storage.</param>
/// <returns>The stable index of the current frame.</returns>
protected int GetCurrentFrameRTStableIndex(int id)
{
return m_Owner.GetFrameRTStableIndex(id, 0);
}
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: b5a8751420b0404cb9679106b091aef9
timeCreated: 1692619927
@@ -0,0 +1,115 @@
using UnityEngine;
namespace UnityEngine.Rendering
{
/// <summary>
/// Utility component allowing users to setup many different static camera and cycle through their positions using the Debug Window.
/// </summary>
[CoreRPHelpURLAttribute("Camera-Switcher")]
public class CameraSwitcher : MonoBehaviour
{
/// <summary>
/// List of target cameras.
/// </summary>
public Camera[] m_Cameras;
private int m_CurrentCameraIndex = -1;
private Camera m_OriginalCamera = null;
private Vector3 m_OriginalCameraPosition;
private Quaternion m_OriginalCameraRotation;
private Camera m_CurrentCamera = null;
GUIContent[] m_CameraNames = null;
int[] m_CameraIndices = null;
DebugUI.EnumField m_DebugEntry;
//saved enum fields for when repainting
int m_DebugEntryEnumIndex;
void OnEnable()
{
m_OriginalCamera = GetComponent<Camera>();
m_CurrentCamera = m_OriginalCamera;
if (m_OriginalCamera == null)
{
Debug.LogError("Camera Switcher needs a Camera component attached");
return;
}
m_CurrentCameraIndex = GetCameraCount() - 1;
m_CameraNames = new GUIContent[GetCameraCount()];
m_CameraIndices = new int[GetCameraCount()];
for (int i = 0; i < m_Cameras.Length; ++i)
{
Camera cam = m_Cameras[i];
if (cam != null)
{
m_CameraNames[i] = new GUIContent(cam.name);
}
else
{
m_CameraNames[i] = new GUIContent("null");
}
m_CameraIndices[i] = i;
}
m_CameraNames[GetCameraCount() - 1] = new GUIContent("Original Camera");
m_CameraIndices[GetCameraCount() - 1] = GetCameraCount() - 1;
m_DebugEntry = new DebugUI.EnumField { displayName = "Camera Switcher", getter = () => m_CurrentCameraIndex, setter = value => SetCameraIndex(value), enumNames = m_CameraNames, enumValues = m_CameraIndices, getIndex = () => m_DebugEntryEnumIndex, setIndex = value => m_DebugEntryEnumIndex = value };
var panel = DebugManager.instance.GetPanel("Camera", true);
panel.children.Add(m_DebugEntry);
}
void OnDisable()
{
if (m_DebugEntry != null && m_DebugEntry.panel != null)
{
var panel = m_DebugEntry.panel;
panel.children.Remove(m_DebugEntry);
}
}
int GetCameraCount()
{
return m_Cameras.Length + 1; // We need +1 for handling the original camera.
}
Camera GetNextCamera()
{
if (m_CurrentCameraIndex == m_Cameras.Length)
return m_OriginalCamera;
else
return m_Cameras[m_CurrentCameraIndex];
}
void SetCameraIndex(int index)
{
if (index > 0 && index < GetCameraCount())
{
m_CurrentCameraIndex = index;
if (m_CurrentCamera == m_OriginalCamera)
{
m_OriginalCameraPosition = m_OriginalCamera.transform.position;
m_OriginalCameraRotation = m_OriginalCamera.transform.rotation;
}
m_CurrentCamera = GetNextCamera();
if (m_CurrentCamera != null)
{
// If we witch back to the original camera, put back the transform in it.
if (m_CurrentCamera == m_OriginalCamera)
m_OriginalCamera.transform.SetPositionAndRotation(m_OriginalCameraPosition, m_OriginalCameraRotation);
transform.SetPositionAndRotation(m_CurrentCamera.transform.position, m_CurrentCamera.transform.rotation);
}
}
}
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: f52d1e5345c395641b482217c8804ff9
timeCreated: 1488380874
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,205 @@
#if ENABLE_INPUT_SYSTEM && ENABLE_INPUT_SYSTEM_PACKAGE
#define USE_INPUT_SYSTEM
using UnityEngine.InputSystem;
#endif
using System.Collections.Generic;
using UnityEngine;
namespace UnityEngine.Rendering
{
/// <summary>
/// Utility Free Camera component.
/// </summary>
[CoreRPHelpURLAttribute("Free-Camera")]
public class FreeCamera : MonoBehaviour
{
const float k_MouseSensitivityMultiplier = 0.01f;
/// <summary>
/// Rotation speed when using a controller.
/// </summary>
public float m_LookSpeedController = 120f;
/// <summary>
/// Rotation speed when using the mouse.
/// </summary>
public float m_LookSpeedMouse = 4.0f;
/// <summary>
/// Movement speed.
/// </summary>
public float m_MoveSpeed = 10.0f;
/// <summary>
/// Value added to the speed when incrementing.
/// </summary>
public float m_MoveSpeedIncrement = 2.5f;
/// <summary>
/// Scale factor of the turbo mode.
/// </summary>
public float m_Turbo = 10.0f;
#if !USE_INPUT_SYSTEM
private static readonly string kMouseX = "Mouse X";
private static readonly string kMouseY = "Mouse Y";
private static readonly string kRightStickX = "Controller Right Stick X";
private static readonly string kRightStickY = "Controller Right Stick Y";
private static readonly string kVertical = "Vertical";
private static readonly string kHorizontal = "Horizontal";
private static readonly string kYAxis = "YAxis";
private static readonly string kSpeedAxis = "Speed Axis";
#endif
#if USE_INPUT_SYSTEM
InputAction lookAction;
InputAction moveAction;
InputAction speedAction;
InputAction yMoveAction;
#endif
void OnEnable()
{
RegisterInputs();
}
void RegisterInputs()
{
#if USE_INPUT_SYSTEM
var map = new InputActionMap("Free Camera");
lookAction = map.AddAction("look", binding: "<Mouse>/delta");
moveAction = map.AddAction("move", binding: "<Gamepad>/leftStick");
speedAction = map.AddAction("speed", binding: "<Gamepad>/dpad");
yMoveAction = map.AddAction("yMove");
lookAction.AddBinding("<Gamepad>/rightStick").WithProcessor("scaleVector2(x=15, y=15)");
moveAction.AddCompositeBinding("Dpad")
.With("Up", "<Keyboard>/w")
.With("Up", "<Keyboard>/upArrow")
.With("Down", "<Keyboard>/s")
.With("Down", "<Keyboard>/downArrow")
.With("Left", "<Keyboard>/a")
.With("Left", "<Keyboard>/leftArrow")
.With("Right", "<Keyboard>/d")
.With("Right", "<Keyboard>/rightArrow");
speedAction.AddCompositeBinding("Dpad")
.With("Up", "<Keyboard>/home")
.With("Down", "<Keyboard>/end");
yMoveAction.AddCompositeBinding("Dpad")
.With("Up", "<Keyboard>/pageUp")
.With("Down", "<Keyboard>/pageDown")
.With("Up", "<Keyboard>/e")
.With("Down", "<Keyboard>/q")
.With("Up", "<Gamepad>/rightshoulder")
.With("Down", "<Gamepad>/leftshoulder");
moveAction.Enable();
lookAction.Enable();
speedAction.Enable();
yMoveAction.Enable();
#endif
#if UNITY_EDITOR && !USE_INPUT_SYSTEM
#pragma warning disable CS0618 // Type or member is obsolete
List<InputManagerEntry> inputEntries = new List<InputManagerEntry>();
// Add new bindings
inputEntries.Add(new InputManagerEntry { name = kRightStickX, kind = InputManagerEntry.Kind.Axis, axis = InputManagerEntry.Axis.Fourth, sensitivity = 1.0f, gravity = 1.0f, deadZone = 0.2f });
inputEntries.Add(new InputManagerEntry { name = kRightStickY, kind = InputManagerEntry.Kind.Axis, axis = InputManagerEntry.Axis.Fifth, sensitivity = 1.0f, gravity = 1.0f, deadZone = 0.2f, invert = true });
inputEntries.Add(new InputManagerEntry { name = kYAxis, kind = InputManagerEntry.Kind.KeyOrButton, btnPositive = "page up", altBtnPositive = "joystick button 5", btnNegative = "page down", altBtnNegative = "joystick button 4", gravity = 1000.0f, deadZone = 0.001f, sensitivity = 1000.0f });
inputEntries.Add(new InputManagerEntry { name = kYAxis, kind = InputManagerEntry.Kind.KeyOrButton, btnPositive = "q", btnNegative = "e", gravity = 1000.0f, deadZone = 0.001f, sensitivity = 1000.0f });
inputEntries.Add(new InputManagerEntry { name = kSpeedAxis, kind = InputManagerEntry.Kind.KeyOrButton, btnPositive = "home", btnNegative = "end", gravity = 1000.0f, deadZone = 0.001f, sensitivity = 1000.0f });
inputEntries.Add(new InputManagerEntry { name = kSpeedAxis, kind = InputManagerEntry.Kind.Axis, axis = InputManagerEntry.Axis.Seventh, gravity = 1000.0f, deadZone = 0.001f, sensitivity = 1000.0f });
InputRegistering.RegisterInputs(inputEntries);
#pragma warning restore CS0618 // Type or member is obsolete
#endif
}
float inputRotateAxisX, inputRotateAxisY;
float inputChangeSpeed;
float inputVertical, inputHorizontal, inputYAxis;
bool leftShiftBoost, leftShift, fire1;
void UpdateInputs()
{
inputRotateAxisX = 0.0f;
inputRotateAxisY = 0.0f;
leftShiftBoost = false;
fire1 = false;
#if USE_INPUT_SYSTEM
var lookDelta = lookAction.ReadValue<Vector2>();
inputRotateAxisX = lookDelta.x * m_LookSpeedMouse * k_MouseSensitivityMultiplier;
inputRotateAxisY = lookDelta.y * m_LookSpeedMouse * k_MouseSensitivityMultiplier;
leftShift = Keyboard.current?.leftShiftKey?.isPressed ?? false;
fire1 = Mouse.current?.leftButton?.isPressed == true || Gamepad.current?.xButton?.isPressed == true;
inputChangeSpeed = speedAction.ReadValue<Vector2>().y;
var moveDelta = moveAction.ReadValue<Vector2>();
inputVertical = moveDelta.y;
inputHorizontal = moveDelta.x;
inputYAxis = yMoveAction.ReadValue<Vector2>().y;
#else
if (Input.GetMouseButton(1))
{
leftShiftBoost = true;
inputRotateAxisX = Input.GetAxis(kMouseX) * m_LookSpeedMouse;
inputRotateAxisY = Input.GetAxis(kMouseY) * m_LookSpeedMouse;
}
inputRotateAxisX += (Input.GetAxis(kRightStickX) * m_LookSpeedController * k_MouseSensitivityMultiplier);
inputRotateAxisY += (Input.GetAxis(kRightStickY) * m_LookSpeedController * k_MouseSensitivityMultiplier);
leftShift = Input.GetKey(KeyCode.LeftShift);
fire1 = Input.GetAxis("Fire1") > 0.0f;
inputChangeSpeed = Input.GetAxis(kSpeedAxis);
inputVertical = Input.GetAxis(kVertical);
inputHorizontal = Input.GetAxis(kHorizontal);
inputYAxis = Input.GetAxis(kYAxis);
#endif
}
void Update()
{
// If the debug menu is running, we don't want to conflict with its inputs.
if (DebugManager.instance.displayRuntimeUI)
return;
UpdateInputs();
if (inputChangeSpeed != 0.0f)
{
m_MoveSpeed += inputChangeSpeed * m_MoveSpeedIncrement;
if (m_MoveSpeed < m_MoveSpeedIncrement) m_MoveSpeed = m_MoveSpeedIncrement;
}
bool moved = inputRotateAxisX != 0.0f || inputRotateAxisY != 0.0f || inputVertical != 0.0f || inputHorizontal != 0.0f || inputYAxis != 0.0f;
if (moved)
{
float rotationX = transform.localEulerAngles.x;
float newRotationY = transform.localEulerAngles.y + inputRotateAxisX;
// Weird clamping code due to weird Euler angle mapping...
float newRotationX = (rotationX - inputRotateAxisY);
if (rotationX <= 90.0f && newRotationX >= 0.0f)
newRotationX = Mathf.Clamp(newRotationX, 0.0f, 90.0f);
if (rotationX >= 270.0f)
newRotationX = Mathf.Clamp(newRotationX, 270.0f, 360.0f);
transform.localRotation = Quaternion.Euler(newRotationX, newRotationY, transform.localEulerAngles.z);
float moveSpeed = Time.deltaTime * m_MoveSpeed;
if (fire1 || leftShiftBoost && leftShift)
moveSpeed *= m_Turbo;
transform.position += transform.forward * (moveSpeed * inputVertical)
+ transform.right * (moveSpeed * inputHorizontal)
+ Vector3.up * (moveSpeed * inputYAxis);
}
}
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 618b0e3f6c65dd247a4a016150006c57
timeCreated: 1488370968
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: