private void UpdateFitStatus(RaycastHit surfaceHit, Vector3 xAxis, Vector3 zAxis) { // All corners have hit something. if (_cornerAHit.collider != null && _cornerBHit.collider != null && _cornerCHit.collider != null && _cornerDHit.collider != null) { // Obtain the even-ness values. float cornerAEvenness = CheckForEvenSurface(surfaceHit.point, _cornerAHit.point, xAxis, zAxis); float cornerBEvenness = CheckForEvenSurface(surfaceHit.point, _cornerBHit.point, xAxis, zAxis); float cornerCEvenness = CheckForEvenSurface(surfaceHit.point, _cornerCHit.point, xAxis, zAxis); float cornerDEvenness = CheckForEvenSurface(surfaceHit.point, _cornerDHit.point, xAxis, zAxis); // Are we within the maxUneven threshold? float largestBump = Mathf.Max(cornerAEvenness, cornerBEvenness, cornerCEvenness, cornerDEvenness); // Determine if we passed even-ness testing. if (largestBump > _maxUneven) { _fitStatus = FitType.Uneven; } else { // Only set as fits if we are in the correct orientation. if (_fitStatus != FitType.WrongOrientation) { _fitStatus = FitType.Fits; Position = surfaceHit.point + (YAxis * largestBump); } } } else { // We are likely hanging over a physical edge. _fitStatus = FitType.Overhang; } }
public void campusResize(int width, int height, FitType fit, Color color) { Bitmap b = new Bitmap(width, height); Graphics g = Graphics.FromImage(b); // キャンパスを塗りつぶす // g.Clear(color); // スケール計算 // float scale = 1; switch (fit) { case FitType.normal: scale = Math.Min((float)width / (float)_bmp.Width, (float)height / (float)_bmp.Height); break; case FitType.zoom: scale = Math.Max((float)width / (float)_bmp.Width, (float)height / (float)_bmp.Height); break; } int w2 = (int)(_bmp.Width * scale); int h2 = (int)(_bmp.Height * scale); g.DrawImage(_bmp, (width - w2) / 2, (height - h2) / 2, w2, h2); g.Dispose(); _bmp = new Bitmap(b); b.Dispose(); }
//禁用layout的缩放,此时只用到layout的布局,缩放通过UIRoot完成,使用camera拉伸填充屏幕/ //禁用缩放时,为了保证正确的布局,窗口大小取制图的大小,当前使用iphone5屏幕为制图标准/ public static void setUILayout(FitType fitType, UIRoot uiRoot, Camera uiCamera) { mFitType = fitType; switch (fitType) { case FitType.AutoFit: UILayout.disableScale = false; aspectIndex = 2; uiRoot.minimumHeight = 1; uiRoot.maximumHeight = 10000; fullWidth = baseWidth; fullHeight = baseHeight; break; case FitType.KeepAspect: uiFit(); UILayout.disableScale = true; fullWidth = baseWidth = (int)uiSize.x; fullHeight = baseHeight = (int)uiSize.y; //======================== //该方法缩放ui根节点,但特效不受缩放影响 //float k1 = 1.0f*baseHeight/Screen.height; //float k2 = 1.0f*baseWidth/Screen.width; //uiRoot.minimumHeight=uiRoot.maximumHeight=(int)(baseHeight*k2/k1); //======================== uiRoot.minimumHeight = 1; uiRoot.maximumHeight = 10000; uiRoot.scalingStyle = UIRoot.Scaling.FixedSize; uiRoot.manualHeight = baseHeight; //高度决定了root的缩放比例,让根节点scale固定,否则特效和ui不一致 //uiCamera.pixelRect=getGameCameraViewport();//裁剪viewport方式 //========================= float uirootscale = 1.0f * Screen.height / baseHeight; float screenAspect = 1.0f * Screen.width / Screen.height; //WindowManager.camera_size = uiCamera.orthographicSize = screenAspect > aspect ? 1 : uirootscale * baseWidth / Screen.width; fullWidth = screenAspect > aspect?(int)(baseHeight * screenAspect + 0.5f):baseWidth; fullHeight = screenAspect > aspect?baseHeight:(int)(baseWidth / screenAspect + 0.5f); setLace("Lace"); break; case FitType.ScaleFull: uiFit(); UILayout.disableScale = true; baseWidth = (int)uiSize.x; baseHeight = (int)uiSize.y; fullWidth = baseWidth; fullHeight = baseHeight; uiRoot.minimumHeight = uiRoot.maximumHeight = UILayout.baseHeight; //======================== //该方法非对称比例拉伸会导致剪切区域问题/ //float k = (1.0f*UILayout.baseHeight*Screen.width)/(UILayout.baseWidth*Screen.height); //uiCamera.transform.localScale = new Vector3(k,1,1); //======================== uiCamera.aspect = 1.0f * baseWidth / baseHeight; break; } }
IEnumerator RecalcKnoten(GameObject _knoten, FitType _fittype) { yield return(new WaitForEndOfFrame()); _knoten.GetComponent <FlexibleGridLayout>().fitType = _fittype; for (int i = 0; i < _knoten.transform.childCount; i++) { _knoten.transform.GetChild(i).GetComponent <TerminalManager>().fitType = _fittype; } }
private void HandlePlacementEvent(FitType newFit) { if (_placement.Fit == FitType.Fits) { _willFitVolume.SetActive(true); _willNotFitVolume.SetActive(false); } else { _willFitVolume.SetActive(false); _willNotFitVolume.SetActive(true); } }
static void Main(string[] args) { string file = "Example.csv"; using (var reader = new StreamReader(file)) using (var csv = new CsvReader(reader, CultureInfo.InvariantCulture)) { List <ExpandoObject> records = csv.GetRecords <dynamic>().Cast <ExpandoObject>().ToList(); var races = records.Select(x => FitType.CoerceFitType <Race>(x)).ToList(); string raceJson = JsonSerializer.Serialize <List <Race> >(races); Console.WriteLine(raceJson); } }
public static Point Fit(Control parent, Size control, FitType type = FitType.Center) { Point pp = parent.Location; Point pc = new Point();// control.Location; int wp = parent.Width; int hp = parent.Height; int wc = control.Width; int hc = control.Height; int dw = wp - wc; int dh = hp - hc; pc.X = dw / 2; pc.Y = dh / 2; return(pc); }
void Update() { if (!IsRunning) { return; } // Adjust the cast by the tilt value. Quaternion adjustmentQuaternion = Quaternion.AngleAxis(_tilt, _source.right); Vector3 castVector = adjustmentQuaternion * _source.forward; if (Physics.Raycast(_source.position, castVector, out _surfaceHit, _maxDistance, _hitLayers)) { // Set the initial values. Position = _surfaceHit.point; UpdateAdjustedPosition(); Surface = GetSurfaceType(_surfaceHit.normal); _fitStatus = GetFitType(Surface); // Obtain a "perfect" normal since meshed surfaces are not smooth. _normal = GetPerfectNormal(Surface, _surfaceHit.normal); ValidateCorners(_surfaceHit); ValidateVolume(); } else { _fitStatus = FitType.NoSurface; Surface = SurfaceType.Unknown; _normal = Vector3.zero; Position = _source.position + (castVector * _maxDistance); Rotation = Quaternion.LookRotation(-_source.forward); } // Event Notification if (Fit != _fitStatus) { Fit = _fitStatus; if (OnPlacementEvent != null) { OnPlacementEvent.Invoke(_fitStatus); } } }
private void GoDown(FitType fit) { int a = 0; a = this.transform.GetSiblingIndex(); if (a == this.transform.parent.childCount && this.transform.parent.parent.GetComponent <TerminalKnoten>()) { a = this.transform.parent.GetSiblingIndex(); } if (a == this.transform.parent.childCount) { return; //Wenn immernoch a = ende der listen ist dann bist du das oberste Objekt } if (this.transform.GetSiblingIndex() == this.transform.parent.childCount - 1) { try { if (this.transform.parent.parent.GetChild(a + 1).GetComponent <TerminalKnoten>()) { this.transform.parent.parent.GetChild(a + 1).GetChild(0).GetComponent <TerminalClickHandler>().SelectInputField(); } else { this.transform.parent.parent.GetChild(a + 1).GetComponent <TerminalClickHandler>().SelectInputField(); } }catch { //Ein fehler im algoritmus sorgt für ein Transform child out of bounds fehler } } else { if (this.transform.parent.GetChild(a + 1).GetComponent <TerminalKnoten>()) { this.transform.parent.GetChild(a + 1).GetChild(0).GetComponent <TerminalClickHandler>().SelectInputField(); } else { this.transform.parent.GetChild(a + 1).GetComponent <TerminalClickHandler>().SelectInputField(); } } this.transform.tag = "Untagged"; }
private void ValidateVolume() { if (_fitStatus == FitType.Fits) { // Determine if the volume is smaller than our actual volume by uneven allowance as a buffer. Vector3 collisionVolumeSize = Scale * (.5f - _maxUneven); // Check for any volume collisions. Collider[] volumeCollisions = Physics.OverlapBox(AdjustedPosition, collisionVolumeSize, Rotation); if (volumeCollisions.Length > 0) { _fitStatus = FitType.VolumeIntersection; } else { _fitStatus = FitType.Fits; } } }
// Start is called before the first frame update void Start() { // erstelle die erste Zeile manager = new CommandsManager(); manager.ReadFileSystem(GameObject.FindWithTag("RootDictory")); newLine(manager.GetDirectoryPath(), false); newLine("", true); if (this.transform.parent.GetComponent <FlexibleGridLayout>()) { knoten = this.transform.parent.gameObject; } historyPointer = 0; _rawEingabenHistory = new Stack <string>(10); _rawEingabenHistory.Push(" "); _tmphistory = new Stack <string>(10); MonsterAttackEvent.MonsterAttack += MonsterAttacks; fitType = knoten.GetComponent <FlexibleGridLayout>().fitType; }
public static Vector2 Fit(this Vector2 inst, Vector2 tar, FitType type) { float instRate = inst.x / inst.y; float tarRate = tar.x / tar.y; bool isWider = instRate > tarRate; switch (type) { case FitType.X: return(new Vector2(tar.y / inst.y * inst.x, tar.y)); case FitType.Y: return(new Vector2(tar.x, tar.x / inst.x * inst.y)); case FitType.Inside: if (isWider) { return(new Vector2(tar.x, tar.x / instRate)); } else { return(new Vector2(tar.y * instRate, tar.y)); } case FitType.Outside: if (isWider) { return(new Vector2(tar.y * instRate, tar.y)); } else { return(new Vector2(tar.x, tar.x / instRate)); } default: Debug.LogError("Vector2不支持的适应类型:" + type); return(inst); } }
private void GoUp(FitType fit) { int a = 0; a = this.transform.GetSiblingIndex(); if (a == 0 && this.transform.parent.parent.GetComponent <TerminalKnoten>()) { a = this.transform.parent.GetSiblingIndex(); } if (a == 0) { return; //Wenn immernoch a = 0 ist dann bist du das oberste Objekt } if (this.transform.GetSiblingIndex() == 0) { if (this.transform.parent.parent.GetChild(a - 1).GetComponent <TerminalKnoten>()) { this.transform.parent.parent.GetChild(a - 1).GetChild(0).GetComponent <TerminalClickHandler>().SelectInputField(); } else { this.transform.parent.parent.GetChild(a - 1).GetComponent <TerminalClickHandler>().SelectInputField(); } } else { if (this.transform.parent.GetChild(a - 1).GetComponent <TerminalKnoten>()) { this.transform.parent.GetChild(a - 1).GetChild(0).GetComponent <TerminalClickHandler>().SelectInputField(); } else { this.transform.parent.GetChild(a - 1).GetComponent <TerminalClickHandler>().SelectInputField(); } } this.transform.tag = "Untagged"; }
// Update is called once per frame void Update() { if (this.tag == "Fokussed") { if (!Input.GetKey(SuperKey)) { if (Input.GetKeyDown(KeyCode.Return)) { //Die Hauptmethode die alle eingaben lesen kann readInput(); } if (terminalBody.transform.GetChild(terminalBody.transform.childCount - 1).GetComponentInChildren <InputField>().text == "" && Input.GetKeyDown(KeyCode.Backspace)) { while (_tmphistory.Count > 0) { _rawEingabenHistory.Push(_tmphistory.Pop()); } } if (Input.GetKeyDown(KeyCode.UpArrow)) { try { if (_rawEingabenHistory.Count == 0) { return; } InputField input = terminalBody.transform.GetChild(terminalBody.transform.childCount - 1).GetComponentInChildren <InputField>(); input.text = _rawEingabenHistory.Peek(); input.MoveTextEnd(false); _tmphistory.Push(_rawEingabenHistory.Pop()); } catch (Exception e) { Debug.Log(e); } } if (Input.GetKeyDown(KeyCode.DownArrow)) { try { if (_tmphistory.Count == 0) { return; } InputField input = terminalBody.transform.GetChild(terminalBody.transform.childCount - 1).GetComponentInChildren <InputField>(); input.text = _tmphistory.Peek(); input.MoveTextEnd(false); _rawEingabenHistory.Push(_tmphistory.Pop()); } catch (Exception e) { Debug.Log(e); } } } else { if (Input.GetKeyDown(KeyCode.Return)) { if (knoten.GetComponent <FlexibleGridLayout>().fitType != fitType) { GameObject newKnoten = transform.parent.GetComponent <TerminalKnoten>().ErzeugeKnoten(); newKnoten.tag = "Knoten"; GameObject newTerminal = Erzeugen(); this.transform.SetParent(newKnoten.transform); newTerminal.transform.SetParent(newKnoten.transform); this.knoten = newKnoten; StartCoroutine(RecalcKnoten(newKnoten, fitType)); } else { Erzeugen(); } } if (Input.GetKey(KeyCode.LeftAlt) && Input.GetKeyDown(KeyCode.Q)) { Delete(); } if (Input.GetKeyDown(KeyCode.LeftArrow)) { GoUp(FitType.Width); } if (Input.GetKeyDown(KeyCode.UpArrow)) { GoUp(FitType.Heigth); } if (Input.GetKeyDown(KeyCode.RightArrow)) { GoDown(FitType.Width); } if (Input.GetKeyDown(KeyCode.DownArrow)) { GoDown(FitType.Heigth); } //Restliche Eingabe muss abgefragt werden, damit Befehle funktionieren if (Input.GetKeyDown(KeyCode.B)) { fitType = FitType.Heigth; //knoten.GetComponent<FlexibleGridLayout>().fitType = FitType.Heigth; } if (Input.GetKeyDown(KeyCode.V)) { fitType = FitType.Width; //knoten.GetComponent<FlexibleGridLayout>().fitType = FitType.Width; } if (Input.GetKey(KeyCode.LeftShift) && (Input.GetKeyDown(KeyCode.UpArrow) || Input.GetKeyDown(KeyCode.LeftArrow))) { if (transform.GetSiblingIndex() - 1 <= -1) { return; } int index = transform.GetSiblingIndex(); this.transform.parent.GetChild(index - 1).SetSiblingIndex(index); this.GetComponent <TerminalClickHandler>().ClickInputField(); StartCoroutine(this.transform.parent.GetChild(index).GetComponent <TerminalClickHandler>().WaitForUnFokussed()); } if (Input.GetKey(KeyCode.LeftShift) && (Input.GetKeyDown(KeyCode.DownArrow) || Input.GetKeyDown(KeyCode.RightArrow))) { if (this.transform.GetSiblingIndex() + 1 > transform.parent.childCount) { return; } int index = this.transform.GetSiblingIndex(); this.transform.parent.GetChild(index + 1).SetSiblingIndex(index); this.GetComponent <TerminalClickHandler>().ClickInputField(); StartCoroutine(this.transform.parent.GetChild(index).GetComponent <TerminalClickHandler>().WaitForUnFokussed()); } } } }
public static void Fit(Control parent, ref Control control, FitType type = FitType.Center) { control.Location = Locations.Fit(parent, control.Size, type); }
public Node Insert(Block block) { if (!IsALeaf()) { Node newNode = Left.Insert(block); if (newNode != null) { return(newNode); } return(Right.Insert(block)); } // Si es una hoja y esta llena if (Block != null) { return(null); } FitType fitType = GetFitType(block); if (fitType == FitType.Bigger) { return(null); } if (fitType == FitType.Exact) { Vector3 position = new Vector3 { x = X, y = Y, z = Z }; block.Position = position; Block = block; return(this); } int widthSpace = Width - block.Width; int lengthSpace = Length - block.Length; int heightSpace = Height - block.Height; int maxSpace = Math.Max(widthSpace, Math.Max(lengthSpace, heightSpace)); if (maxSpace == widthSpace) { Left = new Node( new Vector3(X, Y, Z), new Vector3(block.Width, Length, Height) ); Right = new Node( new Vector3(X + block.Width, Y, Z), new Vector3(widthSpace, Length, Height) ); } else if (maxSpace == lengthSpace) { Left = new Node( new Vector3(X, Y, Z), new Vector3(Width, block.Length, Height) ); Right = new Node( new Vector3(X, Y + block.Length, Z), new Vector3(Width, lengthSpace, Height) ); } else { Left = new Node( new Vector3(X, Y, Z), new Vector3(Width, Length, block.Height) ); Right = new Node( new Vector3(X, Y, Z + block.Height), new Vector3(Width, Length, heightSpace) ); } return(Left.Insert(block)); }
} // 装备类型 public IEquip() : base() { Type = FitType.Weapon; Name = "Equip"; }
///<summary> ///</summary> ///<param name="node"></param> internal RegionInfo(XmlNode node) { XmlNode childNode = node.Attributes.GetNamedItem("id"); if (childNode != null) Id = childNode.Value; childNode = node.Attributes.GetNamedItem("left"); if (childNode != null) Left = childNode.Value; childNode = node.Attributes.GetNamedItem("top"); if (childNode != null) Top = childNode.Value; childNode = node.Attributes.GetNamedItem("width"); if (childNode != null) Width = childNode.Value; childNode = node.Attributes.GetNamedItem("height"); if (childNode != null) Height = childNode.Value; childNode = node.Attributes.GetNamedItem("fit"); if (childNode != null) Fit = (FitType)Enum.Parse(typeof(FitType), childNode.Value, true); }
public Entity MakeDrawable(String resourceUrl, Int32 zIndex, FitType fitType, IAlignment alignment) { ResourceUrl = resourceUrl; ZIndex = zIndex; FitType = fitType; Alignment = alignment; IsDrawable = true; return this; }
public static Vector2 Fit(this Vector2 inst, float tarX, float tarY, FitType type) { return(inst.Fit(new Vector2(tarX, tarY), type)); }
public Node Insert(Box box) { if (!IsALeaf()) { Node newNode = Left.Insert(box); if (newNode != null) { return(newNode); } return(Right.Insert(box)); } if (Box != null) { return(null); } FitType fitType = GetFitType(box); // La caja es muy grande if (fitType == FitType.Bigger) { return(null); } // La caja es exacta if (fitType == FitType.Exact) { box.X = X; box.Y = Y; // box.Width = Width; // box.Height = Height; this.Box = box; return(this); } // La caja es pequeña // Dividir el nodo //fitType == FitType.SMALLER int horizontalLine = Width - box.Width; int verticalLine = Height - box.Height; if (horizontalLine >= verticalLine) { Left = new Node(X, Y, box.Width, Height); /*Left.X = X; * Left.Y = Y; * Left.Width = box.Width; * Left.Height = Height;*/ Right = new Node(X + box.Width, Y, horizontalLine, Height); /*Right.X = X + box.Width; * Right.Y = Y; * Right.Width = horizontalLine; * Right.Height = Height;*/ } else { Left = new Node(X, Y, Width, box.Height); /*Left.X = X; * Left.Y = Y; * Left.Width = Width; * Left.Height = box.Height;*/ Right = new Node(X, Y + box.Height, Width, verticalLine); /*Right.X = X; * Right.Y = Y + box.Height; * Right.Width = Width; * Right.Height = verticalLine;*/ } return(Left.Insert(box)); }
public static string GetResizedImageUrl(this IHtmlHelper hlp, string originalUrl, int width, int height, FitType fit = FitType.Max) { return(GetResizedImageUrl(originalUrl, width, height, fit)); }
private void SetFitType(FitType type, bool autoSave) { bool isPageFit = type == FitType.Page; bool isHorizonal = type == FitType.Horizonal; bool isVertical = type == FitType.Vertical; bool isView100 = type == FitType.View100; SetChecked(barButtonItemPageFit, isPageFit); SetChecked(barButtonItemHorizontalFit, isHorizonal); SetChecked(barButtonItemVerticalFit, isVertical); SetChecked(barButtonItem100View, isView100); if (autoSave) appSetting.CurrentFitType = type; }
public static void FitColliderToParent(BoxCollider fitInCollider, BoxCollider scaleBoxCollider, BoxCollider realSizeBoxCollider, FitType fitType = FitType.Top) { GameObject childToMove = scaleBoxCollider.gameObject; //it need absolutely to be activate fitInCollider.gameObject.SetActive(true); scaleBoxCollider.gameObject.SetActive(true); realSizeBoxCollider.gameObject.SetActive(true); Vector3 masterBoxSize = fitInCollider.bounds.size; //transform.scale * collider.scale //try to fix something // masterBoxSize.x /= fitInCollider.gameObject.transform.localScale.x; // masterBoxSize.y /= fitInCollider.gameObject.transform.localScale.y; // masterBoxSize.z /= fitInCollider.gameObject.transform.localScale.z; Vector3 itemBoxSize = scaleBoxCollider.bounds.size; // itemBoxSize.x /= scaleBoxCollider.gameObject.transform.localScale.x; // itemBoxSize.y /= scaleBoxCollider.gameObject.transform.localScale.y; // itemBoxSize.z /= scaleBoxCollider.gameObject.transform.localScale.z; masterBoxSize.x = Math.Abs(masterBoxSize.x); masterBoxSize.y = Math.Abs(masterBoxSize.y); masterBoxSize.z = Math.Abs(masterBoxSize.z); itemBoxSize.x = Math.Abs(itemBoxSize.x); itemBoxSize.y = Math.Abs(itemBoxSize.y); itemBoxSize.z = Math.Abs(itemBoxSize.z); //Debug.Log(masterBoxSize + " " + itemBoxSize); //checking scale on each axis Vector3 scaleAxis = new Vector3(); scaleAxis.x = masterBoxSize.x / itemBoxSize.x; scaleAxis.y = masterBoxSize.y / itemBoxSize.y; scaleAxis.z = masterBoxSize.z / itemBoxSize.z; //the biggest win float goodScale = scaleAxis.x < scaleAxis.y ? scaleAxis.x : scaleAxis.y; goodScale = goodScale < scaleAxis.z ? goodScale : scaleAxis.z; scaleBoxCollider.gameObject.transform.localScale *= goodScale; //get the bounds now that it's scaled of the real box Vector3 realSize = realSizeBoxCollider.bounds.size; float heightDiff = masterBoxSize.y - realSize.y; switch (fitType) { case FitType.Top: childToMove.transform.position = new Vector3(childToMove.transform.position.x, childToMove.transform.position.y + heightDiff, childToMove.transform.position.z); break; case FitType.Bottom: childToMove.transform.localPosition = new Vector3(0, 0, 0); break; } }
public static void SetPositionToItemInScrollRect(GameObject item, float padding = 0f, FitType fitType = FitType.Top) { ScrollRect useScrollRect = item.GetComponentInParent <ScrollRect>(); float viewportHeight = useScrollRect.viewport.GetComponent <RectTransform>().rect.height; float contentHeight = useScrollRect.content.GetComponent <RectTransform>().rect.height; float itemPositionY = -item.GetComponent <RectTransform>().localPosition.y; float useHeight = contentHeight - viewportHeight; switch (fitType) { case FitType.Center: padding = viewportHeight / 2 - item.GetComponent <RectTransform>().rect.height / 2 - padding / 2; break; case FitType.Bottom: padding -= viewportHeight; break; } useScrollRect.verticalNormalizedPosition = 1 - ((itemPositionY - padding) / useHeight); //Debug.Log("itemposition = " + item.GetComponent<RectTransform>().localPosition.y); //Debug.Log("viewport = " + useScrollRect.viewport.GetComponent<RectTransform>().rect.height); //Debug.Log("content = " + useScrollRect.content.GetComponent<RectTransform>().rect.height); }
/// <summary> /// https://cdn.buttercms.com/cY4EcqMVS7qCA3IA5apQ /// </summary> /// <param name="originalUrl"></param> /// <param name="width"></param> /// <param name="height"></param> /// <param name="maxSideSize"></param> /// <returns></returns> public static string GetResizedImageUrl(string originalUrl, int width, int height, FitType fit = FitType.Max) { if (string.IsNullOrWhiteSpace(originalUrl)) { return(originalUrl); } var baseUrl = "https://fs.buttercms.com"; var id = originalUrl.Substring(originalUrl.LastIndexOf('/')); string fitType; switch (fit) { case FitType.Clip: fitType = "clip"; break; case FitType.Crop: fitType = "crop"; break; case FitType.Scale: fitType = "scale"; break; case FitType.Max: default: fitType = "max"; break; } var resizeParams = $"resize=width:{width},height:{height},fit:{fitType}"; return($"{baseUrl}/{resizeParams}/{id.Trim('/')}"); }
private void Update() { if (!Running) { return; } //apply volume scale: willFitVolume.transform.localScale = volume; willNotFitVolume.transform.localScale = volume; //evaluate surface: RaycastHit surfaceHit; //tilt cast vector: Quaternion adjustmentQuaternion = Quaternion.AngleAxis(tilt, _source.right); Vector3 castVector = adjustmentQuaternion * _source.forward; if (Physics.Raycast(_source.position, castVector, out surfaceHit, maxDistance)) { //feedback: Debug.DrawLine(_source.position, surfaceHit.point); //set initial position: Position = surfaceHit.point; //autosize: if (scaleVolumeWithDistance) { ScaleVolumeByDistance(); } //phase 1: surface validity Surface = GetSurfaceType(surfaceHit.normal); _fitStatus = SurfaceTypeCheck(Surface); //phase 2: corner evenness if (_fitStatus == FitType.Fits) { //get a "perfect" normal since meshing is not perfect: _yAxis = GetPerfectNormal(Surface, surfaceHit.normal); //find axis: Vector3 xAxis = GetCrossAxis(Surface, _yAxis); Vector3 zAxis = Vector3.Cross(_yAxis, xAxis); //set rotation: if (Surface == SurfaceType.Vertical && matchGravityOnVerticals) { Rotation = Quaternion.LookRotation(_yAxis, Vector3.up); } else { Rotation = Quaternion.LookRotation(zAxis, _yAxis); } //locate each surface-proximity corner: Vector3 halfVolume = volume * .5f; Vector3 cornerA = Vector3.zero; Vector3 cornerB = Vector3.zero; Vector3 cornerC = Vector3.zero; Vector3 cornerD = Vector3.zero; RaycastHit cornerAHit = new RaycastHit(); RaycastHit cornerBHit = new RaycastHit(); RaycastHit cornerCHit = new RaycastHit(); RaycastHit cornerDHit = new RaycastHit(); if (matchGravityOnVerticals && Surface == SurfaceType.Vertical) { cornerA = surfaceHit.point + (zAxis * -halfVolume.y) + (xAxis * -halfVolume.x); cornerB = surfaceHit.point + (zAxis * -halfVolume.y) + (xAxis * halfVolume.x); cornerC = surfaceHit.point + (zAxis * halfVolume.y) + (xAxis * halfVolume.x); cornerD = surfaceHit.point + (zAxis * halfVolume.y) + (xAxis * -halfVolume.x); //find corner-to-surface points: cornerAHit = CornerCast(_yAxis, cornerA, volume.z); cornerBHit = CornerCast(_yAxis, cornerB, volume.z); cornerCHit = CornerCast(_yAxis, cornerC, volume.z); cornerDHit = CornerCast(_yAxis, cornerD, volume.z); } else { cornerA = surfaceHit.point + (zAxis * halfVolume.z) + (xAxis * halfVolume.x); cornerB = surfaceHit.point + (zAxis * halfVolume.z) + (xAxis * -halfVolume.x); cornerC = surfaceHit.point + (zAxis * -halfVolume.z) + (xAxis * -halfVolume.x); cornerD = surfaceHit.point + (zAxis * -halfVolume.z) + (xAxis * halfVolume.x); //find corner-to-surface points: cornerAHit = CornerCast(_yAxis, cornerA, volume.y); cornerBHit = CornerCast(_yAxis, cornerB, volume.y); cornerCHit = CornerCast(_yAxis, cornerC, volume.y); cornerDHit = CornerCast(_yAxis, cornerD, volume.y); } //all corners have hit something: if (cornerAHit.collider != null && cornerBHit.collider != null && cornerCHit.collider != null && cornerDHit.collider != null) { //get evenness values: float cornerAEvenness = EvenSurfaceCheck(surfaceHit.point, cornerAHit.point, xAxis, zAxis); float cornerBEvenness = EvenSurfaceCheck(surfaceHit.point, cornerBHit.point, xAxis, zAxis); float cornerCEvenness = EvenSurfaceCheck(surfaceHit.point, cornerCHit.point, xAxis, zAxis); float cornerDEvenness = EvenSurfaceCheck(surfaceHit.point, cornerDHit.point, xAxis, zAxis); //are we within the maxUneven threshold? float largestBump = Mathf.Max(cornerAEvenness, cornerBEvenness, cornerCEvenness, cornerDEvenness); //determine if we passed evenness testing: if (largestBump > maxUneven) { _fitStatus = FitType.Uneven; } else { _fitStatus = FitType.Fits; Position = surfaceHit.point + (_yAxis * largestBump); } } else { //we are likely hanging over a physical edge: _fitStatus = FitType.Overhang; } //push out if we want to align with gravity while on a wall: if (matchGravityOnVerticals && Surface == SurfaceType.Vertical) { //out: Position += _yAxis * (volume.z * .5f); } } //phase 3: volume clearance if (_fitStatus == FitType.Fits) { //locate the center of our volume: Vector3 centerPoint = Position + (_yAxis * (volume.y * .5f)); //test a volume that is smaller than our actual volume by uneven allowance as a buffer: Vector3 collisionVolumeSize = volume * (.5f - maxUneven); //check for volume collisions: Collider[] volumeCollisions = Physics.OverlapBox(centerPoint, collisionVolumeSize, Rotation); //passed? if (volumeCollisions.Length > 0) { _fitStatus = FitType.VolumeIntersection; } else { _fitStatus = FitType.Fits; } } } else { //feedback: Debug.DrawRay(_source.position, castVector * maxDistance); //status: _fitStatus = FitType.NoSurface; //resets: Surface = SurfaceType.Unknown; Position = _source.position + (castVector * maxDistance); Rotation = Quaternion.LookRotation(-_source.forward); } bool customRuleResult = true; if (_customRule != null) { customRuleResult = _customRule(Position); } if (_fitStatus == FitType.Fits && customRuleResult) { //volume handling: willFitVolume.SetActive(true); willNotFitVolume.SetActive(false); } else { //volume handling: willFitVolume.SetActive(false); willNotFitVolume.SetActive(true); } //pose our volumes: if (_fitStatus == FitType.NoSurface) { willFitVolume.transform.position = Position; willNotFitVolume.transform.position = Position; willFitVolume.transform.rotation = Rotation; willNotFitVolume.transform.rotation = Rotation; } else { Vector3 finalLocation = Vector3.zero; if (matchGravityOnVerticals && Surface == SurfaceType.Vertical) { //finalLocation = Position + (_yAxis * Volume.z * .5f); finalLocation = Position; } else { finalLocation = Position + (_yAxis * volume.y * .5f); } willFitVolume.transform.position = finalLocation; willNotFitVolume.transform.position = finalLocation; willFitVolume.transform.rotation = Rotation; willNotFitVolume.transform.rotation = Rotation; } //broadcast status: if (Fit != _fitStatus) { Fit = _fitStatus; if (OnPlacementEvent != null) { OnPlacementEvent.Invoke(_fitStatus); } } }
public static string GetResizedImageUrl(this IHtmlHelper hlp, string originalUrl, int maxSideSize, FitType fit = FitType.Max) { return(GetResizedImageUrl(originalUrl, maxSideSize, maxSideSize, fit)); }
internal static IndexerChoice GetMatch(PropertyInfo propertyInfo, object[] parameterValues) { if ((propertyInfo == null) || (parameterValues == null)) { return(null); } var parameters = propertyInfo.GetIndexParameters(); if ((parameters == null) || (parameters.Length != parameterValues.Length)) { return(null); } var values = new object[parameters.Length]; var fitTypes = new FitType[parameters.Length]; for (int i = 0; i < parameters.Length; i++) { var parameterType = parameters[i].ParameterType; var parameterValue = parameterValues[i]; var parameterValueType = (parameterValue != null) ? parameterValue.GetType() : typeof(object); if (parameterValue == null) { if (!DataItemTypeDescriptor.IsNullableType(parameterType)) { return(null); } fitTypes[i] = FitType.KeepAsType; } else if (!parameterType.IsAssignableFrom(parameterValueType)) { var converter = TypeDescriptor.GetConverter(parameterType); if ((converter == null) || !converter.CanConvertFrom(parameterValueType)) { return(null); } try { parameterValue = converter.ConvertFrom(null, CultureInfo.InvariantCulture, parameterValue); } catch { return(null); } // An indexer that takes a parameter of any other type than string is considered a better candidate than // an indexer that takes a parameter of type string. fitTypes[i] = (typeof(string).IsAssignableFrom(parameterType)) ? FitType.ConvertToString : FitType.ConvertToType; } else { if (typeof(string) == parameterType) { fitTypes[i] = FitType.KeepAsString; } else if (typeof(object) == parameterType) { fitTypes[i] = FitType.KeepAsObject; } else { fitTypes[i] = FitType.KeepAsType; } } values[i] = parameterValue; } return(new IndexerChoice(propertyInfo, values, fitTypes)); }