Skip to content

Instantly share code, notes, and snippets.

@fcnaud
fcnaud / Typewriter.cs
Last active September 24, 2021 08:08
[Type Writer] #Unity
using System;
using System.Collections;
using TMPro;
using UnityEngine;
public class Typewriter : MonoBehaviour
{
public TextMeshProUGUI Writer;
public void TypingText(string text, float speed = 50, Action onComplete = null)
@fcnaud
fcnaud / tw5-server.rb
Created May 23, 2021 11:46 — forked from jimfoltz/tw5-server.rb
A local server for TiddlyWiki5 that allows saving wiki.
require 'webrick'
require 'fileutils'
if ARGV.length != 0
root = ARGV.first.gsub('\\', '/')
else
root = '.'
end
BACKUP_DIR = 'bak'
@fcnaud
fcnaud / CameraAdapt.cs
Last active May 10, 2021 05:10
相机 Orthographic size 按宽度适配
using UnityEngine;
public class CameraAdapt : MonoBehaviour
{
private readonly float AdaptScreenWidth = 720;
private readonly float AdaptScreenHeight = 1280;
private float _adaptSizeW;
private Camera _mainCam;
@fcnaud
fcnaud / UnitySingleton.cs
Last active January 28, 2024 20:25
[Unity Singleton] #Unity #Snippet
// http://wiki.unity3d.com/index.php/Singleton
// http://www.unitygeek.com/unity_c_singleton/
using UnityEngine;
public class SingletonUnity<T> : MonoBehaviour
where T : SingletonUnity<T>
{
private static T instance;
@fcnaud
fcnaud / SingleColor.shader
Last active March 26, 2021 11:52
[single color shader] #Unity #Shader
// https://docs.unity3d.com/Manual/SL-VertexFragmentShaderExamples.html
Shader "Custom/SingleColor"
{
Properties
{
_Color ("Main Color", Color) = (1,1,1,1)
}
SubShader
{
@fcnaud
fcnaud / BezierCurve.cs
Last active March 22, 2021 07:43
[贝塞尔曲线] #Unity #Snippet
public static Vector3 GetBezierCurvePos(Vector3 startPos, Vector3 middlePos, Vector3 endPos, float t)
{
Vector3 segPos1 = Vector3.Lerp(startPos, middlePos, t);
Vector3 segPos2 = Vector3.Lerp(middlePos, endPos, t);
Vector3 segPos3 = Vector3.Lerp(segPos1, segPos2, t);
return segPos3;
}
@fcnaud
fcnaud / SetCustomPivot.cs
Created May 28, 2020 06:59
根据图片的 pivot 设置 RectTransform 的 pivot
using UnityEngine;
using UnityEngine.UI;
public class SetCustomPivot : MonoBehaviour
{
private void Start()
{
var image = GetComponent<Image>();
var sprite = image.sprite;
image.GetComponent<RectTransform>().pivot = new Vector2(
@fcnaud
fcnaud / MeshLightMapSetting.cs
Last active October 28, 2019 05:50
保存prefab的光照贴图信息
using UnityEngine;
public class MeshLightMapSetting : MonoBehaviour
{
public int lightmapIndex;
public Vector4 lightmapScaleOffset;
public void SaveSettings()
{
Renderer renderer = GetComponent<Renderer>();
@fcnaud
fcnaud / CameraAdapt.cs
Last active September 4, 2019 02:58
相机fov按照宽度适配
public class CameraAdapt : MonoBehaviour
{
private float _adaptFieldWidth;
private float _adaptScreenWidth = 720;
private float _adaptScreenHeight = 1280;
private Camera mainCam;
#region unity event function
private void Start()
{
@fcnaud
fcnaud / ExtensionTransform.cs
Created August 16, 2019 12:08
Show Transform Heirarchy
public static class ExtensionTransform
{
private static string lastFirst = "└─";
private static string lastNotFirst = "  ";
private static string notLastFirst = "├─";
private static string notLastNotFirst = "│ ";
public static void ShowHeirarchy(this Transform trans)
{
_ShowHeirarchy(trans, "");