Support N canvases (webview gameobjects)
This commit is contained in:
parent
8551bf9c8f
commit
644b2f80cc
|
@ -5468,7 +5468,7 @@ MonoBehaviour:
|
||||||
m_Calls:
|
m_Calls:
|
||||||
- m_Target: {fileID: 1193822414}
|
- m_Target: {fileID: 1193822414}
|
||||||
m_TargetAssemblyTypeName: ConfigureOrbital, Assembly-CSharp
|
m_TargetAssemblyTypeName: ConfigureOrbital, Assembly-CSharp
|
||||||
m_MethodName: ToggleOrbitalScript
|
m_MethodName: ToggleOrbital
|
||||||
m_Mode: 1
|
m_Mode: 1
|
||||||
m_Arguments:
|
m_Arguments:
|
||||||
m_ObjectArgument: {fileID: 0}
|
m_ObjectArgument: {fileID: 0}
|
||||||
|
@ -6408,10 +6408,7 @@ MonoBehaviour:
|
||||||
m_Script: {fileID: 11500000, guid: 2692de2cb7707be478671c78efb37020, type: 3}
|
m_Script: {fileID: 11500000, guid: 2692de2cb7707be478671c78efb37020, type: 3}
|
||||||
m_Name:
|
m_Name:
|
||||||
m_EditorClassIdentifier:
|
m_EditorClassIdentifier:
|
||||||
canvas1: {fileID: 721930529}
|
endpointLoader: {fileID: 491721038}
|
||||||
canvas2: {fileID: 2137857637}
|
|
||||||
addressField1: {fileID: 76995324}
|
|
||||||
addressField2: {fileID: 102826381}
|
|
||||||
--- !u!1 &1041187335
|
--- !u!1 &1041187335
|
||||||
GameObject:
|
GameObject:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
|
@ -6911,8 +6908,7 @@ MonoBehaviour:
|
||||||
m_Script: {fileID: 11500000, guid: 487c06418920ab945bfc039c0ba92d8a, type: 3}
|
m_Script: {fileID: 11500000, guid: 487c06418920ab945bfc039c0ba92d8a, type: 3}
|
||||||
m_Name:
|
m_Name:
|
||||||
m_EditorClassIdentifier:
|
m_EditorClassIdentifier:
|
||||||
canvas1: {fileID: 721930529}
|
endpointLoader: {fileID: 491721038}
|
||||||
canvas2: {fileID: 2137857637}
|
|
||||||
--- !u!114 &1303729525
|
--- !u!114 &1303729525
|
||||||
MonoBehaviour:
|
MonoBehaviour:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
|
@ -9091,7 +9087,7 @@ MonoBehaviour:
|
||||||
m_Calls:
|
m_Calls:
|
||||||
- m_Target: {fileID: 1193822414}
|
- m_Target: {fileID: 1193822414}
|
||||||
m_TargetAssemblyTypeName: ConfigureOrbital, Assembly-CSharp
|
m_TargetAssemblyTypeName: ConfigureOrbital, Assembly-CSharp
|
||||||
m_MethodName: ToggleOrbitalScript
|
m_MethodName: ToggleOrbital
|
||||||
m_Mode: 1
|
m_Mode: 1
|
||||||
m_Arguments:
|
m_Arguments:
|
||||||
m_ObjectArgument: {fileID: 0}
|
m_ObjectArgument: {fileID: 0}
|
||||||
|
@ -10203,7 +10199,7 @@ GameObject:
|
||||||
- component: {fileID: 2094194865}
|
- component: {fileID: 2094194865}
|
||||||
- component: {fileID: 2094194864}
|
- component: {fileID: 2094194864}
|
||||||
m_Layer: 5
|
m_Layer: 5
|
||||||
m_Name: AddressField (TMP)
|
m_Name: AddressField
|
||||||
m_TagString: Untagged
|
m_TagString: Untagged
|
||||||
m_Icon: {fileID: 0}
|
m_Icon: {fileID: 0}
|
||||||
m_NavMeshLayer: 0
|
m_NavMeshLayer: 0
|
||||||
|
|
|
@ -7,52 +7,42 @@ using UnityEngine.UI;
|
||||||
public class ConfigureNavBar : MonoBehaviour
|
public class ConfigureNavBar : MonoBehaviour
|
||||||
{
|
{
|
||||||
[SerializeField]
|
[SerializeField]
|
||||||
private GameObject canvas1;
|
private EndpointLoader endpointLoader;
|
||||||
|
|
||||||
[SerializeField]
|
|
||||||
private GameObject canvas2;
|
|
||||||
|
|
||||||
[SerializeField]
|
|
||||||
private GameObject addressField1;
|
|
||||||
|
|
||||||
[SerializeField]
|
|
||||||
private GameObject addressField2;
|
|
||||||
|
|
||||||
private BoxCollider boxCollider1;
|
|
||||||
private BoxCollider boxCollider2;
|
|
||||||
|
|
||||||
private bool isVisible = false;
|
private bool isVisible = false;
|
||||||
|
|
||||||
private void Start()
|
|
||||||
{
|
|
||||||
boxCollider1 = canvas1.GetComponent<BoxCollider>();
|
|
||||||
boxCollider2 = canvas2.GetComponent<BoxCollider>();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void ToggleVisibilityMethod()
|
public void ToggleVisibilityMethod()
|
||||||
{
|
{
|
||||||
|
List<GameObject> canvases = endpointLoader.GetInstantiatedItems();
|
||||||
isVisible = !isVisible;
|
isVisible = !isVisible;
|
||||||
addressField1.SetActive(isVisible);
|
foreach (GameObject canvas in canvases)
|
||||||
addressField2.SetActive(isVisible);
|
|
||||||
|
|
||||||
if (boxCollider1 != null)
|
|
||||||
{
|
{
|
||||||
boxCollider1.size = new Vector3(
|
TMP_InputField inputField = canvas.GetComponentInChildren<TMP_InputField>(true);
|
||||||
boxCollider1.size.x,
|
if (inputField != null)
|
||||||
isVisible ? 400 : 370,
|
{
|
||||||
boxCollider1.size.z
|
Debug.Log("Setting address field visibility to " + isVisible);
|
||||||
);
|
inputField.gameObject.SetActive(isVisible);
|
||||||
boxCollider1.center = new Vector3(0, isVisible ? 0 : -16, 0);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (boxCollider2 != null)
|
/*
|
||||||
{
|
Transform addressFieldTransform = canvas.transform.Find("AddressField");
|
||||||
boxCollider2.size = new Vector3(
|
if (addressFieldTransform != null)
|
||||||
boxCollider2.size.x,
|
{
|
||||||
isVisible ? 400 : 370,
|
Debug.Log("Setting address field visibility to " + isVisible);
|
||||||
boxCollider2.size.z
|
addressFieldTransform.gameObject.SetActive(isVisible);
|
||||||
);
|
}
|
||||||
boxCollider2.center = new Vector3(0, isVisible ? 0 : -16, 0);
|
*/
|
||||||
|
|
||||||
|
BoxCollider boxCollider = canvas.GetComponent<BoxCollider>();
|
||||||
|
if (boxCollider != null)
|
||||||
|
{
|
||||||
|
boxCollider.size = new Vector3(
|
||||||
|
boxCollider.size.x,
|
||||||
|
isVisible ? 400 : 370,
|
||||||
|
boxCollider.size.z
|
||||||
|
);
|
||||||
|
boxCollider.center = new Vector3(0, isVisible ? 0 : -16, 0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,72 +8,39 @@ using UnityEngine;
|
||||||
public class ConfigureOrbital : MonoBehaviour
|
public class ConfigureOrbital : MonoBehaviour
|
||||||
{
|
{
|
||||||
[SerializeField]
|
[SerializeField]
|
||||||
private GameObject canvas1;
|
private EndpointLoader endpointLoader;
|
||||||
|
|
||||||
[SerializeField]
|
private bool orbitalEnabled = false;
|
||||||
private GameObject canvas2;
|
|
||||||
|
|
||||||
// public List<GameObject> canvases;
|
public void ToggleOrbital()
|
||||||
|
|
||||||
private Orbital orbital1;
|
|
||||||
private Orbital orbital2;
|
|
||||||
|
|
||||||
private SolverHandler solverHandler1;
|
|
||||||
private SolverHandler solverHandler2;
|
|
||||||
|
|
||||||
void Start()
|
|
||||||
{
|
{
|
||||||
if (canvas1 != null)
|
orbitalEnabled = !orbitalEnabled;
|
||||||
|
List<GameObject> canvases = endpointLoader.GetInstantiatedItems();
|
||||||
|
|
||||||
|
foreach (GameObject canvas in canvases)
|
||||||
{
|
{
|
||||||
orbital1 = canvas1.GetComponent<Orbital>();
|
Orbital orbital = canvas.GetComponent<Orbital>();
|
||||||
solverHandler1 = canvas1.GetComponent<SolverHandler>();
|
SolverHandler solverHandler = canvas.GetComponent<SolverHandler>();
|
||||||
}
|
|
||||||
|
|
||||||
if (canvas2 != null)
|
if (orbital != null && solverHandler != null)
|
||||||
{
|
|
||||||
orbital2 = canvas2.GetComponent<Orbital>();
|
|
||||||
solverHandler2 = canvas2.GetComponent<SolverHandler>();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (
|
|
||||||
orbital1 == null
|
|
||||||
|| solverHandler1 == null
|
|
||||||
|| orbital2 == null
|
|
||||||
|| solverHandler2 == null
|
|
||||||
)
|
|
||||||
{
|
|
||||||
Debug.LogError(
|
|
||||||
"One or both Canvas objects are missing an Orbital or SolverHandler component."
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void ToggleOrbitalScript()
|
|
||||||
{
|
|
||||||
ToggleOrbitalForCanvas(orbital1, solverHandler1);
|
|
||||||
ToggleOrbitalForCanvas(orbital2, solverHandler2);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void ToggleOrbitalForCanvas(Orbital orbital, SolverHandler solverHandler)
|
|
||||||
{
|
|
||||||
if (orbital != null && solverHandler != null)
|
|
||||||
{
|
|
||||||
orbital.enabled = !orbital.enabled;
|
|
||||||
|
|
||||||
if (orbital.enabled)
|
|
||||||
{
|
{
|
||||||
Vector3 headPosition = Camera.main.transform.position;
|
orbital.enabled = orbitalEnabled;
|
||||||
Quaternion headRotation = Camera.main.transform.rotation;
|
|
||||||
Vector3 relativePosition =
|
|
||||||
Quaternion.Inverse(headRotation) * (orbital.transform.position - headPosition);
|
|
||||||
|
|
||||||
orbital.LocalOffset = relativePosition;
|
if (orbitalEnabled)
|
||||||
|
{
|
||||||
|
Vector3 headPosition = Camera.main.transform.position;
|
||||||
|
Quaternion headRotation = Camera.main.transform.rotation;
|
||||||
|
Vector3 relativePosition =
|
||||||
|
Quaternion.Inverse(headRotation) * (orbital.transform.position - headPosition);
|
||||||
|
|
||||||
solverHandler.UpdateSolvers = true;
|
orbital.LocalOffset = relativePosition;
|
||||||
}
|
|
||||||
else
|
solverHandler.UpdateSolvers = true;
|
||||||
{
|
}
|
||||||
solverHandler.UpdateSolvers = false;
|
else
|
||||||
|
{
|
||||||
|
solverHandler.UpdateSolvers = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,12 +8,6 @@ using UnityEngine.UI;
|
||||||
|
|
||||||
public class EndpointLoader : MonoBehaviour
|
public class EndpointLoader : MonoBehaviour
|
||||||
{
|
{
|
||||||
[SerializeField]
|
|
||||||
private WebView webView1;
|
|
||||||
|
|
||||||
[SerializeField]
|
|
||||||
private WebView webView2;
|
|
||||||
|
|
||||||
[SerializeField]
|
[SerializeField]
|
||||||
private GameObject dynamicItem;
|
private GameObject dynamicItem;
|
||||||
|
|
||||||
|
@ -94,24 +88,28 @@ public class EndpointLoader : MonoBehaviour
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<GameObject> GetInstantiatedItems()
|
||||||
|
{
|
||||||
|
return instantiatedItems;
|
||||||
|
}
|
||||||
|
|
||||||
private IEnumerator TryLoadingFromDefaultEndpoints()
|
private IEnumerator TryLoadingFromDefaultEndpoints()
|
||||||
{
|
{
|
||||||
using (UnityWebRequest request = UnityWebRequest.Get(defaultEndpoint1))
|
using (UnityWebRequest request = UnityWebRequest.Get(defaultEndpoint1))
|
||||||
{
|
{
|
||||||
yield return request.SendWebRequest();
|
yield return request.SendWebRequest();
|
||||||
ProcessEndpointResponse(request, webView1, defaultEndpoint1, ref defaultEndpointLoaded);
|
ProcessEndpointResponse(request, defaultEndpoint1, ref defaultEndpointLoaded);
|
||||||
}
|
}
|
||||||
|
|
||||||
using (UnityWebRequest request = UnityWebRequest.Get(defaultEndpoint2))
|
using (UnityWebRequest request = UnityWebRequest.Get(defaultEndpoint2))
|
||||||
{
|
{
|
||||||
yield return request.SendWebRequest();
|
yield return request.SendWebRequest();
|
||||||
ProcessEndpointResponse(request, webView2, defaultEndpoint2, ref defaultEndpointLoaded);
|
ProcessEndpointResponse(request, defaultEndpoint2, ref defaultEndpointLoaded);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ProcessEndpointResponse(
|
private void ProcessEndpointResponse(
|
||||||
UnityWebRequest request,
|
UnityWebRequest request,
|
||||||
WebView webView,
|
|
||||||
string endpoint,
|
string endpoint,
|
||||||
ref bool loadedFlag
|
ref bool loadedFlag
|
||||||
)
|
)
|
||||||
|
@ -126,7 +124,7 @@ public class EndpointLoader : MonoBehaviour
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Debug.Log($"Loaded from {endpoint} successfully.");
|
Debug.Log($"Loaded from {endpoint} successfully.");
|
||||||
webView.Load(endpoint);
|
SpawnItem(endpoint);
|
||||||
loadedFlag = true;
|
loadedFlag = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -233,12 +231,6 @@ public class EndpointLoader : MonoBehaviour
|
||||||
StartCoroutine(LoadEndpoints());
|
StartCoroutine(LoadEndpoints());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void UseDefaultEndpoints()
|
|
||||||
{
|
|
||||||
// webView1.Load(defaultEndpoint1);
|
|
||||||
// webView2.Load(defaultEndpoint2);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Serializable]
|
[Serializable]
|
||||||
public class Endpoint
|
public class Endpoint
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue