-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from chiepomme/gif
Gif に対応した
- Loading branch information
Showing
61 changed files
with
3,402 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using UnityEngine; | ||
using UnityEngine.UI; | ||
using UTJ.FrameCapturer; | ||
|
||
public class GifPlayer : MonoBehaviour | ||
{ | ||
public static GifPlayer Create(RawImage image, List<UniGif.GifTexture> textures) | ||
{ | ||
var player = new GameObject("GifPlayer").AddComponent<GifPlayer>(); | ||
player.Initialize(image, textures); | ||
return player; | ||
} | ||
|
||
class SequenceData | ||
{ | ||
public readonly Texture2D texture; | ||
public readonly float cumulativeSec; | ||
|
||
public SequenceData(Texture2D texture, float cumulativeSec) | ||
{ | ||
this.texture = texture; | ||
this.cumulativeSec = cumulativeSec; | ||
} | ||
} | ||
|
||
RawImage image; | ||
|
||
float lengthSec; | ||
List<SequenceData> sequence = new List<SequenceData>(); | ||
MovieRecorder recorder; | ||
|
||
AudioSource audioSource; | ||
|
||
void Initialize(RawImage image, List<UniGif.GifTexture> textures) | ||
{ | ||
var cumulativeSec = 0f; | ||
foreach (var texture in textures) | ||
{ | ||
sequence.Add(new SequenceData(texture.m_texture2d, cumulativeSec)); | ||
cumulativeSec += texture.m_delaySec; | ||
} | ||
lengthSec = cumulativeSec; | ||
|
||
this.image = image; | ||
this.image.texture = sequence[0].texture; | ||
} | ||
|
||
public void PlaySyncWith(AudioSource audioSource) | ||
{ | ||
this.audioSource = audioSource; | ||
} | ||
|
||
void Update() | ||
{ | ||
if (sequence.Count == 1 || audioSource == null) return; | ||
var currentSec = audioSource.time % lengthSec; | ||
image.texture = sequence.Last(s => s.cumulativeSec <= currentSec).texture; | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Binary file not shown.
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,33 @@ | ||
# ---------------[ Unity generated ]------------------ # | ||
[Aa]pps/ | ||
[Ll]ibrary/ | ||
[Tt]emp/ | ||
[Oo]bj/ | ||
[Ss]treamingAssets/ | ||
[Ss]treamingAssets.meta | ||
UnityGenerated/ | ||
|
||
# ----[ Visual Studio / MonoDevelop generated ]------- # | ||
|
||
ExportedObj/ | ||
*.svd | ||
*.userprefs | ||
*.csproj | ||
*.pidb | ||
*.suo | ||
*.sln | ||
*.user | ||
*.unityproj | ||
*.booproj | ||
[Uu]nityVS/ | ||
[Uu]nityVS.meta | ||
|
||
# -------------[ OS generated ]------------------------ # | ||
.DS_Store | ||
.DS_Store? | ||
._* | ||
.Spotlight-V100 | ||
.Trashes | ||
Icon? | ||
ehthumbs.db | ||
Thumbs.db |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,72 @@ | ||
/* | ||
UniGif | ||
Copyright (c) 2015 WestHillApps (Hironari Nishioka) | ||
This software is released under the MIT License. | ||
http://opensource.org/licenses/mit-license.php | ||
*/ | ||
|
||
using System; | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using UnityEngine; | ||
|
||
public static partial class UniGif | ||
{ | ||
/// <summary> | ||
/// Get GIF texture list Coroutine | ||
/// </summary> | ||
/// <param name="bytes">GIF file byte data</param> | ||
/// <param name="callback">Callback method(param is GIF texture list, Animation loop count, GIF image width (px), GIF image height (px))</param> | ||
/// <param name="filterMode">Textures filter mode</param> | ||
/// <param name="wrapMode">Textures wrap mode</param> | ||
/// <param name="debugLog">Debug Log Flag</param> | ||
/// <returns>IEnumerator</returns> | ||
public static IEnumerator GetTextureListCoroutine( | ||
byte[] bytes, | ||
Action<List<GifTexture>, int, int, int> callback, | ||
FilterMode filterMode = FilterMode.Bilinear, | ||
TextureWrapMode wrapMode = TextureWrapMode.Clamp, | ||
bool debugLog = false) | ||
{ | ||
int loopCount = -1; | ||
int width = 0; | ||
int height = 0; | ||
|
||
// Set GIF data | ||
var gifData = new GifData(); | ||
if (SetGifData(bytes, ref gifData, debugLog) == false) | ||
{ | ||
Debug.LogError("GIF file data set error."); | ||
if (callback != null) | ||
{ | ||
callback(null, loopCount, width, height); | ||
} | ||
yield break; | ||
} | ||
|
||
// Decode to textures from GIF data | ||
List<GifTexture> gifTexList = null; | ||
yield return DecodeTextureCoroutine(gifData, result => gifTexList = result, filterMode, wrapMode); | ||
|
||
if (gifTexList == null || gifTexList.Count <= 0) | ||
{ | ||
Debug.LogError("GIF texture decode error."); | ||
if (callback != null) | ||
{ | ||
callback(null, loopCount, width, height); | ||
} | ||
yield break; | ||
} | ||
|
||
loopCount = gifData.m_appEx.loopCount; | ||
width = gifData.m_logicalScreenWidth; | ||
height = gifData.m_logicalScreenHeight; | ||
|
||
if (callback != null) | ||
{ | ||
callback(gifTexList, loopCount, width, height); | ||
} | ||
|
||
yield break; | ||
} | ||
} |
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.