Dan
4 年前
当前提交
0f0fc62f
共有 16 个文件被更改,包括 653 次插入 和 145 次删除
-
2Assets/Shaders/PositionRendering/Prefabs/AnimatedPlacedObject.prefab
-
344Assets/Shaders/PositionRendering/Scenes/PositionBasedRendering.unity
-
32Assets/Shaders/PositionRendering/Scripts/AnimatedPlaceObject.cs
-
4ProjectSettings/EditorBuildSettings.asset
-
1ProjectSettings/GraphicsSettings.asset
-
2ProjectSettings/ProjectSettings.asset
-
97Assets/Shaders/PositionRendering/Scripts/ARContactPosition.cs
-
60Assets/Shaders/PositionRendering/Scripts/ContactPositionPlacement.cs
-
11Assets/Shaders/PositionRendering/Scripts/ContactPositionPlacement.cs.meta
-
8Assets/Shaders/PositionRendering/Textures.meta
-
20Assets/Shaders/PositionRendering/Textures/icon_plus.png
-
128Assets/Shaders/PositionRendering/Textures/icon_plus.png.meta
-
81Assets/Shaders/PositionRendering/Scripts/ARPositionManager.cs
-
8Assets/ARFoundationDemos.meta
-
0/Assets/Shaders/PositionRendering/Scripts/ARContactPosition.cs.meta
|
|||
using System.Collections; |
|||
using System.Collections.Generic; |
|||
using DG.Tweening; |
|||
using DG.Tweening; |
|||
using UnityEngine.XR.ARSubsystems; |
|||
|
|||
public float ShakeVal; |
|||
|
|||
public Ease MoveEase; |
|||
|
|||
void Update() |
|||
public Transform placementSphere |
|||
#if UNITY_EDITOR
|
|||
if (Input.GetKeyDown(KeyCode.A)) |
|||
{ |
|||
m_PlacementSphere.localPosition = new Vector3(0, 0.375f, 0); |
|||
} |
|||
|
|||
if (Input.GetKeyDown(KeyCode.Space)) |
|||
{ |
|||
AnimatePlacement(); |
|||
} |
|||
#endif
|
|||
get => m_PlacementSphere; |
|||
set => m_PlacementSphere = value; |
|||
|
|||
const float k_ShakeScale = 0.5f; |
|||
const Ease k_MoveEase = Ease.OutBounce; |
|||
m_PlacementSphere.DOLocalMove(Vector3.zero, 0.1f).SetEase(MoveEase).OnComplete(BounceLand); |
|||
m_PlacementSphere.DOLocalMove(Vector3.zero, 0.1f).SetEase(k_MoveEase).OnComplete(BounceLand); |
|||
m_PlacementSphere.DOShakeScale(0.1f, ShakeVal); |
|||
m_PlacementSphere.DOShakeScale(0.1f, k_ShakeScale); |
|||
} |
|||
} |
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using UnityEngine; |
|||
using UnityEngine.XR.ARFoundation; |
|||
using UnityEngine.XR.ARSubsystems; |
|||
|
|||
public class ARContactPosition : MonoBehaviour |
|||
{ |
|||
[SerializeField] |
|||
ARRaycastManager m_RaycastManager; |
|||
|
|||
public ARRaycastManager raycastManager |
|||
{ |
|||
get => m_RaycastManager; |
|||
set => m_RaycastManager = value; |
|||
} |
|||
|
|||
[SerializeField] |
|||
ARPlaneManager m_PlaneManager; |
|||
|
|||
public ARPlaneManager planeManager |
|||
{ |
|||
get => m_PlaneManager; |
|||
set => m_PlaneManager = value; |
|||
} |
|||
|
|||
[SerializeField] |
|||
bool m_DelayPosition; |
|||
|
|||
public bool delayPosition |
|||
{ |
|||
get => m_DelayPosition; |
|||
set => m_DelayPosition = true; |
|||
} |
|||
|
|||
Vector3 m_TargetPosition; |
|||
|
|||
public Vector3 targetPosition |
|||
{ |
|||
get => m_TargetPosition; |
|||
set => m_TargetPosition = value; |
|||
} |
|||
|
|||
Quaternion m_TargetRotation; |
|||
|
|||
public Quaternion targetRotation |
|||
{ |
|||
get => m_TargetRotation; |
|||
set => m_TargetRotation = value; |
|||
} |
|||
|
|||
TrackableId m_HitID; |
|||
Pose m_HitPose; |
|||
|
|||
static List<ARRaycastHit> s_Hits = new List<ARRaycastHit>(); |
|||
|
|||
const string k_ShaderPositionProperty = "_ContactPosition"; |
|||
const string k_ShaderContactProperty = "_IsInContact"; |
|||
const float k_LerpDelayValue = 0.05f; |
|||
|
|||
void OnEnable() |
|||
{ |
|||
m_TargetPosition = Vector3.zero; |
|||
} |
|||
|
|||
void Update() |
|||
{ |
|||
if (m_RaycastManager.Raycast(CenterScreenHelper.Instance.GetCenterScreen(), s_Hits, TrackableType.PlaneWithinBounds)) |
|||
{ |
|||
m_HitID = s_Hits[0].trackableId; |
|||
m_HitPose = s_Hits[0].pose; |
|||
m_TargetRotation = m_HitPose.rotation; |
|||
} |
|||
|
|||
if (m_DelayPosition) |
|||
{ |
|||
m_TargetPosition = Vector3.Lerp(m_TargetPosition, m_HitPose.position, k_LerpDelayValue); |
|||
} |
|||
else |
|||
{ |
|||
m_TargetPosition = m_HitPose.position; |
|||
} |
|||
|
|||
foreach(ARPlane plane in m_PlaneManager.trackables) |
|||
{ |
|||
if (plane.trackableId == m_HitID) |
|||
{ |
|||
plane.transform.GetComponent<MeshRenderer>().material.SetFloat(k_ShaderContactProperty, 1); |
|||
plane.transform.GetComponent<MeshRenderer>().material.SetVector(k_ShaderPositionProperty, m_TargetPosition); |
|||
} |
|||
else |
|||
{ |
|||
plane.transform.GetComponent<MeshRenderer>().material.SetFloat(k_ShaderContactProperty, 0); |
|||
} |
|||
} |
|||
} |
|||
} |
|
|||
using System; |
|||
using System.Collections; |
|||
using System.Collections.Generic; |
|||
using UnityEngine; |
|||
|
|||
public class ContactPositionPlacement : MonoBehaviour |
|||
{ |
|||
[SerializeField] |
|||
ARContactPosition m_ARContactPosition; |
|||
|
|||
public ARContactPosition arContactPosition |
|||
{ |
|||
get => m_ARContactPosition; |
|||
set => m_ARContactPosition = value; |
|||
} |
|||
|
|||
[SerializeField] |
|||
GameObject m_ObjectPrefab; |
|||
|
|||
public GameObject objectPrefab |
|||
{ |
|||
get => m_ObjectPrefab; |
|||
set => m_ObjectPrefab = value; |
|||
} |
|||
|
|||
GameObject m_SpawnedObject; |
|||
bool m_Placed; |
|||
|
|||
void Update() |
|||
{ |
|||
if (Input.touchCount > 0) |
|||
{ |
|||
Touch touch = Input.GetTouch(0); |
|||
|
|||
if (touch.phase == TouchPhase.Began) |
|||
{ |
|||
if (m_SpawnedObject && !m_Placed) |
|||
{ |
|||
m_Placed = true; |
|||
|
|||
if(m_SpawnedObject.TryGetComponent(out AnimatedPlaceObject m_PlacedObject)) |
|||
{ |
|||
m_PlacedObject.AnimatePlacement(); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
|
|||
if (m_SpawnedObject && !m_Placed) |
|||
{ |
|||
m_SpawnedObject.transform.SetPositionAndRotation(m_ARContactPosition.targetPosition, m_ARContactPosition.targetRotation); |
|||
} |
|||
} |
|||
|
|||
public void SpawnPlacementObject() |
|||
{ |
|||
m_SpawnedObject = Instantiate(m_ObjectPrefab, m_ARContactPosition.targetPosition, m_ARContactPosition.targetRotation); |
|||
m_Placed = false; |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 67c3a5279a63942198928254c7a39580 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: 1d2cddb8fdc404abbaab416e16f1843e |
|||
folderAsset: yes |
|||
DefaultImporter: |
|||
externalObjects: {} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: 3397f679b52c548a1bff2845b2a4c080 |
|||
TextureImporter: |
|||
internalIDToNameTable: [] |
|||
externalObjects: {} |
|||
serializedVersion: 11 |
|||
mipmaps: |
|||
mipMapMode: 0 |
|||
enableMipMap: 0 |
|||
sRGBTexture: 1 |
|||
linearTexture: 0 |
|||
fadeOut: 0 |
|||
borderMipMap: 0 |
|||
mipMapsPreserveCoverage: 0 |
|||
alphaTestReferenceValue: 0.5 |
|||
mipMapFadeDistanceStart: 1 |
|||
mipMapFadeDistanceEnd: 3 |
|||
bumpmap: |
|||
convertToNormalMap: 0 |
|||
externalNormalMap: 0 |
|||
heightScale: 0.25 |
|||
normalMapFilter: 0 |
|||
isReadable: 0 |
|||
streamingMipmaps: 0 |
|||
streamingMipmapsPriority: 0 |
|||
grayScaleToAlpha: 0 |
|||
generateCubemap: 6 |
|||
cubemapConvolution: 0 |
|||
seamlessCubemap: 0 |
|||
textureFormat: 1 |
|||
maxTextureSize: 2048 |
|||
textureSettings: |
|||
serializedVersion: 2 |
|||
filterMode: -1 |
|||
aniso: -1 |
|||
mipBias: -100 |
|||
wrapU: 1 |
|||
wrapV: 1 |
|||
wrapW: -1 |
|||
nPOTScale: 0 |
|||
lightmap: 0 |
|||
compressionQuality: 50 |
|||
spriteMode: 1 |
|||
spriteExtrude: 1 |
|||
spriteMeshType: 1 |
|||
alignment: 0 |
|||
spritePivot: {x: 0.5, y: 0.5} |
|||
spritePixelsToUnits: 100 |
|||
spriteBorder: {x: 0, y: 0, z: 0, w: 0} |
|||
spriteGenerateFallbackPhysicsShape: 1 |
|||
alphaUsage: 1 |
|||
alphaIsTransparency: 1 |
|||
spriteTessellationDetail: -1 |
|||
textureType: 8 |
|||
textureShape: 1 |
|||
singleChannelComponent: 0 |
|||
maxTextureSizeSet: 0 |
|||
compressionQualitySet: 0 |
|||
textureFormatSet: 0 |
|||
applyGammaDecoding: 0 |
|||
platformSettings: |
|||
- serializedVersion: 3 |
|||
buildTarget: DefaultTexturePlatform |
|||
maxTextureSize: 2048 |
|||
resizeAlgorithm: 0 |
|||
textureFormat: -1 |
|||
textureCompression: 1 |
|||
compressionQuality: 50 |
|||
crunchedCompression: 0 |
|||
allowsAlphaSplitting: 0 |
|||
overridden: 0 |
|||
androidETC2FallbackOverride: 0 |
|||
forceMaximumCompressionQuality_BC6H_BC7: 0 |
|||
- serializedVersion: 3 |
|||
buildTarget: Standalone |
|||
maxTextureSize: 2048 |
|||
resizeAlgorithm: 0 |
|||
textureFormat: -1 |
|||
textureCompression: 1 |
|||
compressionQuality: 50 |
|||
crunchedCompression: 0 |
|||
allowsAlphaSplitting: 0 |
|||
overridden: 0 |
|||
androidETC2FallbackOverride: 0 |
|||
forceMaximumCompressionQuality_BC6H_BC7: 0 |
|||
- serializedVersion: 3 |
|||
buildTarget: iPhone |
|||
maxTextureSize: 2048 |
|||
resizeAlgorithm: 0 |
|||
textureFormat: -1 |
|||
textureCompression: 1 |
|||
compressionQuality: 50 |
|||
crunchedCompression: 0 |
|||
allowsAlphaSplitting: 0 |
|||
overridden: 0 |
|||
androidETC2FallbackOverride: 0 |
|||
forceMaximumCompressionQuality_BC6H_BC7: 0 |
|||
- serializedVersion: 3 |
|||
buildTarget: Android |
|||
maxTextureSize: 2048 |
|||
resizeAlgorithm: 0 |
|||
textureFormat: -1 |
|||
textureCompression: 1 |
|||
compressionQuality: 50 |
|||
crunchedCompression: 0 |
|||
allowsAlphaSplitting: 0 |
|||
overridden: 0 |
|||
androidETC2FallbackOverride: 0 |
|||
forceMaximumCompressionQuality_BC6H_BC7: 0 |
|||
spriteSheet: |
|||
serializedVersion: 2 |
|||
sprites: [] |
|||
outline: [] |
|||
physicsShape: [] |
|||
bones: [] |
|||
spriteID: 5e97eb03825dee720800000000000000 |
|||
internalID: 0 |
|||
vertices: [] |
|||
indices: |
|||
edges: [] |
|||
weights: [] |
|||
secondaryTextures: [] |
|||
spritePackingTag: |
|||
pSDRemoveMatte: 0 |
|||
pSDShowRemoveMatteOption: 0 |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System; |
|||
using System.Collections; |
|||
using System.Collections.Generic; |
|||
using UnityEngine; |
|||
using UnityEngine.XR.ARFoundation; |
|||
using UnityEngine.XR.ARSubsystems; |
|||
|
|||
public class ARPositionManager : MonoBehaviour |
|||
{ |
|||
[SerializeField] |
|||
ARRaycastManager m_RaycastManager; |
|||
|
|||
[SerializeField] |
|||
ARPlaneManager m_PlaneManager; |
|||
|
|||
[SerializeField] |
|||
GameObject m_ObjectPrefab; |
|||
|
|||
GameObject m_SpawnedObject; |
|||
Vector3 m_DelayedPosition; |
|||
bool m_Placed = false; |
|||
|
|||
TrackableId m_HitID; |
|||
Pose m_HitPose; |
|||
|
|||
static List<ARRaycastHit> s_Hits = new List<ARRaycastHit>(); |
|||
|
|||
const string k_ShaderPositionProperty = "_ContactPosition"; |
|||
const string k_ShaderContactProperty = "_IsInContact"; |
|||
|
|||
void OnEnable() |
|||
{ |
|||
m_SpawnedObject = Instantiate(m_ObjectPrefab); |
|||
m_DelayedPosition = new Vector3(0,0,0); |
|||
} |
|||
|
|||
public void SpawnPlaceableObject() |
|||
{ |
|||
|
|||
} |
|||
|
|||
void Update() |
|||
{ |
|||
if (m_RaycastManager.Raycast(CenterScreenHelper.Instance.GetCenterScreen(), s_Hits, TrackableType.PlaneWithinBounds)) |
|||
{ |
|||
m_HitID = s_Hits[0].trackableId; |
|||
m_HitPose = s_Hits[0].pose; |
|||
} |
|||
|
|||
m_DelayedPosition = Vector3.Lerp(m_DelayedPosition, m_HitPose.position, 0.085f); |
|||
|
|||
if (!m_Placed) |
|||
{ |
|||
m_SpawnedObject.transform.position = m_DelayedPosition; |
|||
} |
|||
|
|||
foreach(ARPlane plane in m_PlaneManager.trackables) |
|||
{ |
|||
if (plane.trackableId == m_HitID) |
|||
{ |
|||
plane.transform.GetComponent<MeshRenderer>().material.SetFloat(k_ShaderContactProperty, 1); |
|||
plane.transform.GetComponent<MeshRenderer>().material.SetVector(k_ShaderPositionProperty, m_DelayedPosition); |
|||
} |
|||
else |
|||
{ |
|||
plane.transform.GetComponent<MeshRenderer>().material.SetFloat(k_ShaderContactProperty, 0); |
|||
} |
|||
} |
|||
|
|||
if (Input.touchCount > 0) |
|||
{ |
|||
Touch touch = Input.GetTouch(0); |
|||
|
|||
if (touch.phase == TouchPhase.Began) |
|||
{ |
|||
m_Placed = true; |
|||
m_SpawnedObject.GetComponent<AnimatedPlaceObject>().AnimatePlacement(); |
|||
} |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: faeaceca7df854ff49277ef3f74f530f |
|||
folderAsset: yes |
|||
DefaultImporter: |
|||
externalObjects: {} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
撰写
预览
正在加载...
取消
保存
Reference in new issue