-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
Develop
- Loading branch information
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// Copyright (c) 2015 The original author or authors | ||
// | ||
// This software may be modified and distributed under the terms | ||
// of the zlib license. See the LICENSE file for details. | ||
|
||
#if UNITY_EDITOR | ||
|
||
using System; | ||
using System.Reflection; | ||
using UnityEditor; | ||
using UnityEditorInternal; | ||
|
||
namespace SpriterDotNetUnity | ||
{ | ||
[CustomEditor(typeof(SpriterDotNetBehaviour))] | ||
public class SpriterDotNetBehaviourEditor : Editor | ||
{ | ||
string[] GetSortingLayerNames() | ||
{ | ||
Type internalEditorUtilityType = typeof(InternalEditorUtility); | ||
PropertyInfo sortingLayersProperty = internalEditorUtilityType.GetProperty("sortingLayerNames", BindingFlags.Static | BindingFlags.NonPublic); | ||
return (string[])sortingLayersProperty.GetValue(null, new object[0]); | ||
} | ||
|
||
public override void OnInspectorGUI() | ||
{ | ||
DrawDefaultInspector(); | ||
|
||
SpriterDotNetBehaviour sdnb = target as SpriterDotNetBehaviour; | ||
|
||
string[] layers = GetSortingLayerNames(); | ||
int currentIndex = Array.IndexOf(layers, sdnb.SortingLayer); | ||
if (currentIndex < 0) currentIndex = 0; | ||
int choiceIndex = EditorGUILayout.Popup("Sorting Layer", currentIndex, layers); | ||
sdnb.SortingLayer = layers[choiceIndex]; | ||
EditorUtility.SetDirty(target); | ||
} | ||
} | ||
} | ||
|
||
#endif |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// Copyright (c) 2015 The original author or authors | ||
// | ||
// This software may be modified and distributed under the terms | ||
// of the zlib license. See the LICENSE file for details. | ||
|
||
namespace SpriterDotNet.AnimationDataProvider | ||
{ | ||
public class DefaultAnimationDataProvider : IAnimationDataProvider | ||
{ | ||
private readonly FrameData data = new FrameData(); | ||
private readonly FrameMetadata metadata = new FrameMetadata(); | ||
|
||
public virtual FrameData GetFrameData(float time, float deltaTime, float factor, SpriterAnimation first, SpriterAnimation second = null) | ||
{ | ||
data.Clear(); | ||
|
||
if (second == null) | ||
{ | ||
SpriterProcessor.UpdateFrameData(data, first, time); | ||
} | ||
else | ||
{ | ||
SpriterProcessor.UpdateFrameData(data, first, second, time, factor); | ||
} | ||
|
||
return data; | ||
} | ||
|
||
public virtual FrameMetadata GetFrameMetadata(float time, float deltaTime, float factor, SpriterAnimation first, SpriterAnimation second = null) | ||
{ | ||
metadata.Clear(); | ||
|
||
if (second == null) | ||
{ | ||
SpriterProcessor.UpdateFrameMetadata(metadata, first, time, deltaTime); | ||
} | ||
else | ||
{ | ||
SpriterProcessor.GetFrameMetadata(metadata, first, second, time, deltaTime, factor); | ||
} | ||
|
||
return metadata; | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// Copyright (c) 2015 The original author or authors | ||
// | ||
// This software may be modified and distributed under the terms | ||
// of the zlib license. See the LICENSE file for details. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
|
||
namespace SpriterDotNet.AnimationDataProvider | ||
{ | ||
public class SnapshotAnimationDataProvider : DefaultAnimationDataProvider | ||
{ | ||
public static IDictionary<string, FrameData[]> GetData(SpriterEntity entity, int interval) | ||
{ | ||
IDictionary<string, FrameData[]> data = new Dictionary<string, FrameData[]>(); | ||
|
||
foreach (SpriterAnimation anim in entity.Animations) | ||
{ | ||
int length = (int)Math.Ceiling(anim.Length / interval); | ||
FrameData[] animData = new FrameData[length]; | ||
|
||
for (int i = 0; i < animData.Length; ++i) | ||
{ | ||
float time = i * interval; | ||
if (time > anim.Length) time = anim.Length; | ||
|
||
FrameData fd = new FrameData(); | ||
SpriterProcessor.UpdateFrameData(fd, anim, time); | ||
animData[i] = fd; | ||
} | ||
|
||
data[anim.Name] = animData; | ||
} | ||
|
||
return data; | ||
} | ||
|
||
private readonly IDictionary<string, FrameData[]> data; | ||
|
||
public SnapshotAnimationDataProvider(IDictionary<string, FrameData[]> data) | ||
{ | ||
this.data = data; | ||
} | ||
|
||
public override FrameData GetFrameData(float time, float deltaTime, float factor, SpriterAnimation first, SpriterAnimation second = null) | ||
{ | ||
if (second != null) return base.GetFrameData(time, deltaTime, factor, first, second); | ||
|
||
FrameData[] animData = data[first.Name]; | ||
int index = (int)(time / first.Length * animData.Length); | ||
if (index == animData.Length) index = animData.Length - 1; | ||
return animData[index]; | ||
} | ||
} | ||
} |