Browse Source

Added NullTargetCheck() to catch cases of orphaned command editors

master
chrisgregan 10 years ago
parent
commit
f91d12ba4b
  1. 3
      Assets/Fungus/Audio/Editor/ControlAudioEditor.cs
  2. 3
      Assets/Fungus/Flowchart/Editor/CallEditor.cs
  3. 26
      Assets/Fungus/Flowchart/Editor/CommandEditor.cs
  4. 3
      Assets/Fungus/Flowchart/Editor/IfEditor.cs
  5. 3
      Assets/Fungus/Flowchart/Editor/InvokeEventEditor.cs
  6. 3
      Assets/Fungus/Flowchart/Editor/JumpEditor.cs
  7. 3
      Assets/Fungus/Flowchart/Editor/LabelEditor.cs
  8. 3
      Assets/Fungus/Flowchart/Editor/SetVariableEditor.cs
  9. 3
      Assets/Fungus/Narrative/Editor/MenuEditor.cs
  10. 3
      Assets/Fungus/Narrative/Editor/MenuTimerEditor.cs
  11. 3
      Assets/Fungus/Narrative/Editor/PortraitEditor.cs
  12. 4
      Assets/Fungus/Narrative/Editor/SayEditor.cs
  13. 3
      Assets/Fungus/Narrative/Editor/StageEditor.cs
  14. 3
      Assets/Fungus/Sprite/Editor/SetColliderEditor.cs

3
Assets/Fungus/Audio/Editor/ControlAudioEditor.cs

@ -24,6 +24,9 @@ namespace Fungus
protected virtual void OnEnable()
{
if (NullTargetCheck()) // Check for an orphaned editor instance
return;
controlProp = serializedObject.FindProperty("control");
audioSourceProp = serializedObject.FindProperty("audioSource");
startVolumeProp = serializedObject.FindProperty("startVolume");

3
Assets/Fungus/Flowchart/Editor/CallEditor.cs

@ -14,6 +14,9 @@ namespace Fungus
protected virtual void OnEnable()
{
if (NullTargetCheck()) // Check for an orphaned editor instance
return;
targetFlowchartProp = serializedObject.FindProperty("targetFlowchart");
targetBlockProp = serializedObject.FindProperty("targetBlock");
callModeProp = serializedObject.FindProperty("callMode");

26
Assets/Fungus/Flowchart/Editor/CommandEditor.cs

@ -192,5 +192,31 @@ namespace Fungus
property.objectReferenceValue = result;
}
/**
* When modifying custom editor code you can occasionally end up with orphaned editor instances.
* When this happens, you'll get a null exception error every time the scene serializes / deserialized.
* Once this situation occurs, the only way to fix it is to restart the Unity editor.
*
* As a workaround, this function detects if this command editor is an orphan and deletes it.
* To use it, just call this function at the top of the OnEnable() method in your custom editor.
*/
protected virtual bool NullTargetCheck()
{
try
{
// The serializedObject accessor create a new SerializedObject if needed.
// However, this will fail with a null exception if the target object no longer exists.
#pragma warning disable 0219
SerializedObject so = serializedObject;
}
catch (System.NullReferenceException)
{
DestroyImmediate(this);
return true;
}
return false;
}
}
}

3
Assets/Fungus/Flowchart/Editor/IfEditor.cs

@ -19,6 +19,9 @@ namespace Fungus
protected virtual void OnEnable()
{
if (NullTargetCheck()) // Check for an orphaned editor instance
return;
variableProp = serializedObject.FindProperty("variable");
compareOperatorProp = serializedObject.FindProperty("compareOperator");
booleanDataProp = serializedObject.FindProperty("booleanData");

3
Assets/Fungus/Flowchart/Editor/InvokeEventEditor.cs

@ -22,6 +22,9 @@ namespace Fungus
protected virtual void OnEnable()
{
if (NullTargetCheck()) // Check for an orphaned editor instance
return;
delayProp = serializedObject.FindProperty("delay");
invokeTypeProp = serializedObject.FindProperty("invokeType");
staticEventProp = serializedObject.FindProperty("staticEvent");

3
Assets/Fungus/Flowchart/Editor/JumpEditor.cs

@ -12,6 +12,9 @@ namespace Fungus
protected virtual void OnEnable()
{
if (NullTargetCheck()) // Check for an orphaned editor instance
return;
targetLabelProp = serializedObject.FindProperty("targetLabel");
}

3
Assets/Fungus/Flowchart/Editor/LabelEditor.cs

@ -53,6 +53,9 @@ namespace Fungus
protected virtual void OnEnable()
{
if (NullTargetCheck()) // Check for an orphaned editor instance
return;
keyProp = serializedObject.FindProperty("key");
}

3
Assets/Fungus/Flowchart/Editor/SetVariableEditor.cs

@ -18,6 +18,9 @@ namespace Fungus
protected virtual void OnEnable()
{
if (NullTargetCheck()) // Check for an orphaned editor instance
return;
variableProp = serializedObject.FindProperty("variable");
setOperatorProp = serializedObject.FindProperty("setOperator");
booleanDataProp = serializedObject.FindProperty("booleanData");

3
Assets/Fungus/Narrative/Editor/MenuEditor.cs

@ -19,6 +19,9 @@ namespace Fungus
protected virtual void OnEnable()
{
if (NullTargetCheck()) // Check for an orphaned editor instance
return;
textProp = serializedObject.FindProperty("text");
descriptionProp = serializedObject.FindProperty("description");
targetBlockProp = serializedObject.FindProperty("targetBlock");

3
Assets/Fungus/Narrative/Editor/MenuTimerEditor.cs

@ -14,6 +14,9 @@ namespace Fungus
protected virtual void OnEnable()
{
if (NullTargetCheck()) // Check for an orphaned editor instance
return;
durationProp = serializedObject.FindProperty("duration");
targetBlockProp = serializedObject.FindProperty("targetBlock");
}

3
Assets/Fungus/Narrative/Editor/PortraitEditor.cs

@ -34,6 +34,9 @@ namespace Fungus
protected virtual void OnEnable()
{
if (NullTargetCheck()) // Check for an orphaned editor instance
return;
stageProp = serializedObject.FindProperty("stage");
displayProp = serializedObject.FindProperty("display");
characterProp = serializedObject.FindProperty("character");

4
Assets/Fungus/Narrative/Editor/SayEditor.cs

@ -112,6 +112,9 @@ namespace Fungus
protected virtual void OnEnable()
{
if (NullTargetCheck()) // Check for an orphaned editor instance
return;
characterProp = serializedObject.FindProperty("character");
portraitProp = serializedObject.FindProperty("portrait");
storyTextProp = serializedObject.FindProperty("storyText");
@ -124,6 +127,7 @@ namespace Fungus
fadeOutProp = serializedObject.FindProperty("fadeOut");
waitForClickProp = serializedObject.FindProperty("waitForClick");
setSayDialogProp = serializedObject.FindProperty("setSayDialog");
if (blackTex == null)
{
blackTex = CustomGUI.CreateBlackTexture();

3
Assets/Fungus/Narrative/Editor/StageEditor.cs

@ -24,6 +24,9 @@ namespace Fungus
protected virtual void OnEnable()
{
if (NullTargetCheck()) // Check for an orphaned editor instance
return;
displayProp = serializedObject.FindProperty("display");
stageProp = serializedObject.FindProperty("stage");
replacedStageProp = serializedObject.FindProperty("replacedStage");

3
Assets/Fungus/Sprite/Editor/SetColliderEditor.cs

@ -15,6 +15,9 @@ namespace Fungus
protected virtual void OnEnable()
{
if (NullTargetCheck()) // Check for an orphaned editor instance
return;
targetObjectsProp = serializedObject.FindProperty("targetObjects");
targetTagProp = serializedObject.FindProperty("targetTag");
activeStateProp = serializedObject.FindProperty("activeState");

Loading…
Cancel
Save