-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Include TidyBehaviour to ensure we clean up references in editor
- Loading branch information
1 parent
6e4bc8e
commit 1a084d4
Showing
6 changed files
with
121 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
using UnityEngine; | ||
|
||
public class NavigationController : MonoBehaviour { | ||
|
||
} | ||
namespace VioletUI { | ||
public class NavigationController : TidyBehaviour { | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using UnityEngine; | ||
using System; | ||
using System.Diagnostics; | ||
using System.Reflection; | ||
|
||
namespace VioletUI { | ||
|
||
public class TidyBehaviour : MonoBehaviour { | ||
protected virtual void OnDestroy() { | ||
ReleaseReferences(); | ||
} | ||
|
||
[Conditional("UNITY_EDITOR")] | ||
void ReleaseReferences() { | ||
foreach (FieldInfo field in this.GetType().GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance)) { | ||
Type fieldType = field.FieldType; | ||
|
||
if (typeof(IList).IsAssignableFrom(fieldType)) { | ||
IList list = field.GetValue(this) as IList; | ||
list?.Clear(); | ||
} else if (typeof(IDictionary).IsAssignableFrom(fieldType)) { | ||
IDictionary dictionary = field.GetValue(this) as IDictionary; | ||
dictionary?.Clear(); | ||
} | ||
|
||
if (!fieldType.IsPrimitive) { | ||
field.SetValue(this, null); | ||
} | ||
} | ||
|
||
foreach (PropertyInfo property in this.GetType().GetProperties(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance)) { | ||
Type fieldType = property.PropertyType; | ||
|
||
if (typeof(IList).IsAssignableFrom(fieldType)) { | ||
IList list = property.GetValue(this) as IList; | ||
list?.Clear(); | ||
} else if (typeof(IDictionary).IsAssignableFrom(fieldType)) { | ||
IDictionary dictionary = property.GetValue(this) as IDictionary; | ||
dictionary?.Clear(); | ||
} | ||
} | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters