Skip to content

Commit

Permalink
Merge pull request #16 from loodakrawa/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
loodakrawa committed Nov 30, 2015
2 parents ebf5623 + 7fa2b9e commit c9450f4
Show file tree
Hide file tree
Showing 11 changed files with 206 additions and 27 deletions.
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
##### 1.0.4
* Fix SpriterImporter to pass prefab instead of destroyed tmp object

##### 1.0.3
* Fix bug when no keyframe in t = 0
* Fix bug when keyframe has no object_refs

##### 1.0.2
* Fix changing pivots when blending animations

##### 1.0.1
* Add XML Documentation to SpriterAnimator
* Fix blend compatibility test
* Fix read only properties in SpriterAnimator
* Fix bug with weird behaviour on extremely short transition time
* Move first animation init from SpriterAnimator cosntructor to Step method
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,19 @@ Being a pure C# implementation, SpriterDotNet doesn't depend on any external lib
6. Call Step in every frame
7. Control the animation with properties

### SpriterAnimator
This class contains the majority of Properties and Methods necessary to control the animation.

###### Properties
* Speed - Playback speed. Negative speeds reverse the animation
* Time - The current time in animation in milliseconds
* Progress - The progress of animation. Ranges from 0.0f to 1.0f

###### Methods
* Play(string name) - Plays the given animation
* Transition(string name, float totalTransitionTime) - Transitions to given animation doing a progressive blend in the given time
* Blend - Blends two animations with the given weight factor

#### Points
* Override SpriterAnimator.ApplyPointTransform

Expand Down
1 change: 0 additions & 1 deletion SpriterDotNet.MonoGame/SpriterGame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ protected override void Update(GameTime gameTime)
string entity = currentAnimator.Entity.Name;
status = String.Format("{0} : {1}", entity, currentAnimator.Name);
metadata = "Variables:\n" + GetVarValues() + "\nTags:\n" + GetTagValues();

base.Update(gameTime);
}

Expand Down
3 changes: 2 additions & 1 deletion SpriterDotNet.UnitTests/SpriterDotNet.UnitTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>SpriterDotNet.UnitTests</RootNamespace>
<AssemblyName>SpriterDotNet.UnitTests</AssemblyName>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand Down
Binary file modified SpriterDotNet.Unity/Assets/SpriterDotNet/Lib/SpriterDotNet.dll
Binary file not shown.
21 changes: 12 additions & 9 deletions SpriterDotNet.Unity/Assets/SpriterDotNet/SpriterImporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ public class SpriterImporter : AssetPostprocessor

public static float DeltaZ = -0.001f;
public static bool UseNativeTags = true;
public static event Action<SpriterEntity, GameObject> EntityImported = (e,g) => { };

public static event Action<SpriterEntity, GameObject> EntityImported = (e, p) => { };

private static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromPath)
{
Expand Down Expand Up @@ -65,18 +65,18 @@ private static void CreateSpriter(string path)
CreateSprites(entity, cd, spriter, sprites);
CreateCollisionRectangles(entity, cd, spriter, metadata);
CreatePoints(entity, cd, spriter, metadata);

behaviour.EntityIndex = entity.Id;
behaviour.enabled = true;
behaviour.SpriterData = spriterData;
behaviour.ChildData = cd;

CreatePrefab(go, rootFolder);
GameObject prefab = CreatePrefab(go, rootFolder);

EntityImported(entity, go);
EntityImported(entity, prefab);
}

if(UseNativeTags) CreateTags(spriter);
if (UseNativeTags) CreateTags(spriter);
}

private static SpriterData CreateSpriterData(Spriter spriter, string rootFolder, string name)
Expand All @@ -91,15 +91,18 @@ private static SpriterData CreateSpriterData(Spriter spriter, string rootFolder,
return data;
}

private static void CreatePrefab(GameObject go, string folder)
private static GameObject CreatePrefab(GameObject go, string folder)
{
string prefabPath = folder + "/" + go.name + ".prefab";
GameObject existing = AssetDatabase.LoadAssetAtPath<GameObject>(prefabPath);

if (existing != null) PrefabUtility.ReplacePrefab(go, existing, ReplacePrefabOptions.Default);
else PrefabUtility.CreatePrefab(prefabPath, go, ReplacePrefabOptions.Default);
GameObject prefab;
if (existing != null) prefab = PrefabUtility.ReplacePrefab(go, existing, ReplacePrefabOptions.Default);
else prefab = PrefabUtility.CreatePrefab(prefabPath, go, ReplacePrefabOptions.Default);

GameObject.DestroyImmediate(go);

return prefab;
}

private static void CreateSprites(SpriterEntity entity, ChildData cd, Spriter spriter, GameObject parent)
Expand Down
33 changes: 30 additions & 3 deletions SpriterDotNet.Unity/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,43 @@ This distribution comes with 2 different packages:
* SpriterDotNet.Unity.unitypackage (contains just the library)
* SpriterDotNet.Unity.Examples.unitypackage (contains the library and a couple of examples)

## Basic Usage
The most easy way of using SpriterDotBNet.Unity with your own animations is the following:
* Install SpriterDotNet.Unity.Examples.unitypackage
* Create a new scene
* Copy your scml and all required files into the Assets folder in your project
* Drag and drop the generated .prefab to the scene (SpriterDotNet.Unity generates a prefab for each entity in the scml)
* Drag and drop Controller.prefab to the scene
* (Optional) Drag and drop Canvas.prefab to the scene to have on-screen instructions about key mappings

**Note that the example Controller supports ony one prefab per scene. If you add multiples, it's only going to affect one of them.**

## Usage
The usual way of using SpriterDotNet.Unity is to get a reference to a UnitySpriterAnimator from a SpriterDotNetBehaviour and controlling the animation as described in the [SpriterAnimator documentation](https://github.com/loodakrawa/SpriterDotNet/tree/develop#spriteranimator).

###### Getting a reference tp UnitySpriterAnimator
In a script attached to the same GameObject which also contains SpriterDotNetBehaviour:
```csharp
UnitySpriterAnimator animator = gameObject.GetComponent<SpriterDotNetBehaviour>().Animator;
```

In a script attached to other GameObjects:
```csharp
UnitySpriterAnimator animator = FindObjectOfType<SpriterDotNetBehaviour>().Animator;
```

## Tags
SpriterDotNet creates Unity tags while importing Spriter assets. This behaviour can be controlled with the UseNativeTags
flag in SpriterImporter. Unfortunately Unity doesn't support multiple tags so SpriterDotNet just sets the first tag as the
GameObject tag. Other tags can be accessed via the Metadata property of UnitySpriterAnimator.
flag in SpriterImporter. Unfortunately Unity doesn't support multiple tags so SpriterDotNet just sets the first tag as the GameObject tag. Other tags can be accessed via the Metadata property of UnitySpriterAnimator.

## Importer Hooks
If you want to do post processing on imported assets, SpriterImporter exposes the EntityImported event. See
TestSpriterImportHook in the examples project.

## Usability
## Generated ScriptableObjects
SpriterDotNet.Unity generates one ScriptableObject per .scml file to hold all parsed scml data which is shared across all entities defined in the same scml. (For example, for squares.scml a squares.asset object gets generated). This means that for most changes to the .scml get reflected in Unity automatically.

## Features
This plugin has been designed with most common scenarios in mind. However, it's hard to cover all possible use-cases.
If you have good ideas about improving functionality and/or ease of use feel free to suggest it either on [Spriter Forum](http://brashmonkey.com/forum/index.php?/topic/4166-spriterdotnet-an-implementation-for-all-c-frameworks/)
or here on GitHub (as an Enhancement Issue).
Binary file modified SpriterDotNet.Unity/SpriterDotNet.Unity.Examples.unitypackage
Binary file not shown.
Binary file modified SpriterDotNet.Unity/SpriterDotNet.Unity.unitypackage
Binary file not shown.
Loading

0 comments on commit c9450f4

Please sign in to comment.