As The last ship sailed towards the distant horizon I sat there watching on a rock My mind slowly drifting away Forming into my... Dreamtale
2019-08-28

A texture repeat without tiling shader:


Demo: https://www.suntabu.com/demos/E4/

Shader "Unlit/TextureRepeat"
{
	Properties
	{
		    _MainTex ("Texture", 2D) = "white" {}
        _BlendRatio("_BlendRatio",Range(0,1))=0.5

	}
	SubShader
	{
		Tags { "RenderType"="Opaque" }
		LOD 100

		Pass
		{
			CGPROGRAM
			#pragma vertex vert
			#pragma fragment frag
			// make fog work
			#pragma multi_compile_fog
			
			#include "UnityCG.cginc"

			struct appdata
			{
				float4 vertex : POSITION;
				float2 uv : TEXCOORD0;
			};

			struct v2f
			{
				float2 uv : TEXCOORD0;
				UNITY_FOG_COORDS(1)
				float4 vertex : SV_POSITION;
			};

			sampler2D _MainTex;
			float4 _MainTex_ST;
			float _BlendRatio;
			
			v2f vert (appdata v)
			{
				v2f o;
				o.vertex = UnityObjectToClipPos(v.vertex);
				o.uv = TRANSFORM_TEX(v.uv, _MainTex);
				UNITY_TRANSFER_FOG(o,o.vertex);
				return o;
			}
			
			float random (float2 uv)
			{
				return frac(sin(dot(uv,float2(12.9898,78.233)))*43758.5453123);
			}
2019-06-29

Extensions

1. Get Hierarchy Path of a GameObject in Scene

public static string GetHierarchyPath(this GameObject obj)
{
    string path = "/" + obj.name;
    while (obj.transform.parent != null)
    {
        obj = obj.transform.parent.gameObject;
        path = "/" + obj.name + path;
    }
2019-06-12

Compress Textures in Unity Editor by using TinyPNG

public class TinyPNGEditor : MonoBehaviour
{
    private const string URL_API = "https://api.tinify.com/shrink";
    
    // your key here
    private const string KEY_API = "xxxxxxx";


    private static UnityWebRequest www;
    private static Action onDone;
2019-06-12

It is because of Texture's alpha is not dilated for the gap.
Details could be found HOWTO-alphamaps

So how to fix it:

  • if it's in your Unity project, just enable this texture's AlphaIsTransparency in Texture Importing Setting inspector.
public static void DilateTexture()
{
    if (Selection.activeObject == null)
    {
        if (EditorUtility.DisplayDialog("Error Selection", "Select a texture", "OK"))
        {
            return;
        }
2019-05-28
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using AssetBundleBrowser.AssetBundlePacker;
using UnityEditor;
using UnityEditor.VersionControl;
using UnityEngine;
using Debug = UnityEngine.Debug;
2019-05-28

a simple image downloader, it downloads images via a queue and by UnityWebRequest and Coroutine.

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;

public class ImageDownloader : MonoSingleton<ImageDownloader>
{
    private const int MAX_REQUEST = 10;

    public Action<UnityWebRequest, string> OnError;
2019-05-04

Sometimes we just wanna record sounds from scene, so Unity's MicroPhone API would not be very useful.

But we have OnAudioFilterRead to do this kind of action.

Share a solution which is from
http://evanxmerz.com/blog/index.php/2016/10/07/recording-in-game-audio-in-unity/

This script should be added to a Unity AudioListener GameObject then it could do its works.

HowTo

  • Create a MonoBehaviour script with an OnAudioFilterRead method
    // write the incoming audio to the output string
    void OnAudioFilterRead(float[] data, int channels)
    {
2019-05-01

New unity plugin has been released:
markdown render for uiwidgets

What is UIWidgets?

UIWidget is a Unity Package which helps developers to create, debug and deploy efficient, cross-platform Apps. Details could be found at their github page

What does this plugin do?

Just parse and render raw markdown strings into UIWidgets elements.

How to use

    1. You must learn how to use UIWidgets first
    1. Import UIWidgets into your Unity project according to Requirements
    1. Then import this plugin into your Unity project
2019-05-01

Recently I war working on creating a blog app by using Unity UIWidgets, actually it's not bad.
But when I click on the page's link, it refered to phone's system browser. It's not what I wanted.

So I found some webview solutions for Unity. Below is what I'm using.
https://github.com/gree/unity-webview

Why did I choose this one?

  • It was the first one working on my iPhone
  • It could work in MacOS Unity Editor, it is so wonderful that I could debug directly in my Editor.

How to use

  • Before use it directly, I wrapped it with below's code.
    public class WebViewManager : MonoSingleton<WebViewManager>
2019-04-12

Simple class for executing Coroutine easily


using UnityEngine;
using System.Collections;
using UnityEngine.SceneManagement;

public class CoroutineExecutor : MonoBehaviour
{
    public System.Action DoneCallback;

    void Start()
    {
        DontDestroyOnLoad(transform.gameObject);
    }

    void Do(AsyncOperation ao, System.Action callback)
    {
        DoneCallback = callback;
        StartCoroutine(_WaitForDone(ao));
    }
2019-04-11

My Unity Plugin published: Asset Checker

1. This tool is developed for checking assets in game project with error or not best practice importing settings

2. Currently Checked Assets Type

  • Texture2D
    • Texture file size
    • Dimensions
    • Read/Write enable
    • Generate mipmap enable
  • AudioClip
    • Large audioclip using Streaming loadtype
    • Force mono
  • Font
2019-04-06

From Scale around points similar to rotate around


    public static void ScaleAround(Transform target, Vector3 pivot, Vector3 newScale)
    {
        Vector3 A = target.localPosition;
        Vector3 B = pivot;

        Vector3 C = A - B; // diff from object pivot to desired pivot/origin

        float RS = newScale.x / target.localScale.x; // relative scale factor

        // calc final position post-scale
2019-04-01

Find references in Assets:


[MenuItem("Assets/Find Refereces")]
public static void FindReferences()
{
    EditorSettings.serializationMode = SerializationMode.ForceText;
    string path = AssetDatabase.GetAssetPath(Selection.activeObject);
    if (!string.IsNullOrEmpty(path))
    {
        string guid = AssetDatabase.AssetPathToGUID(path);
        List<string> withoutExtensions = new List<string>() {".prefab", ".unity", ".mat", ".asset"};
        string[] files = Directory.GetFiles(Application.dataPath, "*.*", SearchOption.AllDirectories)
2019-03-11

EventTriggerListener

using UnityEngine;
using System.Collections;
using UnityEngine.EventSystems;

public class EventTriggerListener : MonoBehaviour, IPointerClickHandler, IPointerDownHandler, IPointerEnterHandler,
    IPointerExitHandler, IPointerUpHandler, IDragHandler
{
    public delegate void VoidDelegate1(GameObject go, PointerEventData eventData);
    public event VoidDelegate1 OnClick;
    public event VoidDelegate1 OnDown;
    public event VoidDelegate1 OnEnter;
    public event VoidDelegate1 OnExit;
    public event VoidDelegate1 OnUp;
    public event VoidDelegate1 OnDragging;
2019-03-10

I'm using marked and highlight in my blog.

Below is how to use:


var marked = require('marked');
marked.setOptions({
    highlight: function (code) {
        return require('highlight.js').highlightAuto(code).value;
    }
});