Skip to content

Instantly share code, notes, and snippets.

S. Tarık Çetin starikcetin

View GitHub Profile
@starikcetin
starikcetin / Reference Unity DLLs in standalone C# project.md
Last active December 5, 2024 00:40
Reference Unity DLLs in standalone C# project

Option 1 - Add a reference directly to the DLLs in Unity installation folder

Create a Directory.Build.props file right next to your .sln file:

<Project>
  <PropertyGroup>
    <UnityDllsPath>path_to_unity_installation\Editor\Data\Managed\</UnityDllsPath>
  </PropertyGroup>
@starikcetin
starikcetin / Configuring Unity YAML Merge KDiff3 and Git on Windows.md
Last active November 28, 2024 14:57
Configuring Unity YAML Merge KDiff3 and Git on Windows

Caution

Edit the paths to point towards your own installations.

Caution

Some paths use backslashes and others use forward slashes. Take notice of how I have given them below.

  1. Add this to your .gitconfig, it is under %homepath%:
[mergetool "unityyamlmerge"]
	cmd = "'C:/Program Files/Unity/Hub/Editor/6000.0.28f1/Editor/Data/Tools/UnityYAMLMerge.exe'" merge -p "$BASE" "$REMOTE" "$LOCAL" "$MERGED"
@starikcetin
starikcetin / ParentAwareContentSizeFitter.cs
Created July 24, 2024 12:52
Modified version of Unity's ContentSizeFitter to allow filling the parent if the content ends up smaller.
using UnityEngine.EventSystems;
using UnityEngine.UI;
using UnityEngine;
using System.Collections.Generic;
[AddComponentMenu("Layout/Parent Aware Content Size Fitter", 141)]
[ExecuteAlways]
[RequireComponent(typeof(RectTransform))]
/// <summary>
/// Resizes a RectTransform to fit the size of its content, while also allowing to fill the parent if the content is smaller.
@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
{