You've already forked UniversalViewer
Initial files
This commit is contained in:
105
Assets/Scripts/ModelViewerBase/UI/Handles/HandleManager.cs
Normal file
105
Assets/Scripts/ModelViewerBase/UI/Handles/HandleManager.cs
Normal file
@@ -0,0 +1,105 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using static SerializableBone;
|
||||
|
||||
public class HandleManager : MonoBehaviour
|
||||
{
|
||||
public static HandleManager Instance;
|
||||
public GameObject HandlesPanel;
|
||||
public GameObject Pfb_HandleDisplay;
|
||||
public UIPopupPanel Pfb_Popup;
|
||||
public Button Pfb_PopupButton;
|
||||
|
||||
public Material LineRendererMaterial;
|
||||
|
||||
public List<BoneTags> EnabledHandles = new List<BoneTags>() { BoneTags.Humanoid };
|
||||
public bool EnabledLines = true;
|
||||
|
||||
public static bool InteractionInProgress;
|
||||
|
||||
private List<UIHandle> AllHandles = new List<UIHandle>();
|
||||
|
||||
public static System.Action<HandleUndoData> RegisterRuntimeGizmoUndoAction;
|
||||
public static System.Action<List<HandleUndoData>> RegisterRuntimeGizmoUndoActions;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
Instance = this;
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
var camera = Camera.main;
|
||||
//var poseModeOn = UmaViewerUI.Instance.PoseManager.PoseModeOn;
|
||||
|
||||
foreach (var handle in AllHandles)
|
||||
{
|
||||
//handle.ForceDisplayOff(!poseModeOn);
|
||||
handle.UpdateManual(camera, EnabledLines);
|
||||
|
||||
if (handle.Popup.gameObject.activeInHierarchy)
|
||||
{
|
||||
handle.Popup.UpdateManual(camera);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void RegisterHandle(UIHandle handle)
|
||||
{
|
||||
var hm = HandleManager.Instance;
|
||||
|
||||
if (hm.AllHandles.Contains(handle))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
hm.AllHandles.Add(handle);
|
||||
}
|
||||
|
||||
public static void UnregisterHandle(UIHandle handle)
|
||||
{
|
||||
var hm = HandleManager.Instance;
|
||||
|
||||
if (!hm.AllHandles.Contains(handle))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
hm.AllHandles.Remove(handle);
|
||||
}
|
||||
|
||||
public static void CloseAllPopups()
|
||||
{
|
||||
var hm = HandleManager.Instance;
|
||||
|
||||
foreach(var handle in hm.AllHandles)
|
||||
{
|
||||
if (handle.Popup.gameObject.activeInHierarchy)
|
||||
{
|
||||
handle.TogglePopup();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary> Used on UI buttons </summary>
|
||||
public void ToggleBonesVisible(string tag)
|
||||
{
|
||||
var enumTag = (BoneTags)System.Enum.Parse(typeof(BoneTags), tag);
|
||||
if (EnabledHandles.Contains(enumTag))
|
||||
{
|
||||
EnabledHandles.Remove(enumTag);
|
||||
}
|
||||
else
|
||||
{
|
||||
EnabledHandles.Add(enumTag);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary> Used on UI buttons </summary>
|
||||
public void ToggleLinesVisible(bool value)
|
||||
{
|
||||
EnabledLines = value;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 491e0b38519c9e94facd88535f6f3458
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
277
Assets/Scripts/ModelViewerBase/UI/Handles/UIHandle.cs
Normal file
277
Assets/Scripts/ModelViewerBase/UI/Handles/UIHandle.cs
Normal file
@@ -0,0 +1,277 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class UIHandle : MonoBehaviour
|
||||
{
|
||||
/// <summary> Object that "owns" the handle </summary>
|
||||
public ObjectContainer Owner;
|
||||
|
||||
/// <summary> Object that the handle refers to. Cast in inheriting class </summary>
|
||||
public Transform Target;
|
||||
|
||||
/// <summary> Display object on the UI </summary>
|
||||
public GameObject Handle;
|
||||
|
||||
/// <summary> Collider for selecting the handle on UI </summary>
|
||||
public SphereCollider Collider;
|
||||
|
||||
/// <summary> Object that appears when right-clicking the handle </summary>
|
||||
public UIPopupPanel Popup;
|
||||
|
||||
public LineRenderer LineRenderer;
|
||||
|
||||
protected SerializableTransform _defaultTransform;
|
||||
protected float _baseScale = 1;
|
||||
protected bool _forceDisplayOff = false;
|
||||
protected ModelViewerMain Main => ModelViewerMain.GetInstance();
|
||||
|
||||
public static T CreateAsChild<T>(Transform parent) where T : UIHandle
|
||||
{
|
||||
var handle = new GameObject(parent.name + "_Handle").AddComponent<T>();
|
||||
handle.transform.parent = parent.transform;
|
||||
handle.transform.localPosition = Vector3.zero;
|
||||
handle.transform.localScale = Vector3.one;
|
||||
handle.transform.rotation = parent.rotation;
|
||||
handle.Target = parent.transform;
|
||||
return handle;
|
||||
}
|
||||
|
||||
public virtual UIHandle Init(ObjectContainer owner, Transform target)
|
||||
{
|
||||
Target = target;
|
||||
return Init(owner);
|
||||
}
|
||||
|
||||
public virtual UIHandle Init(ObjectContainer owner)
|
||||
{
|
||||
HandleManager.RegisterHandle(this);
|
||||
|
||||
gameObject.layer = LayerMask.NameToLayer("UIHandle");
|
||||
Target = Target == null? owner.transform : Target;
|
||||
Owner = owner;
|
||||
Owner.Handles.Add(this);
|
||||
|
||||
Handle = Instantiate(HandleManager.Instance.Pfb_HandleDisplay, HandleManager.Instance.HandlesPanel.transform);
|
||||
Handle.transform.SetAsFirstSibling();
|
||||
|
||||
Popup = Instantiate(HandleManager.Instance.Pfb_Popup, HandleManager.Instance.HandlesPanel.transform).Init(this);
|
||||
Popup.gameObject.SetActive(false);
|
||||
|
||||
_defaultTransform = new SerializableTransform(Target, Space.Self);
|
||||
|
||||
var collider = gameObject.AddComponent<SphereCollider>();
|
||||
collider.center = Vector3.zero;
|
||||
|
||||
Collider = collider;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
private void OnDrawGizmos()
|
||||
{
|
||||
Gizmos.DrawWireSphere(transform.position + Collider.center, transform.lossyScale.x * Collider.radius);
|
||||
}
|
||||
|
||||
public virtual void UpdateManual(Camera camera, bool linesEnabled)
|
||||
{
|
||||
if (Handle != null && camera != null && transform != null)
|
||||
{
|
||||
Handle.transform.localScale = Vector3.one * Mathf.Clamp(_baseScale / Vector3.Distance(camera.transform.position, transform.position), 0.1f, 1);
|
||||
|
||||
if (Collider.transform.localScale.x != 0 && transform.lossyScale.x != 0)
|
||||
{
|
||||
Collider.radius = 35 /* magic number */ * (1 / transform.lossyScale.x) * GetRadiusOnScreen(camera, Collider.transform.position, Handle.transform.localScale.x);
|
||||
Collider.radius = Mathf.Clamp(Collider.radius, 0.001f, 2);
|
||||
}
|
||||
|
||||
Handle.transform.position = camera.WorldToScreenPoint(Collider.transform.TransformPoint(Collider.center));
|
||||
|
||||
if (ShouldBeHidden())
|
||||
{
|
||||
if (Handle.activeSelf == true)
|
||||
{
|
||||
ToggleActive(false);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
bool isOnScreen =
|
||||
!(Handle.transform.position.x < 0 || Handle.transform.position.y < 0 || Handle.transform.position.z < 0
|
||||
|| Handle.transform.position.x > Screen.width || Handle.transform.position.y > Screen.height);
|
||||
|
||||
if (Handle.activeSelf != isOnScreen)
|
||||
{
|
||||
ToggleActive(!Handle.activeSelf);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(Handle.activeSelf && LineRenderer != null)
|
||||
{
|
||||
if (LineRenderer.enabled != linesEnabled)
|
||||
{
|
||||
LineRenderer.enabled = linesEnabled;
|
||||
}
|
||||
if (linesEnabled)
|
||||
{
|
||||
LineRenderer.SetPositions(new Vector3[] { (Target).position, (Target).parent.position });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual bool ShouldBeHidden()
|
||||
{
|
||||
return _forceDisplayOff;
|
||||
}
|
||||
|
||||
/// <summary> For future, `offset` param will allow popups to be spaced out when selecting more than 1 handle at a time. </summary>
|
||||
public void TogglePopup(int offset = 0)
|
||||
{
|
||||
Popup.Offset = offset * Popup.GetComponent<RectTransform>().sizeDelta.x;
|
||||
ModelViewerInterface.ToggleVisible(Popup.gameObject);
|
||||
}
|
||||
|
||||
public UIHandle SetDefaults(Vector3 localPos, Vector3 localRot, Vector3 localScale)
|
||||
{
|
||||
_defaultTransform.Position = localPos;
|
||||
_defaultTransform.Rotation = localRot;
|
||||
_defaultTransform.Scale = localScale;
|
||||
return this;
|
||||
}
|
||||
|
||||
public UIHandle SetColor(Color color)
|
||||
{
|
||||
color.a = Handle.GetComponent<Image>().color.a;
|
||||
Handle.GetComponent<Image>().color = color;
|
||||
return this;
|
||||
}
|
||||
|
||||
public UIHandle SetScale(float scale)
|
||||
{
|
||||
this._baseScale = scale;
|
||||
return this;
|
||||
}
|
||||
|
||||
public UIHandle SetName(string name)
|
||||
{
|
||||
Handle.gameObject.name = name;
|
||||
Popup.NameLabel.text = name;
|
||||
return this;
|
||||
}
|
||||
|
||||
public UIHandle SetOffset(Vector3 offset)
|
||||
{
|
||||
Collider.center = offset;
|
||||
return this;
|
||||
}
|
||||
|
||||
public UIHandle SetContainer(ObjectContainer container)
|
||||
{
|
||||
Owner = container;
|
||||
return this;
|
||||
}
|
||||
|
||||
public float GetRadiusOnScreen(Camera cam, Vector3 position, float screenSize)
|
||||
{
|
||||
Vector3 a = cam.WorldToScreenPoint(position);
|
||||
Vector3 b = new Vector3(a.x, a.y + screenSize, a.z);
|
||||
|
||||
Vector3 aa = cam.ScreenToWorldPoint(a);
|
||||
Vector3 bb = cam.ScreenToWorldPoint(b);
|
||||
|
||||
return (aa - bb).magnitude;
|
||||
}
|
||||
|
||||
public UIHandle WithLineRenderer()
|
||||
{
|
||||
LineRenderer = Handle.gameObject.AddComponent<LineRenderer>();
|
||||
LineRenderer.positionCount = 2;
|
||||
LineRenderer.startWidth = LineRenderer.endWidth = 0.005f;
|
||||
LineRenderer.material = HandleManager.Instance.LineRendererMaterial;
|
||||
LineRenderer.startColor = LineRenderer.endColor = Handle.GetComponent<Image>().color;
|
||||
return this;
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
if (Popup)
|
||||
{
|
||||
Destroy(Popup.gameObject);
|
||||
}
|
||||
if (Handle)
|
||||
{
|
||||
Destroy(Handle);
|
||||
}
|
||||
HandleManager.UnregisterHandle(this);
|
||||
}
|
||||
|
||||
private void TransformReset(PoseLoadOptions options = null)
|
||||
{
|
||||
if(options == null)
|
||||
{
|
||||
options = PoseLoadOptions.All();
|
||||
}
|
||||
|
||||
_defaultTransform.ApplyTo(Target, options);
|
||||
}
|
||||
|
||||
public void TransformResetAll()
|
||||
{
|
||||
var HandleUndoData = new HandleUndoData(this);
|
||||
|
||||
HandleUndoData.OldPosition = new SerializableTransform(Target, Space.World);
|
||||
TransformReset();
|
||||
HandleUndoData.NewPosition = Target;
|
||||
|
||||
HandleManager.RegisterRuntimeGizmoUndoAction.Invoke(HandleUndoData);
|
||||
Owner.SetKeyframe();
|
||||
}
|
||||
|
||||
public void TransformResetPosition()
|
||||
{
|
||||
var HandleUndoData = new HandleUndoData(this);
|
||||
|
||||
HandleUndoData.OldPosition = new SerializableTransform(Target, Space.World);
|
||||
TransformReset(new PoseLoadOptions(false) { Position = true });
|
||||
HandleUndoData.NewPosition = Target;
|
||||
|
||||
HandleManager.RegisterRuntimeGizmoUndoAction.Invoke(HandleUndoData);
|
||||
Owner.SetKeyframe();
|
||||
}
|
||||
|
||||
public void TransformResetRotation()
|
||||
{
|
||||
var HandleUndoData = new HandleUndoData(this);
|
||||
|
||||
HandleUndoData.OldPosition = new SerializableTransform(Target, Space.World);
|
||||
TransformReset(new PoseLoadOptions(false) { Rotation = true });
|
||||
HandleUndoData.NewPosition = Target;
|
||||
|
||||
HandleManager.RegisterRuntimeGizmoUndoAction.Invoke(HandleUndoData);
|
||||
Owner.SetKeyframe();
|
||||
}
|
||||
|
||||
public void TransformResetScale()
|
||||
{
|
||||
var HandleUndoData = new HandleUndoData(this);
|
||||
|
||||
HandleUndoData.OldPosition = new SerializableTransform(Target, Space.World);
|
||||
TransformReset(new PoseLoadOptions(false) { Scale = true });
|
||||
HandleUndoData.NewPosition = Target;
|
||||
|
||||
HandleManager.RegisterRuntimeGizmoUndoAction.Invoke(HandleUndoData);
|
||||
Owner.SetKeyframe();
|
||||
}
|
||||
|
||||
public void ToggleActive(bool value)
|
||||
{
|
||||
Handle.SetActive(value);
|
||||
Collider.enabled = value;
|
||||
Popup.gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
public void ForceDisplayOff(bool value)
|
||||
{
|
||||
_forceDisplayOff = value;
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/ModelViewerBase/UI/Handles/UIHandle.cs.meta
Normal file
11
Assets/Scripts/ModelViewerBase/UI/Handles/UIHandle.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0f855de4e8b12374a8c7ef07e3ce5142
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
51
Assets/Scripts/ModelViewerBase/UI/Handles/UIHandleBone.cs
Normal file
51
Assets/Scripts/ModelViewerBase/UI/Handles/UIHandleBone.cs
Normal file
@@ -0,0 +1,51 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
using static SerializableBone;
|
||||
|
||||
public class UIHandleBone : UIHandle
|
||||
{
|
||||
public Transform Bone => Target;
|
||||
|
||||
public List<BoneTags> Tags;
|
||||
|
||||
public static UIHandleBone CreateAsChild(ObjectContainer owner, Transform parent, List<BoneTags> boneTags)
|
||||
{
|
||||
var handle = CreateAsChild<UIHandleBone>(parent);
|
||||
handle.Init(owner, boneTags);
|
||||
return handle;
|
||||
}
|
||||
|
||||
public override UIHandle Init(ObjectContainer owner)
|
||||
{
|
||||
throw new System.Exception("Use ObjectContainer, List<BoneTags> constructor!");
|
||||
}
|
||||
|
||||
public UIHandleBone Init(ObjectContainer owner, List<BoneTags> boneTags)
|
||||
{
|
||||
if (boneTags == null || !boneTags.Any())
|
||||
{
|
||||
boneTags = new List<BoneTags>() { BoneTags.Untagged };
|
||||
}
|
||||
|
||||
Tags = boneTags.ToList();
|
||||
base.Init(owner);
|
||||
|
||||
SetScale(0.5f);
|
||||
if (Tags.Contains(BoneTags.Left)) SetColor(Color.green);
|
||||
else if (Tags.Contains(BoneTags.Right)) SetColor(Color.blue);
|
||||
else SetColor(Color.white);
|
||||
|
||||
Popup.AddButton("Reset All", TransformResetAll);
|
||||
Popup.AddButton("Reset Position", TransformResetPosition);
|
||||
Popup.AddButton("Reset Rotation", TransformResetRotation);
|
||||
Popup.AddButton("Reset Scale", TransformResetScale);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
protected override bool ShouldBeHidden()
|
||||
{
|
||||
return _forceDisplayOff || !HandleManager.Instance.EnabledHandles.Intersect(Tags).Any();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5ebd7e66c67c47f4fa215b1e3ba00091
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
50
Assets/Scripts/ModelViewerBase/UI/Handles/UIHandleIK.cs
Normal file
50
Assets/Scripts/ModelViewerBase/UI/Handles/UIHandleIK.cs
Normal file
@@ -0,0 +1,50 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
|
||||
public class UIHandleIK : UIHandle
|
||||
{
|
||||
public List<UIHandle> HiddenHandles = new List<UIHandle>();
|
||||
|
||||
public static Transform CreateTransform(string handleName, Transform parent, Vector3 position)
|
||||
{
|
||||
var go = new GameObject(handleName);
|
||||
go.transform.SetParent(parent);
|
||||
go.transform.position = position;
|
||||
return go.transform;
|
||||
}
|
||||
|
||||
public static Transform CreateTransform(string handleName, Transform parent, Vector3 position, Vector3 eulerAngles)
|
||||
{
|
||||
var go = CreateTransform(handleName, parent, position);
|
||||
go.eulerAngles = eulerAngles;
|
||||
return go;
|
||||
}
|
||||
|
||||
public static UIHandleIK CreateAsChild(ObjectContainer owner, Transform parent, Color color, string name, float scale)
|
||||
{
|
||||
var handle = CreateAsChild<UIHandleIK>(parent);
|
||||
handle.Init(owner).SetName(name).SetColor(color).SetScale(scale);
|
||||
return handle;
|
||||
}
|
||||
|
||||
public override UIHandle Init(ObjectContainer owner)
|
||||
{
|
||||
base.Init(owner);
|
||||
Popup.AddButton("Reset Position", () => TransformResetPosition());
|
||||
Popup.AddButton("Reset Rotation", () => TransformResetRotation());
|
||||
Popup.AddButton("Toggle Helper Lines", () =>
|
||||
{
|
||||
foreach (var c in owner.GetComponents<InverseKinematics>())
|
||||
{
|
||||
c.forceLinesInvisible = !c.forceLinesInvisible;
|
||||
}
|
||||
});
|
||||
return this;
|
||||
}
|
||||
|
||||
protected override bool ShouldBeHidden()
|
||||
{
|
||||
return _forceDisplayOff || !HandleManager.Instance.EnabledHandles.Contains(SerializableBone.BoneTags.IK);
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/ModelViewerBase/UI/Handles/UIHandleIK.cs.meta
Normal file
11
Assets/Scripts/ModelViewerBase/UI/Handles/UIHandleIK.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 03de88101ab64404e9d237323c9663b6
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
25
Assets/Scripts/ModelViewerBase/UI/Handles/UIHandleMain.cs
Normal file
25
Assets/Scripts/ModelViewerBase/UI/Handles/UIHandleMain.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class UIHandleMain : UIHandle
|
||||
{
|
||||
public static UIHandleMain CreateAsChild(ObjectContainer owner)
|
||||
{
|
||||
var handle = CreateAsChild<UIHandleMain>(owner.transform);
|
||||
handle.Init(owner).SetColor(Color.yellow).SetScale(1.5f);
|
||||
return handle;
|
||||
}
|
||||
|
||||
public override UIHandle Init(ObjectContainer owner)
|
||||
{
|
||||
base.Init(owner);
|
||||
|
||||
Popup.AddButton("Reset All", TransformResetAll);
|
||||
Popup.AddButton("Reset Position", TransformResetPosition);
|
||||
Popup.AddButton("Reset Rotation", TransformResetRotation);
|
||||
Popup.AddButton("Reset Scale", TransformResetScale);
|
||||
Popup.AddButton("Delete", () => Destroy(Owner));
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: add71905575d4ec44b658c58aa433e1b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,14 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using static SerializableBone;
|
||||
|
||||
public class UIHandlePhysicsBone : UIHandleBone
|
||||
{
|
||||
new public static UIHandlePhysicsBone CreateAsChild(ObjectContainer owner, Transform parent, List<BoneTags> boneTags)
|
||||
{
|
||||
var handle = CreateAsChild<UIHandlePhysicsBone>(parent);
|
||||
handle.Init(owner, boneTags).SetScale(0.5f);
|
||||
return handle;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 43d8d17f43ab7d94ca0a609656dfee90
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
23
Assets/Scripts/ModelViewerBase/UI/Handles/UIHandleProp.cs
Normal file
23
Assets/Scripts/ModelViewerBase/UI/Handles/UIHandleProp.cs
Normal file
@@ -0,0 +1,23 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class UIHandleProp : UIHandle
|
||||
{
|
||||
public static UIHandleProp CreateAsChild(ObjectContainer owner, Transform parent)
|
||||
{
|
||||
var handle = CreateAsChild<UIHandleProp>(parent);
|
||||
handle.Init(owner).SetScale(0.65f);
|
||||
return handle;
|
||||
}
|
||||
|
||||
public override UIHandle Init(ObjectContainer owner)
|
||||
{
|
||||
base.Init(owner);
|
||||
|
||||
Popup.AddButton("Reset All", TransformResetAll);
|
||||
Popup.AddButton("Reset Position", TransformResetPosition);
|
||||
Popup.AddButton("Reset Rotation", TransformResetRotation);
|
||||
Popup.AddButton("Reset Scale", TransformResetScale);
|
||||
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e0fa65a26810d854ebc243e69ff044f6
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
57
Assets/Scripts/ModelViewerBase/UI/Handles/UIPopupPanel.cs
Normal file
57
Assets/Scripts/ModelViewerBase/UI/Handles/UIPopupPanel.cs
Normal file
@@ -0,0 +1,57 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class UIPopupPanel : MonoBehaviour
|
||||
{
|
||||
public UIHandle Owner;
|
||||
public float Offset;
|
||||
public Transform Content;
|
||||
public TMPro.TMP_Text NameLabel;
|
||||
public Dictionary<GameObject, System.Func<bool>> ConditionalButtons = new Dictionary<GameObject, System.Func<bool>>();
|
||||
|
||||
private int _side;
|
||||
|
||||
public UIPopupPanel Init(UIHandle owner)
|
||||
{
|
||||
Owner = owner;
|
||||
transform.SetAsFirstSibling();
|
||||
NameLabel.text = owner.Target.name;
|
||||
return this;
|
||||
}
|
||||
|
||||
public void UpdateManual(Camera camera)
|
||||
{
|
||||
if (camera.WorldToScreenPoint(Owner.transform.position).x < camera.pixelWidth / 2 - _side)
|
||||
{
|
||||
_side = -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
_side = 1;
|
||||
}
|
||||
|
||||
float pos = _side * camera.pixelWidth / 20 + Offset;
|
||||
transform.position = camera.WorldToScreenPoint(Owner.transform.position) + pos * Vector3.right;
|
||||
|
||||
foreach (var kv in ConditionalButtons)
|
||||
{
|
||||
kv.Key.gameObject.SetActive(kv.Value.Invoke());
|
||||
}
|
||||
}
|
||||
|
||||
public void AddButton(string name, System.Action callback)
|
||||
{
|
||||
Button b = Instantiate(HandleManager.Instance.Pfb_PopupButton, Content).GetComponent<Button>();
|
||||
b.onClick.AddListener(()=>callback.Invoke());
|
||||
b.GetComponentInChildren<TMPro.TMP_Text>().text = name;
|
||||
}
|
||||
|
||||
public void AddConditionalButton(string name, System.Func<bool> condition, System.Action callback)
|
||||
{
|
||||
Button b = Instantiate(HandleManager.Instance.Pfb_PopupButton, Content).GetComponent<Button>();
|
||||
b.onClick.AddListener(() => callback.Invoke());
|
||||
b.GetComponentInChildren<TMPro.TMP_Text>().text = name;
|
||||
ConditionalButtons.Add(b.gameObject, condition);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 59083bc243f250f4a8918f69361d09e0
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user