Image is a textured element in the UI hierarchy.
Inherited MembersComponent.GetComponentIndex()
Object.InstantiateAsync<T>(T)
Object.InstantiateAsync<T>(T, Transform)
Object.InstantiateAsync<T>(T, Vector3, Quaternion)
Object.InstantiateAsync<T>(T, Transform, Vector3, Quaternion)
Object.InstantiateAsync<T>(T, InstantiateParameters)
Object.InstantiateAsync<T>(T, Vector3, Quaternion, InstantiateParameters)
Object.Instantiate(Object, Scene)
Object.Instantiate<T>(T, InstantiateParameters)
Object.Instantiate<T>(T, Vector3, Quaternion, InstantiateParameters)
Object.FindObjectsByType<T>(FindObjectsSortMode)
Object.FindObjectsByType<T>(FindObjectsInactive, FindObjectsSortMode)
Object.FindFirstObjectByType<T>()
Object.FindAnyObjectByType<T>()
Object.FindFirstObjectByType<T>(FindObjectsInactive)
Object.FindAnyObjectByType<T>(FindObjectsInactive)
Namespace: UnityEngine.UI Assembly: UnityEngine.UI.dll Syntax[RequireComponent(typeof(CanvasRenderer))]
[AddComponentMenu("UI/Image", 11)]
public class Image : MaskableGraphic, ICanvasElement, IClippable, IMaskable, IMaterialModifier, ISerializationCallbackReceiver, ILayoutElement, ICanvasRaycastFilter
Constructors Image() Declaration Fields s_ETC1DefaultUI Declaration
protected static Material s_ETC1DefaultUI
Field Value Properties alphaHitTestMinimumThreshold
The alpha threshold specifies the minimum alpha a pixel must have for the event to considered a "hit" on the Image.
Declarationpublic float alphaHitTestMinimumThreshold { get; set; }
Property Value Examples
using UnityEngine;
using System.Collections;
using UnityEngine.UI; // Required when Using UI elements.
public class ExampleClass : MonoBehaviour
{
public Image theButton;
// Use this for initialization
void Start()
{
theButton.alphaHitTestMinimumThreshold = 0.5f;
}
}
defaultETC1GraphicMaterial
Cache of the default Canvas Ericsson Texture Compression 1 (ETC1) and alpha Material.
Declarationpublic static Material defaultETC1GraphicMaterial { get; }
Property Value eventAlphaThreshold Declaration
[Obsolete("eventAlphaThreshold has been deprecated. Use eventMinimumAlphaThreshold instead (UnityUpgradable) -> alphaHitTestMinimumThreshold")]
public float eventAlphaThreshold { get; set; }
Property Value fillAmount
Amount of the Image shown when the Image.type is set to Image.Type.Filled.
Declarationpublic float fillAmount { get; set; }
Property Value Examples
using UnityEngine;
using System.Collections;
using UnityEngine.UI; // Required when Using UI elements.
public class Cooldown : MonoBehaviour
{
public Image cooldown;
public bool coolingDown;
public float waitTime = 30.0f;
// Update is called once per frame
void Update()
{
if (coolingDown == true)
{
//Reduce fill amount over 30 seconds
cooldown.fillAmount -= 1.0f / waitTime * Time.deltaTime;
}
}
}
fillCenter
Whether or not to render the center of a Tiled or Sliced image.
Declarationpublic bool fillCenter { get; set; }
Property Value Examples
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class FillCenterScript : MonoBehaviour
{
public Image xmasCalenderDoor;
// removes the center of the image to reveal the image behind it
void OpenCalendarDoor()
{
xmasCalenderDoor.fillCenter = false;
}
}
fillClockwise
Whether the Image should be filled clockwise (true) or counter-clockwise (false).
Declarationpublic bool fillClockwise { get; set; }
Property Value Examples
using UnityEngine;
using System.Collections;
using UnityEngine.UI; // Required when Using UI elements.
public class FillClockwiseScript : MonoBehaviour
{
public Image healthCircle;
// This method sets the direction of the health circle.
// Clockwise for the Player, Counter Clockwise for the opponent.
void SetHealthDirection(GameObject target)
{
if (target.tag == "Player")
{
healthCircle.fillClockwise = true;
}
else if (target.tag == "Opponent")
{
healthCircle.fillClockwise = false;
}
}
}
fillMethod Declaration
public Image.FillMethod fillMethod { get; set; }
Property Value fillOrigin
Controls the origin point of the Fill process. Value means different things with each fill method.
Declarationpublic int fillOrigin { get; set; }
Property Value Examples
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
[RequireComponent(typeof(Image))]
public class ImageOriginCycle : MonoBehaviour
{
void OnEnable()
{
Image image = GetComponent<Image>();
string fillOriginName = "";
switch ((Image.FillMethod)image.fillMethod)
{
case Image.FillMethod.Horizontal:
fillOriginName = ((Image.OriginHorizontal)image.fillOrigin).ToString();
break;
case Image.FillMethod.Vertical:
fillOriginName = ((Image.OriginVertical)image.fillOrigin).ToString();
break;
case Image.FillMethod.Radial90:
fillOriginName = ((Image.Origin90)image.fillOrigin).ToString();
break;
case Image.FillMethod.Radial180:
fillOriginName = ((Image.Origin180)image.fillOrigin).ToString();
break;
case Image.FillMethod.Radial360:
fillOriginName = ((Image.Origin360)image.fillOrigin).ToString();
break;
}
Debug.Log(string.Format("{0} is using {1} fill method with the origin on {2}", name, image.fillMethod, fillOriginName));
}
}
flexibleHeight
See ILayoutElement.flexibleHeight.
Declarationpublic virtual float flexibleHeight { get; }
Property Value flexibleWidth
See ILayoutElement.flexibleWidth.
Declarationpublic virtual float flexibleWidth { get; }
Property Value hasBorder
Whether the Sprite of the image has a border to work with.
Declarationpublic bool hasBorder { get; }
Property Value layoutPriority
See ILayoutElement.layoutPriority.
Declarationpublic virtual int layoutPriority { get; }
Property Value mainTexture
Image's texture comes from the UnityEngine.Image.
Declarationpublic override Texture mainTexture { get; }
Property Value Overrides material
The specified Material used by this Image. The default Material is used instead if one wasn't specified.
Declarationpublic override Material material { get; set; }
Property Value Overrides minHeight
See ILayoutElement.minHeight.
Declarationpublic virtual float minHeight { get; }
Property Value minWidth
See ILayoutElement.minWidth.
Declarationpublic virtual float minWidth { get; }
Property Value multipliedPixelsPerUnit Declaration
protected float multipliedPixelsPerUnit { get; }
Property Value overrideSprite
Set an override sprite to be used for rendering.
Declarationpublic Sprite overrideSprite { get; set; }
Property Value Examples
Note: The script example below has two buttons. The button textures are loaded from the /Resources/ folder. (They are not used in the shown example). Two sprites are added to the example code. /Example1/ and /Example2/ are functions called by the button OnClick functions. Example1 calls overrideSprite and Example2 sets overrideSprite to null.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class ExampleClass : MonoBehaviour
{
private Sprite sprite1;
private Sprite sprite2;
private Image i;
public void Start()
{
i = GetComponent<Image>();
sprite1 = Resources.Load<Sprite>("texture1");
sprite2 = Resources.Load<Sprite>("texture2");
i.sprite = sprite1;
}
// Called by a Button OnClick() with ExampleClass.Example1
// Uses overrideSprite to make this change temporary
public void Example1()
{
i.overrideSprite = sprite2;
}
// Called by a Button OnClick() with ExampleClass.Example2
// Removes the overrideSprite which causes the original sprite to be used again.
public void Example2()
{
i.overrideSprite = null;
}
}
pixelsPerUnit Declaration
public float pixelsPerUnit { get; }
Property Value pixelsPerUnitMultiplier
Pixel per unit modifier to change how sliced sprites are generated.
Declarationpublic float pixelsPerUnitMultiplier { get; set; }
Property Value preferredHeight
If there is a sprite being rendered returns the size of that sprite. In the case of a slided or tiled sprite will return the calculated minimum size possible
Declarationpublic virtual float preferredHeight { get; }
Property Value preferredWidth
If there is a sprite being rendered returns the size of that sprite. In the case of a slided or tiled sprite will return the calculated minimum size possible
Declarationpublic virtual float preferredWidth { get; }
Property Value preserveAspect
Whether this image should preserve its Sprite aspect ratio.
Declarationpublic bool preserveAspect { get; set; }
Property Value sprite
The sprite that is used to render this image.
Declarationpublic Sprite sprite { get; set; }
Property Value Examples
//Attach this script to an Image GameObject and set its Source Image to the Sprite you would like.
//Press the space key to change the Sprite. Remember to assign a second Sprite in this script's section of the Inspector.
using UnityEngine;
using UnityEngine.UI;
public class Example : MonoBehaviour
{
Image m_Image;
//Set this in the Inspector
public Sprite m_Sprite;
void Start()
{
//Fetch the Image from the GameObject
m_Image = GetComponent<Image>();
}
void Update()
{
//Press space to change the Sprite of the Image
if (Input.GetKey(KeyCode.Space))
{
m_Image.sprite = m_Sprite;
}
}
}
type
How to display the image.
Declarationpublic Image.Type type { get; set; }
Property Value useSpriteMesh
Allows you to specify whether the UI Image should be displayed using the mesh generated by the TextureImporter, or by a simple quad mesh.
Declarationpublic bool useSpriteMesh { get; set; }
Property Value Methods CalculateLayoutInputHorizontal()
See ILayoutElement.CalculateLayoutInputHorizontal.
Declarationpublic virtual void CalculateLayoutInputHorizontal()
CalculateLayoutInputVertical()
See ILayoutElement.CalculateLayoutInputVertical.
Declarationpublic virtual void CalculateLayoutInputVertical()
DisableSpriteOptimizations()
Disable all automatic sprite optimizations.
Declarationpublic void DisableSpriteOptimizations()
IsRaycastLocationValid(Vector2, Camera)
Calculate if the ray location for this image is a valid hit location. Takes into account a Alpha test threshold.
Declarationpublic virtual bool IsRaycastLocationValid(Vector2 screenPoint, Camera eventCamera)
Parameters Type Name Description Vector2 screenPoint
The screen point to check against
Camera eventCameraThe camera in which to use to calculate the coordinating position
Returns Type Description boolIf the location is a valid hit or not.
OnAfterDeserialize()See ISerializationCallbackReceiver.
Declarationpublic virtual void OnAfterDeserialize()
OnBeforeSerialize()
See ISerializationCallbackReceiver.
Declarationpublic virtual void OnBeforeSerialize()
OnCanvasHierarchyChanged()
Called when the state of the parent Canvas is changed.
Declarationprotected override void OnCanvasHierarchyChanged()
Overrides OnDidApplyAnimationProperties() Declaration
protected override void OnDidApplyAnimationProperties()
Overrides OnDisable()
Clear references.
Declarationprotected override void OnDisable()
Overrides OnEnable()
Mark the Graphic and the canvas as having been changed.
Declarationprotected override void OnEnable()
Overrides OnPopulateMesh(VertexHelper)
Update the UI renderer mesh.
Declarationprotected override void OnPopulateMesh(VertexHelper toFill)
Parameters Overrides OnValidate() Declaration
protected override void OnValidate()
Overrides SetNativeSize()
Adjusts the image size to make it pixel-perfect.
Declarationpublic override void SetNativeSize()
Overrides UpdateMaterial()
Update the renderer's material.
Declarationprotected override void UpdateMaterial()
Overrides Implements
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4