lh/20250305_merge #6

Merged
UVCXR merged 2 commits from lh/20250305_merge into main 2025-03-06 09:37:35 +09:00
18 changed files with 3152 additions and 0 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 9864e9f028e578f44a4f6f29cbe44ae0
PrefabImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

8
Assets/legacy.meta Normal file
View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: c04ed7ceb0169454a8af4113cec522c4
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: a7c7d3c156415e34fa2a225d94bbca75
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,194 @@
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UnityEngine.PlayerLoop;
using XRLib;
namespace XED
{
public class HierarchyTree : MonoBehaviour, ISingle
{
public event Action<TreeItem_> onAddEvent;
public event Action<TreeItem_> onSelectEvent;
public event Action<TwinObject> onRemoveEvent;
public event Action<TreeItem_> onDeselectEvent;
public event Action<List<TreeItem_>> onDataUpdate;
HashSet<TreeItem_> tempHashSet = new();
HashSet<TwinObject> rootObjects = new();
List<TreeItem_> data = new List<TreeItem_>();
Dictionary<TwinObject, TreeItem_> twinToItem = new Dictionary<TwinObject, TreeItem_>();
TreeItem_ CreateItem(TwinObject to)
{
TreeItem_ item = new TreeItem_(to);
data.Add(item);
twinToItem.Add(to, item);
return item;
}
public bool isExist(TwinObject to)
{
return rootObjects.Contains(to);
}
public void Add(TwinObject to)
{
if (!rootObjects.Add(to))
return;
if (to is Wall)
return;
var item = CreateItem(to);
onAddEvent?.Invoke(item);
}
public void Remove(TwinObject to)
{
if (!rootObjects.Contains(to))
{
return;
}
GetChilds(twinToItem[to]);
foreach (var item in tempHashSet)
{
switch (item.ToItem)
{
case WallGroup wg:
foreach (var items in wg.groupWalls)
{
rootObjects.Remove(items);
}
rootObjects.Remove(wg);
break;
default:
rootObjects.Remove(item.ToItem);
break;
}
item.parent?.RemoveChild(item);
onRemoveEvent?.Invoke(item.ToItem);
item.DestroyTreeItem();
data.Remove(item);
twinToItem.Remove(item.ToItem);
Destroy(item.ToItem.gameObject);
}
tempHashSet.Clear();
onDataUpdate(data);
}
void GetChilds(TreeItem_ go)
{
tempHashSet.Add(go);
foreach (var c in go.children)
{
GetChilds(c);
}
}
public void Attach(TreeItem_ p, TreeItem_ t)
{
if (!data.Contains(p))
{
Debug.LogError("Parent not found");
return;
}
if (!data.Contains(t))
{
Debug.LogError("Child not found");
return;
}
if (p == t)
{
return;
}
GetChilds(t);
foreach (var item in tempHashSet)
{
if (p.parent == item)
{
Debug.LogError("It is infinite");
tempHashSet.Clear();
return;
}
}
t.parent?.RemoveChild(t);
p.Add(t);
t.parent = p;
data.Remove(t);
var index = data.IndexOf(p) + 1;
if (index >= data.Count)
{
if (tempHashSet.Count > 1)
{
foreach (var item in tempHashSet)
{
data?.Remove(item);
data.Add(item);
}
}
else
{
data.Add(t);
}
}
else
{
int i = 0;
if (tempHashSet.Count > 1)
{
foreach (var item in tempHashSet)
{
data?.Remove(item);
data.Insert(index + i, item);
i++;
}
}
else
{
data.Insert(index, t);
}
}
tempHashSet.Clear();
onDataUpdate(data);
}
public void Dettach(TreeItem_ item)
{
if (!data.Contains(item))
{
Debug.LogError("Not found");
return;
}
item.parent?.RemoveChild(item);
item.parent = null;
GetChilds(item);
foreach (var i in tempHashSet)
{
data?.Remove(i);
data.Add(i);
}
tempHashSet.Clear();
onDataUpdate(data);
}
internal void Select(TwinObject to)
{
onSelectEvent?.Invoke(twinToItem[to]);
}
public void Select(TreeItem_ ti)
{
onSelectEvent?.Invoke(ti);
}
internal void Deselect(TwinObject to)
{
onDeselectEvent?.Invoke(twinToItem[to]);
}
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 400f59e21429ab5409c7c43eef737e6f

View File

@@ -0,0 +1,195 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices.Expando;
using System.Security.Cryptography;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.SubsystemsImplementation;
using UnityEngine.UI;
using XRLib;
using XRLib.UI;
using XED.UI;
namespace XED
{
public class Panel_Hierarchy : PanelBase,IDropHandler
{
public ScrollRect scrollrect_hierarchycontent;
public UI_HierarchyItem prf_hierarchyitem;
internal Action<TwinObject> onClickItem;
internal Action<TreeItem_> onItemDrop;
internal Action<TreeItem_, TreeItem_> OnItemDropOnItem;
private Dictionary<TreeItem_, UI_HierarchyItem> itemToView = new();
private Dictionary<UI_HierarchyItem, TreeItem_> viewToItem = new();
HashSet<TreeItem_> tempHashSet = new();
public float tap = 30f;
enum AnimationParameter
{
Contract
}
public override void AfterAwake()
{
prf_hierarchyitem = Resources.Load<UI_HierarchyItem>("Prefabs/UI/PRF_TreeItem");
}
public void OnDrop(PointerEventData eventData)
{
if (eventData.pointerDrag != null)
{
UI_HierarchyItem draggeditem = eventData.pointerDrag.GetComponent<UI_HierarchyItem>();
if (draggeditem)
{
var item = viewToItem[draggeditem];
onItemDrop(item);
}
}
}
void HierarchyExpand(bool value)
{
GetComponent<Animator>().SetBool(AnimationParameter.Contract.ToString(), value);
}
public void AddItem(TreeItem_ item)
{
UI_HierarchyItem itemView = Instantiate(prf_hierarchyitem, scrollrect_hierarchycontent.content);
item.onExpand += Expand;
item.onFold += Fold;
itemView.Set(item);
itemView.onDestroy += RemoveItem;
itemView.onClick += OnClickItem;
UI_DragDrop_ ui_DragDrop = itemView.transform.GetComponent<UI_DragDrop_>();
ui_DragDrop.OnDropItem += ItemDrop;
viewToItem.Add(itemView, item);
itemToView.Add(item, itemView);
}
void ItemDrop(UIBase parent, UIBase child)
{
if(parent is UI_HierarchyItem parentItem && child is UI_HierarchyItem childItem)
{
var pi = viewToItem[parentItem];
var ci = viewToItem[childItem];
OnItemDropOnItem(pi, ci);
}
}
void Expand(TreeItem_ item)
{
var rootChildren = item.children;
for (int i = 0; i < rootChildren.Count; ++i)
{
var rootChild = item.children[i];
tempHashSet.Add(rootChild);
if (!rootChild.expanded)
{
continue;
}
var rootChildItem = rootChild;
for (int j = 0; j < rootChildItem.children.Count; ++j)
{
var leafChild = rootChildItem.children[j];
GetExpandTargets(leafChild);
}
}
foreach (var r in tempHashSet)
{
itemToView[r].gameObject.SetActive(true);
}
tempHashSet.Clear();
}
void GetExpandTargets(TreeItem_ i)
{
tempHashSet.Add(i);
if (!i.expanded)
{
return;
}
var children = i.children;
foreach (var item in children)
{
tempHashSet.Add(item);
GetExpandTargets(item);
}
}
void Fold(TreeItem_ item)
{
GetFoldTargets(item);
foreach (var r in tempHashSet)
{
var view = itemToView[r];
view.SetActive(false);
}
tempHashSet.Clear();
}
void GetFoldTargets(TreeItem_ i)
{
var children = i.children;
foreach (var item in children)
{
if (itemToView[i].gameObject.activeSelf)
{
tempHashSet.Add(item);
GetFoldTargets(item);
}
}
}
public void ActiveHighlightItem(TreeItem_ item)
{
if (itemToView.ContainsKey(item))
{
itemToView[item].ActiveHighlight();
}
}
public void DeactiveHighlightItem(TreeItem_ item)
{
if (itemToView.ContainsKey(item))
{
itemToView[item].DeactvieHighlight();
}
}
public void UpdateIndex(List<TreeItem_> data)
{
for(int i = 0; i < data.Count; i++)
{
var item = data[i];
var view = itemToView[item];
var depth = data[i].depth;
view.transform.SetSiblingIndex(i);
var TapRectTransform = view.transform.GetChild(0).GetComponentInChildren<RectTransform>(true);
TapRectTransform.offsetMin = new Vector2(depth * tap, TapRectTransform.offsetMin.y);
}
}
void OnClickItem(UI_HierarchyItem view)
{
var item = viewToItem[view];
onClickItem?.Invoke(item.ToItem);
}
public void RemoveItem(UI_HierarchyItem to)
{
itemToView.Remove(viewToItem[to]);
viewToItem.Remove(to);
}
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 39734de062d30454a9ebdbf748af07ca

View File

@@ -0,0 +1,34 @@
using UnityEngine;
namespace XED
{
public class Tester : MonoBehaviour
{
Panel_Hierarchy ph;
HierarchyTree ht;
GameObject renderObjectPrefab;
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{
ph=FindObjectOfType<Panel_Hierarchy>();
ht = FindObjectOfType<HierarchyTree>();
ht.onAddEvent += ph.AddItem;
ph.OnItemDropOnItem += ht.Attach;
ht.onDataUpdate += ph.UpdateIndex;
ph.onItemDrop += ht.Dettach;
renderObjectPrefab = Resources.Load<GameObject>("Prefabs/PRF_RenderObject");
}
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.A))
{
var obj = Instantiate(renderObjectPrefab);
var to = obj.GetComponent<TwinObject>();
to.name = to.name.Replace("(Clone)", "");
ht.Add(to);
}
}
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 2f7ab64367eb074498afe02ab1069901

View File

@@ -0,0 +1,63 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace XED
{
public class TreeItem_
{
public TwinObject ToItem;
//public UI_HierarchyItem View;
public event Action OnDestroyTreeItem;
public int depth
{
get
{
TreeItem_ curr = parent;
int result = 0;
while (curr != null)
{
result++;
curr = curr.parent;
}
return result;
}
}
public List<TreeItem_> children = new List<TreeItem_>();
public TreeItem_ parent;
public bool expanded = true;
public event Action<TreeItem_> onExpand;
public event Action<TreeItem_> onFold;
public TreeItem_(TwinObject to)
{
ToItem = to;
}
internal void Add(TreeItem_ t)
{
children.Add(t);
}
internal void RemoveChild(TreeItem_ c)
{
children.Remove(c);
}
public void OnExpand(bool value)
{
expanded = value;
if (value)
onExpand?.Invoke(this);
else
onFold?.Invoke(this);
}
public void DestroyTreeItem()
{
OnDestroyTreeItem?.Invoke();
}
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 77ba20c023097c043a1b8a635d780135

View File

@@ -0,0 +1,47 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
using XRLib.UI;
namespace XED
{
public class UI_DragDrop_ : MonoBehaviour,IBeginDragHandler,IDragHandler,IEndDragHandler,IDropHandler
{
GameObject Clone;
public float cloneAlpha=1f;
public Action<UIBase, UIBase> OnDropItem;
public void OnBeginDrag(PointerEventData eventData)
{
Clone=Instantiate(gameObject,gameObject.transform.parent);
Clone.GetComponent<CanvasGroup>().blocksRaycasts = false;
var CI = Clone.GetComponentsInChildren<Image>();
foreach(var c in CI)
{
c.color = new Color(c.color.r, c.color.g, c.color.b, cloneAlpha);
}
}
public void OnDrag(PointerEventData eventData)
{
Clone.transform.position = Input.mousePosition;
}
public void OnEndDrag(PointerEventData eventData)
{
Destroy(Clone);
}
public void OnDrop(PointerEventData eventData)
{
if (eventData.pointerDrag != null)
{
UI_DragDrop_ draggedItem = eventData.pointerDrag.GetComponent<UI_DragDrop_>();
if (draggedItem)
{
OnDropItem?.Invoke(gameObject.GetComponent<UIBase>(), draggedItem.GetComponent<UIBase>());
}
}
}
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 9e3cc64011e8dbe428cf3fe9304f9a9a

View File

@@ -0,0 +1,68 @@
using System;
using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
using XRLib;
using XRLib.UI;
namespace XED
{
public class UI_HierarchyItem : UIBase
{
public Button button_selectitem;
public event Action<UI_HierarchyItem> onClick;
public event Action<UI_HierarchyItem> onDestroy;
// Start is called before the first frame update
public void Set(TreeItem_ Treeitem)
{
var item = Treeitem;
var toitem = Treeitem.ToItem;
item.OnDestroyTreeItem += DestroyItemView;
TextMeshProUGUI text_name = Find<TextMeshProUGUI>(nameof(text_name));
text_name.SetText(toitem.name);
Toggle toggle_display = Find<Toggle>(nameof(toggle_display));
toggle_display.onValueChanged.AddListener(toitem.SetDisplayable);
Toggle toggle_interactible = Find<Toggle>(nameof(toggle_interactible));
toggle_interactible.onValueChanged.AddListener(toitem.SetInteractible);
Toggle toggle_expand = Find<Toggle>(nameof(toggle_expand));
toggle_expand.onValueChanged.AddListener(item.OnExpand);
button_selectitem = Find<Button>(nameof(button_selectitem));
button_selectitem.onClick.AddListener(OnClickItem);
toitem.IsDisplayable = !toggle_display.isOn;
toitem.IsInteractible = !toggle_interactible.isOn;
}
void OnClickItem()
{
onClick?.Invoke(this);
}
public void ActiveHighlight()
{
//var option = FindSingle<OptionManager>().hierarchyItemOption;
//button_selectitem.image.color = option.selectColor;
}
public void DeactvieHighlight()
{
//var option = FindSingle<OptionManager>().hierarchyItemOption;
//button_selectitem.image.color = option.unselectColor;
}
void DestroyItemView()
{
onDestroy?.Invoke(this);
Destroy(gameObject);
}
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: ac0660c9602721445bf58cd13e50cccd

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 08e9e86ff4c52cb448493fbb4dd1d30a
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant: