Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 85 additions & 0 deletions Packages/com.chark.scriptable-events-uvs/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
# This .gitignore file should be placed at the root of your Unity project directory
#
# Get latest from https://github.com/github/gitignore/blob/main/Unity.gitignore
#
/[Ll]ibrary/
/[Tt]emp/
/[Oo]bj/
/[Bb]uild/
/[Bb]uilds/
/[Ll]ogs/
/[Uu]ser[Ss]ettings/

# MemoryCaptures can get excessive in size.
# They also could contain extremely sensitive data
/[Mm]emoryCaptures/

# Recordings can get excessive in size
/[Rr]ecordings/

# Uncomment this line if you wish to ignore the asset store tools plugin
# /[Aa]ssets/AssetStoreTools*

# Autogenerated Jetbrains Rider plugin
/[Aa]ssets/Plugins/Editor/JetBrains*

# Visual Studio cache directory
.vs/

# JetBrains
.idea/

# Gradle cache directory
.gradle/

# Autogenerated VS/MD/Consulo solution and project files
ExportedObj/
.consulo/
*.csproj
*.unityproj
*.sln
*.suo
*.tmp
*.user
*.userprefs
*.pidb
*.booproj
*.svd
*.pdb
*.mdb
*.opendb
*.VC.db

# Unity3D generated meta files
*.pidb.meta
*.pdb.meta
*.mdb.meta

# Unity3D generated file on crash reports
sysinfo.txt

# Builds
*.apk
*.aab
*.unitypackage
*.app

# Crashlytics generated file
crashlytics-build.properties

# Packed Addressables
/[Aa]ssets/[Aa]ddressable[Aa]ssets[Dd]ata/*/*.bin*

# Temporary auto-generated Android Assets
/[Aa]ssets/[Ss]treamingAssets/aa.meta
/[Aa]ssets/[Ss]treamingAssets/aa/*


## Ignore all core Visual Scripting files, but preserves your project settings and variables.
# Optionally exclude these transient (generated) files,
# because they can be easily re-generated by the package

Assets/Unity.VisualScripting.Generated/VisualScripting.Flow/UnitOptions.db
Assets/Unity.VisualScripting.Generated/VisualScripting.Flow/UnitOptions.db.meta
Assets/Unity.VisualScripting.Generated/VisualScripting.Core/Property Providers
Assets/Unity.VisualScripting.Generated/VisualScripting.Core/Property Providers.meta
21 changes: 21 additions & 0 deletions Packages/com.chark.scriptable-events-uvs/LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2023 CHARK

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
7 changes: 7 additions & 0 deletions Packages/com.chark.scriptable-events-uvs/LICENSE.md.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Empty file.
7 changes: 7 additions & 0 deletions Packages/com.chark.scriptable-events-uvs/README.md.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Packages/com.chark.scriptable-events-uvs/Runtime.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using CHARK.ScriptableEvents.Events;
using Unity.VisualScripting;

namespace CHARK.ScriptableEvents.VisualScripting
{
internal class BoolComponent : ListenerComponent<bool>
{
}

[UnitCategory("CHARK/ScriptableEvents")]
[UnitTitle("Bool Scriptable Event Listener")]
internal class BoolListener : ListenerNode<bool, BoolComponent>
{
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "CHARK.ScriptableEvents.VisualScripting",
"rootNamespace": "CHARK.ScriptableEvents.UVS",
"references": [
"CHARK.ScriptableEvents",
"Unity.VisualScripting.Core",
"Unity.VisualScripting.Flow",
"Unity.VisualScripting.State"
],
"includePlatforms": [],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": false,
"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": [],
"versionDefines": [],
"noEngineReferences": false
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
using System.Collections.Generic;
using UnityEngine;

namespace CHARK.ScriptableEvents.VisualScripting
{
internal delegate void RaisedCallback<in TArg>(TArg arg);
internal interface IListenerComponent<TArg>
{
void RegisterEvent(ScriptableEvent<TArg> evt);
void RegisterEvents(List<ScriptableEvent<TArg>> events);
void RegisterOnRaised(RaisedCallback<TArg> callback);
}

internal class ListenerComponent<TArg> : MonoBehaviour, IListenerComponent<TArg>, IScriptableEventListener<TArg>
{
private readonly List<ScriptableEvent<TArg>> events = new ();
private RaisedCallback<TArg> onRaised;
private bool isEnabled;

private void OnEnable()
{
// Log(gameObject, "OnEnable");

isEnabled = true;
events.ForEach(elem => elem.AddListener(this));
}

private void OnDisable()
{
// Log(gameObject, "OnDisable");

isEnabled = false;
onRaised = null;
events.ForEach(elem => elem.RemoveListener(this));
}

public void RegisterEvent(ScriptableEvent<TArg> evt)
{
// Log(gameObject, "SetListener");

if (isEnabled)
{
evt.AddListener(this);
}

events.Add(evt);
}

public void RegisterEvents(List<ScriptableEvent<TArg>> events)
{
events.ForEach(RegisterEvent);
}

public void RegisterOnRaised(RaisedCallback<TArg> callback)
{
onRaised += callback;
}

public void OnRaised(TArg arg)
{
// Log(gameObject, $"OnRaised {{ arg: {arg} }}");

onRaised(arg);
}

private static void Log(Object target, string message)
{
Debug.Log($"ListenerNode > {target.name} > {message}");
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading