private void updateUV() { if (TargetImage.texture == null) { return; } //テクスチャサイズ float tw = TargetImage.texture.width; float th = TargetImage.texture.height; //float tw_half = tw * 0.5f; float th_half = th * 0.5f; //オブジェクト位置 RectTransform rectObjTrans = GetComponent <RectTransform>(); Vector2 o_pos = RectTransformUtility.WorldToScreenPoint(MainCamera, rectObjTrans.position); //オブジェクトサイズ float ow = rectObjTrans.sizeDelta.x; float oh = rectObjTrans.sizeDelta.y; float ow_half = ow * 0.5f; float oh_half = oh * 0.5f; //スクリーンサイズ float sw = MainCamera.pixelWidth; float sh = MainCamera.pixelHeight; //float sw_half = sw * 0.5f; float sh_half = sh * 0.5f; CanvasSetting canvasSetting = MainCanvas.GetComponent <CanvasSetting>(); if (!canvasSetting.IsHeightReference) { float rate = DefaultCanvasSizeX / sw; o_pos *= rate; float tmp0 = (sh_half * rate) - th_half; Vector2 o_pos_lu = new Vector2(o_pos.x - ow_half, o_pos.y - oh_half - tmp0); TargetImage.uvRect = new Rect(o_pos_lu.x / tw, o_pos_lu.y / th, ow / tw, oh / th); } else { float rate = DefaultCanvasSizeY / sh; o_pos *= rate; float tmp0 = (sh_half * rate) - th_half; Vector2 o_pos_lu = new Vector2(o_pos.x - ow_half, o_pos.y - oh_half - tmp0); TargetImage.uvRect = new Rect((o_pos_lu.x + (canvasSetting.GetAddWidth() * 0.5f)) / tw, o_pos_lu.y / th, ow / tw, oh / th); } #if UNITY_EDITOR TargetImage.OnRebuildRequested(); #endif }