当前位置: 首页>>代码示例>>C#>>正文


C# Bounds.ClosestPoint方法代码示例

本文整理汇总了C#中UnityEngine.Bounds.ClosestPoint方法的典型用法代码示例。如果您正苦于以下问题:C# Bounds.ClosestPoint方法的具体用法?C# Bounds.ClosestPoint怎么用?C# Bounds.ClosestPoint使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在UnityEngine.Bounds的用法示例。


在下文中一共展示了Bounds.ClosestPoint方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ApplyForce

    public void ApplyForce(Transform transObj, float maxForce = 1, float radius = 0)
    {
        //radius = 0;
        //Debug.Log("Cube hit!");

        var b = new Bounds(FinalPosition, transform.localScale);
        b.Expand(radius * 2);

        // Why does radius need to be multiplied by 2?
        //var falloffBounds =new Bounds( new Bounds(FinalPosition, transform.localScale + (Vector3.one * Falloff) + (Vector3.one * radius * 2));

        var falloffBounds = new Bounds(FinalPosition, transform.localScale);
        falloffBounds.Expand(radius * 2 + Falloff * 2);
        if (falloffBounds.Contains(transObj.position))
        {
            //Debug.Log("Object in falloff");

            // inside the obstacle!
            if (b.Contains(transObj.position))
            {
                //Debug.Log("Object has enter bounds!");

                transObj.position = GetClosestBorderFromInsidePoint(b, transObj.position, 0.01f);
            }
            // in the fallout area
            else
            {
                var falloutClosePoint = falloffBounds.ClosestPoint(transObj.position);
                Helpers.DrawDebugPoint(falloutClosePoint, 1, Color.cyan);

                var objClosePoint = b.ClosestPoint(transObj.position);
                Helpers.DrawDebugPoint(objClosePoint, 1, Color.magenta);

                Debug.DrawLine(falloutClosePoint, objClosePoint, Color.yellow);

                var mag = (falloutClosePoint - objClosePoint).magnitude;

                var frac = Mathf.Max(1 - mag / Falloff, 0);

                //Debug.Log("mag = " + mag + " (" + frac + ")");

                var forceVector = (falloutClosePoint - objClosePoint).normalized * frac * maxForce;
                transObj.position += forceVector * Time.deltaTime;
            }
        }
    }
开发者ID:talford2,项目名称:FirstPersonExperiment,代码行数:46,代码来源:CubeObstackeAvoidence.cs

示例2: LateUpdate

 void LateUpdate() {
     var boundedArea = new Bounds(bounds.center, bounds.size);
     foreach (Transform child in transform)
         child.localPosition = boundedArea.ClosestPoint(child.localPosition);
 }
开发者ID:juliosueiras,项目名称:GensoShojokosen,代码行数:5,代码来源:RestrainChildren.cs

示例3: DoOriginEditing

 private void DoOriginEditing()
 {
     ReflectionProbe target = (ReflectionProbe) this.target;
     Vector3 position = target.transform.position;
     Vector3 size = target.size;
     Vector3 center = target.center + position;
     EditorGUI.BeginChangeCheck();
     Vector3 point = Handles.PositionHandle(position, Quaternion.identity);
     bool flag = EditorGUI.EndChangeCheck();
     if (!flag)
     {
         point = position;
         Vector3 vector5 = this.m_OldTransformPosition - point;
         flag = vector5.magnitude > 1E-05f;
         if (flag)
         {
             center = target.center + this.m_OldTransformPosition;
         }
     }
     if (flag)
     {
         Undo.RecordObject(target, "Modified Reflection Probe Origin");
         Bounds bounds = new Bounds(center, size);
         point = bounds.ClosestPoint(point);
         Vector3 vector6 = point;
         target.transform.position = vector6;
         this.m_OldTransformPosition = vector6;
         target.center = bounds.center - point;
         EditorUtility.SetDirty(this.target);
     }
 }
开发者ID:randomize,项目名称:VimConfig,代码行数:31,代码来源:ReflectionProbeEditor.cs

示例4: DoOriginEditing

 private void DoOriginEditing()
 {
   ReflectionProbe target = (ReflectionProbe) this.target;
   Vector3 position = target.transform.position;
   Vector3 size = target.size;
   Vector3 center = target.center + position;
   EditorGUI.BeginChangeCheck();
   Vector3 point = Handles.PositionHandle(position, Quaternion.identity);
   bool flag = EditorGUI.EndChangeCheck();
   if (!flag)
   {
     point = position;
     flag = (double) (this.m_OldTransformPosition - point).magnitude > 9.99999974737875E-06;
     if (flag)
       center = target.center + this.m_OldTransformPosition;
   }
   if (!flag)
     return;
   Undo.RecordObject((UnityEngine.Object) target, "Modified Reflection Probe Origin");
   Bounds bounds = new Bounds(center, size);
   Vector3 vector3_1 = bounds.ClosestPoint(point);
   Vector3 vector3_2 = vector3_1;
   target.transform.position = vector3_2;
   this.m_OldTransformPosition = vector3_2;
   target.center = bounds.center - vector3_1;
   EditorUtility.SetDirty(this.target);
 }
开发者ID:BlakeTriana,项目名称:unity-decompiled,代码行数:27,代码来源:ReflectionProbeEditor.cs

示例5: DoOriginEditing

		private void DoOriginEditing()
		{
			ReflectionProbe reflectionProbe = (ReflectionProbe)this.target;
			Vector3 position = reflectionProbe.transform.position;
			Vector3 size = reflectionProbe.size;
			Vector3 center = reflectionProbe.center + position;
			EditorGUI.BeginChangeCheck();
			Vector3 vector = Handles.PositionHandle(position, Quaternion.identity);
			bool flag = EditorGUI.EndChangeCheck();
			if (!flag)
			{
				vector = position;
				flag = ((this.m_OldTransformPosition - vector).magnitude > 1E-05f);
				if (flag)
				{
					center = reflectionProbe.center + this.m_OldTransformPosition;
				}
			}
			if (flag)
			{
				Undo.RecordObject(reflectionProbe, "Modified Reflection Probe Origin");
				Bounds bounds = new Bounds(center, size);
				vector = bounds.ClosestPoint(vector);
				Vector3 vector2 = vector;
				reflectionProbe.transform.position = vector2;
				this.m_OldTransformPosition = vector2;
				reflectionProbe.center = bounds.center - vector;
				EditorUtility.SetDirty(this.target);
			}
		}
开发者ID:guozanhua,项目名称:UnityDecompiled,代码行数:30,代码来源:ReflectionProbeEditor.cs


注:本文中的UnityEngine.Bounds.ClosestPoint方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。