Initial Commit

This commit is contained in:
jellejurre
2025-07-19 01:03:02 +02:00
commit e7904e3140
304 changed files with 22521 additions and 0 deletions

View File

@@ -0,0 +1,76 @@
using UnityEngine;
using UnityEditor;
using System.Linq;
//Made by Dreadrith#3238
//Discord: https://discord.gg/ZsPfrGn
//Github: https://github.com/Dreadrith/DreadScripts
//Gumroad: https://gumroad.com/dreadrith
//Ko-fi: https://ko-fi.com/dreadrith
namespace DreadScripts.SelectionHelper
{
[System.Serializable]
public class SaveSelection : ScriptableObject
{
[SerializeReference]
public Object[] oldSelection;
public string[] s ={"Boi","Huh"};
[MenuItem("Assets/Selection Helper/Save Selection")]
[MenuItem("GameObject/Selection Helper/Save\\Load/Save Selection", false, 0)]
static void SaveSelected()
{
instance.oldSelection = Selection.objects;
Save();
}
[MenuItem("Assets/Selection Helper/Load Selection")]
[MenuItem("GameObject/Selection Helper/Save\\Load/Load Selection", false, 1)]
static void LoadSelected()
{
if (instance.oldSelection != null)
Selection.objects = Selection.objects.Concat(instance.oldSelection).ToArray();
}
private static SaveSelection _instance;
private static SaveSelection instance => _instance ? _instance : GetInstance();
public static string folderPath = "DreadScripts/Saved Data/SaveSelection";
private static string SavePath => folderPath + "/SaveSelectionData.txt";
public static SaveSelection GetInstance()
{
if (_instance == null && Exists())
{
_instance = CreateInstance<SaveSelection>();
using (System.IO.StreamReader reader = new System.IO.StreamReader(SavePath))
JsonUtility.FromJsonOverwrite(reader.ReadToEnd(),_instance);
}
if (_instance == null)
{
_instance = CreateInstance<SaveSelection>();
string directoryPath = System.IO.Path.GetDirectoryName(SavePath);
if (!System.IO.Directory.Exists(directoryPath))
System.IO.Directory.CreateDirectory(directoryPath);
string json = JsonUtility.ToJson(_instance);
using (System.IO.StreamWriter writer = System.IO.File.CreateText(SavePath))
writer.Write(json);
}
return _instance;
}
public static void Save()
{
string json = EditorJsonUtility.ToJson(_instance);
using (System.IO.StreamWriter writer = new System.IO.StreamWriter(SavePath))
writer.Write(json);
}
public static bool Exists()
{
return System.IO.File.Exists(SavePath);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: a04dba417148dc641a899dc4853dfebb
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,294 @@
using UnityEditor;
using UnityEngine;
using System.Linq;
using System.Collections.Generic;
//By Dreadrith#3238
//https://discord.gg/ZsPfrGn
//Github: https://github.com/Dreadrith/DreadScripts
//Gumroad: https://gumroad.com/dreadrith
namespace DreadScripts.SelectionHelper
{
public class SceneObjectSelector : EditorWindow
{
#region Pref Keys
public const string PREF_PREFIX = "DS_SelectionHelperData_";
public static readonly string PREF_ONCOLOR = $"{PREF_PREFIX}SelectedColor";
public static readonly string PREF_OFFCOLOR = $"{PREF_PREFIX}DeselectedColor";
public static readonly string PREF_MINSIZE = $"{PREF_PREFIX}MinSize";
public static readonly string PREF_MAXSIZE = $"{PREF_PREFIX}MaxSize";
public static readonly string PREF_SIZE = $"{PREF_PREFIX}Size";
public static readonly string PREF_HUMANOID = $"{PREF_PREFIX}OnlyHumanoid";
public static void PrefSetColor(string key, Color value)
{
PlayerPrefs.SetFloat($"{key}R", value.r);
PlayerPrefs.SetFloat($"{key}G", value.g);
PlayerPrefs.SetFloat($"{key}B", value.b);
}
public static Color PrefGetColor(string key, Color defaultColor) => new Color(
PlayerPrefs.GetFloat($"{key}R", defaultColor.r),
PlayerPrefs.GetFloat($"{key}G", defaultColor.g),
PlayerPrefs.GetFloat($"{key}B", defaultColor.b));
public static void PrefSetBool(string key, bool value) => PlayerPrefs.SetInt(key, value ? 1 : 0);
public static bool PrefGetBool(string key, bool defaultValue) => PlayerPrefs.GetInt(key, defaultValue ? 1 : 0) == 1;
#endregion
[InitializeOnLoadMethod]
public static void LoadSettings()
{
OnColor = PrefGetColor(PREF_ONCOLOR, new Color(0.4f, 0.85f, 0.65f));
OffColor = PrefGetColor(PREF_OFFCOLOR, new Color(0.8f, 0.15f, 0.35f));
minHandleSize = PlayerPrefs.GetFloat(PREF_MINSIZE, 0.005f);
maxHandleSize = PlayerPrefs.GetFloat(PREF_MAXSIZE, 0.04f);
handleSize = PlayerPrefs.GetFloat(PREF_SIZE, 0.00525f);
onlyHumanoid = PrefGetBool(PREF_HUMANOID, false);
SceneView.duringSceneGui -= OnScene;
SceneView.duringSceneGui += OnScene;
Selection.selectionChanged -= OnSelectionChange;
Selection.selectionChanged += OnSelectionChange;
}
public static void SaveSettings()
{
PrefSetColor(PREF_ONCOLOR, OnColor);
PrefSetColor(PREF_OFFCOLOR, OffColor);
PlayerPrefs.SetFloat(PREF_MINSIZE, minHandleSize);
PlayerPrefs.SetFloat(PREF_MAXSIZE, maxHandleSize);
PlayerPrefs.SetFloat(PREF_SIZE, handleSize);
PrefSetBool(PREF_HUMANOID, onlyHumanoid);
SceneView.RepaintAll();
}
public static void Disable()
{
SceneView.duringSceneGui -= OnScene;
Selection.selectionChanged -= OnSelectionChange;
}
[MenuItem("DreadTools/Scripts Settings/Scene Object Selector")]
public static void showWindow()
{
GetWindow<SceneObjectSelector>("Scene Selector Settings");
}
private static bool selecting;
private static bool onlyHumanoid;
private static float handleSize, minHandleSize, maxHandleSize;
private static Transform[] sceneObjects;
private static bool ignoreDBones = true, includeRoots = true;
private static bool hasDbones = (null != System.Type.GetType("DynamicBone"));
private static bool[] bitmask;
private static Color OnColor;
private static Color OffColor;
private static void OnScene(SceneView sceneview)
{
Handles.BeginGUI();
GUILayout.Space(20);
EditorGUILayout.BeginHorizontal();
GUILayout.FlexibleSpace();
if (GUILayout.Button(EditorGUIUtility.IconContent("CapsuleCollider2D Icon"), GUIStyle.none, GUILayout.Width(20), GUILayout.Height(20)))
{
Event e = Event.current;
if (e.button == 0)
{
selecting = !selecting;
if (selecting)
{
if (!onlyHumanoid)
{
sceneObjects = FindObjectsOfType<Transform>();
if (hasDbones && ignoreDBones)
{
System.Type dboneType = System.Type.GetType("DynamicBone");
List<Transform> dbones = new List<Transform>();
Object[] dboneScripts = FindObjectsOfType(dboneType);
foreach (Object b in dboneScripts)
{
SerializedObject sb = new SerializedObject(b);
List<Transform> exclusionList = new List<Transform>();
SerializedProperty excProp = sb.FindProperty("m_Exclusions");
for (int i = 0; i < excProp.arraySize; i++)
exclusionList.Add((Transform) excProp.GetArrayElementAtIndex(i).objectReferenceValue);
GetBoneChildren(dbones, exclusionList, (Transform) sb.FindProperty("m_Root").objectReferenceValue, includeRoots);
}
sceneObjects = sceneObjects.Except(dbones).ToArray();
}
}
else
{
var list = new List<Transform>();
foreach (var a in FindObjectsOfType<Animator>().Where(a => a.isHuman && a.avatar))
{
for (int i = 0; i < 55; i++)
{
var t = a.GetBoneTransform((HumanBodyBones) i);
if (t) list.Add(t);
}
}
sceneObjects = list.ToArray();
}
refreshBitMask();
}
}
if (e.button == 1)
{
GetWindow<SceneObjectSelector>(false, "Scene Selector Settings", true);
}
}
EditorGUILayout.EndHorizontal();
if (selecting)
{
//a
EditorGUILayout.BeginHorizontal();
GUILayout.FlexibleSpace();
EditorGUI.BeginChangeCheck();
handleSize = GUILayout.VerticalSlider(handleSize, maxHandleSize, minHandleSize, GUILayout.Height(50), GUILayout.Width(15));
if (EditorGUI.EndChangeCheck())
SaveSettings();
GUILayout.Space(1);
EditorGUILayout.EndHorizontal();
}
Handles.EndGUI();
if (selecting)
{
if (sceneObjects.Length > 0)
{
for (int i = 0; i < sceneObjects.Length; i++)
{
if (!sceneObjects[i])
continue;
int controlID = sceneObjects[i].GetHashCode();
Event e = Event.current;
if (bitmask[i])
Handles.color = OnColor;
else
Handles.color = OffColor;
Handles.SphereHandleCap(controlID, sceneObjects[i].position, Quaternion.identity, handleSize, EventType.Repaint);
switch (e.GetTypeForControl(controlID))
{
case EventType.MouseDown:
if (HandleUtility.nearestControl == controlID && e.button == 0)
{
if (e.control)
{
if (!Selection.objects.Contains(sceneObjects[i].gameObject))
{
Selection.objects = Selection.objects.Concat(new GameObject[] { sceneObjects[i].gameObject }).ToArray();
}
else
{
Selection.objects = Selection.objects.Except(new GameObject[] { sceneObjects[i].gameObject }).ToArray();
}
}
else
{
Selection.activeObject = sceneObjects[i].gameObject;
}
e.Use();
}
break;
case EventType.Layout:
float distance = HandleUtility.DistanceToCircle(sceneObjects[i].position, handleSize / 2f);
HandleUtility.AddControl(controlID, distance);
break;
}
}
}
}
}
private static void GetBoneChildren(List<Transform> dbones, List<Transform> exclusionList, Transform parent, bool first = false)
{
if (exclusionList.Contains(parent)) return;
if (!first) dbones.Add(parent);
for (int i = 0; i < parent.childCount; i++)
GetBoneChildren(dbones, exclusionList, parent.GetChild(i));
}
private void OnGUI()
{
EditorGUI.BeginChangeCheck();
using (new GUILayout.HorizontalScope())
{
EditorGUIUtility.labelWidth = 20;
EditorGUILayout.LabelField("Handle Size");
minHandleSize = EditorGUILayout.FloatField(minHandleSize, GUILayout.Width(40));
handleSize = GUILayout.HorizontalSlider(handleSize, minHandleSize, maxHandleSize);
maxHandleSize = EditorGUILayout.FloatField(maxHandleSize, GUILayout.Width(40));
EditorGUIUtility.labelWidth = 0;
}
OnColor = EditorGUILayout.ColorField("Selected", OnColor);
OffColor = EditorGUILayout.ColorField("Deselected", OffColor);
using (new GUILayout.HorizontalScope())
{
EditorGUIUtility.labelWidth = 70;
onlyHumanoid = EditorGUILayout.ToggleLeft("Only Humanoid", onlyHumanoid);
if (hasDbones)
{
ignoreDBones = EditorGUILayout.ToggleLeft("Ignore D-Bones", ignoreDBones);
includeRoots = EditorGUILayout.ToggleLeft("Include D-Bone Roots", includeRoots);
}
}
if (EditorGUI.EndChangeCheck())
SaveSettings();
EditorGUILayout.LabelField(string.Empty, GUI.skin.horizontalSlider);
using (new GUILayout.HorizontalScope())
{
GUILayout.FlexibleSpace();
if (GUILayout.Button("Made by Dreadrith#3238", "boldlabel"))
Application.OpenURL("https://github.com/Dreadrith/DreadScripts");
}
}
private static void OnSelectionChange()
{
if (selecting) refreshBitMask();
}
private static void refreshBitMask()
{
bitmask = new bool[sceneObjects.Length];
for (int i = 0; i < sceneObjects.Length; i++)
{
if (!sceneObjects[i])
{
sceneObjects = sceneObjects.Except(new Transform[] { sceneObjects[i] }).ToArray();
refreshBitMask();
break;
}
if (Selection.objects.Contains(sceneObjects[i].gameObject))
bitmask[i] = true;
else
bitmask[i] = false;
}
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 02cefda8b1d83074e9c6585e1b599f2c
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,91 @@
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using System.Linq;
namespace DreadScripts.SelectionHelper
{
public class SelectionHelper
{
//By Dreadrith#3238
//Server: https://discord.gg/ZsPfrGn
//Github: https://github.com/Dreadrith/DreadScripts
//Gumroad: https://gumroad.com/dreadrith
public static System.Type myCurrentType = System.Type.GetType(SessionState.GetString("SelectionHelperSelectType", ""));
[MenuItem("CONTEXT/Component/[SH] Choose Type", false, 900)]
static void selectType(MenuCommand selected)
{
myCurrentType = selected.context.GetType();
SessionState.SetString("SelectionHelperSelectType", myCurrentType.AssemblyQualifiedName);
}
[MenuItem("GameObject/Selection Helper/Select Immediate Children", false, 50)]
static void selectImmediate(MenuCommand selected)
{
Transform[] obj = Selection.GetFiltered<Transform>(SelectionMode.Editable);
if (obj.Length == 0)
{
Debug.Log("[SH] No GameObject was selected");
return;
}
List<GameObject> newSelection = new List<GameObject>();
for (int i = 0; i < obj.Length; i++)
{
for (int j = 0; j < obj[i].childCount; j++)
{
newSelection.Add(obj[i].GetChild(j).gameObject);
}
}
Selection.objects = Selection.objects.Concat(newSelection).ToArray();
}
[MenuItem("GameObject/Selection Helper/By Type/Filter", false, -50)]
static void selectSelectedType()
{
Selection.objects = Selection.GetFiltered(myCurrentType, SelectionMode.Editable);
List<GameObject> newSelection = new List<GameObject>();
for (int i = 0; i < Selection.objects.Length; i++)
{
newSelection.Add(((Component)Selection.objects[i]).gameObject);
}
Selection.objects = newSelection.ToArray();
}
[MenuItem("GameObject/Selection Helper/By Type/Children", false, -51)]
static void selectChildrenType(MenuCommand selected)
{
selectByType(selected, true);
}
[MenuItem("GameObject/Selection Helper/By Type/Parents", false, -52)]
static void selectParentsType(MenuCommand selected)
{
selectByType(selected, false);
}
static void selectByType(MenuCommand selected, bool child)
{
if (myCurrentType == null)
{
Debug.Log("[SH] No Component Type Chosen");
return;
}
if (!selected.context)
{
Debug.Log("[SH] No GameObject was selected");
return;
}
GameObject[] objs;
if (child)
objs = ((GameObject)selected.context).GetComponentsInChildren(myCurrentType, true).Select(c => c.gameObject).ToArray();
else
objs = ((GameObject)selected.context).GetComponentsInParent(myCurrentType, true).Select(c => c.gameObject).ToArray();
Selection.objects = objs;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: d370428cfe632814e82b8f8b0aba3da2
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,15 @@
{
"name": "com.dreadscripts.selectionhelper",
"references": [],
"includePlatforms": [
"Editor"
],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": false,
"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": [],
"versionDefines": [],
"noEngineReferences": false
}

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 2816fbc8c0aecd44eb2bcfbd149155be
AssemblyDefinitionImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant: