Skip to content

Commit

Permalink
Upload codes and demo files
Browse files Browse the repository at this point in the history
  • Loading branch information
Mogoson committed Nov 30, 2022
1 parent 85e4af5 commit 38ca289
Show file tree
Hide file tree
Showing 23 changed files with 436 additions and 1 deletion.
32 changes: 31 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,31 @@
# MGS.Graph
[TOC]

# MGS.Graph

## Summary
- Unity plugin for graph.

## Environment
- .Net Framework 3.5 or above.
- Unity 5.0 or above.

## Platform

- Windows

## Demand

- Load Texture2D from GIF file.

## Module

- GraphUtility

- ImageUtility

## Demo
- Demos in the path "MGS.Packages/Graph/Demo/" provide reference to you.

------

Copyright © 2022 Mogoson. [email protected]
9 changes: 9 additions & 0 deletions UnityProject/Assets/MGS.Packages.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions UnityProject/Assets/MGS.Packages/Graph.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions UnityProject/Assets/MGS.Packages/Graph/Demo.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions UnityProject/Assets/MGS.Packages/Graph/Demo/Scenes.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions UnityProject/Assets/MGS.Packages/Graph/Demo/Scripts.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 34 additions & 0 deletions UnityProject/Assets/MGS.Packages/Graph/Demo/Scripts/LoadGifDemo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*************************************************************************
* Copyright © 2022 Mogoson. All rights reserved.
*------------------------------------------------------------------------
* File : LoadGifDemo.cs
* Description :
*------------------------------------------------------------------------
* Author : Mogoson
* Version : 1.0
* Date : 11/30/2022
* Description : Initial development version.
*************************************************************************/

using UnityEngine;
using UnityEngine.UI;

namespace MGS.Graph.Demo
{
public class LoadGifDemo : MonoBehaviour
{
int index = 0;

void Start()
{
var gifFile = string.Format("{0}/MGS.Packages/Graph/Demo/Textures/Running.gif", Application.dataPath);
StartCoroutine(GraphUtility.LoadGifFromFile(gifFile, OnLoadProgress));
}

void OnLoadProgress(float progress, Texture2D texture)
{
transform.GetChild(index).GetComponent<RawImage>().texture = texture;
index++;
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions UnityProject/Assets/MGS.Packages/Graph/Demo/Textures.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 39 additions & 0 deletions UnityProject/Assets/MGS.Packages/Graph/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
[TOC]

# MGS.Graph

## Summary
- Unity plugin for graph.

## Environment
- .Net Framework 3.5 or above.
- Unity 5.0 or above.

## Platform

- Windows

## Version

- 0.1.0

## Demand

- Load Texture2D from GIF file.

## Module

- GraphUtility

- ImageUtility

## Demo
- Demos in the path "MGS.Packages/Graph/Demo/" provide reference to you.

## Source

- https://github.com/mogoson/MGS.Graph

------

Copyright © 2022 Mogoson. [email protected]
8 changes: 8 additions & 0 deletions UnityProject/Assets/MGS.Packages/Graph/README.md.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions UnityProject/Assets/MGS.Packages/Graph/Runtime.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

59 changes: 59 additions & 0 deletions UnityProject/Assets/MGS.Packages/Graph/Runtime/GraphUtility.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*************************************************************************
* Copyright © 2021 Mogoson. All rights reserved.
*------------------------------------------------------------------------
* File : GraphUtility.cs
* Description : Utility for unity Graph.
*------------------------------------------------------------------------
* Author : Mogoson
* Version : 1.0
* Date : 10/04/2021
* Description : Initial development version.
*************************************************************************/

using System;
using System.Collections;
using System.Collections.Generic;
using System.Drawing.Imaging;
using UnityEngine;

namespace MGS.Graph
{
/// <summary>
/// Utility for unity Graph.
/// </summary>
public sealed class GraphUtility
{
/// <summary>
/// Load gif from file.
/// </summary>
/// <param name="file"></param>
/// <param name="progress"></param>
/// <param name="finished"></param>
/// <returns></returns>
public static IEnumerator LoadGifFromFile(string file,
Action<float, Texture2D> progress, Action<List<Texture2D>> finished = null)
{
var frames = ImageUtility.GetFrames(file);
var index = 0;
var textures = new List<Texture2D>();
foreach (var frame in frames)
{
var buffer = ImageUtility.GetBuffer(frame, ImageFormat.Png);
var texture = new Texture2D(frame.Width, frame.Height);
texture.LoadImage(buffer);
textures.Add(texture);

index++;
if (progress != null)
{
progress.Invoke((float)index / frames.Length, texture);
}
yield return null;
}
if (finished != null)
{
finished.Invoke(textures);
}
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 38ca289

Please sign in to comment.