UnityEngine.Vector3.Min(UnityEngine.Vector3, UnityEngine.Vector3)

Here are the examples of the csharp api UnityEngine.Vector3.Min(UnityEngine.Vector3, UnityEngine.Vector3) taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

8 Examples 7

19 View Source File : NGUIMath.cs
License : GNU General Public License v3.0
Project Creator : aelariane

public static Bounds CalculateAbsoluteWidgetBounds(Transform trans)
    {
        UIWidget[] componentsInChildren = trans.GetComponentsInChildren<UIWidget>();
        if (componentsInChildren.Length == 0)
        {
            return new Bounds(trans.position, Vectors.zero);
        }
        Vector3 vector = new Vector3(float.MaxValue, float.MaxValue, float.MaxValue);
        Vector3 vector2 = new Vector3(float.MinValue, float.MinValue, float.MinValue);
        int i = 0;
        int num = componentsInChildren.Length;
        while (i < num)
        {
            UIWidget uiwidget = componentsInChildren[i];
            Vector2 a = uiwidget.relativeSize;
            Vector2 pivotOffset = uiwidget.pivotOffset;
            float num2 = (pivotOffset.x + 0.5f) * a.x;
            float num3 = (pivotOffset.y - 0.5f) * a.y;
            a *= 0.5f;
            Transform cachedTransform = uiwidget.cachedTransform;
            Vector3 lhs = cachedTransform.TransformPoint(new Vector3(num2 - a.x, num3 - a.y, 0f));
            vector2 = Vector3.Max(lhs, vector2);
            vector = Vector3.Min(lhs, vector);
            lhs = cachedTransform.TransformPoint(new Vector3(num2 - a.x, num3 + a.y, 0f));
            vector2 = Vector3.Max(lhs, vector2);
            vector = Vector3.Min(lhs, vector);
            lhs = cachedTransform.TransformPoint(new Vector3(num2 + a.x, num3 - a.y, 0f));
            vector2 = Vector3.Max(lhs, vector2);
            vector = Vector3.Min(lhs, vector);
            lhs = cachedTransform.TransformPoint(new Vector3(num2 + a.x, num3 + a.y, 0f));
            vector2 = Vector3.Max(lhs, vector2);
            vector = Vector3.Min(lhs, vector);
            i++;
        }
        Bounds result = new Bounds(vector, Vectors.zero);
        result.Encapsulate(vector2);
        return result;
    }

19 View Source File : NGUIMath.cs
License : GNU General Public License v3.0
Project Creator : aelariane

public static Bounds CalculateRelativeWidgetBounds(Transform root, Transform child)
    {
        UIWidget[] componentsInChildren = child.GetComponentsInChildren<UIWidget>();
        if (componentsInChildren.Length == 0)
        {
            return new Bounds(Vectors.zero, Vectors.zero);
        }
        Vector3 vector = new Vector3(float.MaxValue, float.MaxValue, float.MaxValue);
        Vector3 vector2 = new Vector3(float.MinValue, float.MinValue, float.MinValue);
        Matrix4x4 worldToLocalMatrix = root.worldToLocalMatrix;
        int i = 0;
        int num = componentsInChildren.Length;
        while (i < num)
        {
            UIWidget uiwidget = componentsInChildren[i];
            Vector2 a = uiwidget.relativeSize;
            Vector2 pivotOffset = uiwidget.pivotOffset;
            Transform cachedTransform = uiwidget.cachedTransform;
            float num2 = (pivotOffset.x + 0.5f) * a.x;
            float num3 = (pivotOffset.y - 0.5f) * a.y;
            a *= 0.5f;
            Vector3 vector3 = new Vector3(num2 - a.x, num3 - a.y, 0f);
            vector3 = cachedTransform.TransformPoint(vector3);
            vector3 = worldToLocalMatrix.MultiplyPoint3x4(vector3);
            vector2 = Vector3.Max(vector3, vector2);
            vector = Vector3.Min(vector3, vector);
            vector3 = new Vector3(num2 - a.x, num3 + a.y, 0f);
            vector3 = cachedTransform.TransformPoint(vector3);
            vector3 = worldToLocalMatrix.MultiplyPoint3x4(vector3);
            vector2 = Vector3.Max(vector3, vector2);
            vector = Vector3.Min(vector3, vector);
            vector3 = new Vector3(num2 + a.x, num3 - a.y, 0f);
            vector3 = cachedTransform.TransformPoint(vector3);
            vector3 = worldToLocalMatrix.MultiplyPoint3x4(vector3);
            vector2 = Vector3.Max(vector3, vector2);
            vector = Vector3.Min(vector3, vector);
            vector3 = new Vector3(num2 + a.x, num3 + a.y, 0f);
            vector3 = cachedTransform.TransformPoint(vector3);
            vector3 = worldToLocalMatrix.MultiplyPoint3x4(vector3);
            vector2 = Vector3.Max(vector3, vector2);
            vector = Vector3.Min(vector3, vector);
            i++;
        }
        Bounds result = new Bounds(vector, Vectors.zero);
        result.Encapsulate(vector2);
        return result;
    }

19 View Source File : OTU_ScrollRect.cs
License : MIT License
Project Creator : slavidodo

internal static Bounds InternalGetBounds(Vector3[] corners, ref Matrix4x4 viewWorldToLocalMatrix) {
            var vMin = new Vector3(float.MaxValue, float.MaxValue, float.MaxValue);
            var vMax = new Vector3(float.MinValue, float.MinValue, float.MinValue);

            for (int j = 0; j < 4; j++) {
                Vector3 v = viewWorldToLocalMatrix.MultiplyPoint3x4(corners[j]);
                vMin = Vector3.Min(v, vMin);
                vMax = Vector3.Max(v, vMax);
            }

            var bounds = new Bounds(vMin, Vector3.zero);
            bounds.Encapsulate(vMax);
            return bounds;
        }

19 View Source File : GridGeneratorEditor.cs
License : MIT License
Project Creator : XINCGer

public override void OnSceneGUI (NavGraph target) {
			Event e = Event.current;

			var graph = target as GridGraph;

			graph.UpdateTransform();
			var currentTransform = graph.transform * Matrix4x4.Scale(new Vector3(graph.width, 1, graph.depth));

			if (e.type == EventType.MouseDown) {
				isMouseDown = true;
			} else if (e.type == EventType.MouseUp) {
				isMouseDown = false;
			}

			if (!isMouseDown) {
				savedTransform = currentTransform;
				savedDimensions = new Vector2(graph.width, graph.depth);
				savedNodeSize = graph.nodeSize;
			}

			Handles.matrix = Matrix4x4.idenreplacedy;
			Handles.color = AstarColor.BoundsHandles;
#if UNITY_5_5_OR_NEWER
			Handles.CapFunction cap = Handles.CylinderHandleCap;
#else
			Handles.DrawCapFunction cap = Handles.CylinderCap;
#endif

			var center = currentTransform.Transform(new Vector3(0.5f, 0, 0.5f));
			if (Tools.current == Tool.Scale) {
				const float HandleScale = 0.1f;

				Vector3 mn = Vector3.zero;
				Vector3 mx = Vector3.zero;
				EditorGUI.BeginChangeCheck();
				for (int i = 0; i < handlePoints.Length; i++) {
					var ps = currentTransform.Transform(handlePoints[i]);
					Vector3 p = savedTransform.InverseTransform(Handles.Slider(ps, ps - center, HandleScale*HandleUtility.GetHandleSize(ps), cap, 0));

					// Snap to increments of whole nodes
					p.x = Mathf.Round(p.x * savedDimensions.x) / savedDimensions.x;
					p.z = Mathf.Round(p.z * savedDimensions.y) / savedDimensions.y;

					if (i == 0) {
						mn = mx = p;
					} else {
						mn = Vector3.Min(mn, p);
						mx = Vector3.Max(mx, p);
					}
				}

				if (EditorGUI.EndChangeCheck()) {
					graph.center = savedTransform.Transform((mn + mx) * 0.5f);
					graph.unclampedSize = Vector2.Scale(new Vector2(mx.x - mn.x, mx.z - mn.z), savedDimensions) * savedNodeSize;
				}
			} else if (Tools.current == Tool.Move) {
				EditorGUI.BeginChangeCheck();
				center = Handles.PositionHandle(graph.center, Quaternion.idenreplacedy);

				if (EditorGUI.EndChangeCheck() && Tools.viewTool != ViewTool.Orbit) {
					graph.center = center;
				}
			} else if (Tools.current == Tool.Rotate) {
				EditorGUI.BeginChangeCheck();
				var rot = Handles.RotationHandle(Quaternion.Euler(graph.rotation), graph.center);

				if (EditorGUI.EndChangeCheck() && Tools.viewTool != ViewTool.Orbit) {
					graph.rotation = rot.eulerAngles;
				}
			}

			Handles.matrix = Matrix4x4.idenreplacedy;
		}

19 View Source File : GraphUpdateShape.cs
License : MIT License
Project Creator : XINCGer

static Bounds GetBounds (Vector3[] points, Vector3 right, Vector3 up, Vector3 forward, Vector3 origin, float minimumHeight) {
			if (points == null || points.Length == 0) return new Bounds();
			float miny = points[0].y, maxy = points[0].y;
			for (int i = 0; i < points.Length; i++) {
				miny = Mathf.Min(miny, points[i].y);
				maxy = Mathf.Max(maxy, points[i].y);
			}
			var extraHeight = Mathf.Max(minimumHeight - (maxy - miny), 0) * 0.5f;
			miny -= extraHeight;
			maxy += extraHeight;

			Vector3 min = right * points[0].x + up * points[0].y + forward * points[0].z;
			Vector3 max = min;
			for (int i = 0; i < points.Length; i++) {
				var p = right * points[i].x + forward * points[i].z;
				var p1 = p + up * miny;
				var p2 = p + up * maxy;
				min = Vector3.Min(min, p1);
				min = Vector3.Min(min, p2);
				max = Vector3.Max(max, p1);
				max = Vector3.Max(max, p2);
			}
			return new Bounds((min+max)*0.5F + origin, max-min);
		}

19 View Source File : GraphTransform.cs
License : MIT License
Project Creator : XINCGer

public Bounds Transform (Bounds b) {
			if (onlyTranslational) return new Bounds(b.center + translation, b.size);

			var corners = ArrayPool<Vector3>.Claim(8);
			var extents = b.extents;
			corners[0] = Transform(b.center + new Vector3(extents.x, extents.y, extents.z));
			corners[1] = Transform(b.center + new Vector3(extents.x, extents.y, -extents.z));
			corners[2] = Transform(b.center + new Vector3(extents.x, -extents.y, extents.z));
			corners[3] = Transform(b.center + new Vector3(extents.x, -extents.y, -extents.z));
			corners[4] = Transform(b.center + new Vector3(-extents.x, extents.y, extents.z));
			corners[5] = Transform(b.center + new Vector3(-extents.x, extents.y, -extents.z));
			corners[6] = Transform(b.center + new Vector3(-extents.x, -extents.y, extents.z));
			corners[7] = Transform(b.center + new Vector3(-extents.x, -extents.y, -extents.z));

			var min = corners[0];
			var max = corners[0];
			for (int i = 1; i < 8; i++) {
				min = Vector3.Min(min, corners[i]);
				max = Vector3.Max(max, corners[i]);
			}
			ArrayPool<Vector3>.Release(ref corners);
			return new Bounds((min+max)*0.5f, max - min);
		}

19 View Source File : GraphTransform.cs
License : MIT License
Project Creator : XINCGer

public Bounds InverseTransform (Bounds b) {
			if (onlyTranslational) return new Bounds(b.center - translation, b.size);

			var corners = ArrayPool<Vector3>.Claim(8);
			var extents = b.extents;
			corners[0] = InverseTransform(b.center + new Vector3(extents.x, extents.y, extents.z));
			corners[1] = InverseTransform(b.center + new Vector3(extents.x, extents.y, -extents.z));
			corners[2] = InverseTransform(b.center + new Vector3(extents.x, -extents.y, extents.z));
			corners[3] = InverseTransform(b.center + new Vector3(extents.x, -extents.y, -extents.z));
			corners[4] = InverseTransform(b.center + new Vector3(-extents.x, extents.y, extents.z));
			corners[5] = InverseTransform(b.center + new Vector3(-extents.x, extents.y, -extents.z));
			corners[6] = InverseTransform(b.center + new Vector3(-extents.x, -extents.y, extents.z));
			corners[7] = InverseTransform(b.center + new Vector3(-extents.x, -extents.y, -extents.z));

			var min = corners[0];
			var max = corners[0];
			for (int i = 1; i < 8; i++) {
				min = Vector3.Min(min, corners[i]);
				max = Vector3.Max(max, corners[i]);
			}
			ArrayPool<Vector3>.Release(ref corners);
			return new Bounds((min+max)*0.5f, max - min);
		}

19 View Source File : MultiTargetPath.cs
License : MIT License
Project Creator : XINCGer

void RecalculateHTarget (bool firstTime) {
			// When pathsForAll is false
			// then no heuristic should be used
			if (!pathsForAll) {
				heuristic = Heuristic.None;
				heuristicScale = 0.0F;
				return;
			}

			// Calculate a new hTarget and rebuild the open list if necessary
			// Rebuilding the open list is necessary when the H score for nodes changes
			switch (heuristicMode) {
			case HeuristicMode.None:
				heuristic = Heuristic.None;
				heuristicScale = 0F;
				break;
			case HeuristicMode.Average:
				if (!firstTime) return;

				// No break
				// The first time the implementation
				// for Average and MovingAverage is identical
				// so we just use fallthrough
				goto case HeuristicMode.MovingAverage;
			case HeuristicMode.MovingAverage:

				// Pick the average position of all nodes that have not been found yet
				var avg = Vector3.zero;
				int count = 0;
				for (int j = 0; j < targetPoints.Length; j++) {
					if (!targetsFound[j]) {
						avg += (Vector3)targetNodes[j].position;
						count++;
					}
				}

				// Should use replacederts, but they were first added in Unity 5.1
				// so I cannot use them because I want to keep compatibility with 4.6
				// (as of 2015)
				if (count == 0) throw new System.Exception("Should not happen");

				avg /= count;
				hTarget = (Int3)avg;
				break;
			case HeuristicMode.Midpoint:
				if (!firstTime) return;

				// No break
				// The first time the implementation
				// for Midpoint and MovingMidpoint is identical
				// so we just use fallthrough
				goto case HeuristicMode.MovingMidpoint;
			case HeuristicMode.MovingMidpoint:

				Vector3 min = Vector3.zero;
				Vector3 max = Vector3.zero;
				bool set = false;

				// Pick the median of all points that have
				// not been found yet
				for (int j = 0; j < targetPoints.Length; j++) {
					if (!targetsFound[j]) {
						if (!set) {
							min = (Vector3)targetNodes[j].position;
							max = (Vector3)targetNodes[j].position;
							set = true;
						} else {
							min = Vector3.Min((Vector3)targetNodes[j].position, min);
							max = Vector3.Max((Vector3)targetNodes[j].position, max);
						}
					}
				}

				var midpoint = (Int3)((min+max)*0.5F);
				hTarget = midpoint;
				break;
			case HeuristicMode.Sequential:

				// The first time the hTarget should always be recalculated
				// But other times we can skip it if we have not yet found the current target
				// since then the hTarget would just be set to the same value again
				if (!firstTime && !targetsFound[sequentialTarget]) {
					return;
				}

				float dist = 0;

				// Pick the target which is furthest away and has not been found yet
				for (int j = 0; j < targetPoints.Length; j++) {
					if (!targetsFound[j]) {
						float d = (targetNodes[j].position-startNode.position).sqrMagnitude;
						if (d > dist) {
							dist = d;
							hTarget = (Int3)targetPoints[j];
							sequentialTarget = j;
						}
					}
				}
				break;
			}

			// Rebuild the open list since all the H scores have changed
			// However the first time we can skip this since
			// no nodes are added to the heap yet
			if (!firstTime) {
				RebuildOpenList();
			}
		}