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 / 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 / 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>
#!/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;
@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"/>.
@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 / 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 / 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>
@starikcetin
starikcetin / QuaternionUtil.cs
Created August 13, 2021 10:37 — forked from maxattack/QuaternionUtil.cs
Some Helper Methods for Quaternions in Unity3D
using UnityEngine;
/*
Copyright 2016 Max Kaufmann (max.kaufmann@gmail.com)
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN