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 / CsvUtil.cs
Created October 11, 2023 19:50
Csv Util
using UnityEngine;
using System.Text.RegularExpressions;
using System.IO;
using System.Linq;
using System.Collections.Generic;
using System;
using System.Reflection;
using System.ComponentModel;
// This class uses Reflection and Linq so it's not the fastest thing in the
@leventeren
leventeren / InternetChecker.cs
Created October 10, 2023 15:48
Internet Checker
using System.Collections;
using System.Collections.Generic;
using System.Threading.Tasks;
using UnityEngine;
using Ping = UnityEngine.Ping;
public class InternetChecker : SingletonBehaviour<InternetChecker>
{
private readonly List<string> _theListOfIPs = new() { "4.2.2.4", "www.google.com" };
private int _counter;
@leventeren
leventeren / instantiateprefabECS.cs
Created October 10, 2023 08:01
How to instantiate a prefab in ECS?
How to instantiate a prefab in ECS?
Reddit is my main social media of choice. I just really like text content more and I can choose to stay in topics or communities that I like and eventually run out of content to consume as compared to endless doom scrolling in other social media sites. Of course, my favorite subs are game development related like r/gamedev, r/Unity3D, and r/programming. One particular thread poked my interest as it is about DOTS. I don’t have the link anymore but I think it was someone showing something cool. Everybody is generally impressed about what DOTS can bring but a certain reply from that thread made me pause and think. He said something like “Yeah, DOTS is great and all but how do you spawn a prefab?” That made me chuckle because I understand what he’s talking about. Spawning an instance of a prefab is trivial in normal Unity C#. It’s still doable in DOTS but takes a few more steps. There are a lot more of these trivial stuff but hard to do in DOTS.
Unity’s DOTS is clearly not fo
@leventeren
leventeren / RaycastCommand.cs
Created October 10, 2023 07:59
How to use RaycastCommand
How to use RaycastCommand
It’s been a while since my last post. I was busy with processing my Visa and exit clearance since the last one. I haven’t opened Unity since then. I arrived in Germany last February 9 and I’m working on my new job now. I waited for a while for things to settle and to be well adjusted before writing a post again. Sorry it took a while. But I’m back and I hope that I can write monthly again.
One of the things that I discovered while optimizing the current game that I’m working on is RaycastCommand. It’s a Unity API to make multiple raycast requests in a single call. This uses the Jobs System so the computation of these raycasts is done in multiple threads. Instead of using multiple calls to methods like Physics.Raycast() or Physics.RaycastNonAlloc(), you can collect all your raycast calls and use RaycastCommand instead. This can significantly reduce the time spent on raycasts on the main thread, thus freeing CPU time that can be used for other things. Another good thing about this is
@leventeren
leventeren / TouchKeyboardManager.cs
Created October 6, 2023 11:19
Touch Screen Keyboard
using System.Collections;
using UnityEngine;
using UnityEngine.UI;
public class TouchKeyboardManager : MonoBehaviour
{
/* public RectTransform targetToReposition;
private TouchScreenKeyboard keyboard;
@leventeren
leventeren / LandFacingUpward.cs
Created September 27, 2023 11:33
Ref : t3ssel8r
using UnityEngine;
public class LandFacingUpward: MonoBehaviour
{
public LayerMask layerMask;
public float maxDistance = 5;
public Vector3 up = Vector3.up;
public float Kp = 100;
public float Kd = 20;
@leventeren
leventeren / HoldClickableButton.cs
Created September 27, 2023 07:01
ref : phillipeaam
using System;
using UnityEngine;
using UnityEngine.EventSystems;
public class HoldClickableButton : MonoBehaviour, IPointerDownHandler, IPointerUpHandler
{
[SerializeField] private float _holdDuration;
public event Action OnClicked;
public event Action OnHoldClicked;
using UnityEngine;
using UnityEngine.UI;
namespace ZG
{
[ExecuteAlways]
public class GridLayoutGroupEx : LayoutGroup
{
/// <summary>
/// The grid axis we are looking at.

Add this script to a GameObject to give it a unique alphanumeric identifier.

Auto-generates an ID when the script is added to a GameObject Only one script per GameObject, meaning each GameObject gets only ONE unique ID Uses system GUID generation Unique ID can only be accessed, it cannot be overwritten by other scripts Custom Editor to show the ID in the inspector, and a button to reset it if needed Keeps the same ID throughout play-mode and in builds

using UnityEngine;
public class GunSprint : MonoBehaviour {
[SerializeField] private Bullet _bulletPrefab;
[SerializeField] private Transform _spawnPoint;
[SerializeField] private ParticleSystem _smokeSystem;
[SerializeField] private LayerMask _targetLayer;
[SerializeField] private float _bulletSpeed = 12;
[SerializeField] private float _torque = 120;