提交Unity 联机Pro

This commit is contained in:
PC-20230316NUNE\Administrator
2024-08-17 14:27:18 +08:00
parent f00193b000
commit 894100ae37
7448 changed files with 854473 additions and 0 deletions

View File

@@ -0,0 +1,593 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1001 &100100000
Prefab:
m_ObjectHideFlags: 1
serializedVersion: 2
m_Modification:
m_TransformParent: {fileID: 0}
m_Modifications: []
m_RemovedComponents: []
m_ParentPrefab: {fileID: 0}
m_RootGameObject: {fileID: 1944314068052120}
m_IsPrefabParent: 1
--- !u!1 &1251304880022356
GameObject:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
serializedVersion: 5
m_Component:
- component: {fileID: 224766109861186050}
- component: {fileID: 222007061184830686}
- component: {fileID: 114332842110793280}
- component: {fileID: 114741082604224458}
- component: {fileID: 114821562994013518}
- component: {fileID: 114970735310707698}
- component: {fileID: 114169851664053792}
m_Layer: 5
m_Name: Start Download Button
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!1 &1298646758441480
GameObject:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
serializedVersion: 5
m_Component:
- component: {fileID: 224796360726838160}
- component: {fileID: 222450923967724424}
- component: {fileID: 114756570423530596}
m_Layer: 5
m_Name: Text
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!1 &1548055376625982
GameObject:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
serializedVersion: 5
m_Component:
- component: {fileID: 224222599636736864}
- component: {fileID: 222263229427737546}
- component: {fileID: 114864362160119752}
- component: {fileID: 114863480533508966}
m_Layer: 5
m_Name: RawImage
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!1 &1549333168510042
GameObject:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
serializedVersion: 5
m_Component:
- component: {fileID: 224641546219099906}
- component: {fileID: 222240980090431082}
- component: {fileID: 114444815419025578}
m_Layer: 5
m_Name: Header
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!1 &1928372766581374
GameObject:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
serializedVersion: 5
m_Component:
- component: {fileID: 224044084468067872}
- component: {fileID: 222379004667598028}
- component: {fileID: 114378960042926580}
m_Layer: 5
m_Name: Status Text
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!1 &1944314068052120
GameObject:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
serializedVersion: 5
m_Component:
- component: {fileID: 224637431015742208}
- component: {fileID: 114589682599655862}
- component: {fileID: 114248578834748736}
m_Layer: 5
m_Name: AssetBundle
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!114 &114169851664053792
MonoBehaviour:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1251304880022356}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 1679637790, guid: f70555f144d8491a825f0804e09c671c, type: 3}
m_Name:
m_EditorClassIdentifier:
m_IgnoreLayout: 0
m_MinWidth: -1
m_MinHeight: -1
m_PreferredWidth: -1
m_PreferredHeight: -1
m_FlexibleWidth: -1
m_FlexibleHeight: 0
m_LayoutPriority: 1
--- !u!114 &114248578834748736
MonoBehaviour:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1944314068052120}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 03eab9c6191c5cd4c9613084e817bd29, type: 3}
m_Name:
m_EditorClassIdentifier:
Category: HTTP
DisplayName: Asset Bundle
Description: 'A small example that shows a possible way to download an AssetBundle
and load a resource from it.
<b>Features demoed in this example:</b>
-Using HTTPRequest without a callback
-Using HTTPRequest in a Coroutine
-Loading an AssetBundle from the downloaded bytes
-Automatic Caching'
_path: /AssetBundles/WebGL/demobundle.assetbundle
_assetnameInBundle: 9443182_orig
_statusText: {fileID: 114378960042926580}
_rawImage: {fileID: 114864362160119752}
_downloadButton: {fileID: 114741082604224458}
--- !u!114 &114332842110793280
MonoBehaviour:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1251304880022356}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: -765806418, guid: f70555f144d8491a825f0804e09c671c, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_RaycastTarget: 1
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_TypeName: UnityEngine.UI.MaskableGraphic+CullStateChangedEvent, UnityEngine.UI,
Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
m_Sprite: {fileID: 10905, guid: 0000000000000000f000000000000000, type: 0}
m_Type: 1
m_PreserveAspect: 0
m_FillCenter: 1
m_FillMethod: 4
m_FillAmount: 1
m_FillClockwise: 1
m_FillOrigin: 0
--- !u!114 &114378960042926580
MonoBehaviour:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1928372766581374}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 708705254, guid: f70555f144d8491a825f0804e09c671c, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 0.19607843, g: 0.19607843, b: 0.19607843, a: 1}
m_RaycastTarget: 0
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_TypeName: UnityEngine.UI.MaskableGraphic+CullStateChangedEvent, UnityEngine.UI,
Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
m_FontData:
m_Font: {fileID: 10102, guid: 0000000000000000e000000000000000, type: 0}
m_FontSize: 14
m_FontStyle: 0
m_BestFit: 0
m_MinSize: 10
m_MaxSize: 40
m_Alignment: 0
m_AlignByGeometry: 0
m_RichText: 1
m_HorizontalOverflow: 0
m_VerticalOverflow: 0
m_LineSpacing: 1
m_Text: Status
--- !u!114 &114444815419025578
MonoBehaviour:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1549333168510042}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 708705254, guid: f70555f144d8491a825f0804e09c671c, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 0.19607843, g: 0.19607843, b: 0.19607843, a: 1}
m_RaycastTarget: 0
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_TypeName: UnityEngine.UI.MaskableGraphic+CullStateChangedEvent, UnityEngine.UI,
Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
m_FontData:
m_Font: {fileID: 10102, guid: 0000000000000000e000000000000000, type: 0}
m_FontSize: 20
m_FontStyle: 1
m_BestFit: 0
m_MinSize: 2
m_MaxSize: 40
m_Alignment: 1
m_AlignByGeometry: 0
m_RichText: 1
m_HorizontalOverflow: 0
m_VerticalOverflow: 0
m_LineSpacing: 1
m_Text: Asset Bundle Example
--- !u!114 &114589682599655862
MonoBehaviour:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1944314068052120}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 1297475563, guid: f70555f144d8491a825f0804e09c671c, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Padding:
m_Left: 5
m_Right: 5
m_Top: 5
m_Bottom: 5
m_ChildAlignment: 0
m_Spacing: 5
m_ChildForceExpandWidth: 1
m_ChildForceExpandHeight: 0
m_ChildControlWidth: 1
m_ChildControlHeight: 1
--- !u!114 &114741082604224458
MonoBehaviour:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1251304880022356}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 1392445389, guid: f70555f144d8491a825f0804e09c671c, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Navigation:
m_Mode: 3
m_SelectOnUp: {fileID: 0}
m_SelectOnDown: {fileID: 0}
m_SelectOnLeft: {fileID: 0}
m_SelectOnRight: {fileID: 0}
m_Transition: 1
m_Colors:
m_NormalColor: {r: 1, g: 1, b: 1, a: 1}
m_HighlightedColor: {r: 0.9607843, g: 0.9607843, b: 0.9607843, a: 1}
m_PressedColor: {r: 0.78431374, g: 0.78431374, b: 0.78431374, a: 1}
m_DisabledColor: {r: 0.78431374, g: 0.78431374, b: 0.78431374, a: 0.5019608}
m_ColorMultiplier: 1
m_FadeDuration: 0.1
m_SpriteState:
m_HighlightedSprite: {fileID: 0}
m_PressedSprite: {fileID: 0}
m_DisabledSprite: {fileID: 0}
m_AnimationTriggers:
m_NormalTrigger: Normal
m_HighlightedTrigger: Highlighted
m_PressedTrigger: Pressed
m_DisabledTrigger: Disabled
m_Interactable: 1
m_TargetGraphic: {fileID: 114332842110793280}
m_OnClick:
m_PersistentCalls:
m_Calls:
- m_Target: {fileID: 114248578834748736}
m_MethodName: OnStartDownloadButton
m_Mode: 1
m_Arguments:
m_ObjectArgument: {fileID: 0}
m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine
m_IntArgument: 0
m_FloatArgument: 0
m_StringArgument:
m_BoolArgument: 0
m_CallState: 2
m_TypeName: UnityEngine.UI.Button+ButtonClickedEvent, UnityEngine.UI, Version=1.0.0.0,
Culture=neutral, PublicKeyToken=null
--- !u!114 &114756570423530596
MonoBehaviour:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1298646758441480}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 708705254, guid: f70555f144d8491a825f0804e09c671c, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 0.19607843, g: 0.19607843, b: 0.19607843, a: 1}
m_RaycastTarget: 1
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_TypeName: UnityEngine.UI.MaskableGraphic+CullStateChangedEvent, UnityEngine.UI,
Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
m_FontData:
m_Font: {fileID: 10102, guid: 0000000000000000e000000000000000, type: 0}
m_FontSize: 14
m_FontStyle: 0
m_BestFit: 0
m_MinSize: 10
m_MaxSize: 40
m_Alignment: 4
m_AlignByGeometry: 0
m_RichText: 1
m_HorizontalOverflow: 0
m_VerticalOverflow: 0
m_LineSpacing: 1
m_Text: Start Download
--- !u!114 &114821562994013518
MonoBehaviour:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1251304880022356}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 1297475563, guid: f70555f144d8491a825f0804e09c671c, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Padding:
m_Left: 5
m_Right: 5
m_Top: 5
m_Bottom: 5
m_ChildAlignment: 0
m_Spacing: 0
m_ChildForceExpandWidth: 1
m_ChildForceExpandHeight: 1
m_ChildControlWidth: 1
m_ChildControlHeight: 1
--- !u!114 &114863480533508966
MonoBehaviour:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1548055376625982}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 1679637790, guid: f70555f144d8491a825f0804e09c671c, type: 3}
m_Name:
m_EditorClassIdentifier:
m_IgnoreLayout: 0
m_MinWidth: -1
m_MinHeight: -1
m_PreferredWidth: -1
m_PreferredHeight: -1
m_FlexibleWidth: -1
m_FlexibleHeight: 1
m_LayoutPriority: 1
--- !u!114 &114864362160119752
MonoBehaviour:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1548055376625982}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: -98529514, guid: f70555f144d8491a825f0804e09c671c, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_RaycastTarget: 0
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_TypeName: UnityEngine.UI.MaskableGraphic+CullStateChangedEvent, UnityEngine.UI,
Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
m_Texture: {fileID: 0}
m_UVRect:
serializedVersion: 2
x: 0
y: 0
width: 1
height: 1
--- !u!114 &114970735310707698
MonoBehaviour:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1251304880022356}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 1741964061, guid: f70555f144d8491a825f0804e09c671c, type: 3}
m_Name:
m_EditorClassIdentifier:
m_HorizontalFit: 0
m_VerticalFit: 2
--- !u!222 &222007061184830686
CanvasRenderer:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1251304880022356}
--- !u!222 &222240980090431082
CanvasRenderer:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1549333168510042}
--- !u!222 &222263229427737546
CanvasRenderer:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1548055376625982}
--- !u!222 &222379004667598028
CanvasRenderer:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1928372766581374}
--- !u!222 &222450923967724424
CanvasRenderer:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1298646758441480}
--- !u!224 &224044084468067872
RectTransform:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1928372766581374}
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_Children: []
m_Father: {fileID: 224637431015742208}
m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 0, y: 0}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 0, y: 0}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!224 &224222599636736864
RectTransform:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1548055376625982}
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_Children: []
m_Father: {fileID: 224637431015742208}
m_RootOrder: 2
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 0, y: 0}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 0, y: 0}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!224 &224637431015742208
RectTransform:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1944314068052120}
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_Children:
- {fileID: 224641546219099906}
- {fileID: 224044084468067872}
- {fileID: 224222599636736864}
- {fileID: 224766109861186050}
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 0, y: 0}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 0, y: 0}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!224 &224641546219099906
RectTransform:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1549333168510042}
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_Children: []
m_Father: {fileID: 224637431015742208}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 0, y: 0}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 0, y: 0}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!224 &224766109861186050
RectTransform:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1251304880022356}
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_Children:
- {fileID: 224796360726838160}
m_Father: {fileID: 224637431015742208}
m_RootOrder: 3
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 0, y: 0}
m_AnchoredPosition: {x: 300, y: 0}
m_SizeDelta: {x: 590, y: 0}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!224 &224796360726838160
RectTransform:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1298646758441480}
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_Children: []
m_Father: {fileID: 224766109861186050}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 0, y: 0}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 0, y: 0}
m_Pivot: {x: 0.5, y: 0.5}

View File

@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: 0a56a1df7e0b38848bb9bf237a577478
timeCreated: 1571226561
licenseType: Store
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 100100000
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,210 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using BestHTTP;
namespace BestHTTP.Examples.HTTP
{
public sealed class AssetBundleSample : BestHTTP.Examples.Helpers.SampleBase
{
#pragma warning disable 0649
[Tooltip("The url of the resource to download")]
[SerializeField]
private string _path = "/AssetBundles/WebGL/demobundle.assetbundle";
[SerializeField]
private string _assetnameInBundle = "9443182_orig";
[SerializeField]
private Text _statusText;
[SerializeField]
private RawImage _rawImage;
[SerializeField]
private Button _downloadButton;
#pragma warning restore
#region Private Fields
/// <summary>
/// Reference to the request to be able to call Abort on it.
/// </summary>
HTTPRequest request;
/// <summary>
/// The downloaded and cached AssetBundle
/// </summary>
AssetBundle cachedBundle;
#endregion
#region Unity Events
protected override void Start()
{
base.Start();
this._statusText.text = "Waiting for user interaction";
}
void OnDestroy()
{
if (this.request != null)
this.request.Abort();
this.request = null;
UnloadBundle();
}
/// <summary>
/// GUI button callback
/// </summary>
public void OnStartDownloadButton()
{
this._downloadButton.enabled = false;
UnloadBundle();
StartCoroutine(DownloadAssetBundle());
}
#endregion
#region Private Helper Functions
IEnumerator DownloadAssetBundle()
{
// Create and send our request
request = new HTTPRequest(new Uri(this.sampleSelector.BaseURL + this._path)).Send();
this._statusText.text = "Download started";
// Wait while it's finishes and add some fancy dots to display something while the user waits for it.
// A simple "yield return StartCoroutine(request);" would do the job too.
while (request.State < HTTPRequestStates.Finished)
{
yield return new WaitForSeconds(0.1f);
this._statusText.text += ".";
}
// Check the outcome of our request.
switch (request.State)
{
// The request finished without any problem.
case HTTPRequestStates.Finished:
if (request.Response.IsSuccess)
{
#if !BESTHTTP_DISABLE_CACHING
if (request.Response.IsFromCache)
this._statusText.text = "Loaded from local cache!";
else
this._statusText.text = "Downloaded!";
#else
this._statusText.text = "Downloaded!";
#endif
// Start creating the downloaded asset bundle
AssetBundleCreateRequest async =
#if UNITY_5_3_OR_NEWER
AssetBundle.LoadFromMemoryAsync(request.Response.Data);
#else
AssetBundle.CreateFromMemory(request.Response.Data);
#endif
// wait for it
yield return async;
BestHTTP.PlatformSupport.Memory.BufferPool.Release(request.Response.Data);
// And process the bundle
yield return StartCoroutine(ProcessAssetBundle(async.assetBundle));
}
else
{
this._statusText.text = string.Format("Request finished Successfully, but the server sent an error. Status Code: {0}-{1} Message: {2}",
request.Response.StatusCode,
request.Response.Message,
request.Response.DataAsText);
Debug.LogWarning(this._statusText.text);
}
break;
// The request finished with an unexpected error. The request's Exception property may contain more info about the error.
case HTTPRequestStates.Error:
this._statusText.text = "Request Finished with Error! " + (request.Exception != null ? (request.Exception.Message + "\n" + request.Exception.StackTrace) : "No Exception");
Debug.LogError(this._statusText.text);
break;
// The request aborted, initiated by the user.
case HTTPRequestStates.Aborted:
this._statusText.text = "Request Aborted!";
Debug.LogWarning(this._statusText.text);
break;
// Connecting to the server is timed out.
case HTTPRequestStates.ConnectionTimedOut:
this._statusText.text = "Connection Timed Out!";
Debug.LogError(this._statusText.text);
break;
// The request didn't finished in the given time.
case HTTPRequestStates.TimedOut:
this._statusText.text = "Processing the request Timed Out!";
Debug.LogError(this._statusText.text);
break;
}
this.request = null;
this._downloadButton.enabled = true;
}
/// <summary>
/// In this function we can do whatever we want with the freshly downloaded bundle.
/// In this example we will cache it for later use, and we will load a texture from it.
/// </summary>
IEnumerator ProcessAssetBundle(AssetBundle bundle)
{
if (bundle == null)
yield break;
// Save the bundle for future use
cachedBundle = bundle;
// Start loading the asset from the bundle
var asyncAsset =
#if UNITY_5_1 || UNITY_5_2 || UNITY_5_3_OR_NEWER
cachedBundle.LoadAssetAsync(this._assetnameInBundle, typeof(Texture2D));
#else
cachedBundle.LoadAsync(this._assetnameInBundle, typeof(Texture2D));
#endif
// wait til load
yield return asyncAsset;
// get the texture
this._rawImage.texture = asyncAsset.asset as Texture2D;
}
void UnloadBundle()
{
this._rawImage.texture = null;
if (cachedBundle != null)
{
cachedBundle.Unload(true);
cachedBundle = null;
}
}
#endregion
}
}

View File

@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: 03eab9c6191c5cd4c9613084e817bd29
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,197 @@
using System;
using System.Collections.Generic;
using System.IO;
using BestHTTP.Extensions;
using BestHTTP.PlatformSupport.Memory;
namespace BestHTTP
{
/// <summary>
/// Stream based implementation of the multipart/form-data Content-Type. Using this class reading a whole file into memory can be avoided.
/// This implementation expects that all streams has a final, accessible Length.
/// </summary>
public sealed class MultipartFormDataStream : System.IO.Stream
{
public override bool CanRead { get { return true; } }
public override bool CanSeek { get { return false; } }
public override bool CanWrite { get { return false; } }
public override long Length
{
get
{
// multipart/form-data requires a leading boundary that we can add when all streams are added.
// This final preparation could be user initiated, but we can do it automatically too when the HTTPRequest
// first access the Length property.
if (!this.prepared)
{
this.prepared = true;
this.Prepare();
}
return this._length;
}
}
private long _length;
public override long Position { get; set; }
/// <summary>
/// A random boundary generated in the constructor.
/// </summary>
private string boundary;
private Queue<StreamList> fields = new Queue<StreamList>(1);
private StreamList currentField;
private bool prepared;
public MultipartFormDataStream(HTTPRequest request)
{
this.boundary = "BestHTTP_MultipartFormDataStream_" + this.GetHashCode().ToString("X2");
request.SetHeader("Content-Type", "multipart/form-data; boundary=" + boundary);
request.UploadStream = this;
request.UseUploadStreamLength = true;
}
public void AddField(string fieldName, string value)
{
AddField(fieldName, value, System.Text.Encoding.UTF8);
}
public void AddField(string fieldName, string value, System.Text.Encoding encoding)
{
var enc = encoding ?? System.Text.Encoding.UTF8;
var byteCount = enc.GetByteCount(value);
var buffer = BufferPool.Get(byteCount, true);
var stream = new BufferPoolMemoryStream();
enc.GetBytes(value, 0, value.Length, buffer, 0);
stream.Write(buffer, 0, byteCount);
stream.Position = 0;
string mime = encoding != null ? "text/plain; charset=" + encoding.WebName : null;
AddStreamField(stream, fieldName, null, mime);
}
public void AddStreamField(System.IO.Stream stream, string fieldName)
{
AddStreamField(stream, fieldName, null, null);
}
public void AddStreamField(System.IO.Stream stream, string fieldName, string fileName)
{
AddStreamField(stream, fieldName, fileName, null);
}
public void AddStreamField(System.IO.Stream stream, string fieldName, string fileName, string mimeType)
{
var header = new BufferPoolMemoryStream();
header.WriteLine("--" + this.boundary);
header.WriteLine("Content-Disposition: form-data; name=\"" + fieldName + "\"" + (!string.IsNullOrEmpty(fileName) ? "; filename=\"" + fileName + "\"" : string.Empty));
// Set up Content-Type head for the form.
if (!string.IsNullOrEmpty(mimeType))
header.WriteLine("Content-Type: " + mimeType);
//header.WriteLine("Content-Length: " + stream.Length.ToString());
header.WriteLine();
header.Position = 0;
var footer = new BufferPoolMemoryStream();
footer.Write(HTTPRequest.EOL, 0, HTTPRequest.EOL.Length);
footer.Position = 0;
// all wrapped streams going to be disposed by the StreamList wrapper.
var wrapper = new StreamList(header, stream, footer);
try
{
if (this._length >= 0)
this._length += wrapper.Length;
}
catch
{
this._length = -1;
}
this.fields.Enqueue(wrapper);
}
/// <summary>
/// Adds the final boundary.
/// </summary>
private void Prepare()
{
var boundaryStream = new BufferPoolMemoryStream();
boundaryStream.WriteLine("--" + this.boundary + "--");
boundaryStream.Position = 0;
this.fields.Enqueue(new StreamList(boundaryStream));
if (this._length >= 0)
this._length += boundaryStream.Length;
}
public override int Read(byte[] buffer, int offset, int length)
{
if (this.currentField == null && this.fields.Count == 0)
return -1;
if (this.currentField == null && this.fields.Count > 0)
this.currentField = this.fields.Dequeue();
int readCount = 0;
do
{
// read from the current stream
int count = this.currentField.Read(buffer, offset + readCount, length - readCount);
if (count > 0)
readCount += count;
else
{
// if the current field's stream is empty, go for the next one.
// dispose the current one first
try
{
this.currentField.Dispose();
}
catch
{ }
// no more fields/streams? exit
if (this.fields.Count == 0)
break;
// grab the next one
this.currentField = this.fields.Dequeue();
}
// exit when we reach the length goal, or there's no more streams to read from
} while (readCount < length && this.fields.Count > 0);
return readCount;
}
public override long Seek(long offset, SeekOrigin origin)
{
throw new NotImplementedException();
}
public override void SetLength(long value)
{
throw new NotImplementedException();
}
public override void Write(byte[] buffer, int offset, int count)
{
throw new NotImplementedException();
}
public override void Flush() { }
}
}

View File

@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: d54866f088b8c154db3325a2771b58af
timeCreated: 1582886645
licenseType: Store
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: ceca5a2f4b7ce1e4fb307cc3d3e4624a
timeCreated: 1571229570
licenseType: Store
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 100100000
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,96 @@
using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using BestHTTP;
namespace BestHTTP.Examples.HTTP
{
public sealed class ResumableStreamingSample : StreamingSample
{
const string ProcessedBytesKey = "ProcessedBytes";
const string DownloadLengthKey = "DownloadLength";
/// <summary>
/// Expected content length
/// </summary>
protected override long DownloadLength { get { return PlayerPrefs.GetInt(this._downloadPath + DownloadLengthKey); } set { PlayerPrefs.SetInt(this._downloadPath + DownloadLengthKey, (int)value); } }
/// <summary>
/// Total processed bytes
/// </summary>
protected override long ProcessedBytes { get { return PlayerPrefs.GetInt(this._downloadPath + ProcessedBytesKey, 0); } set { PlayerPrefs.SetInt(this._downloadPath + ProcessedBytesKey, (int)value); } }
private long downloadStartedAt = 0;
protected override void Start()
{
base.Start();
// If we have a non-finished download, set the progress to the value where we left it
float progress = GetSavedProgress();
if (progress > 0.0f)
{
this._downloadProgressSlider.value = progress;
base._statusText.text = progress.ToString("F2");
}
}
protected override void SetupRequest()
{
base.SetupRequest();
// Are there any progress, that we can continue?
this.downloadStartedAt = this.ProcessedBytes;
if (this.downloadStartedAt > 0)
{
// Set the range header
request.SetRangeHeader(this.downloadStartedAt);
}
else
// This is a new request
DeleteKeys();
}
protected override void OnRequestFinished(HTTPRequest req, HTTPResponse resp)
{
base.OnRequestFinished(req, resp);
if (req.State == HTTPRequestStates.Finished && resp.IsSuccess)
DeleteKeys();
}
protected override void OnDownloadProgress(HTTPRequest originalRequest, long downloaded, long downloadLength)
{
double downloadPercent = ((this.downloadStartedAt + downloaded) / (double)this.DownloadLength) * 100;
this._downloadProgressSlider.value = (float)downloadPercent;
this._downloadProgressText.text = string.Format("{0:F1}%", downloadPercent);
}
protected override void ResetProcessedValues()
{
SetDataProcessedUI(this.ProcessedBytes, this.DownloadLength);
}
private float GetSavedProgress()
{
long down = this.ProcessedBytes;
long length = this.DownloadLength;
if (down > 0 && length > 0)
return (down / (float)length) * 100f;
return -1;
}
private void DeleteKeys()
{
PlayerPrefs.DeleteKey(this._downloadPath + ProcessedBytesKey);
PlayerPrefs.DeleteKey(this._downloadPath + DownloadLengthKey);
PlayerPrefs.Save();
}
}
}

View File

@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: 972fc2301f87c9e46bfb5523f2bc5090
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: cab27f13c267f9e42ab47de965b407b9
timeCreated: 1571294301
licenseType: Store
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 100100000
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,272 @@
using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using BestHTTP;
namespace BestHTTP.Examples.HTTP
{
public class StreamingSample : BestHTTP.Examples.Helpers.SampleBase
{
#pragma warning disable 0649
[Tooltip("The url of the resource to download")]
[SerializeField]
protected string _downloadPath = "/test100mb.dat";
[Header("Streaming Setup")]
[SerializeField]
protected RectTransform _streamingSetupRoot;
[SerializeField]
protected Slider _fragmentSizeSlider;
[SerializeField]
protected Text _fragmentSizeText;
[SerializeField]
protected Toggle _disableCacheToggle;
[Header("Reporting")]
[SerializeField]
protected RectTransform _reportingRoot;
[SerializeField]
protected Slider _downloadProgressSlider;
[SerializeField]
protected Text _downloadProgressText;
[SerializeField]
protected Slider _processedDataSlider;
[SerializeField]
protected Text _processedDataText;
[SerializeField]
protected Text _statusText;
[SerializeField]
protected Button _startDownload;
[SerializeField]
protected Button _cancelDownload;
#pragma warning restore
/// <summary>
/// Cached request to be able to abort it
/// </summary>
protected HTTPRequest request;
/// <summary>
/// Download(processing) progress. Its range is between [0..1]
/// </summary>
protected float progress;
/// <summary>
/// The fragment size that we will set to the request
/// </summary>
protected int fragmentSize = HTTPResponse.MinReadBufferSize;
protected virtual long DownloadLength { get; set; }
protected virtual long ProcessedBytes { get; set; }
protected override void Start()
{
base.Start();
this._streamingSetupRoot.gameObject.SetActive(true);
this._reportingRoot.gameObject.SetActive(false);
this._startDownload.interactable = true;
this._cancelDownload.interactable = false;
this._fragmentSizeSlider.value = (1024 * 1024 - HTTPResponse.MinReadBufferSize) / 1024;
this._fragmentSizeText.text = GUIHelper.GetBytesStr(1024 * 1024, 1);
}
protected void OnDestroy()
{
// Stop the download if we are leaving this example
if (request != null && request.State < HTTPRequestStates.Finished)
{
request.OnDownloadProgress = null;
request.Callback = null;
request.Abort();
}
}
public void OnFragmentSizeSliderChanged(float value)
{
this.fragmentSize = HTTPResponse.MinReadBufferSize + (int)value * 1024;
this._fragmentSizeText.text = GUIHelper.GetBytesStr(this.fragmentSize, 1);
}
public void Cancel()
{
if (this.request != null)
this.request.Abort();
}
protected virtual void SetupRequest()
{
request = new HTTPRequest(new Uri(base.sampleSelector.BaseURL + this._downloadPath), OnRequestFinished);
#if !BESTHTTP_DISABLE_CACHING
// If we are writing our own file set it to true(disable), so don't duplicate it on the file-system
request.DisableCache = this._disableCacheToggle.isOn;
#endif
request.StreamFragmentSize = fragmentSize;
request.Tag = DateTime.Now;
request.OnHeadersReceived += OnHeadersReceived;
request.OnDownloadProgress += OnDownloadProgress;
request.OnStreamingData += OnDataDownloaded;
}
public virtual void StartStreaming()
{
SetupRequest();
// Start Processing the request
request.Send();
this._statusText.text = "Download started!";
// UI
this._streamingSetupRoot.gameObject.SetActive(false);
this._reportingRoot.gameObject.SetActive(true);
this._startDownload.interactable = false;
this._cancelDownload.interactable = true;
ResetProcessedValues();
}
private void OnHeadersReceived(HTTPRequest req, HTTPResponse resp, Dictionary<string, List<string>> newHeaders)
{
var range = resp.GetRange();
if (range != null)
this.DownloadLength = range.ContentLength;
else
{
var contentLength = resp.GetFirstHeaderValue("content-length");
if (contentLength != null)
{
long length = 0;
if (long.TryParse(contentLength, out length))
this.DownloadLength = length;
}
}
}
protected virtual void OnRequestFinished(HTTPRequest req, HTTPResponse resp)
{
switch (req.State)
{
// The request finished without any problem.
case HTTPRequestStates.Finished:
if (resp.IsSuccess)
{
DateTime downloadStarted = (DateTime)req.Tag;
TimeSpan diff = DateTime.Now - downloadStarted;
this._statusText.text = string.Format("Streaming finished in {0:N0}ms", diff.TotalMilliseconds);
}
else
{
this._statusText.text = string.Format("Request finished Successfully, but the server sent an error. Status Code: {0}-{1} Message: {2}",
resp.StatusCode,
resp.Message,
resp.DataAsText);
Debug.LogWarning(this._statusText.text);
request = null;
}
break;
// The request finished with an unexpected error. The request's Exception property may contain more info about the error.
case HTTPRequestStates.Error:
this._statusText.text = "Request Finished with Error! " + (req.Exception != null ? (req.Exception.Message + "\n" + req.Exception.StackTrace) : "No Exception");
Debug.LogError(this._statusText.text);
request = null;
break;
// The request aborted, initiated by the user.
case HTTPRequestStates.Aborted:
this._statusText.text = "Request Aborted!";
Debug.LogWarning(this._statusText.text);
request = null;
break;
// Connecting to the server is timed out.
case HTTPRequestStates.ConnectionTimedOut:
this._statusText.text = "Connection Timed Out!";
Debug.LogError(this._statusText.text);
request = null;
break;
// The request didn't finished in the given time.
case HTTPRequestStates.TimedOut:
this._statusText.text = "Processing the request Timed Out!";
Debug.LogError(this._statusText.text);
request = null;
break;
}
// UI
this._streamingSetupRoot.gameObject.SetActive(true);
this._reportingRoot.gameObject.SetActive(false);
this._startDownload.interactable = true;
this._cancelDownload.interactable = false;
request = null;
}
protected virtual void OnDownloadProgress(HTTPRequest originalRequest, long downloaded, long downloadLength)
{
double downloadPercent = (downloaded / (double)downloadLength) * 100;
this._downloadProgressSlider.value = (float)downloadPercent;
this._downloadProgressText.text = string.Format("{0:F1}%", downloadPercent);
}
protected virtual bool OnDataDownloaded(HTTPRequest request, HTTPResponse response, byte[] dataFragment, int dataFragmentLength)
{
this.ProcessedBytes += dataFragmentLength;
SetDataProcessedUI(this.ProcessedBytes, this.DownloadLength);
// Use downloaded data
// Return true if dataFrament is processed so the plugin can recycle the byte[]
return true;
}
protected void SetDataProcessedUI(long processed, long length)
{
float processedPercent = (processed / (float)length) * 100f;
this._processedDataSlider.value = processedPercent;
this._processedDataText.text = GUIHelper.GetBytesStr(processed, 0);
}
protected virtual void ResetProcessedValues()
{
this.ProcessedBytes = 0;
this.DownloadLength = 0;
SetDataProcessedUI(this.ProcessedBytes, this.DownloadLength);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 7608ce95dba469c42b49baa85e3c300c
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: 1b7ac2a0c58362148840c49056fa7bda
timeCreated: 1571294809
licenseType: Store
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 100100000
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,159 @@
using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using BestHTTP;
namespace BestHTTP.Examples.HTTP
{
public sealed class TextureDownloadSample : BestHTTP.Examples.Helpers.SampleBase
{
#pragma warning disable 0649
[Header("Texture Download Example")]
[Tooltip("The URL of the server that will serve the image resources")]
[SerializeField]
private string _path = "/images/Demo/";
[Tooltip("The downloadable images")]
[SerializeField]
private string[] _imageNames = new string[9] { "One.png", "Two.png", "Three.png", "Four.png", "Five.png", "Six.png", "Seven.png", "Eight.png", "Nine.png" };
[SerializeField]
private RawImage[] _images = new RawImage[0];
[SerializeField]
private Text _maxConnectionPerServerLabel;
[SerializeField]
private Text _cacheLabel;
#pragma warning restore
private byte savedMaxConnectionPerServer;
#if !BESTHTTP_DISABLE_CACHING
private bool allDownloadedFromLocalCache;
#endif
private List<HTTPRequest> activeRequests = new List<HTTPRequest>();
protected override void Start()
{
base.Start();
this.savedMaxConnectionPerServer = HTTPManager.MaxConnectionPerServer;
// Set a well observable value
// This is how many concurrent requests can be made to a server
HTTPManager.MaxConnectionPerServer = 1;
this._maxConnectionPerServerLabel.text = HTTPManager.MaxConnectionPerServer.ToString();
}
void OnDestroy()
{
// Set back to its defualt value.
HTTPManager.MaxConnectionPerServer = this.savedMaxConnectionPerServer;
foreach (var request in this.activeRequests)
request.Abort();
this.activeRequests.Clear();
}
public void OnMaxConnectionPerServerChanged(float value)
{
HTTPManager.MaxConnectionPerServer = (byte)Mathf.RoundToInt(value);
this._maxConnectionPerServerLabel.text = HTTPManager.MaxConnectionPerServer.ToString();
}
public void DownloadImages()
{
// Set these metadatas to its initial values
#if !BESTHTTP_DISABLE_CACHING
allDownloadedFromLocalCache = true;
#endif
for (int i = 0; i < _imageNames.Length; ++i)
{
// Set a blank placeholder texture, overriding previously downloaded texture
this._images[i].texture = null;
// Construct the request
var request = new HTTPRequest(new Uri(this.sampleSelector.BaseURL + this._path + this._imageNames[i]), ImageDownloaded);
// Set the Tag property, we can use it as a general storage bound to the request
request.Tag = this._images[i];
// Send out the request
request.Send();
this.activeRequests.Add(request);
}
this._cacheLabel.text = string.Empty;
}
/// <summary>
/// Callback function of the image download http requests
/// </summary>
void ImageDownloaded(HTTPRequest req, HTTPResponse resp)
{
switch (req.State)
{
// The request finished without any problem.
case HTTPRequestStates.Finished:
if (resp.IsSuccess)
{
// The target RawImage reference is stored in the Tag property
RawImage rawImage = req.Tag as RawImage;
rawImage.texture = resp.DataAsTexture2D;
#if !BESTHTTP_DISABLE_CACHING
// Update the cache-info variable
allDownloadedFromLocalCache = allDownloadedFromLocalCache && resp.IsFromCache;
#endif
}
else
{
Debug.LogWarning(string.Format("Request finished Successfully, but the server sent an error. Status Code: {0}-{1} Message: {2}",
resp.StatusCode,
resp.Message,
resp.DataAsText));
}
break;
// The request finished with an unexpected error. The request's Exception property may contain more info about the error.
case HTTPRequestStates.Error:
Debug.LogError("Request Finished with Error! " + (req.Exception != null ? (req.Exception.Message + "\n" + req.Exception.StackTrace) : "No Exception"));
break;
// The request aborted, initiated by the user.
case HTTPRequestStates.Aborted:
Debug.LogWarning("Request Aborted!");
break;
// Connecting to the server is timed out.
case HTTPRequestStates.ConnectionTimedOut:
Debug.LogError("Connection Timed Out!");
break;
// The request didn't finished in the given time.
case HTTPRequestStates.TimedOut:
Debug.LogError("Processing the request Timed Out!");
break;
}
this.activeRequests.Remove(req);
if (this.activeRequests.Count == 0)
{
#if !BESTHTTP_DISABLE_CACHING
if (this.allDownloadedFromLocalCache)
this._cacheLabel.text = "All images loaded from local cache!";
else
#endif
this._cacheLabel.text = string.Empty;
}
}
}
}

View File

@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: af6ffe2bbf96d2b49ba3ef0713511d45
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,222 @@
using BestHTTP;
using System;
using System.IO;
using System.Threading;
namespace BestHTTP.Examples
{
public sealed class UploadStream : Stream
{
#region Private Fields
/// <summary>
/// Buffer for reads
/// </summary>
MemoryStream ReadBuffer = new MemoryStream();
/// <summary>
/// Buffer for writes
/// </summary>
MemoryStream WriteBuffer = new MemoryStream();
/// <summary>
/// Indicates that we will not write more data to this stream
/// </summary>
bool noMoreData;
/// <summary>
/// For thread synchronization
/// </summary>
AutoResetEvent ARE = new AutoResetEvent(false);
/// <summary>
/// For thread synchronization
/// </summary>
object locker = new object();
#endregion
#region Properties
/// <summary>
/// Name of this stream for easier debugging
/// </summary>
public string Name { get; private set; }
/// <summary>
/// true if we are read all data from the read buffer
/// </summary>
private bool IsReadBufferEmpty { get { lock (locker) return ReadBuffer.Position == ReadBuffer.Length; } }
#endregion
#region Constructors
public UploadStream(string name)
: this()
{
this.Name = name;
}
public UploadStream()
{
this.ReadBuffer = new MemoryStream();
this.WriteBuffer = new MemoryStream();
this.Name = string.Empty;
}
#endregion
#region Stream Implementation
public override int Read(byte[] buffer, int offset, int count)
{
// We will not push more data to the write buffer
if (noMoreData)
{
// No data left in the read buffer
if (ReadBuffer.Position == ReadBuffer.Length)
{
// Is there any data in the write buffer? If so, switch the buffers
if (WriteBuffer.Length > 0)
SwitchBuffers();
else
{
HTTPManager.Logger.Information("UploadStream", string.Format("{0} - Read - End Of Stream", this.Name));
return -1;
}
}
else
return ReadBuffer.Read(buffer, offset, count);
}
// There are no more data in the read buffer? Wait for it.
if (IsReadBufferEmpty)
{
ARE.WaitOne();
lock (locker)
if (IsReadBufferEmpty && WriteBuffer.Length > 0)
SwitchBuffers();
}
int read = -1;
lock (locker)
read = ReadBuffer.Read(buffer, offset, count);
return read;
}
public override void Write(byte[] buffer, int offset, int count)
{
if (noMoreData)
throw new System.ArgumentException("noMoreData already set!");
lock (locker)
{
WriteBuffer.Write(buffer, offset, count);
SwitchBuffers();
}
ARE.Set();
}
public override void Flush()
{
Finish();
}
#endregion
#region Dispose Implementation
protected override void Dispose(bool disposing)
{
if (disposing)
{
HTTPManager.Logger.Information("UploadStream", string.Format("{0} - Dispose", this.Name));
ReadBuffer.Dispose();
ReadBuffer = null;
WriteBuffer.Dispose();
WriteBuffer = null;
#if NETFX_CORE
ARE.Dispose();
#else
ARE.Close();
#endif
ARE = null;
}
base.Dispose(disposing);
}
#endregion
#region Helper Functions
public void Finish()
{
if (noMoreData)
throw new System.ArgumentException("noMoreData already set!");
HTTPManager.Logger.Information("UploadStream", string.Format("{0} - Finish", this.Name));
noMoreData = true;
ARE.Set();
}
private bool SwitchBuffers()
{
// Switch the buffers only when all data are consumed from our read buffer
lock (locker)
{
if (ReadBuffer.Position == ReadBuffer.Length)
{
// This buffer will be the read buffer, we need to seek back to the beginning
WriteBuffer.Seek(0, SeekOrigin.Begin);
// This will be the write buffer, set the length to zero
ReadBuffer.SetLength(0);
// switch the two buffers
MemoryStream tmp = WriteBuffer;
WriteBuffer = ReadBuffer;
ReadBuffer = tmp;
return true;
}
}
return false;
}
#endregion
#region Not Implemented Functions and Properties
public override bool CanRead { get { throw new NotImplementedException(); } }
public override bool CanSeek { get { throw new NotImplementedException(); } }
public override bool CanWrite { get { throw new NotImplementedException(); } }
public override long Length { get { throw new NotImplementedException(); } }
public override long Position { get { throw new NotImplementedException(); } set { throw new NotImplementedException(); } }
public override long Seek(long offset, SeekOrigin origin)
{
throw new NotImplementedException();
}
public override void SetLength(long value)
{
throw new NotImplementedException();
}
#endregion
}
}

View File

@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: a2ab021301a7baf45a80b5a46275a140
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: