From 2e884fd8e677b3cf8987ac9c2da62e7e1274b99f Mon Sep 17 00:00:00 2001 From: niwaniwa Date: Sun, 10 Jul 2022 14:25:27 +0900 Subject: [PATCH 1/4] =?UTF-8?q?Editor=E5=90=91=E3=81=91=E3=81=AE=E3=83=A1?= =?UTF-8?q?=E3=82=BD=E3=83=83=E3=83=89=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Editor/Internal/KinelEditorUtilities.cs | 41 ++++++++++++++++--- 1 file changed, 36 insertions(+), 5 deletions(-) diff --git a/Assets/Kinel/VideoPlayer/Editor/Internal/KinelEditorUtilities.cs b/Assets/Kinel/VideoPlayer/Editor/Internal/KinelEditorUtilities.cs index 16c3944..0d8bad6 100644 --- a/Assets/Kinel/VideoPlayer/Editor/Internal/KinelEditorUtilities.cs +++ b/Assets/Kinel/VideoPlayer/Editor/Internal/KinelEditorUtilities.cs @@ -20,9 +20,14 @@ public static void UpdateKinelVideoUIComponents(MonoBehaviour component) public static void UpdateKinelVideoUIComponents(MonoBehaviour component, Object udon) { var targetObject = component.gameObject; - var components = targetObject.GetUdonSharpComponentsInChildren(); + var components = targetObject.GetUdonSharpComponentsInChildrenByKinel(); foreach (var ui in components) { + if (ui == null) + { + continue; + } + Undo.RecordObject(ui, "kinelUI Udon Update"); var editor = UnityEditor.Editor.CreateEditor(ui, typeof(KinelUIEditor)) as KinelUIEditor; @@ -52,7 +57,7 @@ public static void UpdateKinelVideoUIComponents(MonoBehaviour component, Object public static T[] GetUdonSharpScripts(GameObject parent) where T: UdonSharpBehaviour { - T[] targets = parent.GetUdonSharpComponentsInChildren(); + T[] targets = parent.GetUdonSharpComponentsInChildrenByKinel(); if (targets.Length == 0) { // UdonSharp @@ -60,7 +65,7 @@ public static void UpdateKinelVideoUIComponents(MonoBehaviour component, Object var tempList = new List(); foreach (var rootObject in SceneManager.GetActiveScene().GetRootGameObjects()) { - tempList.AddRange(rootObject.GetUdonSharpComponentsInChildren()); + tempList.AddRange(rootObject.GetUdonSharpComponentsInChildrenByKinel()); } // if (targets.Length == 0) // return targets; @@ -71,7 +76,7 @@ public static void UpdateKinelVideoUIComponents(MonoBehaviour component, Object return targets; } - public static FillResult FillUdonSharpInstance(SerializedProperty targetProperty, GameObject parent, bool overwrite) where T: UdonSharpBehaviour + public static FillResult FillUdonSharpInstance(ref SerializedProperty targetProperty, GameObject parent, bool overwrite) where T: UdonSharpBehaviour { if (targetProperty.objectReferenceValue != null && !overwrite) return FillResult.AlreadyExistence; @@ -85,9 +90,35 @@ public static void UpdateKinelVideoUIComponents(MonoBehaviour component, Object return FillResult.MultipleExistence; targetProperty.objectReferenceValue = instance[0]; - + targetProperty.serializedObject.ApplyModifiedProperties(); + return FillResult.Success; } + + public static void DrawFillMessage(int fillResultInteger /*, params string[] messages*/) + { + switch (fillResultInteger) + { + case((int)FillResult.Success): + EditorGUILayout.HelpBox("自動的に設定されました。", MessageType.Info); + break; + case((int)FillResult.AlreadyExistence): + EditorGUILayout.HelpBox("設定されています。", MessageType.Info); + break; + case((int)FillResult.MultipleExistence): + EditorGUILayout.HelpBox("複数のビデオプレイヤーが存在しています。動画プレイヤーを選択してください。", MessageType.Info); + break; + case((int)FillResult.NoExistence): + EditorGUILayout.HelpBox("動画プレイヤーが存在しません。", MessageType.Info); + break; + case((int)FillResult.NotInitialized): + EditorGUILayout.HelpBox("... 初期化中 ...", MessageType.Info); + break; + default: + EditorGUILayout.HelpBox("不明なエラーが発生しました。(エラーコード#30)", MessageType.Error); + return; + } + } } } \ No newline at end of file From 91667308c9fd6dca3576c3b8d7b442dd1d8c35ac Mon Sep 17 00:00:00 2001 From: niwaniwa Date: Sun, 10 Jul 2022 14:26:55 +0900 Subject: [PATCH 2/4] =?UTF-8?q?GetUdonSharpComponent=E9=96=A2=E9=80=A3?= =?UTF-8?q?=E3=81=AE=E5=87=A6=E7=90=86=E3=82=92=E5=A4=89=E6=9B=B4=20-=20?= =?UTF-8?q?=E3=83=A1=E3=82=BD=E3=83=83=E3=83=89=E5=90=8D=E3=81=AE=E5=A4=89?= =?UTF-8?q?=E6=9B=B4=20-=20Component=E3=81=AE=E5=8F=96=E5=BE=97=E3=81=AB?= =?UTF-8?q?=E9=96=A2=E3=82=8F=E3=82=8B=E5=87=A6=E7=90=86=E3=81=AE=E5=A4=89?= =?UTF-8?q?=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Editor/Internal/KinelUdonUtilities.cs | 74 ++++++++++++------- 1 file changed, 48 insertions(+), 26 deletions(-) diff --git a/Assets/Kinel/VideoPlayer/Editor/Internal/KinelUdonUtilities.cs b/Assets/Kinel/VideoPlayer/Editor/Internal/KinelUdonUtilities.cs index c839b2a..37e25a6 100644 --- a/Assets/Kinel/VideoPlayer/Editor/Internal/KinelUdonUtilities.cs +++ b/Assets/Kinel/VideoPlayer/Editor/Internal/KinelUdonUtilities.cs @@ -1,6 +1,12 @@ +using System; +using System.Collections; using System.Collections.Generic; +using System.Linq; using UdonSharp; +using UdonSharpEditor; using UnityEngine; +using VRC.Udon.Serialization.OdinSerializer.Utilities; +using Object = System.Object; namespace Kinel.VideoPlayer.Editor.Internal { @@ -10,41 +16,57 @@ namespace Kinel.VideoPlayer.Editor.Internal /// public static class KinelUdonUtilities { - public static T UdonToUserSharp(UdonSharpBehaviour udon) where T : UdonSharpBehaviour + public static T[] ConvertToUdonSharpComponent(UdonSharpBehaviour[] udon) where T : UdonSharpBehaviour { - if (udon.GetType().Equals(typeof(T))) - return udon as T; - return null; + var udonSharpList = new List(); + // udonsharp + if(udon.Length == 0) + return udonSharpList.ToArray(); + + foreach (var udonSharpBehaviour in udon) + if (udonSharpBehaviour.GetType().Equals(typeof(T))) + udonSharpList.Add(udonSharpBehaviour as T); + + + + // vanilla udon + //UdonSharpEditorUtility.GetProxyBehaviour(udon); + // + + return udonSharpList.ToArray(); } - public static T[] GetUdonSharpComponentsByKinel(this GameObject gameObject) where T: UdonSharpBehaviour + public static T[] ConvertToUdonSharpComponent(UdonSharpBehaviour udon) where T : UdonSharpBehaviour { - var udonSs = new List(); - var udonS = gameObject.GetComponents(); + return ConvertToUdonSharpComponent(new []{ udon}); + } - foreach (var udon in udonS) - { - var udonSharp = UdonToUserSharp(udon); - if (udonSharp != null) - udonSs.Add(udonSharp); - } - - return udonSs.ToArray(); + public static T GetUdonSharpComponentByKinel(this GameObject gameObject) where T: UdonSharpBehaviour + { + var udon = ConvertToUdonSharpComponent(gameObject.GetComponent()); + if (udon.Length == 0) + return null; + return udon[0]; + } + + public static T[] GetUdonSharpComponentsByKinel(this GameObject gameObject) where T: UdonSharpBehaviour + { + return ConvertToUdonSharpComponent(gameObject.GetComponents()); + } + + + public static T GetUdonSharpComponentInChildrenByKinel(this GameObject gameObject) where T: UdonSharpBehaviour + { + var udon = ConvertToUdonSharpComponent(gameObject.GetComponentInChildren()); + if (udon.Length == 0) + return null; + return udon[0]; } public static T[] GetUdonSharpComponentsInChildrenByKinel(this GameObject gameObject) where T: UdonSharpBehaviour { - var udonSs = new List(); - var udonS = gameObject.GetComponentsInChildren(); - - foreach (var udon in udonS) - { - var udonSharp = UdonToUserSharp(udon); - if (udonSharp != null) - udonSs.Add(udonSharp); - } - - return udonSs.ToArray(); + return ConvertToUdonSharpComponent(gameObject.GetComponentsInChildren()); } + } } \ No newline at end of file From 44599b60341e37b2fdb866e71515ae1bf5cb6604 Mon Sep 17 00:00:00 2001 From: niwaniwa Date: Sun, 10 Jul 2022 14:28:38 +0900 Subject: [PATCH 3/4] =?UTF-8?q?=E8=87=AA=E4=BD=9C=E3=82=AF=E3=83=A9?= =?UTF-8?q?=E3=82=B9=E3=81=AE=E4=BD=BF=E7=94=A8=E3=81=AB=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Editor/KinelVideoSpeedChangerEditor.cs | 20 +------------------ .../Editor/Playlist/KinelPlaylistEditor.cs | 11 ++-------- .../Playlist/KinelQueuePlaylistEditor.cs | 11 ++-------- .../Playlist/KinelVideoHistoryEditor.cs | 2 +- 4 files changed, 6 insertions(+), 38 deletions(-) diff --git a/Assets/Kinel/VideoPlayer/Editor/KinelVideoSpeedChangerEditor.cs b/Assets/Kinel/VideoPlayer/Editor/KinelVideoSpeedChangerEditor.cs index 369fd90..57407a8 100644 --- a/Assets/Kinel/VideoPlayer/Editor/KinelVideoSpeedChangerEditor.cs +++ b/Assets/Kinel/VideoPlayer/Editor/KinelVideoSpeedChangerEditor.cs @@ -116,27 +116,9 @@ private void AutoFillProperties() { if (_kinelVideoPlayer.objectReferenceValue == null) { - - // var playerScripts = GetVideoPlayers(); // - // if (playerScripts.Length != 0) - // { - // if (playerScripts.Length == 1) - // { - // - // var system = playerScripts[0].gameObject.GetUdonSharpComponentsInChildren(); - // if (system.Length == 1) - // { - // Undo.RecordObject(_speedChangerScript, "Instance attached"); - // _kinelVideoPlayer.objectReferenceValue = system[0]; - // _kinelVideoPlayer.serializedObject.ApplyModifiedProperties(); - // EditorUtility.SetDirty(_speedChangerScript); - // } - // } - // } Undo.RecordObject(_speedChangerScript, "Instance attached"); - KinelEditorUtilities.FillUdonSharpInstance(_kinelVideoPlayer, + KinelEditorUtilities.FillUdonSharpInstance(ref _kinelVideoPlayer, _speedChangerScript.transform.parent.gameObject, false); - _kinelVideoPlayer.serializedObject.ApplyModifiedProperties(); EditorUtility.SetDirty(_speedChangerScript); } diff --git a/Assets/Kinel/VideoPlayer/Editor/Playlist/KinelPlaylistEditor.cs b/Assets/Kinel/VideoPlayer/Editor/Playlist/KinelPlaylistEditor.cs index 9af7c75..215d68c 100644 --- a/Assets/Kinel/VideoPlayer/Editor/Playlist/KinelPlaylistEditor.cs +++ b/Assets/Kinel/VideoPlayer/Editor/Playlist/KinelPlaylistEditor.cs @@ -100,14 +100,7 @@ public override void OnInspectorGUI() EditorGUILayout.Space(); EditorGUILayout.PropertyField(_kinelVideoPlayer); AutoFillProperties(); - if (_isAutoFill.enumValueIndex == (int) FillResult.Success) - { - EditorGUILayout.HelpBox("自動的に設定されました。", MessageType.Info); - } - else if (_isAutoFill.enumValueIndex == (int) FillResult.AlreadyExistence) - { - EditorGUILayout.HelpBox("設定されました。", MessageType.Info); - } + KinelEditorUtilities.DrawFillMessage(_isAutoFill.enumValueIndex); EditorGUI.indentLevel--; } @@ -340,7 +333,7 @@ private void ApplyPlaylistProperties() private void AutoFillProperties() { - _isAutoFill.enumValueIndex = (int) KinelEditorUtilities.FillUdonSharpInstance(_kinelVideoPlayer, _playlist.gameObject, false); + _isAutoFill.enumValueIndex = (int) KinelEditorUtilities.FillUdonSharpInstance(ref _kinelVideoPlayer, _playlist.gameObject, false); } diff --git a/Assets/Kinel/VideoPlayer/Editor/Playlist/KinelQueuePlaylistEditor.cs b/Assets/Kinel/VideoPlayer/Editor/Playlist/KinelQueuePlaylistEditor.cs index d4aa0d5..f35a96d 100644 --- a/Assets/Kinel/VideoPlayer/Editor/Playlist/KinelQueuePlaylistEditor.cs +++ b/Assets/Kinel/VideoPlayer/Editor/Playlist/KinelQueuePlaylistEditor.cs @@ -51,14 +51,7 @@ public override void OnInspectorGUI() EditorGUILayout.Space(); EditorGUILayout.PropertyField(_kinelVideoPlayer); AutoFillProperties(); - if (_isAutoFill.enumValueIndex == (int) FillResult.Success) - { - EditorGUILayout.HelpBox("自動的に設定されました。", MessageType.Info); - } - else if (_isAutoFill.enumValueIndex == (int) FillResult.AlreadyExistence) - { - EditorGUILayout.HelpBox("設定されました。", MessageType.Info); - } + KinelEditorUtilities.DrawFillMessage(_isAutoFill.enumValueIndex); EditorGUILayout.Space(); EditorGUI.indentLevel--; } @@ -103,7 +96,7 @@ private void ApplyPlaylistProperties() private void AutoFillProperties() { - _isAutoFill.enumValueIndex = (int) KinelEditorUtilities.FillUdonSharpInstance(_kinelVideoPlayer, _playlist.gameObject, false); + _isAutoFill.enumValueIndex = (int) KinelEditorUtilities.FillUdonSharpInstance(ref _kinelVideoPlayer, _playlist.gameObject, false); } diff --git a/Assets/Kinel/VideoPlayer/Editor/Playlist/KinelVideoHistoryEditor.cs b/Assets/Kinel/VideoPlayer/Editor/Playlist/KinelVideoHistoryEditor.cs index 92c02af..48b748d 100644 --- a/Assets/Kinel/VideoPlayer/Editor/Playlist/KinelVideoHistoryEditor.cs +++ b/Assets/Kinel/VideoPlayer/Editor/Playlist/KinelVideoHistoryEditor.cs @@ -93,7 +93,7 @@ public override void ApplyUdonProperties() private void AutoFillProperties() { - _isAutoFill.enumValueIndex = (int) KinelEditorUtilities.FillUdonSharpInstance(_kinelVideoPlayer, _playlist.gameObject, false); + _isAutoFill.enumValueIndex = (int) KinelEditorUtilities.FillUdonSharpInstance(ref _kinelVideoPlayer, _playlist.gameObject, false); } } From 6c44c5a7f437609377c71b4812cf4fc6aa33d4fd Mon Sep 17 00:00:00 2001 From: niwaniwa Date: Sun, 10 Jul 2022 14:29:33 +0900 Subject: [PATCH 4/4] =?UTF-8?q?=E3=83=97=E3=83=AC=E3=82=A4=E3=83=A4?= =?UTF-8?q?=E3=83=BC=E3=81=AEGameObject=E3=81=8C=E3=82=A2=E3=82=BF?= =?UTF-8?q?=E3=83=83=E3=83=81=E3=81=95=E3=82=8C=E3=81=A6=E3=81=84=E3=82=8B?= =?UTF-8?q?=E3=81=8B=E3=81=AE=E7=8A=B6=E3=81=AE=E8=BF=BD=E5=8A=A0=20-=20No?= =?UTF-8?q?tInitialized=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Assets/Kinel/VideoPlayer/Scripts/Parameter/FillResult.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Assets/Kinel/VideoPlayer/Scripts/Parameter/FillResult.cs b/Assets/Kinel/VideoPlayer/Scripts/Parameter/FillResult.cs index d60380c..9c603d6 100644 --- a/Assets/Kinel/VideoPlayer/Scripts/Parameter/FillResult.cs +++ b/Assets/Kinel/VideoPlayer/Scripts/Parameter/FillResult.cs @@ -5,6 +5,7 @@ public enum FillResult Success = 0, NoExistence = 1, AlreadyExistence = 2, - MultipleExistence = 3 + MultipleExistence = 3, + NotInitialized = 4 } } \ No newline at end of file