Files
.vs
Assets
Library
APIUpdater
Artifacts
Bee
BuildPlayerData
PackageCache
com.unity.collab-proxy@2.5.2
com.unity.editorcoroutines@1.0.0
com.unity.ext.nunit@1.0.6
com.unity.feature.development@1.0.1
com.unity.ide.rider@3.0.31
com.unity.ide.visualstudio@2.0.22
com.unity.ide.vscode@1.2.5
com.unity.modules.ai@1.0.0
com.unity.modules.androidjni@1.0.0
com.unity.modules.animation@1.0.0
com.unity.modules.assetbundle@1.0.0
com.unity.modules.audio@1.0.0
com.unity.modules.cloth@1.0.0
com.unity.modules.director@1.0.0
com.unity.modules.imageconversion@1.0.0
com.unity.modules.imgui@1.0.0
com.unity.modules.jsonserialize@1.0.0
com.unity.modules.particlesystem@1.0.0
com.unity.modules.physics2d@1.0.0
com.unity.modules.physics@1.0.0
com.unity.modules.screencapture@1.0.0
com.unity.modules.subsystems@1.0.0
com.unity.modules.terrain@1.0.0
com.unity.modules.terrainphysics@1.0.0
com.unity.modules.tilemap@1.0.0
com.unity.modules.ui@1.0.0
com.unity.modules.uielements@1.0.0
com.unity.modules.umbra@1.0.0
com.unity.modules.unityanalytics@1.0.0
com.unity.modules.unitywebrequest@1.0.0
com.unity.modules.unitywebrequestassetbundle@1.0.0
com.unity.modules.unitywebrequestaudio@1.0.0
com.unity.modules.unitywebrequesttexture@1.0.0
com.unity.modules.unitywebrequestwww@1.0.0
com.unity.modules.vehicles@1.0.0
com.unity.modules.video@1.0.0
com.unity.modules.vr@1.0.0
com.unity.modules.wind@1.0.0
com.unity.modules.xr@1.0.0
com.unity.performance.profile-analyzer@1.2.2
com.unity.settings-manager@2.0.1
com.unity.test-framework@1.1.33
com.unity.testtools.codecoverage@1.2.6
com.unity.textmeshpro@3.0.6
com.unity.timeline@1.7.6
DocCodeExamples
Documentation~
Editor
Actions
Activation
Analytics
Animation
Attributes
Audio
ControlTrack
CustomEditors
Extensions
Items
Localization
Manipulators
Playables
Properties
Recording
Signals
TreeView
SignalListFactory.cs
SignalListFactory.cs.meta
SignalReceiverItem.cs
SignalReceiverItem.cs.meta
SignalReceiverTreeView.cs
SignalReceiverTreeView.cs.meta
SignalAssetInspector.cs
SignalAssetInspector.cs.meta
SignalEmitterEditor.cs
SignalEmitterEditor.cs.meta
SignalEmitterInspector.cs
SignalEmitterInspector.cs.meta
SignalEventDrawer.cs
SignalEventDrawer.cs.meta
SignalManager.cs
SignalManager.cs.meta
SignalReceiverHeader.cs
SignalReceiverHeader.cs.meta
SignalReceiverInspector.cs
SignalReceiverInspector.cs.meta
SignalUtility.cs
SignalUtility.cs.meta
Styles.cs
Styles.cs.meta
TreeView.meta
State
StyleSheets
Undo
Utilities
Window
inspectors
treeview
Actions.meta
Activation.meta
Analytics.meta
Animation.meta
Attributes.meta
Audio.meta
ControlTrack.meta
CurveEditUtility.cs
CurveEditUtility.cs.meta
CustomEditors.meta
DirectorNamedColor.cs
DirectorNamedColor.cs.meta
DirectorStyles.cs
DirectorStyles.cs.meta
Extensions.meta
Items.meta
Localization.meta
Manipulators.meta
MenuPriority.cs
MenuPriority.cs.meta
Playables.meta
Properties.meta
Recording.meta
Shortcuts.cs
Shortcuts.cs.meta
Signals.meta
State.meta
StyleSheets.meta
TimelineEditor.cs
TimelineEditor.cs.meta
TimelineHelpers.cs
TimelineHelpers.cs.meta
TimelineSelection.cs
TimelineSelection.cs.meta
TimelineUtility.cs
TimelineUtility.cs.meta
Tooltip.cs
Tooltip.cs.meta
Trackhead.cs
Trackhead.cs.meta
Undo.meta
Unity.Timeline.Editor.asmdef
Unity.Timeline.Editor.asmdef.meta
UnityEditorInternals.cs
UnityEditorInternals.cs.meta
Utilities.meta
Window.meta
inspectors.meta
treeview.meta
Runtime
Samples~
.signature
CHANGELOG.md
CHANGELOG.md.meta
DocCodeExamples.meta
Editor.meta
LICENSE.md
LICENSE.md.meta
README.md
README.md.meta
Runtime.meta
ValidationExceptions.json
ValidationExceptions.json.meta
package.json
package.json.meta
com.unity.ugui@1.0.0
com.unity.visualscripting@1.9.4
PackageManager
PlayModeViewStates
PlayerDataCache
ScriptAssemblies
Search
ShaderCache
SplashScreenCache
StateCache
UIElements
AnnotationManager
ArtifactDB
ArtifactDB-lock
BuildPlayer.prefs
BuildSettings.asset
EditorOnlyScriptingSettings.json
EditorOnlyVirtualTextureState.json
EditorSnapSettings.asset
EditorUserBuildSettings.asset
InspectorExpandedItems.asset
LastBuild.buildreport
LastSceneManagerSetup.txt
LibraryFormatVersion.txt
MonoManager.asset
SceneVisibilityState.asset
ScriptMapper
ShaderCache.db
SourceAssetDB
SourceAssetDB-lock
SpriteAtlasDatabase.asset
Style.catalog
expandedItems
ilpp.pid
Logs
Packages
ProjectSettings
UserSettings
obj
.vsconfig
Assembly-CSharp.Player.csproj
Assembly-CSharp.csproj
TM1.sln
Unity.CollabProxy.Editor.csproj
Unity.EditorCoroutines.Editor.csproj
Unity.Performance.Profile-Analyzer.Editor.csproj
Unity.PlasticSCM.Editor.csproj
Unity.Rider.Editor.csproj
Unity.Settings.Editor.csproj
Unity.TestTools.CodeCoverage.Editor.OpenCover.Model.csproj
Unity.TestTools.CodeCoverage.Editor.OpenCover.Mono.Reflection.csproj
Unity.TestTools.CodeCoverage.Editor.csproj
Unity.TextMeshPro.Editor.csproj
Unity.TextMeshPro.Player.csproj
Unity.TextMeshPro.csproj
Unity.Timeline.Editor.csproj
Unity.Timeline.Player.csproj
Unity.Timeline.csproj
Unity.VSCode.Editor.csproj
Unity.VisualScripting.Core.Editor.csproj
Unity.VisualScripting.Core.Player.csproj
Unity.VisualScripting.Core.csproj
Unity.VisualScripting.Flow.Editor.csproj
Unity.VisualScripting.Flow.Player.csproj
Unity.VisualScripting.Flow.csproj
Unity.VisualScripting.SettingsProvider.Editor.csproj
Unity.VisualScripting.Shared.Editor.csproj
Unity.VisualScripting.State.Editor.csproj
Unity.VisualScripting.State.Player.csproj
Unity.VisualScripting.State.csproj
Unity.VisualStudio.Editor.csproj
UnityEditor.TestRunner.csproj
UnityEditor.UI.csproj
UnityEngine.TestRunner.Player.csproj
UnityEngine.TestRunner.csproj
UnityEngine.UI.Player.csproj
UnityEngine.UI.csproj
TP_Multimedia/Library/PackageCache/com.unity.timeline@1.7.6/Editor/Signals/TreeView/SignalReceiverItem.cs

186 lines
7.1 KiB
C#
Raw Normal View History

2025-01-17 13:10:20 +01:00
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEditor.IMGUI.Controls;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.Timeline;
using Object = UnityEngine.Object;
namespace UnityEditor.Timeline.Signals
{
class SignalReceiverItem : TreeViewItem, ISignalAssetProvider
{
static readonly SignalEventDrawer k_EvtDrawer = new SignalEventDrawer();
readonly SerializedProperty m_Asset;
readonly SerializedProperty m_Evt;
readonly SignalReceiverTreeView m_TreeView;
int m_CurrentRowIdx;
SignalReceiver m_CurrentReceiver;
internal readonly bool enabled;
internal readonly bool readonlySignal;
internal const string SignalName = "SignalName";
internal const string SignalNameReadOnly = "SignalNameReadOnly";
internal const string SignalOptions = "SignalOptions";
public SignalReceiverItem(SerializedProperty signalAsset, SerializedProperty eventListEntry, int id, bool readonlySignal, bool enabled, SignalReceiverTreeView treeView)
: base(id, 0)
{
m_Asset = signalAsset;
m_Evt = eventListEntry;
this.enabled = enabled;
this.readonlySignal = readonlySignal;
m_TreeView = treeView;
}
public SignalAsset signalAsset
{
get { return m_CurrentReceiver.GetSignalAssetAtIndex(m_CurrentRowIdx); }
set
{
Undo.RecordObject(m_CurrentReceiver, Styles.UndoCreateSignalAsset);
m_CurrentReceiver.ChangeSignalAtIndex(m_CurrentRowIdx, value);
PrefabUtility.RecordPrefabInstancePropertyModifications(m_CurrentReceiver);
}
}
public float GetHeight()
{
return k_EvtDrawer.GetPropertyHeight(m_Evt, GUIContent.none);
}
public void Draw(Rect rect, int colIdx, int rowIdx, float padding, SignalReceiver target)
{
switch (colIdx)
{
case 0:
DrawSignalNameColumn(rect, padding, target, rowIdx);
break;
case 1:
DrawReactionColumn(rect, rowIdx);
break;
default:
throw new ArgumentOutOfRangeException();
}
}
void DrawSignalNameColumn(Rect rect, float padding, SignalReceiver target, int rowIdx)
{
using (new EditorGUI.DisabledScope(!enabled))
{
if (!readonlySignal)
{
m_CurrentRowIdx = rowIdx;
m_CurrentReceiver = target;
rect.x += padding;
rect.width -= padding;
rect.height = EditorGUIUtility.singleLineHeight;
GUI.SetNextControlName(SignalName);
SignalUtility.DrawSignalNames(this, rect, GUIContent.none, false);
}
else
{
GUI.SetNextControlName(SignalNameReadOnly);
var signalAsset = m_Asset.objectReferenceValue;
GUI.Label(rect,
signalAsset != null
? EditorGUIUtility.TempContent(signalAsset.name)
: Styles.EmptySignalList);
}
}
}
void DrawReactionColumn(Rect rect, int rowIdx)
{
if (!readonlySignal)
{
var optionButtonSize = GetOptionButtonSize();
rect.width -= optionButtonSize.x;
var optionButtonRect = new Rect
{
x = rect.xMax,
y = rect.y,
width = optionButtonSize.x,
height = optionButtonSize.y
};
DrawOptionsButton(optionButtonRect, rowIdx, m_CurrentReceiver);
}
using (new EditorGUI.DisabledScope(!enabled))
{
var nameAsString = m_Asset.objectReferenceValue == null ? "Null" : m_Asset.objectReferenceValue.name;
using (var change = new EditorGUI.ChangeCheckScope())
{
EditorGUI.PropertyField(rect, m_Evt, EditorGUIUtility.TempContent(nameAsString));
if (change.changed)
m_TreeView.dirty = true;
}
}
}
static Vector2 GetOptionButtonSize()
{
EditorGUIUtility.SetIconSize(Vector2.zero);
return EditorStyles.iconButton.CalcSize(EditorGUI.GUIContents.titleSettingsIcon);
}
void DrawOptionsButton(Rect rect, int rowIdx, SignalReceiver target)
{
GUI.SetNextControlName(SignalOptions);
if (EditorGUI.DropdownButton(rect, EditorGUI.GUIContents.titleSettingsIcon, FocusType.Passive, EditorStyles.iconButton))
{
var menu = new GenericMenu();
menu.AddItem(new GUIContent(Styles.SignalListDuplicateOption), false, () =>
{
Undo.RecordObject(target, Styles.UndoDuplicateRow);
var evtCloner = ScriptableObject.CreateInstance<UnityEventCloner>();
evtCloner.evt = target.GetReactionAtIndex(rowIdx);
var clone = Object.Instantiate(evtCloner);
target.AddEmptyReaction(clone.evt);
m_TreeView.dirty = true;
PrefabUtility.RecordPrefabInstancePropertyModifications(target);
});
menu.AddItem(new GUIContent(Styles.SignalListDeleteOption), false, () =>
{
Undo.RecordObject(target, Styles.UndoDeleteRow);
target.RemoveAtIndex(rowIdx);
m_TreeView.dirty = true;
PrefabUtility.RecordPrefabInstancePropertyModifications(target);
});
menu.ShowAsContext();
}
}
IEnumerable<SignalAsset> ISignalAssetProvider.AvailableSignalAssets()
{
var ret = SignalManager.assets.Except(m_CurrentReceiver.GetRegisteredSignals());
return signalAsset == null ? ret : ret.Union(new List<SignalAsset> { signalAsset }).ToList();
}
void ISignalAssetProvider.CreateNewSignalAsset(string path)
{
var newSignalAsset = SignalManager.CreateSignalAssetInstance(path);
Undo.RecordObject(m_CurrentReceiver, Styles.UndoCreateSignalAsset);
// case 1241170 - overwriting an existing signal with throw an exception. Instead, clear the old key
int index = m_CurrentReceiver.GetRegisteredSignals().ToList().IndexOf(newSignalAsset);
if (index != -1)
m_CurrentReceiver.ChangeSignalAtIndex(index, null);
m_CurrentReceiver.ChangeSignalAtIndex(m_CurrentRowIdx, newSignalAsset);
PrefabUtility.RecordPrefabInstancePropertyModifications(m_CurrentReceiver);
}
class UnityEventCloner : ScriptableObject
{
public UnityEvent evt;
}
}
}