This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// this is an adaptation to Unity of the algorithm described | |
//. in https://stackoverflow.com/questions/3749678/expand-fill-of-convex-polygon/3897471 | |
using UnityEngine; | |
using System.Linq; | |
using System.Collections.Generic; | |
static class ConvexHull | |
{ | |
public static Vector2[] ExpandConvexHull(Vector2[] poly, float distance) | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Newtonsoft.Json; | |
using System; | |
using System.Collections.Generic; | |
using System.IO; | |
using UnityEngine; | |
public class GuardianJsonRecorder : MonoBehaviour | |
{ | |
void Update() | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void DrawBezierCurve(Vector3 point0, Vector3 point1, Vector3 point2, Vector3 point3, Vector3 point4) | |
{ | |
lineRenderer.positionCount = 50; | |
float t = 0f; | |
Vector3 B; | |
for (int i = 0; i < lineRenderer.positionCount; i++) | |
{ | |
B = 1 * (1 - t) * (1 - t) * (1 - t) * (1 - t) * point0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Vector3 GetClosestPointOnBounds(Bounds bounds, Vector3 point) | |
{ | |
var boundPoint1 = bounds.min; | |
var boundPoint2 = bounds.max; | |
var points = new Vector3[] { | |
new Vector3(boundPoint1.x, boundPoint1.y), | |
new Vector3(boundPoint1.x, boundPoint2.y), | |
new Vector3(boundPoint2.x, boundPoint2.y), | |
new Vector3(boundPoint2.x, boundPoint1.y), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# use USB to forward profiling on Android / Quest | |
adb forward tcp:54999 localabstract:Unity-{insert bundle identifier here} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os, sys | |
import unityparser | |
import re | |
def get_files(folder_path): | |
return [x for f in os.walk(folder_path) for x in map(lambda x: f"{f[0]}{os.path.sep}{x}", f[2])] | |
scripts = {d.data[0]['guid']: d for d in [unityparser.UnityDocument.load_yaml(path) for path in get_files(os.path.join('Assets', 'Scripts')) if path.endswith(".meta")]} | |
assets_paths = [path for path in get_files('Assets') if path.endswith('.unity') or path.endswith('.prefab') or path.endswith('.asset')] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <see cref="https://github.com/lordofduct/spacepuppy-unity-framework/blob/master/SpacepuppyBaseEditor/EditorHelper.cs"/> | |
public static Type GetTargetTypeOfProperty(SerializedProperty prop) | |
{ | |
if (prop == null) return null; | |
var path = prop.propertyPath.Replace(".Array.data[", "["); | |
path = path.Substring(0, path.LastIndexOf('.')); | |
object obj = prop.serializedObject.targetObject; | |
var elements = path.Split('.'); | |
foreach (var element in elements) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import sys | |
DEFAULT_ASSEMBLY = "Assembly-CSharp" | |
DEFAULT_NS = "" | |
def main(): | |
if len(sys.argv) < 3: | |
print(f"Usage: {sys.argv[0]} <old assembly:?><old ns:?><old name> <new assembly:?><new ns:?><new name>") | |
print() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def h2f(h): | |
h = h.lstrip('#') | |
return tuple(int(h[i:i+2], 16) / 255 for i in (0, 2, 4)) | |
def r2f(r): | |
r = r.lstrip("rgb").lstrip("a").lstrip("(").rstrip(")").strip() | |
return [float(x.strip()) / (255 if i < 3 else 1) for i, x in enumerate(r.split(", "))] | |
def c2u(s): | |
f = r2f(s) if "rgb" in s else h2f(s) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// see https://forum.unity.com/threads/uielements-developer-guide.648043/#post-6073137 | |
void RegisterPropertyChangeCallback(PropertyField field, SerializedProperty property, FieldInfo fieldInfo, Action callback) | |
{ | |
var propertyType = property.propertyType; | |
switch (propertyType) | |
{ | |
case SerializedPropertyType.Integer: | |
case SerializedPropertyType.LayerMask: | |
case SerializedPropertyType.ArraySize: | |
field.RegisterCallback<ChangeEvent<int>>( (evt) => callback()); |
OlderNewer