Skip to content

Commit

Permalink
Fixed team error
Browse files Browse the repository at this point in the history
Fixes team NullReference when removing character
  • Loading branch information
WyrnCael committed May 2, 2018
1 parent d76ce99 commit 4079b1d
Show file tree
Hide file tree
Showing 12 changed files with 16 additions and 301 deletions.
61 changes: 0 additions & 61 deletions Assets/TRPGMaker/Database/Characters/NewCharacter(1).asset

This file was deleted.

10 changes: 0 additions & 10 deletions Assets/TRPGMaker/Database/Characters/NewCharacter(1).asset.meta

This file was deleted.

65 changes: 0 additions & 65 deletions Assets/TRPGMaker/Database/Characters/NewCharacter(4).asset

This file was deleted.

10 changes: 0 additions & 10 deletions Assets/TRPGMaker/Database/Characters/NewCharacter(4).asset.meta

This file was deleted.

62 changes: 0 additions & 62 deletions Assets/TRPGMaker/Database/Characters/NewCharacter(5).asset

This file was deleted.

10 changes: 0 additions & 10 deletions Assets/TRPGMaker/Database/Characters/NewCharacter(5).asset.meta

This file was deleted.

60 changes: 0 additions & 60 deletions Assets/TRPGMaker/Database/Characters/NewCharacter(7).asset

This file was deleted.

10 changes: 0 additions & 10 deletions Assets/TRPGMaker/Database/Characters/NewCharacter(7).asset.meta

This file was deleted.

4 changes: 0 additions & 4 deletions Assets/TRPGMaker/Database/Database.asset
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,6 @@ MonoBehaviour:
- {fileID: 11400000, guid: 684c928e26a3b364c9cc9cff30e18082, type: 2}
characters:
- {fileID: 11400000, guid: 36a63a88f336fee4fbee3ca4e3812861, type: 2}
- {fileID: 11400000, guid: 2ce6ded48f42c8e46b99a9a665a8efda, type: 2}
- {fileID: 11400000, guid: 47430d8af55fb254dbd2af8d116d196d, type: 2}
- {fileID: 11400000, guid: 75942776545ea02418c221a9273f406b, type: 2}
- {fileID: 11400000, guid: bac31a58c9f786c4a9d5b67034ba5482, type: 2}
- {fileID: 11400000, guid: 496024b31fb8d604ba8b12317f0d4762, type: 2}
- {fileID: 11400000, guid: a0544f3bb46f87e4b902b7442a6702ca, type: 2}
teams:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ MonoBehaviour:
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 4a7b1fcdece9778478b2575993f98a72, type: 3}
m_Name: Playable Tea
m_Name: Playable Team
m_EditorClassIdentifier:
name: Playable Team
id: 0
characters:
- {fileID: 11400000, guid: 36a63a88f336fee4fbee3ca4e3812861, type: 2}
- {fileID: 11400000, guid: 47430d8af55fb254dbd2af8d116d196d, type: 2}
playable: 1
- {fileID: 11400000, guid: a0544f3bb46f87e4b902b7442a6702ca, type: 2}
playable: 0
19 changes: 13 additions & 6 deletions Assets/TRPGMaker/Editor/TeamEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,20 +45,27 @@ private void OnEnable()
}
menu.ShowAsContext();
};

// Remove character
listCharacters.onRemoveCallback = (ReorderableList l) =>
{
Team team = (Team)target;
team.characters.Remove(listCharacters.serializedProperty.GetArrayElementAtIndex(l.index).objectReferenceValue as Character);
};
}

public override void OnInspectorGUI()
{
serializedObject.Update();

Team team = (Team)target;
// Clean array if there are null objects
for (int i = 0; i < listCharacters.serializedProperty.arraySize; i++)
for (int i = 0; i < team.characters.Count; i++)
{
var elementProperty = listCharacters.serializedProperty.GetArrayElementAtIndex(i);
if (elementProperty.objectReferenceValue == null)
listCharacters.serializedProperty.DeleteArrayElementAtIndex(i);
if (team.characters[i] == null)
team.characters.RemoveAt(i);
}

serializedObject.Update();

var customStyle = new GUIStyle();
customStyle.alignment = TextAnchor.UpperCenter;
customStyle.fontSize = 17;
Expand Down

0 comments on commit 4079b1d

Please sign in to comment.