Initial Commit

This commit is contained in:
Simeon Radivoev 2022-02-12 12:53:50 +02:00
commit ee5c2f922d
Signed by: simeonradivoev
GPG key ID: 7611A451D2A5D37A
2255 changed files with 547750 additions and 0 deletions

View file

@ -0,0 +1,19 @@
using DefaultNamespace;
using UnityEditor;
using UnityEngine;
namespace Trive.Editor
{
[CustomPropertyDrawer(typeof(bool1))]
public class Bool1Drawer : PropertyDrawer
{
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
using (var valProp = property.FindPropertyRelative("_value"))
{
var valueRect = EditorGUI.PrefixLabel(position, label);
valProp.intValue = EditorGUI.Toggle(valueRect, valProp.intValue == 1) ? 1 : 0;
}
}
}
}

View file

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

View file

@ -0,0 +1,123 @@
using System;
using System.Linq;
using System.Reflection;
using UnityEditor;
using UnityEditorInternal;
using UnityEngine;
namespace Trive.Editor
{
[CustomEditor(typeof(SoundLibrary)),CanEditMultipleObjects]
public class SoundLibraryInspector : UnityEditor.Editor
{
private ReorderableList list;
private void OnEnable()
{
list = new ReorderableList(serializedObject,serializedObject.FindProperty("audoClips"));
list.drawElementCallback = (rect, index, active, focused) =>
{
var prop = list.serializedProperty.GetArrayElementAtIndex(index);
var clipProp = prop.FindPropertyRelative("clip");
var volumeProp = prop.FindPropertyRelative("volume");
var weightProp = prop.FindPropertyRelative("weight");
EditorGUI.PropertyField(new Rect(rect.x,rect.y,rect.width * 0.5f,EditorGUIUtility.singleLineHeight), clipProp,GUIContent.none);
EditorGUI.PropertyField(new Rect(rect.width * 0.5f + rect.x, rect.y,rect.width * 0.4f, EditorGUIUtility.singleLineHeight), volumeProp, GUIContent.none);
EditorGUI.PropertyField(new Rect(rect.width * 0.5f + rect.width * 0.4f + 4 + rect.x, rect.y, rect.width * 0.1f - 4, EditorGUIUtility.singleLineHeight), weightProp, GUIContent.none);
};
list.onAddCallback = reorderableList =>
{
reorderableList.serializedProperty.arraySize++;
var prop = reorderableList.serializedProperty.GetArrayElementAtIndex(reorderableList.serializedProperty.arraySize - 1);
prop.FindPropertyRelative("clip").objectReferenceValue = null;
prop.FindPropertyRelative("volume").floatValue = 1;
prop.FindPropertyRelative("weight").intValue = 1;
reorderableList.serializedProperty.serializedObject.ApplyModifiedProperties();
};
list.onRemoveCallback = reorderableList =>
{
reorderableList.serializedProperty.DeleteArrayElementAtIndex(reorderableList.index);
reorderableList.serializedProperty.serializedObject.ApplyModifiedProperties();
reorderableList.index--;
};
}
public override void OnInspectorGUI()
{
if (Event.current.type == EventType.DragUpdated)
{
if (DragAndDrop.objectReferences.Any(o => o is AudioClip))
{
Event.current.Use();
DragAndDrop.visualMode = DragAndDropVisualMode.Generic;
}
}
else if (Event.current.type == EventType.DragPerform)
{
AudioClip[] clips = DragAndDrop.objectReferences.OfType<AudioClip>().Distinct().OrderBy(c => c.name).ToArray();
if (clips.Length > 0)
{
Event.current.Use();
DragAndDrop.AcceptDrag();
var clipsProp = serializedObject.FindProperty("audoClips");
clipsProp.arraySize += clips.Length;
for (int i = 0; i < clips.Length; i++)
{
var clipProp = clipsProp.GetArrayElementAtIndex(clipsProp.arraySize - 1 - i);
clipProp.FindPropertyRelative("clip").objectReferenceValue = clips[i];
clipProp.FindPropertyRelative("volume").floatValue = 1;
clipProp.FindPropertyRelative("weight").intValue = 1;
serializedObject.ApplyModifiedProperties();
}
}
}
base.OnInspectorGUI();
list.DoLayoutList();
serializedObject.ApplyModifiedProperties();
EditorGUILayout.BeginHorizontal();
if (GUILayout.Button("Play Random"))
{
foreach (var t in targets)
{
SoundLibrary library = t as SoundLibrary;
SoundLibrary.AudoClipWrapper clip = library.RandomWrapper();
PlayClip(clip.Clip);
}
}
if (GUILayout.Button("Play Shuffle"))
{
foreach (var t in targets)
{
SoundLibrary library = t as SoundLibrary;
SoundLibrary.AudoClipWrapper clip = library.ShuffledWrapper();
PlayClip(clip.Clip);
}
}
EditorGUILayout.EndHorizontal();
}
public static void PlayClip(AudioClip clip,int startSample = 0, bool loop = false)
{
Assembly unityEditorAssembly = typeof(AudioImporter).Assembly;
Type audioUtilClass = unityEditorAssembly.GetType("UnityEditor.AudioUtil");
MethodInfo method = audioUtilClass.GetMethod(
"PlayClip",
BindingFlags.Static | BindingFlags.Public,
null,
new System.Type[] {
typeof(AudioClip), typeof(int), typeof(bool)
},
null
);
method.Invoke(
null,
new object[] {
clip,
startSample,
loop
}
);
}
}
}

View file

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

View file

@ -0,0 +1,58 @@
using System;
using UnityEditor;
using UnityEngine;
public class WaypointHelperWindow : EditorWindow
{
public static event Action<int> OnSelectEvent;
public static void ClearSelectEvent()
{
OnSelectEvent = null;
}
[MenuItem("Window/Debug/Waypoint Helper")]
private static void Open()
{
EditorWindow.GetWindow<WaypointHelperWindow>();
}
private void OnEnable()
{
SceneView.duringSceneGui += SceneGui;
}
private void OnDisable()
{
SceneView.duringSceneGui -= SceneGui;
}
private void SceneGui(SceneView view)
{
var objects = GameObject.FindGameObjectsWithTag("Waypoint");
Vector3 mousePosition = Event.current.mousePosition;
mousePosition.y = view.camera.pixelHeight - mousePosition.y;
foreach (var o in objects)
{
var transform = o.transform;
Vector2 screenPos = view.camera.WorldToScreenPoint(transform.position);
float d = Vector2.Distance(screenPos, mousePosition);
if(Selection.activeInstanceID != o.GetInstanceID())
{
Handles.CircleHandleCap(o.GetInstanceID(),transform.position,transform.rotation,0.1f,Event.current.type);
}
if (d < 32)
{
if (Event.current.type == EventType.MouseDown && Event.current.button == 0)
{
Selection.activeInstanceID = o.GetInstanceID();
OnSelectEvent?.Invoke(transform.GetInstanceID());
}
}
}
}
}

View file

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: a6870c4bf4e94092adfeff8dfbce7364
timeCreated: 1531402849