Wednesday, June 30, 2021

Attribute execute button on editor mode

 #region namespace

using System;
using System.Collections;
using System.Collections.Generic;
using System.Reflection;
using UnityEngine;
using UnityEditor;
#endregion
public class CuonglhButton : MonoBehaviour
{
    [ButtonEditor]
    public void TestButton()
    {
        Debug.Log("Execute");
    }
}

[AttributeUsage(AttributeTargets.Method)]
public class ButtonEditor : Attribute { }

[CustomEditor(typeof(MonoBehaviour), true)]
public class CuonglhButtonEditor : Editor
{
    public override void OnInspectorGUI()
    {
        base.OnInspectorGUI();
        var mTarget = (MonoBehaviour) target;
        var methodInfors = mTarget.GetType().GetMethods();
        foreach (var methodInfor in methodInfors)
        {
            var buttonEditor = methodInfor.GetCustomAttribute(typeof(ButtonEditor), true);
            if (buttonEditor != null)
            {
                if (GUILayout.Button(methodInfor.Name))
                {
                    methodInfor.Invoke((object)mTarget, null);
                }
            }
        }
    }
}

Wednesday, June 16, 2021

save byte[] array in webGL

 https://forum.unity.com/threads/webgl-saving-a-file-in-the-browser.506800/


https://answers.unity.com/questions/1095407/saving-webgl.html

Tuesday, June 15, 2021

compare UI system

 https://docs.unity3d.com/2020.1/Documentation/Manual/UI-system-compare.html

Friday, June 11, 2021

evenly distributed points in a circle

https://stackoverflow.com/questions/28567166/uniformly-distribute-x-points-inside-a-circle


spawn them in a circle, then let them evolve their positions based on a flocking algorithm like suggested above.
2
  • Like