Initialer Upload neues Unity-Projekt
This commit is contained in:
@ -0,0 +1,115 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Convai.Scripts.Narrative_Design.Models;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Convai.Scripts.Narrative_Design.Editor
|
||||
{
|
||||
[CustomEditor(typeof(NarrativeDesignManager))]
|
||||
public class NarrativeDesignManagerEditor : UnityEditor.Editor
|
||||
{
|
||||
/// Dictionary to keep track of which sections are expanded in the editor
|
||||
private readonly Dictionary<string, bool> _sectionIdExpanded = new();
|
||||
|
||||
/// Reference to the NarrativeDesignManager that this editor is modifying
|
||||
private NarrativeDesignManager _narrativeDesignManager;
|
||||
|
||||
/// SerializedProperty for the section change events in the NarrativeDesignManager
|
||||
private SerializedProperty _sectionChangeEvents;
|
||||
|
||||
/// Whether the section events are expanded in the editor
|
||||
private bool _sectionEventsExpanded = true;
|
||||
|
||||
/// SerializedObject for the target object
|
||||
private SerializedObject _serializedObject;
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
_serializedObject = new SerializedObject(target);
|
||||
_narrativeDesignManager = target as NarrativeDesignManager;
|
||||
|
||||
if (_narrativeDesignManager != null) FindProperties();
|
||||
}
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
_serializedObject.Update();
|
||||
|
||||
if (GUILayout.Button("Check for Updates")) OnUpdateNarrativeDesignButtonClicked();
|
||||
|
||||
GUILayout.Space(10);
|
||||
|
||||
if (_narrativeDesignManager.sectionDataList.Count > 0)
|
||||
{
|
||||
_sectionEventsExpanded = EditorGUILayout.Foldout(_sectionEventsExpanded, "Section Events", true, EditorStyles.foldoutHeader);
|
||||
|
||||
if (_sectionEventsExpanded)
|
||||
{
|
||||
EditorGUI.indentLevel++;
|
||||
|
||||
EditorGUI.BeginChangeCheck();
|
||||
|
||||
for (int i = 0; i < _narrativeDesignManager.sectionDataList.Count; i++)
|
||||
{
|
||||
SectionData sectionData = _narrativeDesignManager.sectionDataList[i];
|
||||
string sectionId = sectionData.sectionId;
|
||||
|
||||
SectionChangeEventsData sectionChangeEventsData = _narrativeDesignManager.sectionChangeEventsDataList.Find(x => x.id == sectionId);
|
||||
|
||||
if (sectionChangeEventsData == null)
|
||||
{
|
||||
sectionChangeEventsData = new SectionChangeEventsData { id = sectionId };
|
||||
_narrativeDesignManager.sectionChangeEventsDataList.Add(sectionChangeEventsData);
|
||||
}
|
||||
|
||||
_sectionIdExpanded.TryAdd(sectionId, false);
|
||||
|
||||
GUIStyle sectionIdStyle = new(EditorStyles.foldoutHeader)
|
||||
{
|
||||
fontStyle = FontStyle.Bold,
|
||||
fontSize = 14
|
||||
};
|
||||
|
||||
string sectionIdText = $"{sectionData.sectionName} - {sectionId}";
|
||||
_sectionIdExpanded[sectionId] = EditorGUILayout.Foldout(_sectionIdExpanded[sectionId], sectionIdText, true, sectionIdStyle);
|
||||
|
||||
if (_sectionIdExpanded[sectionId])
|
||||
{
|
||||
EditorGUI.indentLevel++;
|
||||
|
||||
SerializedProperty sectionChangeEventsProperty = _sectionChangeEvents.GetArrayElementAtIndex(i);
|
||||
EditorGUILayout.PropertyField(sectionChangeEventsProperty, GUIContent.none, true);
|
||||
|
||||
EditorGUI.indentLevel--;
|
||||
}
|
||||
}
|
||||
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
_serializedObject.ApplyModifiedProperties();
|
||||
_narrativeDesignManager.OnSectionEventListChange();
|
||||
}
|
||||
|
||||
EditorGUI.indentLevel--;
|
||||
}
|
||||
}
|
||||
|
||||
_serializedObject.ApplyModifiedProperties();
|
||||
}
|
||||
|
||||
private async void OnUpdateNarrativeDesignButtonClicked()
|
||||
{
|
||||
await Task.WhenAll(_narrativeDesignManager.UpdateSectionListAsync(), _narrativeDesignManager.UpdateTriggerListAsync());
|
||||
_serializedObject.ApplyModifiedProperties();
|
||||
_narrativeDesignManager.OnSectionEventListChange();
|
||||
}
|
||||
|
||||
private void FindProperties()
|
||||
{
|
||||
_serializedObject.FindProperty(nameof(NarrativeDesignManager.sectionDataList));
|
||||
_serializedObject.FindProperty(nameof(NarrativeDesignManager.triggerDataList));
|
||||
_sectionChangeEvents = _serializedObject.FindProperty(nameof(NarrativeDesignManager.sectionChangeEventsDataList));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1537f32558f6e8042878f1a95c1fe984
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -0,0 +1,43 @@
|
||||
using Convai.Scripts.Narrative_Design.Models;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Convai.Scripts.Narrative_Design.Editor
|
||||
{
|
||||
[CustomPropertyDrawer(typeof(SectionChangeEventsData))]
|
||||
public class NarrativeDesignSectionChangeEventsDataPropertyDrawer : PropertyDrawer
|
||||
{
|
||||
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
|
||||
{
|
||||
EditorGUI.BeginProperty(position, label, property);
|
||||
|
||||
SerializedProperty sectionIdProperty = property.FindPropertyRelative("id");
|
||||
SerializedProperty onSectionStartProperty = property.FindPropertyRelative("onSectionStart");
|
||||
SerializedProperty onSectionEndProperty = property.FindPropertyRelative("onSectionEnd");
|
||||
|
||||
Rect sectionIdRect = new(position.x, position.y, position.width, EditorGUIUtility.singleLineHeight);
|
||||
EditorGUI.LabelField(sectionIdRect, "Section ID", sectionIdProperty.stringValue);
|
||||
|
||||
position.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
|
||||
EditorGUI.PropertyField(position, onSectionStartProperty, true);
|
||||
position.y += EditorGUI.GetPropertyHeight(onSectionStartProperty) + EditorGUIUtility.standardVerticalSpacing;
|
||||
|
||||
EditorGUI.PropertyField(position, onSectionEndProperty, true);
|
||||
|
||||
EditorGUI.EndProperty();
|
||||
}
|
||||
|
||||
public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
|
||||
{
|
||||
SerializedProperty onSectionStartProperty = property.FindPropertyRelative("onSectionStart");
|
||||
SerializedProperty onSectionEndProperty = property.FindPropertyRelative("onSectionEnd");
|
||||
|
||||
float height = EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
height += EditorGUI.GetPropertyHeight(onSectionStartProperty) + EditorGUIUtility.standardVerticalSpacing;
|
||||
height += EditorGUI.GetPropertyHeight(onSectionEndProperty);
|
||||
|
||||
return height;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 23fcdcc9acc44804e991455dcd85953d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -0,0 +1,19 @@
|
||||
using UnityEditor;
|
||||
|
||||
namespace Convai.Scripts.Narrative_Design.Editor
|
||||
{
|
||||
[CustomEditor(typeof(NarrativeDesignTrigger))]
|
||||
public class NarrativeDesignTriggerEditor : UnityEditor.Editor
|
||||
{
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
NarrativeDesignTrigger narrativeDesignTrigger = (NarrativeDesignTrigger)target;
|
||||
|
||||
DrawDefaultInspector();
|
||||
|
||||
if (narrativeDesignTrigger.availableTriggers is { Count: > 0 })
|
||||
narrativeDesignTrigger.selectedTriggerIndex =
|
||||
EditorGUILayout.Popup("Trigger", narrativeDesignTrigger.selectedTriggerIndex, narrativeDesignTrigger.availableTriggers.ToArray());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cdf68c1817bd4102879052a18d773fec
|
||||
timeCreated: 1706873993
|
||||
Reference in New Issue
Block a user