DavidMohrhardt
6 年前
当前提交
872e8efc
共有 4 个文件被更改,包括 162 次插入 和 0 次删除
-
81Assets/Scripts/Logger.cs
-
11Assets/Scripts/Logger.cs.meta
-
59Assets/Scripts/ReferencePointCreator.cs
-
11Assets/Scripts/ReferencePointCreator.cs.meta
|
|||
using System; |
|||
using System.Collections; |
|||
using System.Collections.Generic; |
|||
using System.Text; |
|||
using UnityEngine; |
|||
using UnityEngine.UI; |
|||
|
|||
public class Logger : MonoBehaviour |
|||
{ |
|||
[SerializeField] |
|||
Text m_LogText; |
|||
public Text logText |
|||
{ |
|||
get { return s_LogText; } |
|||
set |
|||
{ |
|||
m_LogText = value; |
|||
s_LogText = value; |
|||
} |
|||
} |
|||
|
|||
[SerializeField] |
|||
int m_VisibleMessageCount = 40; |
|||
public int visibleMessageCount |
|||
{ |
|||
get { return s_VisibleMessageCount; } |
|||
set |
|||
{ |
|||
m_VisibleMessageCount = value; |
|||
s_VisibleMessageCount = value; |
|||
} |
|||
} |
|||
|
|||
int m_LastMessageCount; |
|||
|
|||
static int s_VisibleMessageCount; |
|||
|
|||
static Text s_LogText; |
|||
|
|||
static List<string> s_Log = new List<string>(); |
|||
|
|||
static StringBuilder s_StringBuilder = new StringBuilder(); |
|||
|
|||
void Awake() |
|||
{ |
|||
s_LogText = m_LogText; |
|||
s_VisibleMessageCount = m_VisibleMessageCount; |
|||
Log("Log console initialized."); |
|||
} |
|||
|
|||
void Update() |
|||
{ |
|||
lock (s_Log) |
|||
{ |
|||
if (m_LastMessageCount != s_Log.Count) |
|||
{ |
|||
s_StringBuilder.Clear(); |
|||
var startIndex = Mathf.Max(s_Log.Count - s_VisibleMessageCount, 0); |
|||
for (int i = startIndex; i < s_Log.Count; ++i) |
|||
{ |
|||
s_StringBuilder.Append($"{i:000}> {s_Log[i]}\n"); |
|||
} |
|||
|
|||
s_LogText.text = s_StringBuilder.ToString(); |
|||
} |
|||
|
|||
m_LastMessageCount = s_Log.Count; |
|||
} |
|||
} |
|||
|
|||
public static void Log(string message) |
|||
{ |
|||
lock (s_Log) |
|||
{ |
|||
if (s_Log == null) |
|||
s_Log = new List<string>(); |
|||
|
|||
s_Log.Add(message); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 6b9ec441ecd1d4c21b5736659749bcf2 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System.Collections.Generic; |
|||
using UnityEngine; |
|||
using UnityEngine.XR.ARFoundation; |
|||
using UnityEngine.XR.ARSubsystems; |
|||
|
|||
[RequireComponent(typeof(ARReferencePointManager))] |
|||
[RequireComponent(typeof(ARRaycastManager))] |
|||
public class ReferencePointCreator : MonoBehaviour |
|||
{ |
|||
public void RemoveAllReferencePoints() |
|||
{ |
|||
foreach (var referencePoint in m_ReferencePoints) |
|||
{ |
|||
m_ReferencePointManager.RemoveReferencePoint(referencePoint); |
|||
} |
|||
m_ReferencePoints.Clear(); |
|||
} |
|||
|
|||
void Awake() |
|||
{ |
|||
m_RaycastManager = GetComponent<ARRaycastManager>(); |
|||
m_ReferencePointManager = GetComponent<ARReferencePointManager>(); |
|||
m_ReferencePoints = new List<ARReferencePoint>(); |
|||
} |
|||
|
|||
void Update() |
|||
{ |
|||
if (Input.touchCount == 0) |
|||
return; |
|||
|
|||
var touch = Input.GetTouch(0); |
|||
if (touch.phase != TouchPhase.Began) |
|||
return; |
|||
|
|||
if (m_RaycastManager.Raycast(touch.position, s_Hits, TrackableType.FeaturePoint)) |
|||
{ |
|||
// Raycast hits are sorted by distance, so the first one
|
|||
// will be the closest hit.
|
|||
var hitPose = s_Hits[0].pose; |
|||
var referencePoint = m_ReferencePointManager.AddReferencePoint(hitPose); |
|||
if (referencePoint == null) |
|||
{ |
|||
Logger.Log("Error creating reference point"); |
|||
} |
|||
else |
|||
{ |
|||
m_ReferencePoints.Add(referencePoint); |
|||
} |
|||
} |
|||
} |
|||
|
|||
static List<ARRaycastHit> s_Hits = new List<ARRaycastHit>(); |
|||
|
|||
List<ARReferencePoint> m_ReferencePoints; |
|||
|
|||
ARRaycastManager m_RaycastManager; |
|||
|
|||
ARReferencePointManager m_ReferencePointManager; |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: f68fbc98b9133456f8a212911c899469 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
撰写
预览
正在加载...
取消
保存
Reference in new issue