-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ feat(dynamic-loaders): MultiImageDownloader
- Loading branch information
Showing
26 changed files
with
1,404 additions
and
91 deletions.
There are no files selected for viewing
164 changes: 164 additions & 0 deletions
164
Packages/com.nekometer.esnya.inari-udon/DynamicLoaders/MultiImageDisplay_P.prefab
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,164 @@ | ||
%YAML 1.1 | ||
%TAG !u! tag:unity3d.com,2011: | ||
--- !u!1 &3883530557703760817 | ||
GameObject: | ||
m_ObjectHideFlags: 0 | ||
m_CorrespondingSourceObject: {fileID: 0} | ||
m_PrefabInstance: {fileID: 0} | ||
m_PrefabAsset: {fileID: 0} | ||
serializedVersion: 6 | ||
m_Component: | ||
- component: {fileID: 2466384166363282616} | ||
- component: {fileID: 918643036875566830} | ||
- component: {fileID: 8976094248313711874} | ||
- component: {fileID: 1642931380015449425} | ||
- component: {fileID: 8576674997620115003} | ||
- component: {fileID: 8576674997620115002} | ||
m_Layer: 0 | ||
m_Name: DynamicSinage_A0_P (1) | ||
m_TagString: Untagged | ||
m_Icon: {fileID: 0} | ||
m_NavMeshLayer: 0 | ||
m_StaticEditorFlags: 4294967295 | ||
m_IsActive: 1 | ||
--- !u!4 &2466384166363282616 | ||
Transform: | ||
m_ObjectHideFlags: 0 | ||
m_CorrespondingSourceObject: {fileID: 0} | ||
m_PrefabInstance: {fileID: 0} | ||
m_PrefabAsset: {fileID: 0} | ||
m_GameObject: {fileID: 3883530557703760817} | ||
m_LocalRotation: {x: 0.00000016784921, y: -0.7071069, z: -0.70710677, w: -0.00000016391276} | ||
m_LocalPosition: {x: 2.5, y: 0, z: 5} | ||
m_LocalScale: {x: 1, y: 1, z: 1} | ||
m_Children: [] | ||
m_Father: {fileID: 0} | ||
m_RootOrder: 0 | ||
m_LocalEulerAnglesHint: {x: -90.00001, y: 0, z: -179.99998} | ||
--- !u!33 &918643036875566830 | ||
MeshFilter: | ||
m_ObjectHideFlags: 0 | ||
m_CorrespondingSourceObject: {fileID: 0} | ||
m_PrefabInstance: {fileID: 0} | ||
m_PrefabAsset: {fileID: 0} | ||
m_GameObject: {fileID: 3883530557703760817} | ||
m_Mesh: {fileID: -2123421631549176347, guid: 34b3cff5a0697324ca4dc8abf1f4ca9a, type: 3} | ||
--- !u!23 &8976094248313711874 | ||
MeshRenderer: | ||
m_ObjectHideFlags: 0 | ||
m_CorrespondingSourceObject: {fileID: 0} | ||
m_PrefabInstance: {fileID: 0} | ||
m_PrefabAsset: {fileID: 0} | ||
m_GameObject: {fileID: 3883530557703760817} | ||
m_Enabled: 1 | ||
m_CastShadows: 1 | ||
m_ReceiveShadows: 1 | ||
m_DynamicOccludee: 1 | ||
m_MotionVectors: 1 | ||
m_LightProbeUsage: 1 | ||
m_ReflectionProbeUsage: 1 | ||
m_RayTracingMode: 2 | ||
m_RenderingLayerMask: 1 | ||
m_RendererPriority: 0 | ||
m_Materials: | ||
- {fileID: 2100000, guid: b8d1d81e0baef9c46a5169b34315a5b2, type: 2} | ||
- {fileID: 2100000, guid: 088f40b7e7cb4db4089c576998a3259a, type: 2} | ||
m_StaticBatchInfo: | ||
firstSubMesh: 0 | ||
subMeshCount: 0 | ||
m_StaticBatchRoot: {fileID: 0} | ||
m_ProbeAnchor: {fileID: 0} | ||
m_LightProbeVolumeOverride: {fileID: 0} | ||
m_ScaleInLightmap: 1 | ||
m_ReceiveGI: 1 | ||
m_PreserveUVs: 0 | ||
m_IgnoreNormalsForChartDetection: 0 | ||
m_ImportantGI: 0 | ||
m_StitchLightmapSeams: 1 | ||
m_SelectedEditorRenderState: 3 | ||
m_MinimumChartSize: 4 | ||
m_AutoUVMaxDistance: 0.5 | ||
m_AutoUVMaxAngle: 89 | ||
m_LightmapParameters: {fileID: 0} | ||
m_SortingLayerID: 0 | ||
m_SortingLayer: 0 | ||
m_SortingOrder: 0 | ||
--- !u!65 &1642931380015449425 | ||
BoxCollider: | ||
m_ObjectHideFlags: 0 | ||
m_CorrespondingSourceObject: {fileID: 0} | ||
m_PrefabInstance: {fileID: 0} | ||
m_PrefabAsset: {fileID: 0} | ||
m_GameObject: {fileID: 3883530557703760817} | ||
m_Material: {fileID: 0} | ||
m_IsTrigger: 0 | ||
m_Enabled: 1 | ||
serializedVersion: 2 | ||
m_Size: {x: 0.891, y: 0.11499998, z: 1.7194998} | ||
m_Center: {x: 0, y: 0, z: 0.8597499} | ||
--- !u!114 &8576674997620115003 | ||
MonoBehaviour: | ||
m_ObjectHideFlags: 0 | ||
m_CorrespondingSourceObject: {fileID: 0} | ||
m_PrefabInstance: {fileID: 0} | ||
m_PrefabAsset: {fileID: 0} | ||
m_GameObject: {fileID: 3883530557703760817} | ||
m_Enabled: 1 | ||
m_EditorHideFlags: 0 | ||
m_Script: {fileID: 11500000, guid: 45115577ef41a5b4ca741ed302693907, type: 3} | ||
m_Name: | ||
m_EditorClassIdentifier: | ||
interactTextPlacement: {fileID: 0} | ||
interactText: Use | ||
interactTextGO: {fileID: 0} | ||
proximity: 2 | ||
SynchronizePosition: 0 | ||
AllowCollisionOwnershipTransfer: 0 | ||
Reliable: 0 | ||
_syncMethod: 1 | ||
programSource: {fileID: 11400000, guid: 2e0065df1795bf542a2cf74fe3f200cc, type: 2} | ||
serializedPublicVariablesBytesString: Ai8AAAAAATIAAABWAFIAQwAuAFUAZABvAG4ALgBDAG8AbQBtAG8AbgAuAFUAZABvAG4AVgBhAHIAaQBhAGIAbABlAFQAYQBiAGwAZQAsACAAVgBSAEMALgBVAGQAbwBuAC4AQwBvAG0AbQBvAG4AAAAAAAYBAAAAAAAAACcBBAAAAHQAeQBwAGUAAWgAAABTAHkAcwB0AGUAbQAuAEMAbwBsAGwAZQBjAHQAaQBvAG4AcwAuAEcAZQBuAGUAcgBpAGMALgBMAGkAcw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AYQBsAHUAZQACAAAABwUHBQcF | ||
publicVariablesUnityEngineObjects: [] | ||
publicVariablesSerializationDataFormat: 0 | ||
--- !u!114 &8576674997620115002 | ||
MonoBehaviour: | ||
m_ObjectHideFlags: 0 | ||
m_CorrespondingSourceObject: {fileID: 0} | ||
m_PrefabInstance: {fileID: 0} | ||
m_PrefabAsset: {fileID: 0} | ||
m_GameObject: {fileID: 3883530557703760817} | ||
m_Enabled: 1 | ||
m_EditorHideFlags: 0 | ||
m_Script: {fileID: 11500000, guid: 4fa124338179c694fbd93e49ac19598e, type: 3} | ||
m_Name: | ||
m_EditorClassIdentifier: | ||
serializationData: | ||
SerializedBytes: | ||
ReferencedUnityObjects: [] | ||
SerializedBytesString: | ||
Prefab: {fileID: 0} | ||
PrefabModificationsReferencedUnityObjects: [] | ||
PrefabModifications: [] | ||
SerializationNodes: [] | ||
_udonSharpBackingUdonBehaviour: {fileID: 8576674997620115003} | ||
materialIndex: 0 | ||
minDelay: 5 | ||
maxDelay: 10 | ||
textureInfo: | ||
WrapModeU: 0 | ||
WrapModeV: 0 | ||
WrapModeW: 0 | ||
FilterMode: 1 | ||
AnisoLevel: 9 | ||
MaterialProperty: _MainTex | ||
GenerateMipMaps: 1 | ||
loaderMaterial: {fileID: 2100000, guid: 169901c81c7b1644684fd2f087007405, type: 2} | ||
urls: | ||
- url: https://placekitten.com/297/421 | ||
- url: https://placekitten.com/297/422 | ||
- url: https://placekitten.com/297/423 | ||
- url: https://placekitten.com/297/424 | ||
shuffle: 1 | ||
minInterval: 5 | ||
maxInterval: 5 | ||
cache: 1 |
7 changes: 7 additions & 0 deletions
7
Packages/com.nekometer.esnya.inari-udon/DynamicLoaders/MultiImageDisplay_P.prefab.meta
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
84 changes: 84 additions & 0 deletions
84
Packages/com.nekometer.esnya.inari-udon/DynamicLoaders/Scripts/AbstractImageDownloder.cs
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,84 @@ | ||
| ||
using UdonSharp; | ||
using UnityEngine; | ||
using VRC.SDK3.Image; | ||
using VRC.SDKBase; | ||
using VRC.Udon.Common.Interfaces; | ||
|
||
namespace InariUdon.DynamicDownloaders | ||
{ | ||
/// <summary> | ||
/// Download an image from a specified VRCUrl and apply it as a texture to a specified material on a renderer. | ||
/// </summary> | ||
[RequireComponent(typeof(Renderer))] | ||
[UdonBehaviourSyncMode(BehaviourSyncMode.None)] | ||
public abstract class AbstractSingleImageDownloder : UdonSharpBehaviour | ||
{ | ||
/// <summary> | ||
/// Index of the material on the renderer that the downloaded texture should be applied to. | ||
/// </summary> | ||
public int materialIndex; | ||
|
||
/// <summary> | ||
/// Minimum delay (in seconds) before the image download begins. | ||
/// </summary> | ||
public float minDelay = 10; | ||
|
||
/// <summary> | ||
/// Maximum delay (in seconds) before the image download begins. | ||
/// </summary> | ||
public float maxDelay = 30; | ||
|
||
/// <summary> | ||
/// Information tells how convert downlded image as texture. | ||
/// </summary> | ||
public TextureInfo textureInfo; | ||
|
||
/// <summary> | ||
/// Temporarily used internally to getting download the texture, and must not be null. It is not used to render the final material, and can be set to any valid material. | ||
/// </summary> | ||
public Material loaderMaterial; | ||
private VRCImageDownloader downloader; | ||
|
||
public virtual VRCUrl ImageUrl => null; | ||
|
||
/// <summary> | ||
/// Invoke dowloading after specified delay time. | ||
/// </summary> | ||
public virtual void _DownloadDelayed() | ||
{ | ||
SendCustomEventDelayedSeconds(nameof(_Download), Random.Range(minDelay, maxDelay)); | ||
} | ||
|
||
/// <summary> | ||
/// Invoke dowloading. | ||
/// </summary> | ||
public virtual void _Download() | ||
{ | ||
if (downloader == null) downloader = new VRCImageDownloader(); | ||
downloader.DownloadImage(ImageUrl, loaderMaterial, (IUdonEventReceiver)this, textureInfo); | ||
} | ||
|
||
public override void OnImageLoadSuccess(IVRCImageDownload result) | ||
{ | ||
ApplyTexture(result.Material.GetTexture(textureInfo.MaterialProperty)); | ||
} | ||
|
||
public override void OnImageLoadError(IVRCImageDownload result) | ||
{ | ||
Debug.LogError(result.ErrorMessage, this); | ||
} | ||
|
||
protected void ApplyTexture(Texture texture) | ||
{ | ||
var properties = new MaterialPropertyBlock(); | ||
var renderer = GetComponent<MeshRenderer>(); | ||
|
||
renderer.GetPropertyBlock(properties, materialIndex); | ||
properties.SetTexture(textureInfo.MaterialProperty, texture); | ||
renderer.SetPropertyBlock(properties, materialIndex); | ||
|
||
RendererExtensions.UpdateGIMaterials(renderer); | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
...ages/com.nekometer.esnya.inari-udon/DynamicLoaders/Scripts/AbstractImageDownloder.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.