/// <summary> /// Bring in elements that need to be known to this object, set properties related to this object and set the UI accordingly /// </summary> public void SetUp(bool usable, CrewMember crewMember, int mood, TrackerTriggerSource source = TrackerTriggerSource.TeamManagementScreen) { CrewMember = crewMember; Current = crewMember.Current(); Usable = usable; _source = source; _borderImage = GetComponent <Image>(); _backImage = transform.FindImage("AvatarIcon"); _button = GetComponent <Button>(); _avatarDisplay = GetComponentInChildren <AvatarDisplay>(); _positionImage = transform.FindImage("Position"); _positionButton = transform.FindButton("Position"); _nameText = transform.FindText("Name"); _sortImage = transform.FindImage("Sort"); _sortText = transform.FindText("Sort/Sort Text"); _aspectFitter = GetComponent <AspectRatioFitter>(); _defaultParent = transform.parent; _nameText.text = CrewMember.FirstInitialLastName(); _backImage.color = Usable ? new Color(0, 1, 1) : Current ? new Color(0, 0.5f, 0.5f) : Color.white; _borderImage.color = ShowEmotion ? AvatarDisplay.MoodColor(mood) : Current ? Color.grey : Color.black; UpdateAvatar(mood); _button.enabled = Current && GameManagement.SeasonOngoing; _positionButton.enabled = GameManagement.SeasonOngoing; _aspectFitter.aspectMode = Usable ? AspectRatioFitter.AspectMode.FitInParent : AspectRatioFitter.AspectMode.WidthControlsHeight; }
/// <summary> /// 父节点为显示的最大区域 /// </summary> /// <param name="image"></param> public static void SetImageSuitable(Image image) { if (image == null) { return; } float spriteWidth = 0; float spriteHeight = 0; if (image.sprite != null && image.sprite.texture != null) { spriteWidth = image.sprite.texture.width; spriteHeight = image.sprite.texture.height; } else { return; } AspectRatioFitter arf = image.GetComponent <AspectRatioFitter>(); if (arf == null) { arf = image.gameObject.AddComponent <AspectRatioFitter>(); } arf.aspectMode = AspectRatioFitter.AspectMode.FitInParent; arf.aspectRatio = spriteWidth / spriteHeight; }
// カメラ画像を受信 public void UpdateCameraImage(string msg) { // データの先頭についている "data:image/png;base64," という部分を取り除く var data = msg.Split(','); if (data.Length <= 1) { return; } var image = data[1]; // テクスチャが作成されていない場合 if (arCameraTexture == null) { // 新しいテクスチャを作成 arCameraTexture = new Texture2D(1, 1); // AspectRatioFitter コンポーネントを追加 // アスペクト比を保ったまま画像を最大化させる aspectRationFitter = ARCameraImage.gameObject.AddComponent<AspectRatioFitter>(); aspectRationFitter.aspectMode = AspectRatioFitter.AspectMode.FitInParent; } // base64 エンコードされた文字列を元に戻す byte[] bytes = System.Convert.FromBase64String(image); // 画像をテクスチャにロード arCameraTexture.LoadImage(bytes); ARCameraImage.texture = arCameraTexture; // アスペクト比をカメラ画像に合わせて設定 aspectRationFitter.aspectRatio = (float)arCameraTexture.width / arCameraTexture.height; }
private void Log(Message message, Canvas WorldCanvas) { if (message.type == LogMessageType.Debug) { Debug.Log(message.message); } if (message.type == LogMessageType.World && WorldCanvas != null) { WorldText.Enqueue(message.message); if (WorldText.Count > 20) { WorldText.Dequeue(); } if (WorldTextComponent == null) { GameObject WorldTextGameObject = new GameObject("World text"); WorldTextGameObject.transform.SetParent(WorldCanvas.transform); AspectRatioFitter aspect = WorldTextGameObject.AddComponent <AspectRatioFitter>(); aspect.aspectRatio = 1.7777f; aspect.aspectMode = AspectRatioFitter.AspectMode.FitInParent; WorldTextComponent = WorldTextGameObject.AddComponent <Text>(); WorldTextComponent.font = LoggingFont; WorldTextComponent.material = LoggingFont.material; } WorldTextComponent.text = string.Join("\n", WorldText); } }
/// <summary>Setup <see cref="Background"/> to work in augmented reality mode.</summary> /// <remarks> /// This should be called after <see cref="FindAndSetupBackgroundCanvas"/>, to make sure that any /// changes in <see cref="Background"/>'s <see cref="RectTransform"/> reflect the final settings /// of its parent <see cref="Canvas"/>. /// </remarks> private void SetupBackground() { // Check if an Aspect Ratio Fitter has been added to the Background UI element, adding one now // if not. This component is needed to make sure the Background UI element is correctly // displayed for screens with different aspect ratios and orientations. BackgroundFitter = Background.GetComponent <AspectRatioFitter>(); if (BackgroundFitter == null) { Debug.LogWarningFormat("No {0} found on {1} defined as {2}.{3}.Background.\nA {0} is needed " + "to make sure the rendered AR view is correctly scaled to screens of different aspect " + "ratios and orientations.\nAdding an {0} now.", typeof(AspectRatioFitter), typeof(RawImage), name, GetType()); BackgroundFitter = Background.gameObject.AddComponent <AspectRatioFitter>(); BackgroundFitter.aspectRatio = ScreenDimensions.x / ScreenDimensions.y; BackgroundFitter.aspectMode = AspectRatioFitter.AspectMode.HeightControlsWidth; } // Store Background's RectTransform, and make sure it is stretched to fill its parent Canvas. BackgroundRect = Background.rectTransform; if (AreDifferent(BackgroundRect.offsetMin, Vector2.zero) || AreDifferent(BackgroundRect.offsetMin, Vector2.zero) || AreDifferent(BackgroundRect.anchorMin, Vector2.zero) || AreDifferent(BackgroundRect.anchorMax, Vector2.one)) { Debug.LogWarningFormat("Defined {0}.{1}.Background ({2}) did not fill the screen.\nAdjusting " + "{2}'s RectTransform so that the default background image is relative to screen size.", name, GetType(), Background.name); BackgroundRect.offsetMin = Vector2.zero; BackgroundRect.offsetMax = Vector2.zero; BackgroundRect.anchorMin = Vector2.zero; BackgroundRect.offsetMax = Vector2.one; } }
static void FitAnchorsToRect() { foreach (GameObject go in Selection.gameObjects) { RectTransform selectedRT = go.GetComponent <RectTransform>(); RectTransform parentRT = null; if (go.transform.parent) { parentRT = go.transform.parent.GetComponent <RectTransform>(); } if (!selectedRT || !parentRT) { continue; } AspectRatioFitter arf = selectedRT.GetComponent <AspectRatioFitter>(); bool arfDisabled = false; if (arf && arf.enabled) { arf.enabled = false; arfDisabled = true; } Undo.RecordObject(selectedRT, "Change Anchor"); selectedRT.anchorMin = new Vector2(selectedRT.anchorMin.x + selectedRT.offsetMin.x / parentRT.rect.width, selectedRT.anchorMin.y + selectedRT.offsetMin.y / parentRT.rect.height); selectedRT.anchorMax = new Vector2(selectedRT.anchorMax.x + selectedRT.offsetMax.x / parentRT.rect.width, selectedRT.anchorMax.y + selectedRT.offsetMax.y / parentRT.rect.height); selectedRT.offsetMin = selectedRT.offsetMax = Vector2.zero; if (arfDisabled) { arf.enabled = true; } } }
public void TearDown() { GameObject.DestroyImmediate(m_PrefabRoot); m_PrefabRoot = null; m_AspectRatioFitter = null; m_RectTransform = null; }
void Start() { /* * Layout Element * 点开image,属性面板中的最下面,点开可以看到左上角有一个上下的选项,选择LayoutProperties * 此时可以看到,UI对象隐藏自带的 Layout Element 属性 * 当然,我们可以给UI添加 Layout Element 组件,用来精确控制子物体的属性值 */ LayoutElement element = Imgelement.GetComponent <LayoutElement>(); /* * 通过拉伸verGroup的高度看出效果 */ VerticalLayoutGroup verGroup = ImgLayoutGroup.GetComponent <VerticalLayoutGroup>(); /* * */ GridLayoutGroup gridGruoup = ImgGridLayout.GetComponent <GridLayoutGroup>(); ContentSizeFitter sizefitter = ImgContentSize.GetComponent <ContentSizeFitter>(); sizefitter.horizontalFit = ContentSizeFitter.FitMode.Unconstrained; sizefitter.horizontalFit = ContentSizeFitter.FitMode.MinSize; sizefitter.horizontalFit = ContentSizeFitter.FitMode.PreferredSize; AspectRatioFitter aspect = ImgAspect.GetComponent <AspectRatioFitter>(); aspect.aspectMode = AspectRatioFitter.AspectMode.None; aspect.aspectRatio = 1; }
private void OnEnable() { front = false; arf = GetComponent <AspectRatioFitter>(); image = GetComponent <RawImage>(); WebCamDevice[] devices = WebCamTexture.devices; if (devices.Length == 0) { Debug.Log("No camera detected !"); return; } for (int i = 0; i < devices.Length; i++) { if (!devices[i].isFrontFacing) { FrontCam = devices[i]; CurrentCam = devices[i]; Tex = new WebCamTexture(CurrentCam.name, Screen.width, Screen.height, 30); } else { BackCam = devices[i]; } } Tex.Play(); image.texture = Tex; }
public void AddItem() { GameObject item = new GameObject("item"); Image imgItem = item.AddComponent <Image> (); AddRightClickEvent(item); UnityEngine.UI.Button btnItem = item.AddComponent <UnityEngine.UI.Button> (); Sprite sprite = Ultils.ChangeOffset(texture); imgItem.sprite = sprite; AspectRatioFitter ratioFitter = item.AddComponent <AspectRatioFitter> (); ratioFitter.aspectRatio = sprite.rect.width / sprite.rect.height; ratioFitter.aspectMode = AspectRatioFitter.AspectMode.HeightControlsWidth; item.transform.SetParent(currentButtonContainer.transform, false); item.transform.localScale = Vector3.one; item.transform.localPosition = Vector3.zero; IsoObjectFactory factory = item.AddComponent <IsoObjectFactory> (); factory.FilePath = path; factory.offset = PivotEditForm.realSpriteOffset; IsoLayerManager.currentLayer.isoFactories.Add(factory); btnItem.onClick.AddListener(() => { loadedImage = btnItem.image.sprite; IsoObjectFactory.instance = factory; IsoLayerManager.currentLayer.NewObject(); }); }
void Start() { _rawImage = GetComponent <RawImage>(); _aspectRatioFitter = GetComponent <AspectRatioFitter>(); _audioSource = GetComponent <AudioSource>(); Play(0); }
void UpdateCamera() { /** Credit https://bit.ly/2ImTiPm **/ if (camTexture.width < 100) { return; } RectTransform rectTransform = GetComponent <RectTransform>(); AspectRatioFitter aspectRatioFitter = GetComponent <AspectRatioFitter>(); RawImage rawImage = GetComponent <RawImage>(); int cwNeeded = camTexture.videoRotationAngle; int ccwNeeded = -cwNeeded; if (camTexture.videoVerticallyMirrored) { ccwNeeded += 180; } rectTransform.localEulerAngles = new Vector3(0f, 0f, ccwNeeded); float videoRatio = (float)camTexture.width / (float)camTexture.height; aspectRatioFitter.aspectRatio = videoRatio; if (camTexture.videoVerticallyMirrored) { rawImage.uvRect = new Rect(1, 0, -1, 1); } else { rawImage.uvRect = new Rect(0, 0, 1, 1); } }
// Configuration void SetImage(Texture image) { this.image.texture = image; AspectRatioFitter arf = this.image.gameObject.GetComponent <AspectRatioFitter> (); arf.aspectRatio = (float)image.width / (float)image.height; }
//========================================================================= #region Unity events private void Awake() { AspectRatioFitter ratioFitter = this.gameObject.AddComponent <AspectRatioFitter>(); ratioFitter.aspectMode = AspectRatioFitter.AspectMode.FitInParent; ratioFitter.aspectRatio = 1.777778f; }
public static void CreateCoverFlow(MenuCommand menuCommand) { //从asset中获取coverflow参数 CoverFlowParameters.Instance = AssetDatabase.LoadAssetAtPath <CoverFlowParameters>("Assets/Settings/CoverFlowParameters.asset"); CoverFlowParameters coverFlowParameters = CoverFlowParameters.Instance; //CoverFlow根对象 GameObject coverflow = new GameObject("CoverFlow"); RectTransform coverflowRTrs = coverflow.AddComponent <RectTransform>(); Transform parent = (menuCommand.context as GameObject).transform; coverflow.transform.SetParent(parent, false); CoverFlowBehavior coverFlowBehavior = coverflow.AddComponent <CoverFlowBehavior>(); coverFlowBehavior.imageHeight = coverFlowParameters.imageSizeDelta.y; //CoverFlow图片子对象 for (int i = 0; i < coverFlowParameters.imageCount; i++) { GameObject image = new GameObject("Image" + i); RectTransform imageRTrs = image.AddComponent <RectTransform>(); image.transform.SetParent(coverflowRTrs, false); imageRTrs.sizeDelta = coverFlowParameters.imageSizeDelta; image.AddComponent <RawImage>(); AspectRatioFitter aspectRatioFitter = image.AddComponent <AspectRatioFitter>(); aspectRatioFitter.aspectMode = AspectRatioFitter.AspectMode.HeightControlsWidth; CoverFlowImageBehavior coverFlowImageBehavior = image.AddComponent <CoverFlowImageBehavior>(); coverFlowImageBehavior.coverFlowIndex = i - coverFlowParameters.imageCount / 2; } }
private void Awake() { bgImage = GetComponent <Image>(); bgImage.enabled = false; rootRT = SimulatorManager.Instance.UIManager.VisualizerCanvasGO.GetComponent <RectTransform>(); HeaderRT.gameObject.SetActive(false); ContractTextGO.SetActive(false); ExpandTextGO.SetActive(false); windowSize = new Vector2(Screen.width / 4f, Screen.height / 4f); fullSize = new Vector2(Screen.width, Screen.height); rt = GetComponent <RectTransform>(); headerAnchoredYPos = HeaderRT.anchoredPosition.y; CurrentWindowSizeType = WindowSizeType.Window; CameraRawImage = CameraVisualGO.GetComponentInChildren <RawImage>(); cameraRT = CameraVisualGO.GetComponent <RectTransform>(); ValuesText = ValuesVisualGO.GetComponent <Text>(); fitter = CameraVisualGO.GetComponentInChildren <AspectRatioFitter>(); windowResizers = GetComponentsInChildren <VisualizerWindowResize>(true).ToList(); windowResizers.ForEach(win => win.gameObject.SetActive(true)); CameraVisualGO.SetActive(false); ValuesVisualGO.SetActive(false); UpdateWindowSize((int)CurrentWindowSizeType); }
private void Start() { AspectRatioFitter ar = GetComponent <AspectRatioFitter>(); Sprite sprite = image.sprite; ar.aspectRatio = sprite.rect.width / sprite.rect.height; }
void Start() { Rect rect = GetComponent <Image>().sprite.rect; AspectRatioFitter fitter = GetComponent <AspectRatioFitter>(); fitter.aspectRatio = rect.width / rect.height; }
// Use this for initialization private void Start() { var devices = WebCamTexture.devices; aspectRatioFitter = showCameraDisplay.GetComponent <AspectRatioFitter>(); aspectRatioFitter.aspectMode = AspectRatioFitter.AspectMode.EnvelopeParent; if (devices.Length == 0) { print("Not found any device"); return; } for (int i = 0; i < devices.Length; i++) { if (devices[i].isFrontFacing == getFrontFacing) { cameraTexture = new WebCamTexture(devices[i].name, Screen.width, Screen.height); break; } } if (cameraTexture == null) { return; } cameraTexture.Play(); // Start the camera showCameraDisplay.texture = cameraTexture; // Set the texture on UI cameraAvailable = true; // Set the camAvailable for future purposes. }
public void InitWebcam(RawImage image, AspectRatioFitter fit) { devices = WebCamTexture.devices; if (devices.Length == 0) { camAvailable = false; return; } this.image = image; this.fit = fit; defaultBackground = image.texture; for (int a = 0; a < devices.Length; a++) { if (devices[a].isFrontFacing) { webcam = new WebCamTexture(devices[a].name, Screen.width, Screen.height); } } if (webcam == null) { return; } webcam.Play(); image.texture = webcam; camAvailable = true; }
void Awake() { if (Screen.width == 2436 && Screen.height == 1125) { if (!Reduce) { AspectRatioFitter aspectRatioFitter = GetComponent <AspectRatioFitter>(); if (aspectRatioFitter) { aspectRatioFitter.aspectRatio = 2.165333f; } else { RectTransform rectTransform = transform as RectTransform; if (rectTransform.anchorMax.x == 1f) { rectTransform.offsetMin = new Vector2(rectTransform.offsetMin.x - 44f, rectTransform.offsetMin.y); rectTransform.offsetMax = new Vector2(rectTransform.offsetMax.x + 44f, rectTransform.offsetMax.y); } } } else { RectTransform rectTransform = transform as RectTransform; rectTransform.offsetMin = new Vector2(44f, 0f); rectTransform.offsetMax = new Vector2(-44f, 0f); } } }
void Awake() { aspectRatioFitter = GetComponent <AspectRatioFitter>(); rawImage = GetComponent <RawImage>(); try { Application.RequestUserAuthorization(UserAuthorization.WebCam); if (WebCamTexture.devices.Length == 0) { Debug.LogWarning("No 🎥 cameras found"); } else { // Get Main Camera == Back Camera webCamTexture = new WebCamTexture( WebCamTexture.devices[0].name, Screen.width, Screen.height, 30); Play(); rawImage.texture = webCamTexture; } } catch (System.Exception e) { Debug.LogWarning("Camera 🎥 is not available: " + e); } }
void Awake() { aspectRatioFitter = targetImage.GetComponent <AspectRatioFitter>(); grayButton.onClick.AddListener(OnGray); binaryButton.interactable = false; binaryButton.onClick.AddListener(OnBinary); }
void AddRatioFitter(GameObject item, Image imgItem) { AspectRatioFitter ratioFitter = item.AddComponent <AspectRatioFitter> (); ratioFitter.aspectRatio = imgItem.sprite.rect.width / imgItem.sprite.rect.height; ratioFitter.aspectMode = AspectRatioFitter.AspectMode.HeightControlsWidth; }
protected GameObject CreateTextureWidget( string name, GameObject parent, Texture2D tex, Vector2 anchorMin, Vector2 anchorMax, bool fixAspectRatio = false, Vector2 offsetMin = new Vector2(), Vector2 offsetMax = new Vector2()) { GameObject widget = new GameObject(name); RectTransform transform = widget.AddComponent <RectTransform>(); Image plotImage = widget.AddComponent <Image>(); transform.SetParent(parent.transform, false); transform.anchorMin = anchorMin; transform.anchorMax = anchorMax; transform.offsetMin = offsetMin; transform.offsetMax = offsetMax; plotImage.overrideSprite = Sprite.Create(tex, new Rect(0, 0, tex.width, tex.height), new Vector2(0, 0), 100f); if (fixAspectRatio) { AspectRatioFitter fitter = widget.AddComponent <AspectRatioFitter>(); fitter.aspectMode = AspectRatioFitter.AspectMode.FitInParent; fitter.aspectRatio = tex.width / (float)tex.height; } return(widget); }
void Awake() { cameraImage = GetComponent <RawImage>(); cameraAspectRatioFitter = GetComponent <AspectRatioFitter>(); animaAspectRatioFitter = animaImage.GetComponent <AspectRatioFitter>(); Screen.sleepTimeout = SleepTimeout.NeverSleep; }
// Use this for initialization void Start() { m_inputManager = GameObject.Find("ARCamera").GetComponent <SelfieInputManager>(); m_button = GetComponent <Button>(); m_button.onClick.AddListener(OnDecorationButtonClick); m_decorationSlotImage = GetComponent <Image>(); m_decorationSprite = m_decorationSlotImage.sprite; RectTransform rectTransform = transform as RectTransform; m_canvas = GameObject.FindWithTag("Canvas"); m_decoration = transform.GetChild(0) as RectTransform; m_aspectRatioFitter = m_decoration.GetComponent <AspectRatioFitter>(); m_decoration.sizeDelta = rectTransform.sizeDelta; m_decoration.GetComponent <Image>().sprite = m_decorationSprite; //m_decoration.SetActive(false); //m_decoration.transform.parent = gameObject.transform; //m_originalColor = m_decorationImage.color; Color deactiveColor; ColorUtility.TryParseHtmlString("#0000007D", out deactiveColor); m_decorationSlotImage.color = deactiveColor; //m_decorationSlotImage m_decoration.gameObject.SetActive(m_isActive); }
private void InitializeComponentsIfRequired() { if (!IsComponentsInitialized) { image = GetComponent <Image>(); aspectRatioFitter = GetComponent <AspectRatioFitter>(); } }
private void setupController(TWLoadingImageLib loadImageLibrary, ImageLoadType imageLoadType) { aspectRatioFitter = loadImage.gameObject.GetComponent <AspectRatioFitter>(); this.loadImageLibrary = loadImageLibrary; changeImageLoadAspectFitter(imageLoadType); }
void OnEnable() { arf = GetComponent <AspectRatioFitter> (); image = GetComponent <RawImage>(); cam = new WebCamTexture(Screen.width, Screen.height); image.texture = cam; cam.Play(); }