-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Editor for StateHurtboxDefinition.
StateHurtboxDefinition can now properly add custom hurtboxes and box definitions in the inspector.
- Loading branch information
1 parent
4479d7e
commit 9d26e39
Showing
15 changed files
with
4,787 additions
and
2,438 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
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,60 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using UnityEditor; | ||
using UnityEngine; | ||
|
||
namespace CAF.Combat | ||
{ | ||
[CustomEditor(typeof(StateHurtboxDefinition), true)] | ||
public class StateHurtboxDefinitionEditor : Editor | ||
{ | ||
StateHurtboxDefinition t; | ||
|
||
protected Dictionary<string, Type> hurtboxGroupTypes = new Dictionary<string, Type>(); | ||
|
||
private void OnEnable() | ||
{ | ||
hurtboxGroupTypes.Clear(); | ||
foreach (var a in AppDomain.CurrentDomain.GetAssemblies()) | ||
{ | ||
foreach (var givenType in a.GetTypes()) | ||
{ | ||
if (givenType.IsSubclassOf(typeof(HurtboxGroup)) || givenType == typeof(HurtboxGroup)) | ||
{ | ||
hurtboxGroupTypes.Add(givenType.FullName, givenType); | ||
} | ||
} | ||
} | ||
} | ||
|
||
public override void OnInspectorGUI() | ||
{ | ||
t = target as StateHurtboxDefinition; | ||
|
||
if (GUILayout.Button("Add Hurtbox Group")) | ||
{ | ||
GenericMenu menu = new GenericMenu(); | ||
|
||
foreach (string hType in hurtboxGroupTypes.Keys) | ||
{ | ||
string destination = hType.Replace('.', '/'); | ||
menu.AddItem(new GUIContent(destination), true, OnHurtboxGroupTypeSelected, hType); | ||
} | ||
menu.ShowAsContext(); | ||
} | ||
|
||
for(int i = 0; i < t.hurtboxGroups.Count; i++) | ||
{ | ||
EditorGUILayout.LabelField($"Hurtbox Group {i}"); | ||
EditorGUI.indentLevel++; | ||
t.hurtboxGroups[i].DrawInspector(15); | ||
EditorGUI.indentLevel--; | ||
} | ||
} | ||
|
||
private void OnHurtboxGroupTypeSelected(object type) | ||
{ | ||
t.hurtboxGroups.Add((HurtboxGroup)Activator.CreateInstance(hurtboxGroupTypes[(string)type])); | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
Assets/CAF/Editor/Combat/StateHurtboxDefinitionEditor.cs.meta
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
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
Oops, something went wrong.