This file contains hidden or 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
using System; | |
using UnityEditor; | |
using UnityEditor.SceneManagement; | |
using UnityEngine.SceneManagement; | |
[InitializeOnLoad] | |
public static class EditorSceneMemoryManager | |
{ | |
static EditorSceneMemoryManager() | |
{ |
This file contains hidden or 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
public class ReferenceHolder : MonoBehaviour | |
{ | |
public Sprite m_SpriteValue; | |
} |
This file contains hidden or 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
public class ReferenceHolder : MonoBehaviour | |
{ | |
public Sprite m_SpriteValue; | |
void OnDestroy() | |
{ | |
m_SpriteValue = null; | |
} | |
} |
This file contains hidden or 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
public class BaseMonoBehaviour : MonoBehaviour | |
{ | |
void OnDestroy() | |
{ | |
foreach (FieldInfo field in GetType().GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance)) | |
{ | |
Type fieldType = field.FieldType; | |
if (typeof(IList).IsAssignableFrom(fieldType)) | |
{ |
This file contains hidden or 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
[RequireComponent(typeof(Rigidbody2D))] | |
public class Example : MonoBehaviour | |
{ | |
void OnValidate() | |
{ | |
GetComponent<Rigidbody2D>().bodyType = RigidbodyType2D.Dynamic; | |
} | |
} |
This file contains hidden or 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
public class BaseMonoBehaviour : MonoBehaviour | |
{ | |
public virtual bool OnValidateProperty(string propertyName) | |
{ | |
return false; | |
} | |
// Remember to include the OnDestroy code from Step 3 as well | |
} |
This file contains hidden or 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
[CanEditMultipleObjects, CustomEditor(typeof(BaseMonoBehaviour), true)] | |
public class BaseMonoBehaviourEditor : Editor | |
{ | |
public override void OnInspectorGUI() | |
{ | |
serializedObject.Update(); | |
SerializedProperty iterator = serializedObject.GetIterator(); | |
bool enterChildren = true; | |
while (iterator.NextVisible(enterChildren)) |
This file contains hidden or 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
[RequireComponent(typeof(Rigidbody2D))] | |
public class MyCustomClass : BaseMonoBehaviour | |
{ | |
public bool m_CanMove; | |
public override bool OnValidateProperty(string propertyName) | |
{ | |
if (propertyName == "m_CanMove") | |
{ | |
if (!m_CanMove) |
This file contains hidden or 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
[CanEditMultipleObjects, CustomEditor(typeof(MyCustomClass), true)] | |
public class MyCustomEditor : BaseMonoBehaviourEditor | |
{ | |
protected override void DrawProperty(Rect position, SerializedProperty property, GUIContent label) | |
{ | |
if (property.name == "m_CanMove") | |
{ | |
// insert custom editor code for this property | |
} | |
else |
This file contains hidden or 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
#if UNITY_EDITOR | |
if (!EditorApplication.isPlayingOrWillChangePlaymode) | |
{ | |
// time intensive code you don’t want executed when entering play mode | |
} | |
#endif |