Skip to content

Instantly share code, notes, and snippets.

View CodeSmile-0000011110110111's full-sized avatar

CodeSmile CodeSmile-0000011110110111

View GitHub Profile
@CodeSmile-0000011110110111
CodeSmile-0000011110110111 / CalculatedFieldTest.cs
Created March 4, 2023 09:39
Read-only field displays a calculated value in Inspector
// example usage of [ReadOnlyField] that displays a calculated/converted value
// calculated value is updated whenever underlying value(s) change(s)
using UnityEngine;
public class CalculatedFieldTest : MonoBehaviour
{
private const float TargetFramerate = 60f;
[SerializeField] private int m_Ticks;
[SerializeField] [ReadOnlyField] private float m_CalculatedSeconds;
@CodeSmile-0000011110110111
CodeSmile-0000011110110111 / AutoDisablePickability.cs
Created February 28, 2023 19:33
MonoBehaviour that keeps pickability of a GameObject and its children disabled
// MIT License
// Copyright 2023 Steffen Itterheim
// 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 CONNECTION WITH TH
@CodeSmile-0000011110110111
CodeSmile-0000011110110111 / RandomMeshSelectorEditor
Created February 22, 2023 15:47
Fixing the "unsaved" random seed by changing the serializedObject's property and ApplyModifiedProperties
public override void OnInspectorGUI()
{
DrawDefaultInspector();
var script = (RandomMeshSelector)target;
if (GUILayout.Button("Change Random Seed"))
{
serializedObject.FindProperty("m_RandomSeed").intValue = script.GenerateNewRandomSeed();
serializedObject.ApplyModifiedProperties();
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.NetworkInformation;
using System.Net.Sockets;
using Unity.Netcode.Transports.UTP;
using UnityEngine;
namespace Unity.Netcode.Samples
{
@CodeSmile-0000011110110111
CodeSmile-0000011110110111 / actually it's two files ...
Last active August 2, 2022 09:51
Unity MeshPreview embedded in UI Toolkit VisualElement using IMGUIContainer
// MonoBehaviour
using UnityEngine;
public class MeshPreview : MonoBehaviour
{
public Mesh mesh;
[Range(1, 1000)] public int previewHeight = 100;
public bool showSettings = true;
}