Skip to content

Commit

Permalink
Merge branch 'feature/Editor#34' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
niwaniwa committed Jul 10, 2022
2 parents e12dc6f + 6c44c5a commit 46785c4
Show file tree
Hide file tree
Showing 7 changed files with 92 additions and 70 deletions.
41 changes: 36 additions & 5 deletions Assets/Kinel/VideoPlayer/Editor/Internal/KinelEditorUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<KinelVideoPlayerUI>();
var components = targetObject.GetUdonSharpComponentsInChildrenByKinel<KinelVideoPlayerUI>();
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;
Expand Down Expand Up @@ -52,15 +57,15 @@ public static void UpdateKinelVideoUIComponents(MonoBehaviour component, Object

public static T[] GetUdonSharpScripts<T>(GameObject parent) where T: UdonSharpBehaviour
{
T[] targets = parent.GetUdonSharpComponentsInChildren<T>();
T[] targets = parent.GetUdonSharpComponentsInChildrenByKinel<T>();
if (targets.Length == 0)
{
// UdonSharp
// targets = GameObject.FindObjectsOfType<T>();
var tempList = new List<T>();
foreach (var rootObject in SceneManager.GetActiveScene().GetRootGameObjects())
{
tempList.AddRange(rootObject.GetUdonSharpComponentsInChildren<T>());
tempList.AddRange(rootObject.GetUdonSharpComponentsInChildrenByKinel<T>());
}
// if (targets.Length == 0)
// return targets;
Expand All @@ -71,7 +76,7 @@ public static void UpdateKinelVideoUIComponents(MonoBehaviour component, Object
return targets;
}

public static FillResult FillUdonSharpInstance<T>(SerializedProperty targetProperty, GameObject parent, bool overwrite) where T: UdonSharpBehaviour
public static FillResult FillUdonSharpInstance<T>(ref SerializedProperty targetProperty, GameObject parent, bool overwrite) where T: UdonSharpBehaviour
{
if (targetProperty.objectReferenceValue != null && !overwrite)
return FillResult.AlreadyExistence;
Expand All @@ -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;
}
}

}
}
74 changes: 48 additions & 26 deletions Assets/Kinel/VideoPlayer/Editor/Internal/KinelUdonUtilities.cs
Original file line number Diff line number Diff line change
@@ -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
{
Expand All @@ -10,41 +16,57 @@ namespace Kinel.VideoPlayer.Editor.Internal
/// </summary>
public static class KinelUdonUtilities
{
public static T UdonToUserSharp<T>(UdonSharpBehaviour udon) where T : UdonSharpBehaviour
public static T[] ConvertToUdonSharpComponent<T>(UdonSharpBehaviour[] udon) where T : UdonSharpBehaviour
{
if (udon.GetType().Equals(typeof(T)))
return udon as T;
return null;
var udonSharpList = new List<T>();
// 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<T>(this GameObject gameObject) where T: UdonSharpBehaviour
public static T[] ConvertToUdonSharpComponent<T>(UdonSharpBehaviour udon) where T : UdonSharpBehaviour
{
var udonSs = new List<T>();
var udonS = gameObject.GetComponents<UdonSharpBehaviour>();
return ConvertToUdonSharpComponent<T>(new []{ udon});
}

foreach (var udon in udonS)
{
var udonSharp = UdonToUserSharp<T>(udon);
if (udonSharp != null)
udonSs.Add(udonSharp);
}

return udonSs.ToArray();
public static T GetUdonSharpComponentByKinel<T>(this GameObject gameObject) where T: UdonSharpBehaviour
{
var udon = ConvertToUdonSharpComponent<T>(gameObject.GetComponent<UdonSharpBehaviour>());
if (udon.Length == 0)
return null;
return udon[0];
}

public static T[] GetUdonSharpComponentsByKinel<T>(this GameObject gameObject) where T: UdonSharpBehaviour
{
return ConvertToUdonSharpComponent<T>(gameObject.GetComponents<UdonSharpBehaviour>());
}


public static T GetUdonSharpComponentInChildrenByKinel<T>(this GameObject gameObject) where T: UdonSharpBehaviour
{
var udon = ConvertToUdonSharpComponent<T>(gameObject.GetComponentInChildren<UdonSharpBehaviour>());
if (udon.Length == 0)
return null;
return udon[0];
}

public static T[] GetUdonSharpComponentsInChildrenByKinel<T>(this GameObject gameObject) where T: UdonSharpBehaviour
{
var udonSs = new List<T>();
var udonS = gameObject.GetComponentsInChildren<UdonSharpBehaviour>();

foreach (var udon in udonS)
{
var udonSharp = UdonToUserSharp<T>(udon);
if (udonSharp != null)
udonSs.Add(udonSharp);
}

return udonSs.ToArray();
return ConvertToUdonSharpComponent<T>(gameObject.GetComponentsInChildren<UdonSharpBehaviour>());
}

}
}
20 changes: 1 addition & 19 deletions Assets/Kinel/VideoPlayer/Editor/KinelVideoSpeedChangerEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<KinelVideoPlayer>();
// 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>(_kinelVideoPlayer,
KinelEditorUtilities.FillUdonSharpInstance<KinelVideoPlayer>(ref _kinelVideoPlayer,
_speedChangerScript.transform.parent.gameObject, false);
_kinelVideoPlayer.serializedObject.ApplyModifiedProperties();
EditorUtility.SetDirty(_speedChangerScript);

}
Expand Down
11 changes: 2 additions & 9 deletions Assets/Kinel/VideoPlayer/Editor/Playlist/KinelPlaylistEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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--;
}
Expand Down Expand Up @@ -340,7 +333,7 @@ private void ApplyPlaylistProperties()

private void AutoFillProperties()
{
_isAutoFill.enumValueIndex = (int) KinelEditorUtilities.FillUdonSharpInstance<KinelVideoPlayer>(_kinelVideoPlayer, _playlist.gameObject, false);
_isAutoFill.enumValueIndex = (int) KinelEditorUtilities.FillUdonSharpInstance<KinelVideoPlayer>(ref _kinelVideoPlayer, _playlist.gameObject, false);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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--;
}
Expand Down Expand Up @@ -103,7 +96,7 @@ private void ApplyPlaylistProperties()
private void AutoFillProperties()
{

_isAutoFill.enumValueIndex = (int) KinelEditorUtilities.FillUdonSharpInstance<KinelVideoPlayer>(_kinelVideoPlayer, _playlist.gameObject, false);
_isAutoFill.enumValueIndex = (int) KinelEditorUtilities.FillUdonSharpInstance<KinelVideoPlayer>(ref _kinelVideoPlayer, _playlist.gameObject, false);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public override void ApplyUdonProperties()

private void AutoFillProperties()
{
_isAutoFill.enumValueIndex = (int) KinelEditorUtilities.FillUdonSharpInstance<KinelVideoPlayer>(_kinelVideoPlayer, _playlist.gameObject, false);
_isAutoFill.enumValueIndex = (int) KinelEditorUtilities.FillUdonSharpInstance<KinelVideoPlayer>(ref _kinelVideoPlayer, _playlist.gameObject, false);
}

}
Expand Down
3 changes: 2 additions & 1 deletion Assets/Kinel/VideoPlayer/Scripts/Parameter/FillResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ public enum FillResult
Success = 0,
NoExistence = 1,
AlreadyExistence = 2,
MultipleExistence = 3
MultipleExistence = 3,
NotInitialized = 4
}
}

0 comments on commit 46785c4

Please sign in to comment.