Skip to content

Instantly share code, notes, and snippets.

View leventeren's full-sized avatar
🤘
I love to code and can do it all day long ;)

Levent EREN leventeren

🤘
I love to code and can do it all day long ;)
View GitHub Profile
@leventeren
leventeren / CameraFollow.cs
Created February 19, 2024 15:30
Camera Follow Character with forward offset
using UnityEngine;
public class CameraFollow : MonoBehaviour
{
public Transform target;
public float smoothSpeed = 0.125f;
public Vector3 offset;
public float forwardOffset = 2f;
@leventeren
leventeren / Grid.cs
Created February 5, 2024 16:21
Unity Procedural Grid (Mesh Generate)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[RequireComponent(typeof(MeshFilter), typeof(MeshRenderer))]
public class Grid : MonoBehaviour {
public int xSize, ySize;
private Vector3[] vertices;
private Mesh mesh;
@leventeren
leventeren / HexToColor.cs
Created February 2, 2024 12:37
Hex To Color
Color HexToColor(string hex)
{
hex = hex.TrimStart('#'); // Eğer renk kodu başında '#' varsa kaldır
Color color = new Color();
color.r = byte.Parse(hex.Substring(0, 2), System.Globalization.NumberStyles.HexNumber) / 255f;
color.g = byte.Parse(hex.Substring(2, 2), System.Globalization.NumberStyles.HexNumber) / 255f;
color.b = byte.Parse(hex.Substring(4, 2), System.Globalization.NumberStyles.HexNumber) / 255f;
if (hex.Length == 8)
@leventeren
leventeren / LockCameraZ.cs
Created January 28, 2024 19:21
CinemachineExtension
using UnityEngine;
using Cinemachine;
/// <summary>
/// An add-on module for Cinemachine Virtual Camera that locks the camera's Z co-ordinate
/// </summary>
[ExecuteInEditMode] [SaveDuringPlay] [AddComponentMenu("")] // Hide in menu
public class LockCameraZ : CinemachineExtension
{
[Tooltip("Lock the camera's Z position to this value")]
{
"m_SGVersion": 2,
"m_Type": "UnityEditor.ShaderGraph.GraphData",
"m_ObjectId": "e2b331ef653b41b4bf142a758a559a70",
"m_Properties": [
{
"m_Id": "97f832e3db3744f1aa1394cae928aff4"
}
],
"m_Keywords": [],
private static Vector2 WorldToPixelCoords(Vector3 projectedPoint, Sprite sprite, Transform transform)
{
var textureRect = sprite.textureRect;
var spriteBounds = sprite.bounds;
var localPoint = transform.InverseTransformPoint(projectedPoint);
localPoint.x = (localPoint.x - spriteBounds.min.x) / (spriteBounds.size.x);
localPoint.y = (localPoint.y - spriteBounds.min.y) / (spriteBounds.size.y);
using UnityEditor;
namespace EditorBehaviourTest
{
[InitializeOnLoad]
public static class EditorBehaviour
{
static EditorBehaviour()
{
EditorApplication.playModeStateChanged += OnPlayModeStateChanged;
@leventeren
leventeren / AssetCopyUtils.cs
Created November 27, 2023 06:23 — forked from FreyaHolmer/AssetCopyUtils.cs
Adds context menu items to assets: Copy/Paste import settings & Copy GUID. Put this script in any Editor/ folder in your project and recompile!
// written by https://github.com/FreyaHolmer so use at your own risk c:
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
/// <summary>Utility functions to copy GUIDs, as well as Copy/Paste import settings</summary>
public static class AssetCopyUtils {
const int CTX_MENU_LOCATION = 70;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[RequireComponent(typeof(MeshFilter))]
public class PointTracker : MonoBehaviour
{
private MeshFilter meshFilter;
private Transform[] markers;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
[System.Serializable]
public struct SerializedDictionary<T, U> {
public List<T> Keys;
public List<U> Values;