-
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.
- Loading branch information
Showing
12 changed files
with
1,854 additions
and
122 deletions.
There are no files selected for viewing
1,075 changes: 1,075 additions & 0 deletions
1,075
Assets/InariUdon/Driver/FloatMultiValueDriver.asset
Large diffs are not rendered by default.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
#pragma warning disable IDE1006 | ||
|
||
using UdonSharp; | ||
using UdonToolkit; | ||
using UnityEngine; | ||
using VRC.Udon; | ||
|
||
namespace InariUdon.Driver | ||
{ | ||
[UdonBehaviourSyncMode(BehaviourSyncMode.NoVariableSync)] | ||
public class FloatMultiValueDriver : UdonSharpBehaviour | ||
{ | ||
public float value; | ||
public bool castToInt = false; | ||
|
||
[SectionHeader("Write UdonBehaviour ProgramVariables")] | ||
public bool writeProgramVariables = false; | ||
[HideIf("@!writeProgramVariables")] public bool sendEvent = false; | ||
[HideIf("@!writeProgramVariables"), HideIf("@!sendEvent")] public bool ignoreFirstEvent = false; | ||
[HideIf("@!writeProgramVariables")] public bool findTargetFromChildren = false; | ||
[HideIf("@!writeProgramVariables"), HideIf("@findTargetFromChildren"), ListView("ProgramVariable Targets")] public UdonSharpBehaviour[] behaviours = {}; | ||
[HideIf("@!writeProgramVariables"), HideIf("@findTargetFromChildren"), ListView("ProgramVariable Targets"), Popup("programVariable", "@behaviours", true)] public string[] variableNames = {}; | ||
[HideIf("@!writeProgramVariables"), HideIf("@findTargetFromChildren"), HideIf("@!sendEvent"), ListView("ProgramVariable Targets"), Popup("behaviour", "@behaviours", true)] public string[] eventNames = {}; | ||
[HideIf("@!writeProgramVariables"), HideIf("@!findTargetFromChildren")] public Transform behaviourParent; | ||
[HideIf("@!writeProgramVariables"), HideIf("@!findTargetFromChildren")] public string variableName; | ||
[HideIf("@!writeProgramVariables"), HideIf("@!findTargetFromChildren"), HideIf("@!sendEvent")] public string eventName; | ||
|
||
private bool isFirst = true; | ||
|
||
private void Start() | ||
{ | ||
if (writeProgramVariables && findTargetFromChildren) | ||
{ | ||
var targetCount = 0; | ||
for (int i = 0; i < behaviourParent.childCount; i++) | ||
{ | ||
var udon = (UdonSharpBehaviour)behaviourParent.GetChild(i).GetComponent(typeof(UdonBehaviour)); | ||
if (udon != null) targetCount++; | ||
} | ||
|
||
behaviours = new UdonSharpBehaviour[targetCount]; | ||
variableNames = new string[targetCount]; | ||
eventNames = new string[targetCount]; | ||
for (int i = 0; i < targetCount; i++) | ||
{ | ||
behaviours[i] = (UdonSharpBehaviour)behaviourParent.GetChild(i).GetComponent(typeof(UdonBehaviour)); | ||
variableNames[i] = variableName; | ||
eventNames[i] = eventName; | ||
} | ||
} | ||
} | ||
|
||
private void WriteProgramVariables() | ||
{ | ||
if (!writeProgramVariables) return; | ||
|
||
var variableLength = Mathf.Min(behaviours.Length, variableNames.Length); | ||
for (int i = 0; i < variableLength; i++) | ||
{ | ||
var target = behaviours[i]; | ||
if (target == null) continue; | ||
|
||
if (castToInt) target.SetProgramVariable(variableNames[i], (int)value); | ||
else target.SetProgramVariable(variableNames[i], value); | ||
} | ||
|
||
if (!sendEvent) return; | ||
|
||
if (ignoreFirstEvent && isFirst) | ||
{ | ||
isFirst = false; | ||
return; | ||
} | ||
|
||
var eventLength = Mathf.Min(variableLength, eventNames.Length); | ||
for (int i = 0; i < eventLength; i++) | ||
{ | ||
var target = behaviours[i]; | ||
if (target == null) continue; | ||
target.SendCustomEvent(eventNames[i]); | ||
} | ||
} | ||
|
||
public void _ValueChanged() | ||
{ | ||
WriteProgramVariables(); | ||
} | ||
|
||
public void _SetValue(float value) | ||
{ | ||
this.value = value; | ||
_ValueChanged(); | ||
} | ||
|
||
} | ||
} |
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
Oops, something went wrong.