From 8cbc651c8cee914f25b82e427cc6540ac7b161ae Mon Sep 17 00:00:00 2001 From: Finn Ericson Date: Fri, 1 Sep 2023 14:56:51 +0200 Subject: [PATCH 1/2] Fix default values --- Assets/Klak/Wiring/Basic/Accumulator.cs | 2 +- Assets/Klak/Wiring/Basic/FloatAnimation.cs | 3 ++- Assets/Klak/Wiring/Input/BoolInput.cs | 2 +- Assets/Klak/Wiring/Input/FloatInput.cs | 2 +- Assets/Klak/Wiring/Input/FloatValue.cs | 2 +- Assets/Klak/Wiring/Input/IntInput.cs | 2 +- 6 files changed, 7 insertions(+), 6 deletions(-) diff --git a/Assets/Klak/Wiring/Basic/Accumulator.cs b/Assets/Klak/Wiring/Basic/Accumulator.cs index 2f838d3..acbdc36 100644 --- a/Assets/Klak/Wiring/Basic/Accumulator.cs +++ b/Assets/Klak/Wiring/Basic/Accumulator.cs @@ -36,7 +36,7 @@ public class Accumulator : NodeBase public float reset { set { if (!enabled) return; - _floatValue = 0; + _floatValue = value; _valueEvent.Invoke(_floatValue); } } diff --git a/Assets/Klak/Wiring/Basic/FloatAnimation.cs b/Assets/Klak/Wiring/Basic/FloatAnimation.cs index 5d75a7a..594ee01 100644 --- a/Assets/Klak/Wiring/Basic/FloatAnimation.cs +++ b/Assets/Klak/Wiring/Basic/FloatAnimation.cs @@ -84,7 +84,8 @@ public void TogglePause() void Start() { - _isPlaying = _playOnStart; + if (_playOnStart) + _isPlaying = true; _timeScale = 1; } diff --git a/Assets/Klak/Wiring/Input/BoolInput.cs b/Assets/Klak/Wiring/Input/BoolInput.cs index 748f76f..748e2c0 100644 --- a/Assets/Klak/Wiring/Input/BoolInput.cs +++ b/Assets/Klak/Wiring/Input/BoolInput.cs @@ -26,7 +26,7 @@ public class BoolInput : NodeBase #region Private members PropertyInfo _propertyInfo; - float _value; + float _value = float.MaxValue; void OnEnable() { diff --git a/Assets/Klak/Wiring/Input/FloatInput.cs b/Assets/Klak/Wiring/Input/FloatInput.cs index 9406273..5a18654 100644 --- a/Assets/Klak/Wiring/Input/FloatInput.cs +++ b/Assets/Klak/Wiring/Input/FloatInput.cs @@ -49,7 +49,7 @@ public class FloatInput : NodeBase #region Private members PropertyInfo _propertyInfo; - float _value; + float _value = float.MaxValue; void OnEnable() { diff --git a/Assets/Klak/Wiring/Input/FloatValue.cs b/Assets/Klak/Wiring/Input/FloatValue.cs index 4246dcb..51d9768 100644 --- a/Assets/Klak/Wiring/Input/FloatValue.cs +++ b/Assets/Klak/Wiring/Input/FloatValue.cs @@ -19,7 +19,7 @@ public float floatValue { #endregion - float _prevValue; + float _prevValue = float.MinValue; #region Monobehaviour diff --git a/Assets/Klak/Wiring/Input/IntInput.cs b/Assets/Klak/Wiring/Input/IntInput.cs index 41e8077..f30daf7 100644 --- a/Assets/Klak/Wiring/Input/IntInput.cs +++ b/Assets/Klak/Wiring/Input/IntInput.cs @@ -26,7 +26,7 @@ public class IntInput : NodeBase #region Private members PropertyInfo _propertyInfo; - float _value; + float _value = float.MaxValue; void OnEnable() { From 23a25614bcc73ca80579097a2c9db6af901a13cc Mon Sep 17 00:00:00 2001 From: Finn Ericson Date: Fri, 1 Sep 2023 14:57:10 +0200 Subject: [PATCH 2/2] SkinnedMeshOut node --- .../Editor/Output/SkinnedMeshOutEditor.cs | 46 +++++++++++++++++++ .../Output/SkinnedMeshOutEditor.cs.meta | 12 +++++ Assets/Klak/Wiring/Output/SkinnedMeshOut.cs | 33 +++++++++++++ .../Klak/Wiring/Output/SkinnedMeshOut.cs.meta | 12 +++++ 4 files changed, 103 insertions(+) create mode 100644 Assets/Klak/Wiring/Editor/Output/SkinnedMeshOutEditor.cs create mode 100644 Assets/Klak/Wiring/Editor/Output/SkinnedMeshOutEditor.cs.meta create mode 100644 Assets/Klak/Wiring/Output/SkinnedMeshOut.cs create mode 100644 Assets/Klak/Wiring/Output/SkinnedMeshOut.cs.meta diff --git a/Assets/Klak/Wiring/Editor/Output/SkinnedMeshOutEditor.cs b/Assets/Klak/Wiring/Editor/Output/SkinnedMeshOutEditor.cs new file mode 100644 index 0000000..4a2a68f --- /dev/null +++ b/Assets/Klak/Wiring/Editor/Output/SkinnedMeshOutEditor.cs @@ -0,0 +1,46 @@ +using UnityEngine; +using UnityEditor; + +namespace Klak.Wiring +{ + [CanEditMultipleObjects] + [CustomEditor(typeof(SkinnedMeshOut))] + public class SkinnedMeshOutEditor : Editor + { + SerializedProperty _skinnedMesh; + SerializedProperty _blendShapeIndex; + + void OnEnable() + { + _skinnedMesh = serializedObject.FindProperty("_skinnedMesh"); + _blendShapeIndex = serializedObject.FindProperty("_blendShapeIndex"); + } + + public override void OnInspectorGUI() + { + serializedObject.Update(); + + EditorGUILayout.PropertyField(_skinnedMesh); + + SkinnedMeshRenderer skinnedMesh = _skinnedMesh.objectReferenceValue as SkinnedMeshRenderer; + if (skinnedMesh) + { + string[] blendShapeNames = GetBlendShapeNames(skinnedMesh.gameObject); + _blendShapeIndex.intValue = EditorGUILayout.Popup("Blend Shape Index", _blendShapeIndex.intValue, blendShapeNames); + } + + serializedObject.ApplyModifiedProperties(); + } + + public string[] GetBlendShapeNames(GameObject obj) + { + SkinnedMeshRenderer head = obj.GetComponent(); + Mesh m = head.sharedMesh; + string[] names = new string[m.blendShapeCount]; + for (int i = 0; i < m.blendShapeCount; i++) + names[i] = m.GetBlendShapeName(i); + + return names; + } + } +} \ No newline at end of file diff --git a/Assets/Klak/Wiring/Editor/Output/SkinnedMeshOutEditor.cs.meta b/Assets/Klak/Wiring/Editor/Output/SkinnedMeshOutEditor.cs.meta new file mode 100644 index 0000000..d8ed674 --- /dev/null +++ b/Assets/Klak/Wiring/Editor/Output/SkinnedMeshOutEditor.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 95e4cd1a5f2d9488aa053fb7bb68a693 +timeCreated: 1521804449 +licenseType: Pro +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Klak/Wiring/Output/SkinnedMeshOut.cs b/Assets/Klak/Wiring/Output/SkinnedMeshOut.cs new file mode 100644 index 0000000..e75acea --- /dev/null +++ b/Assets/Klak/Wiring/Output/SkinnedMeshOut.cs @@ -0,0 +1,33 @@ +using UnityEngine; + +namespace Klak.Wiring +{ + [AddComponentMenu("Klak/Wiring/Output/Component/Skinned Mesh Out")] + public class SkinnedMeshOut : NodeBase + { + #region Editable properties + + [SerializeField] + SkinnedMeshRenderer _skinnedMesh; + + [SerializeField] + int _blendShapeIndex; + + #endregion + + int blendShapeCount; + + #region Node I/O + + [Inlet] + public float weight { + set { + if (!enabled || _skinnedMesh == null) return; + float w = Mathf.Clamp(value * 100, 0, 100); + _skinnedMesh.SetBlendShapeWeight(_blendShapeIndex, w); + } + } + + #endregion + } +} \ No newline at end of file diff --git a/Assets/Klak/Wiring/Output/SkinnedMeshOut.cs.meta b/Assets/Klak/Wiring/Output/SkinnedMeshOut.cs.meta new file mode 100644 index 0000000..20e9022 --- /dev/null +++ b/Assets/Klak/Wiring/Output/SkinnedMeshOut.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 503fa3199e4a4499da7066383f19a241 +timeCreated: 1521799843 +licenseType: Pro +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: