-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat: added simple image retrieve UI object (#235)
- Loading branch information
1 parent
81f703e
commit 10bcb83
Showing
15 changed files
with
217 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
%YAML 1.1 | ||
%TAG !u! tag:unity3d.com,2011: | ||
--- !u!1 &7225474628005434785 | ||
GameObject: | ||
m_ObjectHideFlags: 0 | ||
m_CorrespondingSourceObject: {fileID: 0} | ||
m_PrefabInstance: {fileID: 0} | ||
m_PrefabAsset: {fileID: 0} | ||
serializedVersion: 6 | ||
m_Component: | ||
- component: {fileID: 6521834947971461802} | ||
- component: {fileID: 3735591345964488943} | ||
- component: {fileID: 5031392240167187892} | ||
- component: {fileID: 6280177048631039952} | ||
m_Layer: 5 | ||
m_Name: Image | ||
m_TagString: Untagged | ||
m_Icon: {fileID: 0} | ||
m_NavMeshLayer: 0 | ||
m_StaticEditorFlags: 0 | ||
m_IsActive: 1 | ||
--- !u!224 &6521834947971461802 | ||
RectTransform: | ||
m_ObjectHideFlags: 0 | ||
m_CorrespondingSourceObject: {fileID: 0} | ||
m_PrefabInstance: {fileID: 0} | ||
m_PrefabAsset: {fileID: 0} | ||
m_GameObject: {fileID: 7225474628005434785} | ||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} | ||
m_LocalPosition: {x: 0, y: 0, z: 0} | ||
m_LocalScale: {x: 1, y: 1, z: 1} | ||
m_ConstrainProportionsScale: 0 | ||
m_Children: [] | ||
m_Father: {fileID: 0} | ||
m_RootOrder: -1 | ||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} | ||
m_AnchorMin: {x: 0.5, y: 0.5} | ||
m_AnchorMax: {x: 0.5, y: 0.5} | ||
m_AnchoredPosition: {x: -16, y: 0} | ||
m_SizeDelta: {x: 100, y: 100} | ||
m_Pivot: {x: 0.5, y: 0.5} | ||
--- !u!222 &3735591345964488943 | ||
CanvasRenderer: | ||
m_ObjectHideFlags: 0 | ||
m_CorrespondingSourceObject: {fileID: 0} | ||
m_PrefabInstance: {fileID: 0} | ||
m_PrefabAsset: {fileID: 0} | ||
m_GameObject: {fileID: 7225474628005434785} | ||
m_CullTransparentMesh: 1 | ||
--- !u!114 &5031392240167187892 | ||
MonoBehaviour: | ||
m_ObjectHideFlags: 0 | ||
m_CorrespondingSourceObject: {fileID: 0} | ||
m_PrefabInstance: {fileID: 0} | ||
m_PrefabAsset: {fileID: 0} | ||
m_GameObject: {fileID: 7225474628005434785} | ||
m_Enabled: 1 | ||
m_EditorHideFlags: 0 | ||
m_Script: {fileID: 11500000, guid: fe87c0e1cc204ed48ad3b37840f39efc, type: 3} | ||
m_Name: | ||
m_EditorClassIdentifier: | ||
m_Material: {fileID: 0} | ||
m_Color: {r: 1, g: 1, b: 1, a: 1} | ||
m_RaycastTarget: 1 | ||
m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0} | ||
m_Maskable: 1 | ||
m_OnCullStateChanged: | ||
m_PersistentCalls: | ||
m_Calls: [] | ||
m_Sprite: {fileID: 0} | ||
m_Type: 0 | ||
m_PreserveAspect: 0 | ||
m_FillCenter: 1 | ||
m_FillMethod: 4 | ||
m_FillAmount: 1 | ||
m_FillClockwise: 1 | ||
m_FillOrigin: 0 | ||
m_UseSpriteMesh: 0 | ||
m_PixelsPerUnitMultiplier: 1 | ||
--- !u!114 &6280177048631039952 | ||
MonoBehaviour: | ||
m_ObjectHideFlags: 0 | ||
m_CorrespondingSourceObject: {fileID: 0} | ||
m_PrefabInstance: {fileID: 0} | ||
m_PrefabAsset: {fileID: 0} | ||
m_GameObject: {fileID: 7225474628005434785} | ||
m_Enabled: 1 | ||
m_EditorHideFlags: 0 | ||
m_Script: {fileID: 11500000, guid: 1e79e296834574c5d9138852d94c8998, type: 3} | ||
m_Name: | ||
m_EditorClassIdentifier: | ||
<LoadingObject>k__BackingField: {fileID: 0} | ||
<Image>k__BackingField: {fileID: 5031392240167187892} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
using CommunicationData.URLHelpers; | ||
using Cysharp.Threading.Tasks; | ||
using DCL.WebRequests; | ||
using Utility; | ||
using System.Threading; | ||
using UnityEngine; | ||
|
||
namespace DCL.UI | ||
{ | ||
public class ImageController | ||
{ | ||
private const int PIXELS_PER_UNIT = 50; | ||
private readonly ImageView view; | ||
private readonly IWebRequestController webRequestController; | ||
private CancellationTokenSource cts; | ||
|
||
public ImageController(ImageView view, IWebRequestController webRequestController) | ||
{ | ||
this.view = view; | ||
this.webRequestController = webRequestController; | ||
} | ||
|
||
public void RequestImage(string uri) | ||
{ | ||
cts.SafeCancelAndDispose(); | ||
cts = new CancellationTokenSource(); | ||
RequestImageAsync(uri, cts.Token).Forget(); | ||
} | ||
|
||
private async UniTaskVoid RequestImageAsync(string uri, CancellationToken ct) | ||
{ | ||
view.LoadingObject.SetActive(true); | ||
Texture2D texture = (await webRequestController.GetTextureAsync(new CommonArguments(URLAddress.FromString(uri)), new GetTextureArguments(false), ct)).CreateTexture(TextureWrapMode.Clamp); | ||
view.Image.sprite = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), VectorUtilities.OneHalf, PIXELS_PER_UNIT, 0, SpriteMeshType.FullRect, Vector4.one, false); | ||
view.LoadingObject.SetActive(false); | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using UnityEngine; | ||
using UnityEngine.UI; | ||
|
||
namespace DCL.UI | ||
{ | ||
public class ImageView : MonoBehaviour | ||
{ | ||
[field: SerializeField] | ||
internal GameObject LoadingObject { get; private set; } | ||
|
||
[field: SerializeField] | ||
internal Image Image { get; private set; } | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters