《UnityAPI.Physics物理》
版本 |
作者 |
參與者 |
完成日期 |
備註 |
UnityAPI_Physics_V01_1.0 |
嚴立鑽 |
|
2020.05.21 |
|
|
|
|
|
|
#《UnityAPI.Physics物理》發佈說明:
++++“UnityAPI.Physics物理”是對UnityAPI中Physics類的剖析和拓展;
立鑽哥哥:Unity是一個入門快、提高難的遊戲引擎,想要提升能力,至少需要越過3道坎:API+Shader+綜合能力;++1、API的積累:對API的合理利用不僅可以減輕自己的編碼負擔,而且往往可以提高程序的運行效率;這也是鑽哥開始“Unity API”獨立打造分類的初衷; ++2、Shader編程:想要做出一款精品遊戲往往需要有高效的Shader的支持;Unity提供了一套改良的“Shader Lab”系統,優化了繁雜的“Open GL”編程; ++3、綜合能力(技術+業務+管理):一款產品的製作除了功能編程外,往往會涉及很多其他領域,例如產品架構、UI交互設計、模型製作等,作爲主要的編程人員,對其他相關領域的瞭解程序往往會影響到產品製作直至最後的產品體驗; ++++立鑽哥哥一直在推動【VR雲遊戲=Unity+SteamVR+雲技術+5G+AI】,這個只是一個引子,拋磚引玉讓大家對整個知識體系有一個明確的落地方向,寶寶們可以根據自己的興趣方向進行拓展:比如Unity這裏是指一種“3D遊戲引擎”,也可拓展至“UE4、Cocos2dx”等遊戲引擎;SteamVR是一種跨硬件解決方案,也可拓展至“VRTK”等第三方插件;“雲技術+5G”是一種跨平臺解決方案的核心技術,同樣可拓展至其他平臺解決方案;AI也是一種先進技術的舉例,也可以拓展至任何一種前沿技術; |
@@提示:有些博客可能只是開了頭,如果感興趣的同學,可以“點贊”或“評論區留言”,只要關注的同學多了,那就會繼續完善喲!(“++==”,表示沒有寫完的,如果關注度不高就不完善了;“++ok++”,表示此篇博客已經完成,是階段性完整的!)
$$$$博客溯源:
++++VR雲遊戲=Unity+SteamVR+雲技術+5G+AI;(說明:AI人工智能不是我們的主要研究技術,只是瞭解一下,領略一下有風的感覺!但是,VR是我們的研究重點)
++++【Unity API】分類:https://blog.csdn.net/vrunsoftyanlz/category_7637520.html
++++【Unity開發基礎】分類:https://blog.csdn.net/vrunsoftyanlz/category_7309057.html
++++【Linux系統編程】分類:https://blog.csdn.net/vrunsoftyanlz/category_9694767.html
++++【C++C鑄就生存利器】分類:https://blog.csdn.net/vrunsoftyanlz/category_9325802.html
++++【人工智能AI2026】分類:https://blog.csdn.net/vrunsoftyanlz/category_9212024.html
++++【立鑽哥哥CSDN空間】:https://blog.csdn.net/VRunSoftYanlz/
#Physics物理
#Physics物理 |
#Physics物理++A1、Description描述++B2、Variables變量++C3、Public Function共有函數++D4、Message消息 |
#A1、Description描述
#A1、Description描述 |
++A1、Description描述
++++立鑽哥哥:Physics(物理)是全局物理屬性和輔助方法;
立鑽哥哥:Global physics properties and helper methods. |
#B2、Static Variables靜態變量
#B2、Static Variables靜態變量 |
++B2、Static Variables靜態變量++++B2.1、AllLayers++++B2.2、bounceThreshold++++B2.3、defaultContactOffset++++B2.4、DefaultRaycastLayers++++B2.5、gravity++++B2.6、IgnoreRaycastLayer++++B2.7、queriesHitTriggers++++B2.8、sleepThreshold++++B2.9、solverIterationCount++++B2.10、YanlzXREngine.Physics.StaticVariables |
++B2.1、AllLayers
++B2.1、AllLayers |
++B2.1、AllLayers
++++立鑽哥哥:所有層;
public static int AllLayers; |
++++選擇所有層的層蒙版常量;
++++可用於Physics.Raycast的層蒙版字段以及其他,來選擇所有層;
++B2.2、bounceThreshold
++B2.2、bounceThreshold |
++B2.2、bounceThreshold
++++立鑽哥哥:反彈閥值;
public static float bounceThreshold; |
++++兩個碰撞物體的相對速度如果在這個設定值之下,不會反彈;默認值2;取值範圍0到無窮大;必須爲正數;
++++這個值在【Edit->Project Settings->Physics】菜單下設定;而不用在腳本中;
using UnityEngine; using System.Collections; using YanlzXREngine;
public class YanlzPhysics : MonoBehaviour{ void MyTestFunc(){ Physics.bounceThreshold = 1; } } //立鑽哥哥:public class YanlzPhysics{} |
++B2.3、defaultContactOffset
++B2.3、defaultContactOffset |
++B2.3、defaultContactOffset
++++立鑽哥哥:默認觸點偏移;
public static float defaultContactOffset; |
++++新創建碰撞器的默認接觸偏移值;
++++那些碰撞器間的距離比它們的contactOffset值之和小將產生接觸;該觸點偏移必須爲正;觸點偏移允許碰撞檢測系統預判接觸,即使對象稍微分開點;
++B2.4、DefaultRaycastLayers
++B2.4、DefaultRaycastLayers |
++B2.4、DefaultRaycastLayers
++++立鑽哥哥:默認投射層;
public static int DefaultRaycastLayers; |
++++選擇默認投射層的層蒙版常數;
++++可用於Physics.Raycast的層蒙版字段以及其他,來選擇默認投射層;該默認層是除了忽略層的所有層;
++B2.5、gravity
++B2.5、gravity |
++B2.5、gravity
++++立鑽哥哥:重力;
public static Vector3 gravity; |
++++場景中應用到所有剛體的重力;
++++使用useGravity屬性,可以單個開關剛體重力;
using UnityEngine; using System.Collections; using YanlzXREngine;
public class YanlzPhysics : MonoBehaviour{ void MyTestFunc(){ Physics.gravity = new Vector3(0, -1.0F, 0); } } //立鑽哥哥:public class YanlzPhysics{} |
++B2.6、IgnoreRaycastLayer
++B2.6、IgnoreRaycastLayer |
++B2.6、IgnoreRaycastLayer
++++立鑽哥哥:忽略投射層;
public static int IgnoreRaycastLayer; |
++++選擇忽略層的層蒙版常量;
++++可用於Physics.Raycast的層蒙版字段以及其他,來選擇忽略層(默認不接受投射);
++B2.7、queriesHitTriggers
++B2.7、queriesHitTriggers |
++B2.7、queriesHitTriggers
++++立鑽哥哥:查詢碰到觸發器;
public static bool queriesHitTriggers; |
++++指定查詢(raycasts, spherecasts, overlap tests, etc.)是否碰到觸發器;
++++這能通過指定QueryTriggerInteraction參數,重寫查詢;
++B2.8、sleepThreshold
++B2.8、sleepThreshold |
++B2.8、sleepThreshold
++++立鑽哥哥:休眠閥值;
public static float sleepThreshold; |
++++質量歸一化的能量閥值,哪個對象開始休眠;
++B2.9、solverIterationCount
++B2.9、solverIterationCount |
++B2.9、solverIterationCount
++++立鑽哥哥:求解迭代次數;
public static int solverIterationCount; |
++++默認的求解迭代次數允許使用任意剛體(默認爲7);必須爲正數;(可以糾正關節間連接的錯誤行爲);
++++solverIterationCount決定了關節和接觸點有多精確;可以糾正關節間連接的錯誤行爲;如果關節剛體有搖擺現象和行爲雜亂,爲solverIterationCount設置一個較高的值將改善他們的穩定性;通常情況下設置爲7;
++++這個值在【Edit->Project Settings->Physics】菜單下設定,而不同在腳本中;
using UnityEngine; using System.Collections; using YanlzXREngine;
public class YanlzGameObject : MonoBehaviour{ void MyTestFunc(){ Physics.solverIterationCount = 10; } } //立鑽哥哥:public class YanlzGameObject{} |
#C3、Static Functions靜態函數
#C3、Static Functions靜態函數 |
++C3、Variables變量++++C3.1、BoxCast++++C3.2、BoxCastAll++++C3.3、BoxCastNonAlloc++++C3.4、CapsuleCast++++C3.5、CapsuleCastAll++++C3.6、CapsuleCastNonAlloc++++C3.7、CheckBox++++C3.8、CheckCapsule++++C3.9、CheckSphere++++C3.10、GetIgnoreLayerCollision++++C3.11、IgnoreCollision++++C3.12、IgnoreLayerCollision++++C3.13、Linecast++++C3.14、OverlapBox++++C3.15、OverlapBoxNonAlloc++++C3.16、OverlapSphere++++C3.17、OverlapSphereNonAlloc++++C3.18、Raycast++++C3.19、RaycastAll++++C3.20、RaycastNonAlloc++++C3.21、SphereCast++++C3.22、SphereCastAll++++C3.23、SphereCastNonAlloc++++C3.24、YanlzXREngine.Physics.StaticFunctions |
++C3.1、BoxCast
++C3.1、BoxCast |
++C3.1、BoxCast
++++立鑽哥哥:盒投射;
public static bool BoxCast(Vector3 center, Vector3 halfExtents, Vector3 direction, Quaternion orientation=Quaternion.identity, float maxDistance=Mathf.Infinity, int layerMask=DefaultRaycastLayers, QueryTriggerInteraction queryTriggerInteraction = QueryTriggerInteraction.UseGlobal);public static bool BoxCast(Vector3 center, Vector3 halfExtents, Vector3 direction, out RaycastHit hitInfo, Quaternion orientation = Quaternion.identity, float maxDistance=Mathf.Infinity, int layerMask = DefaultRaycastLayers, QueryTriggerInteraction queryTriggerInteraction=QueryTriggerInteraction.UseGlobal); |
++++[center]:盒中心;
++++[halfExtents]:盒的每軸的一半大小;
++++[direction]:投射盒的方向;
++++[orientation]:盒的旋轉;
++++[maxDistance]:投射的最大長度;
++++[layerMask]:選擇投射的碰撞器層蒙版;
++++[queryTriggerInteraction]:指定查詢碰到觸發器;
++++[hitInfo]:包含更多的碰到碰撞器的信息;
++++[返回值]:如果發現交叉,返回true;
++++沿射線投射立方體,並返回碰到的信息;
++C3.2、BoxCastAll
++C3.2、BoxCastAll |
++C3.2、BoxCastAll
++++立鑽哥哥:全部盒投射;
public static RaycastHit[] BoxCastAll(Vector3 center, Vector3 halfExtents, Vector3 direction, Quaternion orientation=Quaternion.identity, float maxDistance=Mathf.Infinity, int layerMask=DefaultRaycastLayers, QueryTriggerInteraction queryTriggerInteraction=QueryTriggerInteraction.UseGlobal); |
++++[center]:盒的中心;
++++[halfExtents]:盒的每軸的一半大小;
++++[direction]:投射盒的方向;
++++[orientation]:盒的旋轉;
++++[maxDistance]:投射的最大長度;
++++[layerMask]:選擇投射的碰撞器層蒙版;
++++[queryTriggerInteraction]:指定查詢碰到觸發器;
++++[返回值]:返回碰到的所有碰撞器的RaycastHit[];
++++就像Physics.BoxCast,反返回的是所有碰到的對象信息;
++C3.3、BoxCastNonAlloc
++C3.3、BoxCastNonAlloc |
++C3.3、BoxCastNonAlloc
++++立鑽哥哥:盒投射非分配;
public static int BoxCastNonAlloc(Vector3 center, Vector3 halfExtents, Vector3 direction, RaycastHit[] results, Quaternion orientation=Quaternion.identity, float maxDistance=Mathf.Infinity, int layermask=DefaultRaycastLayers, QueryTriggerInteraction queryInteraction=QueryTriggerInteraction.UseGlobal); |
++++[center]:盒中心;
++++[halfExtents]:盒每軸的一半大小;
++++[direction]:盒投射方向;
++++[results]:儲存結果的緩衝器;
++++[orientation]:盒的旋轉;
++++[maxDistance]:投射的最大長度;
++++[layermask]:選擇投射的層蒙版;
++++[queryTriggerInteracion]:指定是否查詢碰到觸發器;
++++[返回值]:返回碰到的儲存在results緩衝器中的數量;
++++沿方向投射立方體,並儲存到提供的緩衝器;
++C3.4、CapsuleCast
++C3.4、CapsuleCast |
++C3.4、CapsuleCast
++++立鑽哥哥:膠囊投射;
public static bool CapsuleCast(Vector3 point1, Vector3 point2, float radius, Vector3 direction, float maxDistance=Mathf.Infinity, int layerMask=DefaultRaycastLayers, QueryTriggerInteraction queryTriggerInteraction=QueryTriggerInteraction.UseGlobal); |
++++[point1]:球體開始中心點;
++++[point2]:球體結束的中心點;
++++[radius]:膠囊的半徑;
++++[direction]:膠囊掃描的方向;
++++[maxDistance]:掃描的最大長度;
++++[layerMask]:選擇投射的層蒙版;
++++[queryTriggerInteraction]:指定是否查詢碰到觸發器;
++C3.5、CapsuleCastAll
++C3.5、CapsuleCastAll |
++C3.5、CapsuleCastAll
++++立鑽哥哥:膠囊投射全部;
public static RaycastHit[] CapsuleCastAll(Vector3 point1, Vector3 point2, float radius, Vector3 direction, float maxDistance=Mathf.Infinity, int layerMask=DefaultRaycastLayers, QueryTriggerInteraction queryTriggerInteraction=QueryTriggerInteraction.UseGlobal); |
++++[point1]:球體開始中心點;
++++[point2]:球體結束的中心點;
++++[radius]:膠囊的半徑;
++++[direction]:膠囊掃描的方向;
++++[maxDistance]:掃描的最大長度;
++++[layerMask]:選擇投射的層蒙版;
++++[queryTriggerInteraction]:指定是否查詢碰到觸發器;
++++[返回值]:返回掃描到的所有碰撞器RaycastHit信息;
++++像Physics.CapsuleCast,但這個函數將返回所有膠囊掃描交叉碰到的對象;
++++投射一個膠囊針對場景中所有碰撞器,並返回所有碰到的每個碰撞器的細節信息;膠囊是由point1和point2位置的兩個球帶有radius半徑形成膠囊的兩端定義;返回膠囊沿direction方向碰到的第一個碰撞器;這通常用於投射不需足夠的精度,因爲要找出一個特定大小的物體,如人物,能移動到某處而不在途中碰撞到任何東西;
++++如果從腳本或動畫移動碰撞器,需要有至少一個在FixedUpdate中執行,使得物理庫可以更新它的數據結構,在CapsuleCast碰到碰撞器之前是在它的新位置;
using UnityEngine; using System.Collections; using YanlzXREngine;
public class YanlzPhysics : MonoBehaviour{
void Update(){ RaycastHit[] hits; CharacterController charCtrl = GetComponent<CharacterController>(); Vector3 p1 = transform.position + charCtrl.center + Vector3.up * -charCtrl.height * 0.5F; Vector3 p2 = p1 + Vector3.up * charCtrl.height;
//Cast character controller shape 10 meters forward, to see if it is about to hit anything hits = Physics.CapsuleCastAll(p1, p2, charCtrl.radius, transform.forward, 10);
//Change the material of all hit colliders to use a transparent Shader for(int i = 0; i < hits.Length; i++){ RaycastHit hit = hits[i]; Renderer rend = hit.transform.GetComponent<Renderer>();
if(rend){ rend.material.shader = Shader.Find(“Transparent/Diffuse”); Color tempColor = rend.material.Color; tempColor.a = 0.3F; rend.material.color = tempColor; } //立鑽哥哥:if(){} } //立鑽哥哥:for(){}
} //立鑽哥哥:void Update(){}
} //立鑽哥哥:public class YanlzPhysics{} |
++C3.6、CapsuleCastNonAlloc
++C3.6、CapsuleCastNonAlloc |
++C3.6、CapsuleCastNonAlloc
++++立鑽哥哥:膠囊投射非分配;
public static int CapsuleCastNonAlloc(Vector3 point1, Vector3 point2, float radius, Vector3 direction, RaycastHit[] results, float maxDistance=Mathf.Infinity, int layerMask=DefaultRaycastLayers, QueryTriggerInteraction queryTriggerInteraction=QueryTriggerInteraction.UseGlobal); |
++++[point1]:球體開始中心點;
++++[point2]:球體結束的中心點;
++++[radius]:膠囊的半徑;
++++[direction]:膠囊掃描的方向;
++++[results]:緩衝器用來儲存碰到的信息;
++++[maxDistance]:掃描的最大長度;
++++[layerMask]:選擇投射的層蒙版;
++++[queryTriggerInteraction]:指定是否查詢碰到觸發器;
++++[返回值]:返回碰到的對象儲存在緩衝器中的數量;
++++針對場景中所有的碰撞器投射一個膠囊,並返回緩衝器中碰到什麼的信息;
++++像Physics.CapsuleCastAll,但不產生垃圾信息;
++C3.7、CheckBox
++C3.7、CheckBox |
++C3.7、CheckBox
++++立鑽哥哥:檢測盒;
public static bool CheckBox(Vector3 center, Vector3 halfExtents, Quaternion orientation=Quaternion.identity, int layermask=DefaultRaycastLayer, QueryTriggerInteraction queryTriggerInteraction=QueryTriggerInteraction.UseGlobal); |
++++[center]:盒的中心;
++++[halfExtents]:盒每軸的一半大小;
++++[orientation]:盒的旋轉;
++++[layermask]:旋轉投射的層蒙版;
++++[queryTriggerInteraction]:指定是否查詢碰到觸發器;
++++[返回值]:如果盒重疊任意碰撞器,返回true;
++++檢測給定盒是否與其他碰撞器重疊;
++C3.8、CheckCapsule
++C3.8、CheckCapsule |
++C3.8、CheckCapsule
++++立鑽哥哥:檢測膠囊;
public static bool CheckCapsule(Vector3 start, Vector3 end, float radius, int layermask=DefaultRaycastLayers, QueryTriggerInteraction queryTriggerInteraction=QueryTriggerInteraction.UseGlobal); |
++++[start]:膠囊開始處的球中心;
++++[end]:膠囊結束處的球中心;
++++[radius]:膠囊的半徑;
++++[layermask]:選擇膠囊投射的層蒙版;
++++[queryTriggerInteraction]:指定是否查詢碰到觸發器;
++++在世界座標空間,檢查膠囊體是否與任意碰撞器重疊;
++++膠囊是由radius半徑與point1和point2位置的兩個球形成膠囊的兩端定義;
using UnityEngine; using System.Collections; using YanlzXREngine;
public class YanlzPhysics : MonoBehaviour{ bool CorridorIsWideEnough(Vector3 startPt, Vector3 endPt, float width){ return Physics.CheckCapsule(startPt, endPt, width); } } //立鑽哥哥:public class YanlzPhysics{} |
++C3.9、CheckSphere
++C3.9、CheckSphere |
++C3.9、CheckSphere
++++立鑽哥哥:檢測球;
public static bool CheckSphere(Vector3 position, float radius, int layermask=DefaultRaycastLayers, QueryTriggerInteraction queryTriggerInteraction=QueryTriggerInteraction.UseGlobal); |
++++[position]:球的中心;
++++[radius]:球的中心;
++++[layermask]:選擇膠囊投射的層蒙版;
++++[queryTriggerInteraction]:指定是否查詢碰到觸發器;
++++在世界座標空間,由位置和半徑定義的球與任意碰撞器重疊,如果重疊則返回true;
using UnityEngine; using System.Collections; using YanlzXREngine;
public class YanlzPhysics : MonoBehaviour{ public float sphereRadius; AudioSource audio;
void Start(){ audio = GetComponent<AudioSource>(); } //立鑽哥哥:void Start(){}
void MyWarningNoise(){ //Play a noise if an object is within the sphere’s radius if(Physics.CheckSphere(transform.position, sphereRadius)){ audio.Play(); } } //立鑽哥哥:void MyWarningNoise(){}
} //立鑽哥哥:public class YanlzPhysics{} |
++C3.10、GetIgnoreLayerCollision
++C3.10、GetIgnoreLayerCollision |
++C3.10、GetIgnoreLayerCollision
++++立鑽哥哥:獲取忽略層碰撞;
public static bool GetIgnoreLayerCollision(int layer1, int layer2); |
++++layer1和layer2的層忽略了嗎?
++++返回Physics.IgnoreLayerCollision或在物理檢視面板設置的值;
++C3.11、IgnoreCollision
++C3.11、IgnoreCollision |
++C3.11、IgnoreCollision
++++立鑽哥哥:忽略碰撞;
public static void IgnoreCollision(Collider collider1, Collider collider2, bool ignore=true); |
++++使碰撞檢測系統忽略所有collider1和collider2碰撞;
++++這用於,比如說,防止炮彈與發射的對象碰撞(避免炮彈與炮筒碰撞);
++立鑽哥哥:IgnoreCollision有一些侷限性:++++1)不具有持續性,這意味着忽略的碰撞狀態當場景保存時,在編輯器中不會儲存;++++2)只能在運行時應用忽略碰撞到碰撞器;當禁用該碰撞器或剛體,IgnoreCollision狀態將丟失,必須再次調用Physics.IgnoreCollision; |
++++注意:IgnoreCollision將重置受影響的碰撞器的觸發狀態,因此可能收到OnTriggerEnter和OnTriggerExit的響應消息;
using UnityEngine; using System.Collections; using YanlzXREngine;
public class YanlzPhysics : MonoBehaviour{ public Transform bulletPrefab;
void Start(){ Transform bullect = Instantiate(bulletPrefab) as Transform; Physics.IgnoreCollision(bullet.GetComponent<Collider>(), GetComponent<Collider>()); } //立鑽哥哥:void Start(){}
} //立鑽哥哥:public class YanlzPhysics{} |
++C3.12、IgnoreLayerCollision
++C3.12、IgnoreLayerCollision |
++C3.12、IgnoreLayerCollision
++++立鑽哥哥:忽略層碰撞;
public static void IgnoreLayerCollision(int layer1, int layer2, bool ignore=true); |
++++使碰撞檢測系統忽略layer1和layer2中的任意碰撞器的所有碰撞;
++++注意:IgnoreLayerCollision將重置受影響碰撞器的觸發狀態,因此可能收到OnTriggerEnter和OnTriggerExit的響應消息;
++++可以在物理檢視面板爲項目設置任意層組合的碰撞;
++C3.13、Linecast
++C3.13、Linecast |
++C3.13、Linecast
++++立鑽哥哥:線投射;
public static bool Linecast(Vector3 start, Vector3 end, int layerMask=DefaultRaycastLayers);public static bool Linecast(Vector3 start, Vector3 end, out RaycastHit hitInfo, int layerMask=DefaultRaycastLayers); |
++++在線的開始和結束位置之間,如果與任何碰撞器相交返回真;
++++Layer mask是用來指定投射的層;
++++如果返回true,hitInfo返回碰到的RaycastHit信息;
using UnityEngine; using System.Collections; using YanlzXREngine;
public class YanlzPhysics : MonoBehaviour{ public Transform target;
void Update(){ if(!Physics.Linecast(transform.position, target.position)){ } } //立鑽哥哥:void Update(){}
} //立鑽哥哥:public class YanlzPhysics{} |
++C3.14、OverlapBox
++C3.14、OverlapBox |
++C3.14、OverlapBox
++++立鑽哥哥:重疊盒;
public static Collider[] OverlapBox(Vector3 center, Vector3 halfExtents, Quaternion orientation=Quaternion.identity, int layerMask=AllLayers, QueryTriggerInteraction queryTriggerInteraction=QueryTriggerInteraction.UseGlobal); |
++++[center]:盒中心;
++++[halfExtents]:盒每軸大小的一半;
++++[orientation]:盒的旋轉;
++++[layerMask]:選擇投射的層蒙版;
++++[queryTriggerInteraction]:指定是否查詢碰到觸發器;
++++[返回值]:返回與給定立方體重疊的所有碰撞器;
++++查找給定立方體內或與之接觸的所有碰撞器;
++C3.15、OverlapBoxNonAlloc
++C3.15、OverlapBoxNonAlloc |
++C3.15、OverlapBoxNonAlloc
++++立鑽哥哥:重疊盒非分配;
public static int OverlapBoxNonAlloc(Vector3 center, Vector3 halfExtents, Collider[] results, Quaternion orientation=Quaternion.identity, int layerMask=AllLayers, Quaternion queryTriggerInteraction=QueryTriggerInteraction.UseGlobal); |
++++[center]:盒中心;
++++[halfExtents]:盒每軸大小的一半;
++++[results]:儲存結果到緩衝器;
++++[orientation]:盒的旋轉;
++++[layerMask]:選擇投射的層蒙版;
++++[queryTriggerInteraction]:指定是否查詢碰到觸發器;
++++[返回值]:返回儲存在results中碰撞器的數量;
++++查找給定立方體內或與之接觸的所有碰撞器,並儲存在緩衝器中;
++C3.16、OverlapSphere
++C3.16、OverlapSphere |
++C3.16、OverlapSphere
++++立鑽哥哥:重疊球;
public static Collider[] OverlapSphere(Vector3 position, float radius, int layerMask=AllLayers, QueryTriggerInteraction queryTriggerInteraction=QueryTriggerInteraction.UseGlobal); |
++++[position]:球體中心;
++++[radius]:球的半徑;
++++[layerMask]:選擇投射的層蒙版;
++++[queryTriggerInteraction]:指定是否查詢碰到觸發器;
++++返回球內或與之接觸的所有碰撞器;
++++注意:這個僅針對碰撞器的邊界體檢測,而不是針對實際的碰撞器;
using UnityEngine; using System.Collections; using YanlzXREngine;
public class YanlzPhysics : MonoBehaviour{
void MyExplosionDamage(Vector3 center, float radius){ Collider[] hitColliders = Physics.OverlapSphere(center, radius);
int i = 0; while(i < hitColliders.Length){ hitColliders[i].SendMessage(“MyAddDamage”); i++; } } //立鑽哥哥:void MyExplosionDamage(){}
} //立鑽哥哥:public class YanlzPhysics{} |
++C3.17、OverlapSphereNonAlloc
++C3.17、OverlapSphereNonAlloc |
++C3.17、OverlapSphereNonAlloc
++++立鑽哥哥:重疊球非分配;
public static int OverlapSphereNonAlloc(Vector3 position, float radius, Collider[] results, int layerMask=AllLayers, QueryTriggerInteraction queryTriggerInteraction=QueryTriggerInteraction.UseGlobal); |
++++[position]:球體中心;
++++[radius]:球的半徑;
++++[results]:儲存結果到緩衝器;
++++[layerMask]:選擇投射的層蒙版;
++++[queryTriggerInteraction]:指定是否查詢碰到觸發器;
++++[返回值]:返回儲存在results緩衝器中碰撞器的數量;
++++計算並儲存該球內或與之接觸的所有碰撞器到提供的緩衝器中;
++++像Physics.OverlapSphere,但不產生垃圾;
立鑽哥哥:Like Physics.OverlapSphere, but generates no garbage. |
++C3.18、Raycast
++C3.18、Raycast |
@@提示:有些博客可能只是開了頭,如果感興趣的同學,可以“點贊”或“評論區留言”,只要關注的同學多了,那就會繼續完善喲!(“++==”,表示沒有寫完的,如果關注度不高就不完善了;“++ok++”,表示此篇博客已經完成,是階段性完整的!)
++++VR雲遊戲=Unity+SteamVR+雲技術+5G+AI;(說明:AI人工智能不是我們的主要研究技術,只是瞭解一下,領略一下有風的感覺!但是,VR是我們的研究重點)
++++【Unity API】分類:https://blog.csdn.net/vrunsoftyanlz/category_7637520.html
++++【Unity開發基礎】分類:https://blog.csdn.net/vrunsoftyanlz/category_7309057.html
++++【Linux系統編程】分類:https://blog.csdn.net/vrunsoftyanlz/category_9694767.html
++++【C++C鑄就生存利器】分類:https://blog.csdn.net/vrunsoftyanlz/category_9325802.html
++++【人工智能AI2026】分類:https://blog.csdn.net/vrunsoftyanlz/category_9212024.html
++++【立鑽哥哥CSDN空間】:https://blog.csdn.net/VRunSoftYanlz/
【XR遊戲開發QQ羣:784477094】
++立鑽哥哥推薦的拓展學習鏈接(Link_Url):
立鑽哥哥推薦的拓展學習鏈接(Link_Url) |
++++立鑽哥哥Unity 學習空間: http://blog.csdn.net/VRunSoftYanlz/
++++虛擬現實VR資訊: https://blog.csdn.net/VRunSoftYanlz/article/details/89165846
++++HTC_VIVE開發基礎:https://blog.csdn.net/VRunSoftYanlz/article/details/81989970
++++Oculus雜談:https://blog.csdn.net/VRunSoftYanlz/article/details/82469850
++++Oculus安裝使用:https://blog.csdn.net/VRunSoftYanlz/article/details/82718982
++++Unity+SteamVR=>VR:https://blog.csdn.net/VRunSoftYanlz/article/details/88809370
++++Unity減少VR暈眩症:https://blog.csdn.net/VRunSoftYanlz/article/details/89115518
++++SteamVR簡介:https://blog.csdn.net/VRunSoftYanlz/article/details/86484254
++++SteamVR腳本功能分析:https://blog.csdn.net/VRunSoftYanlz/article/details/86531480
++++SteamVR2.0開發指南:https://blog.csdn.net/VRunSoftYanlz/article/details/86618187
++++SteamVR2.2.0開發指南:https://blog.csdn.net/VRunSoftYanlz/article/details/88784527
++++SteamVR2.2.0快速入門:https://blog.csdn.net/VRunSoftYanlz/article/details/88833579
++++SteamVR2.2.0交互系統:https://blog.csdn.net/VRunSoftYanlz/article/details/89199778
++++SteamVR2.2.0傳送機制:https://blog.csdn.net/VRunSoftYanlz/article/details/89390866
++++SteamVR2.2.0教程(一):https://blog.csdn.net/VRunSoftYanlz/article/details/89324067
++++SteamVR2.2.0教程(二):https://blog.csdn.net/VRunSoftYanlz/article/details/89894097
++++SteamVR_Skeleton_Poser:https://blog.csdn.net/VRunSoftYanlz/article/details/89931725
++++SteamVR實戰之PMCore:https://blog.csdn.net/VRunSoftYanlz/article/details/89463658
++++SteamVR/Extras:https://blog.csdn.net/VRunSoftYanlz/article/details/86584108
++++SteamVR/Input:https://blog.csdn.net/VRunSoftYanlz/article/details/86601950
++++OpenXR簡介:https://blog.csdn.net/VRunSoftYanlz/article/details/85726365
++++VRTK雜談:https://blog.csdn.net/VRunSoftYanlz/article/details/82562993
++++VRTK快速入門(雜談):https://blog.csdn.net/VRunSoftYanlz/article/details/82955267
++++VRTK官方示例(目錄):https://blog.csdn.net/VRunSoftYanlz/article/details/82955410
++++VRTK代碼結構(目錄):https://blog.csdn.net/VRunSoftYanlz/article/details/82780085
++++VRTK(SceneResources):https://blog.csdn.net/VRunSoftYanlz/article/details/82795400
++++VRTK_ControllerEvents:https://blog.csdn.net/VRunSoftYanlz/article/details/83099512
++++VRTK_InteractTouch:https://blog.csdn.net/VRunSoftYanlz/article/details/83120220
++++虛擬現實行業應用:https://blog.csdn.net/VRunSoftYanlz/article/details/88360157
++++Steam平臺上的VR:https://blog.csdn.net/VRunSoftYanlz/article/details/88960085
++++Steam平臺熱銷VR:https://blog.csdn.net/VRunSoftYanlz/article/details/89007741
++++VR實驗:以太網幀的構成:https://blog.csdn.net/VRunSoftYanlz/article/details/82598140
++++實驗四:存儲器擴展實驗:https://blog.csdn.net/VRunSoftYanlz/article/details/87834434
++++FrameVR示例V0913:https://blog.csdn.net/VRunSoftYanlz/article/details/82808498
++++FrameVR示例V1003:https://blog.csdn.net/VRunSoftYanlz/article/details/83066516
++++SwitchMachineV1022:https://blog.csdn.net/VRunSoftYanlz/article/details/83280886
++++PlaySceneManagerV1022:https://blog.csdn.net/VRunSoftYanlz/article/details/83280886
++++Unity5.x用戶手冊:https://blog.csdn.net/VRunSoftYanlz/article/details/81712741
++++Unity面試題ABC:https://blog.csdn.net/vrunsoftyanlz/article/details/78630687
++++Unity面試題D:https://blog.csdn.net/VRunSoftYanlz/article/details/78630838
++++Unity面試題E:https://blog.csdn.net/vrunsoftyanlz/article/details/78630913
++++Unity面試題F:https://blog.csdn.net/VRunSoftYanlz/article/details/78630945
++++Cocos2dx面試題:https://blog.csdn.net/VRunSoftYanlz/article/details/78630967
++++禪道[zentao]:https://blog.csdn.net/VRunSoftYanlz/article/details/83964057
++++Lua快速入門篇(Xlua拓展):https://blog.csdn.net/VRunSoftYanlz/article/details/81173818
++++Lua快速入門篇(XLua教程):https://blog.csdn.net/VRunSoftYanlz/article/details/81141502
++++Lua快速入門篇(基礎概述):https://blog.csdn.net/VRunSoftYanlz/article/details/81041359
++++框架知識點:https://blog.csdn.net/VRunSoftYanlz/article/details/80862879
++++遊戲框架(UI框架夯實篇):https://blog.csdn.net/vrunsoftyanlz/article/details/80781140
++++遊戲框架(初探篇):https://blog.csdn.net/VRunSoftYanlz/article/details/80630325
++++.Net框架設計:https://blog.csdn.net/VRunSoftYanlz/article/details/87401225
++++從零開始學架構:https://blog.csdn.net/VRunSoftYanlz/article/details/88095895
++++設計模式簡單整理:https://blog.csdn.net/vrunsoftyanlz/article/details/79839641
++++專題:設計模式(精華篇):https://blog.csdn.net/VRunSoftYanlz/article/details/81322678
++++U3D小項目參考:https://blog.csdn.net/vrunsoftyanlz/article/details/80141811
++++Unity小遊戲算法分析:https://blog.csdn.net/VRunSoftYanlz/article/details/87908365
++++Unity案例(Vehicle):https://blog.csdn.net/VRunSoftYanlz/article/details/82355876
++++UML類圖:https://blog.csdn.net/vrunsoftyanlz/article/details/80289461
++++PowerDesigner簡介:https://blog.csdn.net/VRunSoftYanlz/article/details/86500084
++++Unity知識點0001:https://blog.csdn.net/vrunsoftyanlz/article/details/80302012
++++Unity知識點0008:https://blog.csdn.net/VRunSoftYanlz/article/details/81153606
++++U3D_Shader編程(第一篇:快速入門篇):https://blog.csdn.net/vrunsoftyanlz/article/details/80372071
++++U3D_Shader編程(第二篇:基礎夯實篇):https://blog.csdn.net/vrunsoftyanlz/article/details/80372628
++++Unity引擎基礎:https://blog.csdn.net/vrunsoftyanlz/article/details/78881685
++++Unity面向組件開發:https://blog.csdn.net/vrunsoftyanlz/article/details/78881752
++++Unity物理系統:https://blog.csdn.net/vrunsoftyanlz/article/details/78881879
++++Unity2D平臺開發:https://blog.csdn.net/vrunsoftyanlz/article/details/78882034
++++UGUI基礎:https://blog.csdn.net/vrunsoftyanlz/article/details/78884693
++++UGUI進階:https://blog.csdn.net/vrunsoftyanlz/article/details/78884882
++++UGUI綜合:https://blog.csdn.net/vrunsoftyanlz/article/details/78885013
++++Unity動畫系統基礎:https://blog.csdn.net/vrunsoftyanlz/article/details/78886068
++++Unity動畫系統進階:https://blog.csdn.net/vrunsoftyanlz/article/details/78886198
++++Navigation導航系統:https://blog.csdn.net/vrunsoftyanlz/article/details/78886281
++++Unity特效渲染:https://blog.csdn.net/vrunsoftyanlz/article/details/78886403
++++Unity數據存儲:https://blog.csdn.net/vrunsoftyanlz/article/details/79251273
++++Unity中Sqlite數據庫:https://blog.csdn.net/vrunsoftyanlz/article/details/79254162
++++WWW類和協程:https://blog.csdn.net/vrunsoftyanlz/article/details/79254559
++++Unity網絡:https://blog.csdn.net/vrunsoftyanlz/article/details/79254902
++++Unity資源加密:https://blog.csdn.net/VRunSoftYanlz/article/details/87644514
++++PhotonServer簡介:https://blog.csdn.net/VRunSoftYanlz/article/details/86652770
++++編寫Photon遊戲服務器:https://blog.csdn.net/VRunSoftYanlz/article/details/86682935
++++C#事件:https://blog.csdn.net/vrunsoftyanlz/article/details/78631267
++++C#委託:https://blog.csdn.net/vrunsoftyanlz/article/details/78631183
++++C#集合:https://blog.csdn.net/vrunsoftyanlz/article/details/78631175
++++C#泛型:https://blog.csdn.net/vrunsoftyanlz/article/details/78631141
++++C#接口:https://blog.csdn.net/vrunsoftyanlz/article/details/78631122
++++C#靜態類:https://blog.csdn.net/vrunsoftyanlz/article/details/78630979
++++C#中System.String類:https://blog.csdn.net/vrunsoftyanlz/article/details/78630945
++++C#數據類型:https://blog.csdn.net/vrunsoftyanlz/article/details/78630913
++++Unity3D默認的快捷鍵:https://blog.csdn.net/vrunsoftyanlz/article/details/78630838
++++遊戲相關縮寫:https://blog.csdn.net/vrunsoftyanlz/article/details/78630687
++++UnityAPI.Rigidbody剛體:https://blog.csdn.net/VRunSoftYanlz/article/details/81784053
++++UnityAPI.Material材質:https://blog.csdn.net/VRunSoftYanlz/article/details/81814303
++++UnityAPI.Android安卓:https://blog.csdn.net/VRunSoftYanlz/article/details/81843193
++++UnityAPI.AndroidJNI安卓JNI:https://blog.csdn.net/VRunSoftYanlz/article/details/81879345
++++UnityAPI.Transform變換:https://blog.csdn.net/VRunSoftYanlz/article/details/81916293
++++UnityAPI.WheelCollider輪碰撞器:https://blog.csdn.net/VRunSoftYanlz/article/details/82356217
++++UnityAPI.Resources資源:https://blog.csdn.net/VRunSoftYanlz/article/details/83155518
++++JSON數據結構:https://blog.csdn.net/VRunSoftYanlz/article/details/82026644
++++CocosStudio快速入門:https://blog.csdn.net/VRunSoftYanlz/article/details/82356839
++++Unity企業內訓(目錄):https://blog.csdn.net/VRunSoftYanlz/article/details/82634668
++++Unity企業內訓(第1講):https://blog.csdn.net/VRunSoftYanlz/article/details/82634733
++++Unity企業內訓(第2講):https://blog.csdn.net/VRunSoftYanlz/article/details/82861180
++++Unity企業內訓(第3講):https://blog.csdn.net/VRunSoftYanlz/article/details/82927699
++++Unity企業內訓(第4講):https://blog.csdn.net/VRunSoftYanlz/article/details/83479776
++++Unity企業內訓(第5講):https://blog.csdn.net/VRunSoftYanlz/article/details/83963811
++++Unity企業內訓(第6講):https://blog.csdn.net/VRunSoftYanlz/article/details/84207696
++++鑽哥帶您瞭解產品原型:https://blog.csdn.net/VRunSoftYanlz/article/details/87303828
++++插件<Obi Rope>:https://blog.csdn.net/VRunSoftYanlz/article/details/83963905
++++計算機組成原理(教材篇):https://blog.csdn.net/VRunSoftYanlz/article/details/82719129
++++5G接入:雲計算和霧計算:https://blog.csdn.net/VRunSoftYanlz/article/details/88372718
++++雲計算通俗講義:https://blog.csdn.net/VRunSoftYanlz/article/details/88652803
++++立鑽哥哥Unity 學習空間: http://blog.csdn.net/VRunSoftYanlz
--_--VRunSoft:lovezuanzuan--_--