Skip to content

Instantly share code, notes, and snippets.

@randomize
Last active October 23, 2017 21:16
Show Gist options
  • Save randomize/73ca6d3b6aa7210073692eb5cabd537e to your computer and use it in GitHub Desktop.
Save randomize/73ca6d3b6aa7210073692eb5cabd537e to your computer and use it in GitHub Desktop.
Since 2017.2 LayoutGroup restores child properties in OnDisable, to prevent that and force old behavior use this override
//===----------------------------------------------------------------------===//
//
// vim: ft=cs tw=80
//
// Date: 10/23/2017 23:10:37
// Creator: Eugene Mihailenco <mihailencoe@gmail.com>
//
//===----------------------------------------------------------------------===//
using UnityEngine.UI;
namespace BullyFramework
{
public class GoodHorizontalLayout : HorizontalLayoutGroup
{
#region Serializable data
#endregion
#region Private fields
#endregion
#region Public methods and properties
// Copy-pasted original HorizontalLayoutGroup impl, note it calls base
// OnDisable - i.e UIBehaviour.OnDisable()
// protected override void OnDisable()
// {
// m_Tracker.Clear();
// LayoutRebuilder.MarkLayoutForRebuild(rectTransform);
// base.OnDisable();
// }
protected override void OnDisable()
{
m_Tracker.Clear(false); // key change - do not restore - false
LayoutRebuilder.MarkLayoutForRebuild(rectTransform);
// UIBehaviour.OnDisable(); C# sucks on calling grand parent, but luckily in Unity 2017.2 that OnDisable() is empty
}
#endregion
#region MonoBehaviour methods
#endregion
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment