Skip to content

Instantly share code, notes, and snippets.

View mrtrizer's full-sized avatar
💾

Denis Zdorovtsov mrtrizer

💾
View GitHub Profile
@mrtrizer
mrtrizer / Test.cs
Last active September 5, 2023 09:09
Basic Tweener for Unity3d
static bool initialized;
static Action staticUpdate;
public static Task Tween<T>(T startValue, T endValue, float duration, Func<T, T, float, T> function, Action<T> callback, CancellationToken? cToken = null)
{
if (!initialized)
{
initialized = true;
var playerLoop = UnityEngine.LowLevel.PlayerLoop.GetCurrentPlayerLoop();
const int updateSubSystemIndex = 5;
@mrtrizer
mrtrizer / ReferenceFixTool.cs
Created December 15, 2022 03:41
Fix fileId in asset file. May be useful if you change type of field and Unity doesn't fix references. Make sure to change regex pattern for your needs.
using UnityEngine;
using UnityEditor;
using System.IO;
using System.Text.RegularExpressions;
public class ReferenceFixTool
{
[MenuItem("CONTEXT/ScriptableObject/Fix References")]
static void FixReferences(MenuCommand command)
{
@mrtrizer
mrtrizer / coroutine.c
Last active November 2, 2022 12:12
C language coroutine with switch-case
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#define COROUTINE_START(line) switch (line) { case 0:
#define WAIT_WHILE(condition) return __LINE__; case __LINE__: if (condition) return __LINE__;
#define COROUTINE_END default: return -1; }
@mrtrizer
mrtrizer / c_containers.c
Last active June 2, 2022 11:25
C++ style containers in C language with just few macro C99 (msvc, gcc, clang). Doesn't work in C++ mainly because of anonymous struct declaration in function arguments.
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <assert.h>
// *******************
// CONTAINERS LIBRARY
// *******************
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using System;
using System.IO;
using System.Text.RegularExpressions;
public class AttributeManager : EditorWindow
{
public static void autoDeserialize(ObjectContext context, AutoSerialisedObject autoSerializedObject, RestoreProcess restoreProcess)
{
var cache = getClassReflectionCache(context.type);
foreach (var field in cache.fields)
{
var serializedField = autoSerializedObject.autoSerialiedFields.Find(item => item.name == field.fieldInfo.Name);
if (serializedField.value != null)
{
@mrtrizer
mrtrizer / CMakeLists.txt
Created October 26, 2020 08:56
CMake Vulkan build shaders. Tested in Visual Studio, but should also work under Linux and MacOS
cmake_minimum_required (VERSION 3.8)
set(PROJECT_NAME SimpleVulkan)
add_executable (${PROJECT_NAME} "main.c")
find_package(Vulkan REQUIRED)
target_include_directories(${PROJECT_NAME} PRIVATE "./")
@mrtrizer
mrtrizer / windows_c_opengl.c
Created October 24, 2020 23:49
Windows API OpenGL initialization
#include <stdio.h>
#include <windows.h>
#include <gl/GL.h>
HDC dc;
HGLRC rc;
LRESULT CALLBACK WindowProc(HWND hwnd,
UINT msg,
@mrtrizer
mrtrizer / c_ecs_quick_access.c
Last active October 21, 2020 09:57
The main idea is to make serial components access as fast as possible because this is the most usual way to interact with components.
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <limits.h>
#include <assert.h>
#include <stdbool.h>
typedef uint32_t EId;
typedef struct
@mrtrizer
mrtrizer / c_reflection.c
Last active October 5, 2021 01:31
Basic 10 lines type reflection implementation in C (see another gist if you need reflection for functions)
#include <stdio.h>
#include <stdlib.h>
#include <stddef.h>
#include <stdint.h>
// Lib code
char* ___tid(const char* strPtr) { return (char*)strPtr; }
#define TID(type) ((intptr_t)___tid(#type))