Initial Commit

This commit is contained in:
2025-07-04 20:33:06 +03:00
commit 8f09347ae0
9219 changed files with 2447903 additions and 0 deletions
@@ -0,0 +1,135 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.Eventing.Reader;
using UnityEditor;
using UnityEngine;
namespace Meta.Voice.Hub.UIComponents
{
public class FoldoutHierarchy<T>
{
private Dictionary<string, FoldoutGroup<T>> _groups = new Dictionary<string, FoldoutGroup<T>>();
private List<FoldoutGroup<T>> _orderedGroups = new List<FoldoutGroup<T>>();
public void Add(string path, FoldoutHierarchyItem<T> item)
{
string[] parts = path.Split('/');
FoldoutGroup<T> currentGroup = null;
for (int i = 0; i < parts.Length; i++)
{
string key = string.Join("/", parts, 0, i + 1);
if (!_groups.ContainsKey(key))
{
FoldoutGroup<T> newGroup = new FoldoutGroup<T>(parts[i]);
_groups.Add(key, newGroup);
_orderedGroups.Add(newGroup);
if (currentGroup != null)
{
currentGroup.AddChild(newGroup, item, i == parts.Length - 1);
}
}
currentGroup = _groups[key];
}
}
public void Draw()
{
foreach (var group in _orderedGroups)
{
if (group.Parent == null)
{
group.Draw();
}
}
}
}
public class FoldoutHierarchyItem<T>
{
public string path;
public T item;
public Action<T> onDraw;
}
public class FoldoutGroup<T>
{
private string _name;
private FoldoutGroup<T> _parent;
private List<object> _children = new List<object>();
private List<FoldoutHierarchyItem<T>> _data = new List<FoldoutHierarchyItem<T>>();
private int _indentSpace = 10;
private bool _isFoldedOut = false;
public string Name => _name;
public FoldoutGroup<T> Parent => _parent;
public FoldoutGroup(string name)
{
this._name = name;
}
public void AddChild(FoldoutGroup<T> child, FoldoutHierarchyItem<T> data, bool isLeaf)
{
child._parent = this;
_data.Add(data);
if(isLeaf) _children.Add(data);
else _children.Add(child);
}
public void Draw(int indentLevel = 0)
{
if (string.IsNullOrEmpty(_name))
{
DrawExpanded(indentLevel);
}
else
{
GUILayout.BeginHorizontal();
if (indentLevel >= 0)
{
GUILayout.Space(_indentSpace);
}
GUILayout.BeginVertical();
_isFoldedOut = EditorGUILayout.Foldout(_isFoldedOut, _name, true);
if (_isFoldedOut)
{
DrawExpanded(indentLevel);
}
GUILayout.EndVertical();
GUILayout.EndHorizontal();
}
}
private void DrawExpanded(int indentLevel)
{
foreach (var child in _children)
{
if (child is FoldoutGroup<T> foldoutGroup)
{
foldoutGroup.Draw(indentLevel);
} else if (child is FoldoutHierarchyItem<T> leaf)
{
GUILayout.BeginHorizontal();
if (indentLevel >= 0)
{
GUILayout.Space(_indentSpace);
}
GUILayout.BeginVertical();
leaf.onDraw(leaf.item);
GUILayout.EndVertical();
GUILayout.EndHorizontal();
}
}
}
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 5b3b26502f774dd2b597ed1657a8f0a4
timeCreated: 1681274028
@@ -0,0 +1,104 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
* All rights reserved.
*
* This source code is licensed under the license found in the
* LICENSE file in the root directory of this source tree.
*/
using System;
using UnityEditor;
using UnityEngine;
using UnityEngine.UIElements;
namespace Meta.Voice.Hub.UIComponents
{
public class ImageView
{
private EditorWindow _editorWindow;
private Editor _editor;
private Vector2 pan;
private float zoom = -1f;
public ImageView(EditorWindow editorWindow) => _editorWindow = editorWindow;
public ImageView(Editor editor) => _editor = editor;
private float ViewHeight => _editorWindow ? _editorWindow.position.height : Screen.height;
private float ViewWidth => _editorWindow ? _editorWindow.position.width : EditorGUIUtility.currentViewWidth;
private void Repaint()
{
if(_editorWindow) _editorWindow.Repaint();
else if (_editor) _editor.Repaint();
}
public void Draw(Texture2D image)
{
GUILayout.Box("",GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true));
var windowRect = GUILayoutUtility.GetLastRect();
if (windowRect.width <= 1 && windowRect.height <= 1) return;
if (image == null)
{
EditorGUILayout.HelpBox("No Texture2D assigned.", MessageType.Info);
return;
}
// Handle input for panning and zooming
HandleInput();
GUI.BeginGroup(windowRect);
var imageWidth = image.width * zoom;
var imageHeight = image.height * zoom;
if (zoom < 0 || imageWidth < windowRect.width && imageHeight < windowRect.height)
{
float widthScale = windowRect.width / image.width;
float heightScale = windowRect.height / image.height;
zoom = Mathf.Min(widthScale, heightScale);
}
if (imageWidth < windowRect.width) pan.x = (windowRect.width - imageWidth) / 2.0f;
else if (pan.x + imageWidth < windowRect.width) pan.x += windowRect.width - (pan.x + imageWidth);
if (imageHeight < windowRect.height) pan.y = (windowRect.height - imageHeight) / 2.0f;
else if (pan.y + imageHeight < windowRect.height) pan.y += windowRect.height - (pan.y + imageHeight);
if (pan.x > 0) pan.x = 0;
if (pan.y > 0) pan.y = 0;
if (imageHeight < windowRect.height) pan.y = (windowRect.height - imageHeight) / 2.0f;
GUI.DrawTexture(new Rect(pan.x, pan.y, image.width * zoom, image.height * zoom), image, ScaleMode.ScaleAndCrop);
GUI.EndGroup();
}
private void HandleInput()
{
Event e = Event.current;
// Panning
if (e.type == EventType.MouseDown)
{
e.Use();
}
if (e.type == EventType.MouseDrag)
{
pan += e.delta;
e.Use();
}
// Zooming
if (e.type == EventType.ScrollWheel)
{
float zoomDelta = -e.delta.y * 0.01f;
zoom = Mathf.Clamp(zoom + zoomDelta, 0.1f, 10f);
e.Use();
}
}
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 1767e34a605743579a6cb935eff19e64
timeCreated: 1680888171