diff --git a/spine-unity/Assets/spine-unity/Asset Types/AtlasAsset.cs b/spine-unity/Assets/spine-unity/Asset Types/AtlasAsset.cs
index d39014021..5eb5b87f1 100644
--- a/spine-unity/Assets/spine-unity/Asset Types/AtlasAsset.cs
+++ b/spine-unity/Assets/spine-unity/Asset Types/AtlasAsset.cs
@@ -57,7 +57,7 @@ namespace Spine.Unity {
return atlasAsset;
}
-
+
///
/// Creates a runtime AtlasAsset. Only providing the textures is slower because it has to search for atlas page matches.
public static AtlasAsset CreateRuntimeInstance (TextAsset atlasText, Texture2D[] textures, Shader shader, bool initialize) {
@@ -94,12 +94,25 @@ namespace Spine.Unity {
materials[i] = mat;
else
throw new ArgumentException("Could not find matching atlas page in the texture array.");
-
}
// Create AtlasAsset normally
return CreateRuntimeInstance(atlasText, materials, initialize);
}
+
+ ///
+ /// Creates a runtime AtlasAsset. Only providing the textures is slower because it has to search for atlas page matches.
+ public static AtlasAsset CreateRuntimeInstance (TextAsset atlasText, Texture2D[] textures, Material materialPropertySource, bool initialize) {
+ var shader = materialPropertySource.shader;
+ var oa = CreateRuntimeInstance(atlasText, textures, shader, initialize);
+
+ foreach (var m in oa.materials) {
+ m.CopyPropertiesFromMaterial(materialPropertySource);
+ m.shaderKeywords = materialPropertySource.shaderKeywords;
+ }
+
+ return oa;
+ }
#endregion
void Reset () {
diff --git a/spine-unity/Assets/spine-unity/Modules/SkeletonGraphic/SkeletonGraphic.cs b/spine-unity/Assets/spine-unity/Modules/SkeletonGraphic/SkeletonGraphic.cs
index 81e869ace..c65d7002b 100644
--- a/spine-unity/Assets/spine-unity/Modules/SkeletonGraphic/SkeletonGraphic.cs
+++ b/spine-unity/Assets/spine-unity/Modules/SkeletonGraphic/SkeletonGraphic.cs
@@ -86,6 +86,23 @@ namespace Spine.Unity {
#endif
#endregion
+ #region Runtime Instantiation
+ public static SkeletonGraphic NewSkeletonGraphicGameObject (SkeletonDataAsset skeletonDataAsset, Transform parent) {
+ SkeletonGraphic sg = SkeletonGraphic.AddSkeletonGraphicComponent(new GameObject("New Spine GameObject"), skeletonDataAsset);
+ if (parent != null) sg.transform.SetParent(parent, false);
+ return sg;
+ }
+
+ public static SkeletonGraphic AddSkeletonGraphicComponent (GameObject gameObject, SkeletonDataAsset skeletonDataAsset) {
+ var c = gameObject.AddComponent();
+ if (skeletonDataAsset != null) {
+ c.skeletonDataAsset = skeletonDataAsset;
+ c.Initialize(false);
+ }
+ return c;
+ }
+ #endregion
+
#region Internals
// This is used by the UI system to determine what to put in the MaterialPropertyBlock.
public override Texture mainTexture {
diff --git a/spine-unity/Assets/spine-unity/Modules/SkeletonRenderSeparator/SkeletonRenderSeparator.cs b/spine-unity/Assets/spine-unity/Modules/SkeletonRenderSeparator/SkeletonRenderSeparator.cs
index 648563a38..3c4915baa 100644
--- a/spine-unity/Assets/spine-unity/Modules/SkeletonRenderSeparator/SkeletonRenderSeparator.cs
+++ b/spine-unity/Assets/spine-unity/Modules/SkeletonRenderSeparator/SkeletonRenderSeparator.cs
@@ -71,6 +71,36 @@ namespace Spine.Unity.Modules {
#endif
#endregion
+ #region Runtime Instantiation
+ public static SkeletonRenderSeparator AddToSkeletonRenderer (SkeletonRenderer skeletonRenderer, int sortingLayerID = 0, int extraPartsRenderers = 0, int sortingOrderIncrement = DefaultSortingOrderIncrement, int baseSortingOrder = 0, bool addMinimumPartsRenderers = true) {
+ if (skeletonRenderer == null) {
+ Debug.Log("Tried to add SkeletonRenderSeparator to a null SkeletonRenderer reference.");
+ return null;
+ }
+
+ var srs = skeletonRenderer.gameObject.AddComponent();
+ srs.skeletonRenderer = skeletonRenderer;
+
+ skeletonRenderer.Initialize(false);
+ int count = extraPartsRenderers;
+ if (addMinimumPartsRenderers)
+ count = extraPartsRenderers + skeletonRenderer.separatorSlots.Count + 1;
+
+ var skeletonRendererTransform = skeletonRenderer.transform;
+ var componentRenderers = srs.partsRenderers;
+
+ for (int i = 0; i < count; i++) {
+ var smr = SkeletonPartsRenderer.NewPartsRendererGameObject(skeletonRendererTransform, i.ToString());
+ var mr = smr.MeshRenderer;
+ mr.sortingLayerID = sortingLayerID;
+ mr.sortingOrder = baseSortingOrder + (i * sortingOrderIncrement);
+ componentRenderers.Add(smr);
+ }
+
+ return srs;
+ }
+ #endregion
+
void OnEnable () {
if (skeletonRenderer == null) return;
if (copiedBlock == null) copiedBlock = new MaterialPropertyBlock();