Top Related Projects
Source from the Microsoft .NET Reference Source that represent a subset of the .NET Framework
.NET is a cross-platform runtime for cloud, mobile, desktop, and IoT apps.
Mono open source ECMA CLI, C# and .NET implementation.
Godot Engine – Multi-platform 2D and 3D game engine
Cocos2d-x is a suite of open-source, cross-platform, game-development tools utilized by millions of developers across the globe. Its core has evolved to serve as the foundation for Cocos Creator 1.x & 2.x.
A simple and easy-to-use library to enjoy videogames programming
Quick Overview
Unity-Technologies/UnityCsReference is the C# reference source code for the Unity game engine. It provides developers with access to Unity's core C# codebase, allowing for a deeper understanding of the engine's internals and facilitating advanced debugging and customization.
Pros
- Enables developers to explore and understand Unity's internal workings
- Facilitates advanced debugging by providing source-level insight
- Allows for custom modifications and extensions to Unity's core functionality
- Serves as a valuable learning resource for game development best practices
Cons
- Not intended for direct use in Unity projects; it's primarily for reference
- May be challenging for beginners to navigate and understand
- Updates may not always align perfectly with the latest Unity release
- Doesn't include all of Unity's codebase, as some parts are closed-source
Code Examples
This repository is not a code library for direct use, but rather a reference source. However, here are a few examples of interesting code snippets from the repository:
// From UnityEngine.CoreModule/Math/Vector3.cs
public static Vector3 Lerp(Vector3 a, Vector3 b, float t)
{
t = Mathf.Clamp01(t);
return new Vector3(
a.x + (b.x - a.x) * t,
a.y + (b.y - a.y) * t,
a.z + (b.z - a.z) * t
);
}
This code shows the implementation of Vector3 linear interpolation in Unity.
// From UnityEngine.CoreModule/GameObject.cs
public Component AddComponent(Type componentType)
{
return AddComponent(componentType, false);
}
internal Component AddComponent(Type componentType, bool assertOnInvalidType)
{
return AddComponentInternal(componentType, assertOnInvalidType);
}
This snippet demonstrates how Unity handles adding components to GameObjects.
// From UnityEngine.CoreModule/SceneManagement/SceneManager.cs
public static Scene LoadScene(string sceneName, LoadSceneMode mode = LoadSceneMode.Single)
{
LoadSceneParameters parameters = new LoadSceneParameters(mode);
return LoadScene(sceneName, parameters);
}
This code shows the implementation of scene loading in Unity's SceneManager.
Getting Started
As this is a reference source repository, there's no traditional "getting started" process. However, to make use of this repository:
- Clone the repository:
git clone https://github.com/Unity-Technologies/UnityCsReference.git
- Use it alongside your Unity development for reference and debugging
- When debugging Unity C# code, you can set up source linking in your IDE to step through this code
Remember that this is not meant to be directly included or modified in your Unity projects. It's primarily for reference and advanced debugging purposes.
Competitor Comparisons
Source from the Microsoft .NET Reference Source that represent a subset of the .NET Framework
Pros of referencesource
- More comprehensive coverage of .NET Framework
- Larger community and broader usage across various applications
- Better documentation and official Microsoft support
Cons of referencesource
- Less focused on game development and real-time applications
- May include more legacy code and older design patterns
- Potentially more complex due to broader scope
Code Comparison
UnityCsReference:
public static float Lerp(float a, float b, float t)
{
return a + (b - a) * Mathf.Clamp01(t);
}
referencesource:
public static double Lerp(double start, double end, double amount)
{
return start + (end - start) * amount;
}
The UnityCsReference implementation includes a clamp function to ensure the interpolation factor is between 0 and 1, while the referencesource version doesn't include this safety check. This reflects Unity's focus on game development, where preventing unexpected behavior is crucial.
UnityCsReference is tailored for game development and real-time applications, offering optimized implementations for common game-related operations. referencesource, on the other hand, provides a broader set of functionalities for general-purpose .NET development, making it more versatile but potentially less optimized for specific use cases like game development.
.NET is a cross-platform runtime for cloud, mobile, desktop, and IoT apps.
Pros of runtime
- Broader scope, covering the entire .NET runtime and core libraries
- More active development with frequent updates and contributions
- Extensive documentation and community support
Cons of runtime
- Larger codebase, potentially more complex to navigate
- Less focused on game development-specific features
- Steeper learning curve for those primarily interested in Unity development
Code Comparison
UnityCsReference:
public class GameObject : Object
{
public Transform transform { get; }
public GameObject(string name) : base(name) { }
public T GetComponent<T>() where T : Component { }
}
runtime:
public class Object : IDisposable
{
protected Object() { }
~Object() { }
public void Dispose() { }
protected virtual void Dispose(bool disposing) { }
}
The UnityCsReference code snippet shows a game-specific class structure, while the runtime example demonstrates a more general-purpose base class. UnityCsReference focuses on game object functionality, whereas runtime provides a foundation for broader .NET object management.
Mono open source ECMA CLI, C# and .NET implementation.
Pros of mono
- Broader scope: Implements the entire .NET framework, not just Unity-specific parts
- More active community: Larger contributor base and more frequent updates
- Cross-platform support: Runs on various operating systems beyond game development
Cons of mono
- Less Unity-specific: May not have optimizations tailored for game development
- Larger codebase: Can be more challenging to navigate for Unity-focused developers
- Potentially slower performance: Generic implementation may not be as optimized for Unity use cases
Code Comparison
mono:
public override Type[] GetGenericArguments()
{
if (!IsGenericType)
return Type.EmptyTypes;
return GetGenericTypeDefinition().GetGenericArguments();
}
UnityCsReference:
public override Type[] GetGenericArguments()
{
if (!IsGenericType)
return Type.EmptyTypes;
return GetGenericTypeDefinition().GetGenericArguments();
}
In this case, the code is identical, demonstrating that both projects implement some core .NET functionality similarly. However, UnityCsReference likely contains more game-specific optimizations and features in other areas of the codebase.
Godot Engine – Multi-platform 2D and 3D game engine
Pros of Godot
- Open-source and completely free, allowing for full customization and community contributions
- Lighter weight and more efficient, resulting in faster compile times and better performance
- Built-in support for 2D and 3D game development with a user-friendly scene system
Cons of Godot
- Smaller ecosystem and community compared to Unity, resulting in fewer available assets and plugins
- Less extensive documentation and learning resources for beginners
- Limited support for high-end graphics and advanced rendering techniques
Code Comparison
Godot (GDScript):
extends Sprite
func _ready():
position = Vector2(100, 100)
scale = Vector2(2, 2)
UnityCsReference (C#):
using UnityEngine;
public class Example : MonoBehaviour
{
void Start()
{
transform.position = new Vector3(1f, 1f, 0f);
transform.localScale = new Vector3(2f, 2f, 1f);
}
}
Both examples demonstrate basic object positioning and scaling, showcasing the syntax differences between GDScript and C#. Godot's approach is more concise, while Unity's offers more familiar object-oriented programming patterns.
Cocos2d-x is a suite of open-source, cross-platform, game-development tools utilized by millions of developers across the globe. Its core has evolved to serve as the foundation for Cocos Creator 1.x & 2.x.
Pros of cocos2d-x
- Open-source and free to use, with a large community of developers
- Cross-platform development for mobile, desktop, and web
- Lightweight and efficient, suitable for 2D game development
Cons of cocos2d-x
- Steeper learning curve compared to Unity's visual editor
- Less extensive documentation and tutorials
- Limited 3D capabilities compared to Unity's robust 3D engine
Code Comparison
cocos2d-x (C++):
auto sprite = Sprite::create("sprite.png");
sprite->setPosition(Vec2(100, 100));
this->addChild(sprite);
UnityCsReference (C#):
GameObject sprite = new GameObject("Sprite");
SpriteRenderer renderer = sprite.AddComponent<SpriteRenderer>();
renderer.sprite = Resources.Load<Sprite>("sprite");
sprite.transform.position = new Vector3(1, 1, 0);
Both examples demonstrate creating and positioning a sprite, but cocos2d-x uses a more concise syntax while Unity's approach is more object-oriented and verbose.
A simple and easy-to-use library to enjoy videogames programming
Pros of raylib
- Lightweight and simple to use, with a focus on ease of learning
- Cross-platform support with minimal dependencies
- Open-source with a permissive license (zlib/libpng)
Cons of raylib
- Less feature-rich compared to Unity's extensive ecosystem
- Smaller community and fewer resources available
- Limited built-in tools for complex game development workflows
Code Comparison
raylib:
#include "raylib.h"
int main() {
InitWindow(800, 450, "raylib [core] example - basic window");
while (!WindowShouldClose()) {
BeginDrawing();
ClearBackground(RAYWHITE);
DrawText("Congrats! You created your first window!", 190, 200, 20, LIGHTGRAY);
EndDrawing();
}
CloseWindow();
return 0;
}
UnityCsReference:
using UnityEngine;
public class BasicExample : MonoBehaviour
{
void Start()
{
Debug.Log("Hello, Unity!");
}
}
The raylib example demonstrates a complete program for creating a window and drawing text, while the Unity example shows a basic script component that would be attached to a GameObject in a scene.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
Unity 6000.0.18f1 C# reference source code
The C# part of the Unity engine and editor source code. May be used for reference purposes only.
For terms of use, see https://unity3d.com/legal/licenses/Unity_Reference_Only_License
The repository includes third-party code subject to third-party notices.
The terms of use do not permit you to modify or redistribute the C# code (in either source or binary form). If you want to modify Unity's source code (C# and C++), contact Unity sales for a commercial source code license: https://store.unity.com/contact?type=source-code
We do not take pull requests at this time (sorry). But if you find something that looks like a bug, we'd appreciate it if you'd file it using the Unity Bug Reporter. For more information, see our blog post: https://blogs.unity3d.com/2018/03/26/releasing-the-unity-c-source-code/
Unless expressly provided otherwise, the software under this license is made available strictly on an "AS IS" BASIS WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED. Please review the license for details on these and other terms and conditions.
The C# solution is in Projects/CSharp/UnityReferenceSource.sln
The folder and file layout of the reference source matches the Unity source tree layout; it can and will change between different Unity versions.
Top Related Projects
Source from the Microsoft .NET Reference Source that represent a subset of the .NET Framework
.NET is a cross-platform runtime for cloud, mobile, desktop, and IoT apps.
Mono open source ECMA CLI, C# and .NET implementation.
Godot Engine – Multi-platform 2D and 3D game engine
Cocos2d-x is a suite of open-source, cross-platform, game-development tools utilized by millions of developers across the globe. Its core has evolved to serve as the foundation for Cocos Creator 1.x & 2.x.
A simple and easy-to-use library to enjoy videogames programming
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot