本文整理汇总了C#中UnityEngine.Plane类的典型用法代码示例。如果您正苦于以下问题:C# Plane类的具体用法?C# Plane怎么用?C# Plane使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Plane类属于UnityEngine命名空间,在下文中一共展示了Plane类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Update
void Update() {
if (navMeshAgent.remainingDistance < 0.5f) {
if (idle != null && anim != null) anim.CrossFade(idle.name);
} else {
if (run != null && anim != null) anim.CrossFade(run.name);
}
// Moves the Player if the Left Mouse Button was clicked:
if (Input.GetMouseButtonDown((int) mouseButton) && GUIUtility.hotControl == 0) {
Plane playerPlane = new Plane(Vector3.up, myTransform.position);
Ray ray = UnityEngine.Camera.main.ScreenPointToRay(Input.mousePosition);
float hitdist = 0.0f;
if (playerPlane.Raycast(ray, out hitdist)) {
navMeshAgent.SetDestination(ray.GetPoint(hitdist));
}
}
// Moves the player if the mouse button is held down:
else if (Input.GetMouseButton((int) mouseButton) && GUIUtility.hotControl == 0) {
Plane playerPlane = new Plane(Vector3.up, myTransform.position);
Ray ray = UnityEngine.Camera.main.ScreenPointToRay(Input.mousePosition);
float hitdist = 0.0f;
if (playerPlane.Raycast(ray, out hitdist)) {
navMeshAgent.SetDestination(ray.GetPoint(hitdist));
}
}
}
示例2: ExtractFrustumPlanes
/// <summary>
/// Same functionality as GeometryUtility.CalculateFrustumPlanes, but doesn't allocate memory.
/// </summary>
public static void ExtractFrustumPlanes(Plane[] planes, Camera camera)
{
Matrix4x4 viewProjMatrix = camera.projectionMatrix * camera.worldToCameraMatrix;
Vector3 normal = new Vector3(viewProjMatrix[3, 0] + viewProjMatrix[0, 0], viewProjMatrix[3, 1] + viewProjMatrix[0, 1], viewProjMatrix[3, 2] + viewProjMatrix[0, 2]);
float length = normal.magnitude;
planes[0].normal = normal.normalized;
planes[0].distance = (viewProjMatrix[3, 3] + viewProjMatrix[0, 3]) / length;
normal = new Vector3(viewProjMatrix[3, 0] - viewProjMatrix[0, 0], viewProjMatrix[3, 1] - viewProjMatrix[0, 1], viewProjMatrix[3, 2] - viewProjMatrix[0, 2]);
length = normal.magnitude;
planes[1].normal = normal.normalized;
planes[1].distance = (viewProjMatrix[3, 3] - viewProjMatrix[0, 3]) / length;
normal = new Vector3(viewProjMatrix[3, 0] + viewProjMatrix[1, 0], viewProjMatrix[3, 1] + viewProjMatrix[1, 1], viewProjMatrix[3, 2] + viewProjMatrix[1, 2]);
length = normal.magnitude;
planes[2].normal = normal.normalized;
planes[2].distance = (viewProjMatrix[3, 3] + viewProjMatrix[1, 3]) / length;
normal = new Vector3(viewProjMatrix[3, 0] - viewProjMatrix[1, 0], viewProjMatrix[3, 1] - viewProjMatrix[1, 1], viewProjMatrix[3, 2] - viewProjMatrix[1, 2]);
length = normal.magnitude;
planes[3].normal = normal.normalized;
planes[3].distance = (viewProjMatrix[3, 3] - viewProjMatrix[1, 3]) / length;
normal = new Vector3(viewProjMatrix[3, 0] + viewProjMatrix[2, 0], viewProjMatrix[3, 1] + viewProjMatrix[2, 1], viewProjMatrix[3, 2] + viewProjMatrix[2, 2]);
length = normal.magnitude;
planes[4].normal = normal.normalized;
planes[4].distance = (viewProjMatrix[3, 3] + viewProjMatrix[2, 3]) / length;
normal = new Vector3(viewProjMatrix[3, 0] - viewProjMatrix[2, 0], viewProjMatrix[3, 1] - viewProjMatrix[2, 1], viewProjMatrix[3, 2] - viewProjMatrix[2, 2]);
length = normal.magnitude;
planes[5].normal = normal.normalized;
planes[5].distance = (viewProjMatrix[3, 3] - viewProjMatrix[2, 3]) / length;
}
示例3: Update
void Update () {
Plane playerPlane = new Plane(Vector3.up, transform.position + new Vector3(0, 0, 0));
switch (state) {
case State.Walking:
Walking();
break;
case State.Attacking:
Attacking();
break;
}
if(state != nextState){
state = nextState;
switch(state){
case State.Walking:
WalkStart();
break;
case State.Attacking:
AttackStart();
break;
case State.Died:
Died();
break;
}
}
}
示例4: RaycastScreenPointFromCamera
public RaycastScreenPointFromCamera(Camera targetCamera, Vector2 screenPosition)
{
this._targetCamera = targetCamera;
this._screenPosition = screenPosition;
_plane = new Plane(Vector3.down, Vector3.zero);
Invalidate();
}
示例5: OnUpdate
// Update is called once per frame
public override void OnUpdate()
{
var vrcam = SteamVR_Render.Top();
GameObject go = Fsm.GetOwnerDefaultTarget(gazeObject);
Ray r = new Ray(vrcam.transform.position, vrcam.transform.forward);
Plane p = new Plane(vrcam.transform.forward, go.transform.position);
float enter = 0.0f;
if (p.Raycast(r, out enter))
{
Vector3 intersect = vrcam.transform.position + vrcam.transform.forward * enter;
float dist = Vector3.Distance(intersect, go.transform.position);
//Debug.Log("Gaze dist = " + dist);
if (dist < gazeInCutoff.Value && !isInGaze.Value)
{
isInGaze.Value = true;
GazeEventArgsPlaymaker e;
e.distance = dist;
OnGazeOn(e);
}
else if (dist >= gazeOutCutoff.Value && isInGaze.Value)
{
isInGaze.Value = false;
GazeEventArgsPlaymaker e;
e.distance = dist;
OnGazeOff(e);
}
}
}
示例6: AdjustEdgeHandleColor
private void AdjustEdgeHandleColor(Vector3 handlePos, Vector3 slideDir1, Vector3 slideDir2, Matrix4x4 transform, float alphaFactor)
{
bool flag;
Vector3 inPoint = transform.MultiplyPoint(handlePos);
Vector3 normalized = transform.MultiplyVector(slideDir1).normalized;
Vector3 rhs = transform.MultiplyVector(slideDir2).normalized;
if (Camera.current.isOrthoGraphic)
{
flag = (Vector3.Dot(-Camera.current.transform.forward, normalized) < 0f) && (Vector3.Dot(-Camera.current.transform.forward, rhs) < 0f);
}
else
{
Plane plane = new Plane(normalized, inPoint);
Plane plane2 = new Plane(rhs, inPoint);
flag = !plane.GetSide(Camera.current.transform.position) && !plane2.GetSide(Camera.current.transform.position);
}
if (flag)
{
alphaFactor *= 0.2f;
}
if (alphaFactor < 1f)
{
Handles.color = new Color(Handles.color.r, Handles.color.g, Handles.color.b, Handles.color.a * alphaFactor);
}
}
示例7: Update
// Update is called once per frame
void Update()
{
//Movement Input
//Look Input
Ray ray = viewCamera.ScreenPointToRay(Input.mousePosition);
Plane groundPlane = new Plane(Vector3.up, Vector3.zero);
float rayDistance;
if (groundPlane.Raycast(ray, out rayDistance))
{
Vector3 point = ray.GetPoint(rayDistance);
//Debug.DrawLine(ray.origin, point, Color.red);
}
if (hasMoveTarget)
{
StartCoroutine(UpdatePath());
}
//Movement
if (Input.GetMouseButtonDown(1))
{
hasMoveTarget = true;
moveTarget = new Vector3(Input.mousePosition.x, Input.mousePosition.y);
Debug.Log("Right-Click: " + moveTarget);
}
}
示例8: Start
/// <summary>
/// Initialises the component.
/// </summary>
public void Start()
{
this.planeZ = new Plane(Vector3.back, Vector3.zero);
// Get a refernce to the terrain's touchable component
this.terrainTouchable = GameObject.Find("Terrain").GetComponent<TouchableComponent>();
}
示例9: RaycastSmoke
public static bool RaycastSmoke(Ray ray)
{
if(!CMDropper.smokePool)
{
return false;
}
for(int i = 0; i < CMDropper.smokePool.size; i++)
{
Transform smokeTf = CMDropper.smokePool.GetPooledObject(i).transform;
if(smokeTf.gameObject.activeInHierarchy)
{
Plane smokePlane = new Plane((ray.origin-smokeTf.position).normalized, smokeTf.position);
float enter;
if(smokePlane.Raycast(ray, out enter))
{
float dist = (ray.GetPoint(enter)-smokeTf.position).magnitude;
if(dist < 16)
{
return true;
}
}
}
}
return false;
}
示例10: CameraToPlaneProjection
/// <summary>
/// Projects a screen point to a plane.
/// </summary>
/// <param name="position">Screen point.</param>
/// <param name="camera">The camera.</param>
/// <param name="projectionPlane">The projection plane.</param>
/// <returns></returns>
public static Vector3 CameraToPlaneProjection(Vector2 position, Camera camera, Plane projectionPlane)
{
var ray = camera.ScreenPointToRay(position);
var relativeIntersection = 0f;
projectionPlane.Raycast(ray, out relativeIntersection);
return ray.origin + ray.direction*relativeIntersection;
}
示例11: ScreenPointToWorldPointOnPlane
public static Vector3 ScreenPointToWorldPointOnPlane(Vector3 screenPoint , Plane plane , Camera camera )
{
// Set up a ray corresponding to the screen position
Ray ray = camera.ScreenPointToRay(screenPoint);
// Find out where the ray intersects with the plane
return PlaneRayIntersection(plane, ray);
}
示例12: RaycastGUIPointToWorldHit
internal static bool RaycastGUIPointToWorldHit(Vector2 guiPoint, Plane plane, out Vector3 hit)
{
Ray worldRay = HandleUtility.GUIPointToWorldRay(guiPoint);
float enter = 0.0f;
bool flag = plane.Raycast(worldRay, out enter);
hit = !flag ? Vector3.zero : worldRay.GetPoint(enter);
return flag;
}
示例13: RaycastGUIPointToWorldHit
internal static bool RaycastGUIPointToWorldHit(Vector2 guiPoint, Plane plane, out Vector3 hit)
{
Ray ray = HandleUtility.GUIPointToWorldRay(guiPoint);
float distance = 0f;
bool flag = plane.Raycast(ray, out distance);
hit = ((!flag) ? Vector3.zero : ray.GetPoint(distance));
return flag;
}
示例14: CameraToPlaneProjection
/// <summary>
/// Projects a screen point to a plane from a camera's point of view.
/// </summary>
/// <param name="position">Screen point.</param>
/// <param name="camera">The camera.</param>
/// <param name="projectionPlane">Projection plane.</param>
/// <returns>Projected point on the plane in World coordinates.</returns>
public static Vector3 CameraToPlaneProjection(Vector2 position, Camera camera, Plane projectionPlane)
{
var distance = 0f;
var ray = camera.ScreenPointToRay(position);
var result = projectionPlane.Raycast(ray, out distance);
if (!result && Mathf.Approximately(distance, 0f)) return -projectionPlane.normal * projectionPlane.GetDistanceToPoint(Vector3.zero); // perpendicular to the screen
return ray.origin + ray.direction * distance;
}
示例15: ScreenToPlaneProjection
/// <summary>
/// Projects a screen point to a plane using parallel projection.
/// </summary>
/// <param name="position">Screen point.</param>
/// <param name="projectionPlane">Projection plane.</param>
/// <returns>Projected point on the plane in World coordinates.</returns>
public static Vector3 ScreenToPlaneProjection(Vector2 position, Plane projectionPlane)
{
var distance = 0f;
var ray = new Ray(position, Vector3.forward);
var result = projectionPlane.Raycast(ray, out distance);
if (!result && Mathf.Approximately(distance, 0f)) return -projectionPlane.normal * projectionPlane.GetDistanceToPoint(Vector3.zero); // perpendicular to the screen
return ray.origin + new Vector3(0, 0, distance);
}