Version: Unity 6.6 Alpha (6000.6)
LanguageEnglish
  • C#

FitResult

enumeration

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

Description

Indicates the result of a RectTransform fit operation.

The FitResult enumeration identifies the outcome of RectTransform.TryFitInsideCoplanarRectTransform and RectTransform.FitInsideCoplanarRectTransform. It contains the result of the fit operation, indicating whether it succeeded or failed, and if it failed, the reason for the failure.

using UnityEngine;
using UnityEngine.UI;

public class TooltipController : MonoBehaviour { [SerializeField] RectTransform m_ScreenRectTransform;

[SerializeField] Button m_Button;

RectTransform m_TooltipRectTransform;

void Awake() { m_TooltipRectTransform = GetComponent<RectTransform>(); gameObject.SetActive(false); m_Button.onClick.AddListener(() => { ShowAt(m_Button.GetComponent<RectTransform>()); }); }

public void ShowAt(RectTransform anchor) { gameObject.SetActive(true); m_TooltipRectTransform.position = anchor.position;

// Constrain the tooltip to the container. RectTransform.FitResult fitResult = m_TooltipRectTransform.TryFitInsideCoplanarRectTransform(m_ScreenRectTransform, true); switch (fitResult) { case RectTransform.FitResult.Success: case RectTransform.FitResult.AlreadyInside: Debug.Log("Tooltip fit inside container successfully.", this); break; case RectTransform.FitResult.FailInvalidSizeTarget: Debug.LogWarning("Target container has invalid size and cannot be fit inside.", this); break; case RectTransform.FitResult.FailLargerThanTarget: Debug.LogWarning("Tooltip is larger than container and cannot be shrunk to fit.", this); break; case RectTransform.FitResult.FailNotCoplanar: Debug.LogWarning("Tooltip and container are not on the same canvas plane.", this); break; case RectTransform.FitResult.FailZRotationMismatch: Debug.LogWarning("Tooltip and container have mismatched Z rotations.", this); break; } } }

Properties

Property Description
SuccessThe RectTransform is moved, shrunk, or both, to fit inside the target.
AlreadyInsideThe RectTransform is already fully inside the target. No change is made.
FailLargerThanTargetThe RectTransform is too large to fit inside the target and allowShrink is false. No change is made.
FailNotCoplanarThe RectTransform is not coplanar with the target. No change is made.
FailZRotationMismatchThe RectTransform and the target have different Z rotations. No change is made.
FailInvalidSizeTargetThe target RectTransform has a zero or negative width or height. No change is made.