Skip to content

Instantly share code, notes, and snippets.

View fanhexin's full-sized avatar
🏠
Working from home

Dongdong Fan fanhexin

🏠
Working from home
View GitHub Profile
@fanhexin
fanhexin / DiffusePlusLightmap.shader
Created August 30, 2024 08:41
Sample lightmap texture unity generated and multiply to the diffuse color. Must setup correct _LightmapTex_ST first.
Shader "Custom/DiffusePlusLightmap"
{
Properties
{
_MainTex ("Main Texture", 2D) = "white" {}
_LightmapTex ("Lightmap", 2D) = "white" {}
_LightIntensity ("Light Intensity", Range(0, 10)) = 1
_Emission ("Emission", Color) = (0, 0, 0, 1)
}
@fanhexin
fanhexin / PlanarShadow.shader
Last active August 30, 2024 08:42
Planar shadow shader for unity buildin render pipline.
Shader "Custom/PlanarShadow"
{
Properties {
_ShadowColor ("Shadow Color", Color) = (0,0,0,1)
_PlaneHeight ("planeHeight", Float) = 0
}
SubShader {
Tags {"Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent"}
@fanhexin
fanhexin / ClipNinePatch.cs
Last active May 18, 2023 02:59
Keep only the four corners of the nine-patch image and combine them into a small image.
using System.IO;
using UnityEngine;
using UnityEditor;
public static class ClipNinePatch
{
[MenuItem("Assets/Clip Nine Patch", true)]
static bool ValidateClipNinePatchImage()
{
Texture2D texture = Selection.activeObject as Texture2D;
using UnityEngine;
using UnityEngine.UI;
namespace UGuiExtension
{
public class CenterTiledImage : Image
{
protected override void OnPopulateMesh(VertexHelper toFill)
{
if (type != Type.Tiled ||
Shader "Custom/Sprite"
{
Properties
{
[PerRendererData] _MainTex ("Sprite Texture", 2D) = "white" {}
_Color ("Tint", Color) = (1,1,1,1)
[MaterialToggle] PixelSnap ("Pixel snap", Float) = 0
[HideInInspector] _RendererColor ("RendererColor", Color) = (1,1,1,1)
[HideInInspector] _Flip ("Flip", Vector) = (1,1,1,1)
[PerRendererData] _AlphaTex ("External Alpha", 2D) = "white" {}
@fanhexin
fanhexin / MobileLocalNotification.cs
Last active June 10, 2020 01:26
A simple wrapper of Unity Mobile Notifications.
using System;
#if UNITY_ANDROID
using Unity.Notifications.Android;
#elif UNITY_IOS
using UnityEngine.iOS;
using CalendarUnit = UnityEngine.iOS.CalendarUnit;
using LocalNotification = UnityEngine.iOS.LocalNotification;
using NotificationServices = UnityEngine.iOS.NotificationServices;
#endif
using UnityEngine;
using System;
using System.IO;
using System.Linq;
using UnityEditor;
using UnityEngine;
namespace .Editor
{
public static class CustomFontHelper
{
using System;
using System.Collections.Generic;
namespace Game.Util
{
public class FluentFsm<TState, TEvent>
where TState : Enum
where TEvent : Enum
{
readonly Dictionary<TState, State> _states = new Dictionary<TState, State>();
using HopTiles.GamePlay;
using UnityEditor;
using UnityEngine;
namespace HopTiles.Editor
{
[CustomEditor(typeof(SlicedCube))]
public class SlicedCubeInspector : UnityEditor.Editor
{
SerializedProperty _borderSize;
#if UNITY_EDITOR
using UnityEditor;
#endif
using UnityEngine;
namespace HopTiles.GamePlay
{
// todo 待删除
public class SlicedCube : MonoBehaviour
{