Skip to content

Instantly share code, notes, and snippets.

View starikcetin's full-sized avatar

S. Tarık Çetin starikcetin

View GitHub Profile
@starikcetin
starikcetin / Running Code at Unity Editor Launch Before Scripts Compile.md
Last active March 6, 2024 13:16
Running Code at Unity Editor Launch Before Scripts Compile

Create a standalone pure C# project.

Create a Directory.Build.props right alongside your .csproj file:

<Project>
    <PropertyGroup>
        <UnityProjectPath>$(MSBuildProjectDirectory)\relative_path_to_unity_project\</UnityProjectPath>
    </PropertyGroup>
</Project>
@starikcetin
starikcetin / Copty C# DLL to somewhere after build.md
Created February 6, 2024 13:30
Copty C# DLL to somewhere after build

Add this to .csproj:

  <Target Name="CopyDLL" AfterTargets="Build">
    <Message Text="Copying DLL" Importance="High" />
    <Copy
      SourceFiles="$(TargetDir)$(ProjectName).dll"
      DestinationFolder="$(MSBuildProjectDirectory)\relative_target_folder_path_here\"
    />
  </Target>
@starikcetin
starikcetin / EditorUtils.cs
Last active November 20, 2023 20:16
Unity get Attributes of a specific type on a SerializedProperty
using System;
using System.Reflection;
using UnityEditor;
public static class EditorUtils
{
private const BindingFlags AllBindingFlags = (BindingFlags)(-1);
/// <summary>
/// Returns attributes of type <typeparamref name="TAttribute"/> on <paramref name="serializedProperty"/>.
#!/bin/bash
shopt -s globstar
FILES=(./**/*.*)
TOTAL_COUNT=${#FILES[@]}
CURRENT_COUNT=1
for i in "${FILES[@]}"; do
echo "processing (${CURRENT_COUNT} of ${TOTAL_COUNT}) ${i}"
@starikcetin
starikcetin / GuidTools.cs
Created June 11, 2023 18:19
Unity Project Window GUID Tools
using System.Text;
using UnityEditor;
using UnityEngine;
public static class GuidTools
{
[MenuItem("Assets/GUID Tools/Log GUIDs")]
private static void LogGuids()
{
var guids = Selection.assetGUIDs;
// container component
// a constructor is automatically generated for a component that has the same order with field declaration
// for example, for position component following ctor is generated: (x, y, z)
component position
float x
float y
float z
// component with single field
@starikcetin
starikcetin / MainThreadDispatcher.cs
Last active July 27, 2022 16:45
Main thread dispatcher for Unity.
using System;
using System.Threading;
// TODO: Make sure Singleton implementation is also thread-safe.
/// <summary>
/// Provides means of executing code on the main Unity thread while in other threads.
/// </summary>
public class MainThreadDispatcher
{
@starikcetin
starikcetin / SceneExtensions.cs
Last active July 27, 2022 16:41
SceneUtils, GetAllRootGameObjects, DontDestroyOnLoadScene, etc.
using System.Linq;
using UnityEngine;
using UnityEngine.SceneManagement;
public static class SceneExtensions
{
/// <summary>
/// Returns whether the given scene contains the given component on any of its GameObjects.
/// </summary>
public static bool HasComponent<T>(this Scene scene)
@starikcetin
starikcetin / AssetDefinePostprocessor.cs
Created July 8, 2022 16:34 — forked from nonathaj/AssetDefinePostprocessor.cs
A script for creating and removing defines in Unity with C# along with certain files.
using UnityEngine;
using UnityEditor;
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
[InitializeOnLoad]
public class AssetDefinePostprocessor : AssetPostprocessor
{
@starikcetin
starikcetin / CanvasPositioningExtensions.cs
Created August 19, 2021 18:53 — forked from FlaShG/CanvasPositioningExtensions.cs
A small Unity helper class to convert viewport, screen or world positions to canvas space.
using UnityEngine;
/// <summary>
/// Small helper class to convert viewport, screen or world positions to canvas space.
/// Only works with screen space canvases.
/// </summary>
/// <example>
/// <code>
/// objectOnCanvasRectTransform.anchoredPosition = specificCanvas.WorldToCanvasPoint(worldspaceTransform.position);
/// </code>