Skip to content

Commit

Permalink
perf: クリーンアップの削除対象を強化 (まったく同じ設定のスキンパーツを消去対象に)
Browse files Browse the repository at this point in the history
  • Loading branch information
pspkurara committed Nov 8, 2020
1 parent 98a59b7 commit 41f1d0b
Show file tree
Hide file tree
Showing 7 changed files with 145 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ public void DrawInspector(EditorSkinPartsPropertry property)
userLogic.ValidateProperty(validateProperty);
UserLogicExtension.ReleaseActiveUserLogic();
validateProperty.objectReferenceValues.Insert(ScriptableLogic.LogicIndex, userLogic);
SkinnerEditorUtility.MapRuntimePropertyFromEditorProperty(property, validateProperty);
SkinnerEditorUtility.MapEditorPropertyFromRuntimeProperty(property, validateProperty);
}
}

Expand Down
2 changes: 1 addition & 1 deletion Packages/uGUI-Skinner/Editor/SkinnerEditorUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ public static void MapRuntimePropertyFromEditorProperty(SkinPartsPropertry mapTa
/// </summary>
/// <param name="mapTarget">マップ対象となるオブジェクト</param>
/// <param name="mapSource">マップ元となるオブジェクト</param>
public static void MapRuntimePropertyFromEditorProperty(EditorSkinPartsPropertry mapTarget, SkinPartsPropertry mapSource)
public static void MapEditorPropertyFromRuntimeProperty(EditorSkinPartsPropertry mapTarget, SkinPartsPropertry mapSource)
{
MapEditorFromRuntimeSingleProperty(mapTarget.objectReferenceValues, mapSource.objectReferenceValues, (v, p) => p.objectReferenceValue = v);
MapEditorFromRuntimeSingleProperty(mapTarget.floatValues, mapSource.floatValues, (v, p) => p.floatValue = v);
Expand Down
23 changes: 23 additions & 0 deletions Packages/uGUI-Skinner/Editor/UISkinnerInspector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using UnityEngine;
using Object = UnityEngine.Object;
using System;
using System.Collections.Generic;

namespace Pspkurara.UI
{
Expand Down Expand Up @@ -32,6 +33,7 @@ public static class FieldName
private SerializedProperty m_SkinStyles;

private EditorSkinPartsPropertry m_SkinPartsProperty = null;
private SkinParts m_RuntimeSkinParts = null;

private int[] m_SkinnerPartsOptionValues = null;
private GUIContent[] m_SkinnerPartsDisplayNames = null;
Expand Down Expand Up @@ -69,6 +71,7 @@ private void OnEnable()
m_StyleIndex = serializedObject.FindProperty(FieldName.StyleIndex);

m_SkinPartsProperty = new EditorSkinPartsPropertry();
m_RuntimeSkinParts = new SkinParts();

m_GuiUniqueIdCounter.ResetLastControlGuiId();
}
Expand Down Expand Up @@ -369,8 +372,10 @@ private void ApplySkin()

private void Cleanup()
{
var checkedSkinParts = new List<SkinParts>();
for (int skinStylesIndex = 0; skinStylesIndex < m_SkinStyles.arraySize; skinStylesIndex++)
{
checkedSkinParts.Clear();
SerializedProperty skinPartsProperty = m_SkinStyles.GetArrayElementAtIndex(skinStylesIndex).FindPropertyRelative(FieldName.Parts);
for (int skinPartsIndex = skinPartsProperty.arraySize-1; skinPartsIndex >= 0; skinPartsIndex--)
{
Expand Down Expand Up @@ -419,6 +424,24 @@ private void Cleanup()
{
// オブジェクト参照がない場合何にも影響しないのでいらないと思う
skinPartsProperty.DeleteArrayElementAtIndex(skinPartsIndex);
continue;
}

// まったく同じ設定のスキンパーツがないか調べる
m_RuntimeSkinParts.type = skinPartsType;
SkinnerEditorUtility.MapRuntimePropertyFromEditorProperty(m_RuntimeSkinParts.property, m_SkinPartsProperty);
if (checkedSkinParts.Any(p => p.Equals(m_RuntimeSkinParts)))
{
// 同じ設定はいらないと思う
skinPartsProperty.DeleteArrayElementAtIndex(skinPartsIndex);
}
else
{
// ユニークなものとしてチェックリストに増やす
var cacheParts = new SkinParts();
cacheParts.type = skinPartsType;
SkinnerEditorUtility.MapRuntimePropertyFromEditorProperty(cacheParts.property, m_SkinPartsProperty);
checkedSkinParts.Add(cacheParts);
}

}
Expand Down
71 changes: 71 additions & 0 deletions Packages/uGUI-Skinner/Runtime/ArrayHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
using System.Collections.Generic;
using System.Linq;

namespace Pspkurara.UI.Skinner
{

/// <summary>
/// 配列系のいろいろをサポートするヘルパークラス
/// </summary>
internal static class ArrayHelper
{

/// <summary>
/// 一致チェック用メソッドデリゲート
/// </summary>
/// <typeparam name="T">要素の型</typeparam>
/// <param name="a">1つ目の比較対象の要素</param>
/// <param name="b">2つ目の比較対象の要素</param>
/// <returns></returns>
public delegate bool ElementComparer<T>(T a, T b);

/// <summary>
/// 配列の中身が一致しているかを調べる
/// </summary>
/// <typeparam name="T">配列の要素の型</typeparam>
/// <param name="a">1つ目比較対象の配列</param>
/// <param name="b">2つ目比較対象の配列</param>
/// <param name="comparer">一致チェック用メソッド</param>
/// <returns>一致する</returns>
public static bool ArrayEquals<T>(IEnumerable<T> a, IEnumerable<T> b, ElementComparer<T> comparer)
{
if (a == null && b == null) return true;
if (a == null || b == null) return false;
if (a.Count() != b.Count()) return false;
for (int i = 0; i < a.Count(); i++)
{
if (!comparer.Invoke(a.ElementAt(i), b.ElementAt(i))) return false;
}
return true;
}

/// <summary>
/// <see cref="foreach"/>をまわす
/// </summary>
/// <param name="arraySize">配列サイズ</param>
/// <param name="elementAction">呼び出すメソッド</param>
public static void ForEach<T>(int arraySize, System.Action<int> elementAction)
{
for (int i = 0; i < arraySize; i++)
{
elementAction.Invoke(i);
}
}

/// <summary>
/// <see cref="foreach"/>をまわす
/// </summary>
/// <param name="array">配列</param>
/// <param name="elementAction">呼び出すメソッド</param>
public static void ForEach<T>(IEnumerable<T> array, System.Action<T> elementAction)
{
if (array == null) return;
for (int i = 0; i < array.Count(); i++)
{
elementAction.Invoke(array.ElementAt(i));
}
}

}

}
11 changes: 11 additions & 0 deletions Packages/uGUI-Skinner/Runtime/ArrayHelper.cs.meta

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

13 changes: 12 additions & 1 deletion Packages/uGUI-Skinner/Runtime/SkinParts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace Pspkurara.UI.Skinner
/// 見た目の個別データ
/// </summary>
[System.Serializable]
public sealed class SkinParts
public sealed class SkinParts : System.IEquatable<SkinParts>
{

#region 変数
Expand Down Expand Up @@ -112,6 +112,17 @@ internal void OnValidate()
applySkinFunction = null;
}

/// <summary>
/// 引数に指定したものと自身の中身が一致するか調べる
/// </summary>
/// <param name="other">調査対象</param>
/// <returns>一致する</returns>
public bool Equals(SkinParts other)
{
if (m_Type != other.m_Type) return false;
return m_Property.Equals(other);
}

}

}
28 changes: 26 additions & 2 deletions Packages/uGUI-Skinner/Runtime/SkinPartsProperty.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace Pspkurara.UI.Skinner
/// プロパティパック
/// </summary>
[System.Serializable]
public sealed class SkinPartsPropertry : SkinPartsPropertryWithoutObjectReference, ISkinPartsProperty
public sealed class SkinPartsPropertry : SkinPartsPropertryWithoutObjectReference, ISkinPartsProperty, System.IEquatable<SkinPartsPropertry>
{

#region 変数
Expand Down Expand Up @@ -58,6 +58,17 @@ public override void Clear()
m_ObjectReferenceValues.Clear();
}

/// <summary>
/// 引数に指定したものと自身の中身が一致するか調べる
/// </summary>
/// <param name="other">調査対象</param>
/// <returns>一致する</returns>
public bool Equals(SkinPartsPropertry other)
{
if (!ArrayHelper.ArrayEquals(m_ObjectReferenceValues, other.m_ObjectReferenceValues, (a, b) => a == b)) return false;
return base.Equals(other);
}

#endregion

}
Expand All @@ -67,7 +78,7 @@ public override void Clear()
/// オブジェクト参照は除く
/// </summary>
[System.Serializable]
public class SkinPartsPropertryWithoutObjectReference
public class SkinPartsPropertryWithoutObjectReference : System.IEquatable<SkinPartsPropertryWithoutObjectReference>
{

#region 変数
Expand Down Expand Up @@ -140,6 +151,19 @@ public virtual void Clear()
m_StringValues.Clear();
}

/// <summary>
/// 引数に指定したものと自身の中身が一致するか調べる
/// </summary>
/// <param name="other">調査対象</param>
/// <returns>一致する</returns>
public bool Equals(SkinPartsPropertryWithoutObjectReference other)
{
if (!ArrayHelper.ArrayEquals(m_FloatValues, other.m_FloatValues, (a, b) => Mathf.Approximately(a, b))) return false;
if (!ArrayHelper.ArrayEquals(m_Vector4Values, other.m_Vector4Values, (a, b) => a == b)) return false;
if (!ArrayHelper.ArrayEquals(m_StringValues, other.m_StringValues, (a, b) => string.Equals(a, b))) return false;
return true;
}

#endregion

}
Expand Down

0 comments on commit 41f1d0b

Please sign in to comment.