Skip to content

Instantly share code, notes, and snippets.

View CodeSmile-0000011110110111's full-sized avatar

CodeSmile CodeSmile-0000011110110111

View GitHub Profile
using CodeSmile.Components.Registry;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
namespace CodeSmile.Components.Pool
{
[DisallowMultipleComponent]
@CodeSmile-0000011110110111
CodeSmile-0000011110110111 / NestedNativeListSerializationTests.cs
Last active June 6, 2023 13:45
Unity.Serialization for NativeList<UnsafeList<T>> with adapters
// Copyright (C) 2021-2023 Steffen Itterheim
// Refer to included LICENSE file for terms and conditions.
using NUnit.Framework;
using System;
using System.Collections.Generic;
using Unity.Collections;
using Unity.Collections.LowLevel.Unsafe;
using Unity.Serialization.Binary;
using UnityEngine;
@CodeSmile-0000011110110111
CodeSmile-0000011110110111 / FasterTests.cs
Created May 2, 2023 19:13
Speed up Unity TestRunner running tests
// This work is Public Domain (CC0) - "No Rights Reserved"
// License: https://creativecommons.org/publicdomain/zero/1.0/
using System.Reflection;
using UnityEditor;
using UnityEditor.TestTools.TestRunner.Api;
using UnityEngine;
namespace CodeSmile.Tests.Utilities
{
@CodeSmile-0000011110110111
CodeSmile-0000011110110111 / TestCustomBuildProcess.cs
Created March 5, 2023 11:33
Example PreProcessing script for Unity's build process and overriding File-Build command the official way
#if UNITY_EDITOR
using UnityEditor;
using UnityEditor.SceneManagement;
using UnityEngine;
using UnityEngine.SceneManagement;
namespace CodeSmile.EditorTests
{
[InitializeOnLoad]
public class TestCustomBuildProcess
@CodeSmile-0000011110110111
CodeSmile-0000011110110111 / ExampleEditorSwitchOnEventType.cs
Created March 5, 2023 11:27
On*GUI should only switch on EventType and call methods to reduce code complexity
using CodeSmile.UnityEditor;
using System;
using UnityEditor;
using UnityEngine;
using UnityEngine.UIElements;
namespace CodeSmile.Tile.UnityEditor
{
[CustomEditor(typeof(TileWorld))]
public class TileWorldDrawer : Editor
@CodeSmile-0000011110110111
CodeSmile-0000011110110111 / EditorUndoRedoExample.cs
Created March 5, 2023 11:20
Editor On*GUI undo/redo example
protected virtual void OnSceneGUI()
{
HandlesTest testObject = (HandlesTest)target;
// begin monitoring for GUI changes
EditorGUI.BeginChangeCheck();
// do whatever GUI stuff that lets user change something on the testObject
var newPos = Handles.PositionHandle(testObject.transform.position, Quaternion.identity);
@CodeSmile-0000011110110111
CodeSmile-0000011110110111 / EditorInputState.cs
Created March 5, 2023 10:54
Handles input in OnSceneGUI and other "On..GUI" methods
// Public Domain
// Usage: Add an instance of EditorInputState to an editor script, create the instance on Awake.
// Then call m_InputState.Update() in every On*GUI method you implement and then query the m_InputState
// wherever you need to test for input.
using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UIElements;
@CodeSmile-0000011110110111
CodeSmile-0000011110110111 / RayExt.cs
Created March 5, 2023 10:51
Ray extension method that tests whether a ray hits a "virtual" plane
using UnityEngine;
namespace CodeSmile
{
public static class RayExt
{
const float MinDenominator = 0.00001f;
/// <summary>
@CodeSmile-0000011110110111
CodeSmile-0000011110110111 / DropToGround.cs
Last active March 5, 2023 10:49
Script that drops an object to ground (collider) and optionally rotates to that surface
// Public Domain
using UnityEngine;
namespace CodeSmile
{
[ExecuteInEditMode]
public class DropToGround : MonoBehaviour
{
[SerializeField] private bool m_SnapPosition;
@CodeSmile-0000011110110111
CodeSmile-0000011110110111 / GameObjectExt.cs
Created March 5, 2023 10:47
GameObject extension to check if an object is null OR "missing reference"
using UnityEngine;
namespace CodeSmile.EditorTests
{
public static class GameObjectExt
{
public static bool IsNullOrMissing(this GameObject instance) => instance == null || ReferenceEquals(instance, null);
}
}