Storyline+Dialog初步
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
using UnityEditor;
|
||||
using UnityEditor.UIElements;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
namespace SubAssetsToolbox.Samples.Editor
|
||||
{
|
||||
[CustomEditor(typeof(SubAssetAwareSO), true)]
|
||||
public class SubAssetAwareSOEditor : UnityEditor.Editor
|
||||
{
|
||||
public VisualTreeAsset lineTemplate;
|
||||
public VisualTreeAsset extrasTemplate;
|
||||
|
||||
private SerializedProperty _subAssetsProp;
|
||||
|
||||
public override VisualElement CreateInspectorGUI()
|
||||
{
|
||||
VisualElement inspector = new();
|
||||
InspectorElement.FillDefaultInspector(inspector, serializedObject, this);
|
||||
|
||||
_subAssetsProp = serializedObject.FindProperty("_subAssets");
|
||||
if (_subAssetsProp.arraySize != 0)
|
||||
{
|
||||
extrasTemplate.CloneTree(inspector);
|
||||
|
||||
// Draw sub-assets list
|
||||
ListView subAssetsList = inspector.Q<ListView>("SubAssetsList");
|
||||
subAssetsList.makeItem += MakeItem;
|
||||
subAssetsList.bindItem += BindItem;
|
||||
subAssetsList.BindProperty(_subAssetsProp);
|
||||
}
|
||||
|
||||
return inspector;
|
||||
}
|
||||
|
||||
private VisualElement MakeItem()
|
||||
{
|
||||
return lineTemplate.Instantiate();
|
||||
}
|
||||
|
||||
private void BindItem(VisualElement visualElement, int index)
|
||||
{
|
||||
Object subAsset = _subAssetsProp.GetArrayElementAtIndex(index).objectReferenceValue;
|
||||
visualElement.Q<ObjectField>("SubAssetField").value = subAsset;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 21cab18be96345ce975cfe1380654953
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences:
|
||||
- lineTemplate: {fileID: 9197481963319205126, guid: a3eb80c229d604b8a8483f6df0d7f204,
|
||||
type: 3}
|
||||
- extrasTemplate: {fileID: 9197481963319205126, guid: 213eed75602b6410d8cdd7fd24509144,
|
||||
type: 3}
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 284154
|
||||
packageName: SubAssets Toolbox
|
||||
packageVersion: 1.1.0
|
||||
assetPath: Packages/io.continis.subassets/Samples~/SubAssetAwareScriptableObjects/Editor/SubAssetAwareSOEditor.cs
|
||||
uploadId: 869944
|
||||
@@ -0,0 +1,25 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace SubAssetsToolbox.Samples
|
||||
{
|
||||
/// <summary>
|
||||
/// ScriptableObject class that implements the <see cref="ISubAssetAware"/> interface to interact with sub-asset workflows.
|
||||
/// Contains a List to keep references to its sub-assets. The list is displayed in the asset's Inspector using a custom editor.
|
||||
/// Use this class as a starting point, and implement your own sub-asset aware ScriptableObjects.
|
||||
/// </summary>
|
||||
[CreateAssetMenu(menuName = "SubAssets Toolbox/SubAsset Aware SO", fileName = "SubAssetAwareSO")]
|
||||
public class SubAssetAwareSO : ScriptableObject, ISubAssetAware
|
||||
{
|
||||
[SerializeField, HideInInspector] private List<Object> _subAssets = new();
|
||||
|
||||
public void AddSubAsset(Object newSubAsset) => _subAssets.Add(newSubAsset);
|
||||
public void RemoveSubAsset(Object removedSubAsset) => _subAssets.Remove(removedSubAsset);
|
||||
|
||||
public virtual Object GetSubAssetByName(string subAssetName) => _subAssets.Find(o => o.name == subAssetName);
|
||||
public virtual List<Object> GetAllSubAssetsByName(string subAssetName) => _subAssets.FindAll(o => o.name == subAssetName);
|
||||
|
||||
public virtual Object GetSubAssetByType<T>() => _subAssets.Find(o => o.GetType() == typeof(T));
|
||||
public virtual List<Object> GetAllSubAssetsByType<T>() => _subAssets.FindAll(o => o.GetType() == typeof(T));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ff267a32cfc64732a2ca1cc5b4acf09f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 284154
|
||||
packageName: SubAssets Toolbox
|
||||
packageVersion: 1.1.0
|
||||
assetPath: Packages/io.continis.subassets/Samples~/SubAssetAwareScriptableObjects/SubAssetAwareSO.cs
|
||||
uploadId: 869944
|
||||
Reference in New Issue
Block a user