Skip to content

Commit

Permalink
fix: 全てのオブジェクトにRecordObjectが行われるように修正
Browse files Browse the repository at this point in the history
  • Loading branch information
pspkurara committed Nov 6, 2020
1 parent 8575729 commit 78eb45f
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 1 deletion.
1 change: 1 addition & 0 deletions Packages/uGUI-Skinner/Runtime/SkinParts/AnimationSample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public void SetValues(SkinLogicProperty property)
//値がないなら何もしない
if (property.floatValues.Count < FloatLength) return;
activeTime = property.floatValues[TimeIndex];
SkinnerRuntimeEditorUtility.DeepRecordObject(rootGameObject);
animationClip.SampleAnimation(rootGameObject, activeTime);
}

Expand Down
1 change: 1 addition & 0 deletions Packages/uGUI-Skinner/Runtime/SkinParts/GraphicMaterial.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public void SetValues(SkinLogicProperty property)
{
material = property.objectReferenceValues[MaterialIndex] as Material;
}
SkinnerRuntimeEditorUtility.RecordObject(graphic);
graphic.material = material;
SkinnerUtility.ReloadGameObject(graphic);
}
Expand Down
1 change: 1 addition & 0 deletions Packages/uGUI-Skinner/Runtime/SkinParts/ImageSprite.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public void SetValues(SkinLogicProperty property)
{
sprite = property.objectReferenceValues[SpriteIndex] as Sprite;
}
SkinnerRuntimeEditorUtility.RecordObject(image);
image.sprite = sprite;
SkinnerUtility.ReloadGameObject(image);
}
Expand Down
1 change: 1 addition & 0 deletions Packages/uGUI-Skinner/Runtime/SkinParts/RawImageTexture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public void SetValues(SkinLogicProperty property)
{
texture2D = property.objectReferenceValues[Texture2DIndex] as Texture2D;
}
SkinnerRuntimeEditorUtility.RecordObject(rawImage);
rawImage.texture = texture2D;
SkinnerUtility.ReloadGameObject(rawImage);
}
Expand Down
1 change: 1 addition & 0 deletions Packages/uGUI-Skinner/Runtime/SkinParts/ScriptableLogic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public void SetValues(SkinLogicProperty property)
// 自由に処理をかけるのでエラー回避を入れておく
try
{
SkinnerRuntimeEditorUtility.RecordObjects(ignoredLogicProperty.Value.objectReferenceValues);
userLogic.SetValues(ignoredLogicProperty.Value);
}
// エラーが起こっても何もせず終わる
Expand Down
56 changes: 55 additions & 1 deletion Packages/uGUI-Skinner/Runtime/SkinnerRuntimeEditorUtility.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using UnityEngine;
using System.Collections.Generic;
#if UNITY_EDITOR
using UnityEditor;
#endif
Expand All @@ -9,7 +10,7 @@ namespace Pspkurara.UI.Skinner
/// <summary>
/// ランタイム用asmdef上でエディタ関数を使うためのクラス
/// </summary>
internal static class SkinnerRuntimeEditorUtility
public static class SkinnerRuntimeEditorUtility
{

/// <summary>
Expand All @@ -19,11 +20,64 @@ internal static class SkinnerRuntimeEditorUtility
[System.Diagnostics.Conditional("UNITY_EDITOR")]
public static void RecordObject(Object @object)
{
if (@object == null) return;
#if UNITY_EDITOR
Undo.RecordObject(@object, "SkinnerPartsEdit");
#endif
}

/// <summary>
/// <seealso cref="Undo.RecordObject(Object, string)"/>を呼び出す
/// </summary>
/// <param name="objects">履歴を記録する対象のオブジェクト群</param>
[System.Diagnostics.Conditional("UNITY_EDITOR")]
public static void RecordObjects(IEnumerable<Object> objects)
{
foreach (var @object in objects)
{
RecordObject(@object);
}
}

/// <summary>
/// <seealso cref="Undo.RecordObject(Object, string)"/>を呼び出す
/// 全ての子に対して適応する
/// </summary>
/// <param name="object">履歴を記録する対象のオブジェクト</param>
[System.Diagnostics.Conditional("UNITY_EDITOR")]
public static void DeepRecordObject(GameObject rootGameObject)
{
// ルートがなければ何もしない
if (rootGameObject == null) return;

// 全てのコンポーネントのUndoを書き込む
foreach (var component in rootGameObject.GetComponentsInChildren<Component>(true))
{
RecordObject(component);
}

// 全てのtransformとgameObjectのUndoを書き込む
DeepRecordObjectWithTransformAndGameObject(rootGameObject.transform);
}

/// <summary>
/// <see cref="Transform"/>と<see cref="GameObject">に対して<seealso cref="Undo.RecordObject(Object, string)"/>を呼び出す
/// 全ての子に適応する
/// </summary>
/// <param name="transform">親オブジェクト</param>
[System.Diagnostics.Conditional("UNITY_EDITOR")]
private static void DeepRecordObjectWithTransformAndGameObject(Transform transform)
{
if (transform == null) return;
RecordObject(transform);
RecordObject(transform.gameObject);
for (int i = 0; i < transform.childCount; i++)
{
var child = transform.GetChild(i);
DeepRecordObjectWithTransformAndGameObject(child);
}
}

}

}

0 comments on commit 78eb45f

Please sign in to comment.