Пример #1
0
    private void SetupUdonBehaviour(UdonBehaviour udonBehaviour, string exportedSymbol)
    {
        // PublicVariables取得
        IUdonVariableTable publicVariables = udonBehaviour.publicVariables;

        var audioSources = GameObject.FindObjectsOfType <AudioSource>();

        // Undo用意
        Undo.RecordObject(udonBehaviour, "Modify Public Variable");
        // 値をPublicVariablesに設定
        if (!publicVariables.TrySetVariableValue(exportedSymbol, audioSources))
        {
            Debug.Log("Error! Failed Setting Public Variables.");
            return;
        }

        Debug.Log("Setup Completed.");
    }
        private void FixPrimitivesWarning()
        {
            UdonBehaviour[] allObjects = Object.FindObjectsOfType <UdonBehaviour>();
            foreach (UdonBehaviour behaviour in allObjects)
            {
                IUdonVariableTable publicVariables = behaviour.publicVariables;
                foreach (string symbol in publicVariables.VariableSymbols)
                {
                    if (!publicVariables.TryGetVariableValue(symbol, out Mesh mesh))
                    {
                        continue;
                    }

                    if (mesh == null)
                    {
                        continue;
                    }

                    bool all = true;
                    foreach (Mesh primitiveMesh in _primitiveMeshes)
                    {
                        if (mesh != primitiveMesh)
                        {
                            continue;
                        }

                        all = false;
                        break;
                    }

                    if (all)
                    {
                        continue;
                    }

                    Mesh clone = Object.Instantiate(mesh);

                    Scene  scene     = behaviour.gameObject.scene;
                    string scenePath = Path.GetDirectoryName(scene.path) ?? "Assets";

                    string folderName = $"{scene.name}_MeshClones";
                    string folderPath = Path.Combine(scenePath, folderName);

                    if (!AssetDatabase.IsValidFolder(folderPath))
                    {
                        AssetDatabase.CreateFolder(scenePath, folderName);
                    }

                    string assetPath = Path.Combine(folderPath, $"{clone.name}.asset");

                    Mesh existingClone = AssetDatabase.LoadAssetAtPath <Mesh>(assetPath);
                    if (existingClone == null)
                    {
                        AssetDatabase.CreateAsset(clone, assetPath);
                        AssetDatabase.Refresh();
                    }
                    else
                    {
                        clone = existingClone;
                    }

                    publicVariables.TrySetVariableValue(symbol, clone);
                    EditorSceneManager.MarkSceneDirty(behaviour.gameObject.scene);
                }
            }
        }
Пример #3
0
    static async Task Youtubeset(UdonBehaviour udonBehaviour, string youtubelistid)
    {
        Debug.Log("セット開始");
        var youtubeService = new YouTubeService(new BaseClientService.Initializer()
        {
            ApiKey = ""
        });

        var searchListRequest = youtubeService.PlaylistItems.List("snippet");

        searchListRequest.PlaylistId = youtubelistid;
        searchListRequest.MaxResults = 50;
        Debug.Log("YoutubeAPI");

        List <string> titles    = new List <string>();
        List <string> urlString = new List <string>();

        do
        {
            var searchListResponse = await searchListRequest.ExecuteAsync();

            Debug.Log("取得");

            foreach (var searchResult in searchListResponse.Items)
            {
                Debug.Log($"{searchResult.Snippet.ResourceId.VideoId}, {searchResult.Snippet.Title}");
                titles.Add($"{searchResult.Snippet.Title}");
                urlString.Add("https://youtu.be/" + $"{searchResult.Snippet.ResourceId.VideoId}");
            }
            searchListRequest.PageToken = searchListResponse.NextPageToken;
        } while (searchListRequest.PageToken != null && searchListRequest.PageToken != "");
        int nagasa = titles.Count;

        // PublicVariables取得
        IUdonVariableTable publicVariables = udonBehaviour.publicVariables;

        // Undo用意
        Undo.RecordObject(udonBehaviour, "Modify Public Variable");
        // 値をPublicVariablesに設定
        if (!publicVariables.TrySetVariableValue("titles", titles.ToArray()))
        {
            Debug.Log("タイトルをセットできません");
            return;
        }
        if (!publicVariables.TrySetVariableValue("urlString", urlString.ToArray()))
        {
            Debug.Log("URLをセットできません");
            return;
        }
        if (!publicVariables.TrySetVariableValue("dummy", new string[nagasa]))
        {
            Debug.Log("長さをセットできません");
            return;
        }
        if (!publicVariables.TrySetVariableValue("descriptions", new string[nagasa]))
        {
            Debug.Log("長さをセットできません");
            return;
        }
        if (!publicVariables.TrySetVariableValue("playMode", new int[nagasa]))
        {
            Debug.Log("長さをセットできません");
            return;
        }
    }
Пример #4
0
        protected void DrawPublicVariables(UdonBehaviour udonBehaviour, ref bool dirty)
        {
            IUdonVariableTable publicVariables = null;

            if (udonBehaviour != null)
            {
                publicVariables = udonBehaviour.publicVariables;
            }

            EditorGUILayout.LabelField("Public Variables", EditorStyles.boldLabel);
            EditorGUI.indentLevel++;
            if (program?.SymbolTable == null)
            {
                EditorGUILayout.LabelField("No public variables.");
                EditorGUI.indentLevel--;
                return;
            }

            IUdonSymbolTable symbolTable = program.SymbolTable;

            string[] exportedSymbolNames = symbolTable.GetExportedSymbols();

            if (publicVariables != null)
            {
                foreach (string publicVariableSymbol in publicVariables.VariableSymbols.ToArray())
                {
                    if (!exportedSymbolNames.Contains(publicVariableSymbol))
                    {
                        publicVariables.RemoveVariable(publicVariableSymbol);
                    }
                }
            }

            if (exportedSymbolNames.Length <= 0)
            {
                EditorGUILayout.LabelField("No public variables.");
                EditorGUI.indentLevel--;
                return;
            }

            foreach (string exportedSymbol in exportedSymbolNames)
            {
                Type symbolType = symbolTable.GetSymbolType(exportedSymbol);
                if (publicVariables == null)
                {
                    DrawPublicVariableField(exportedSymbol, GetPublicVariableDefaultValue(exportedSymbol, symbolType), symbolType, ref dirty, false);
                    continue;
                }

                if (!publicVariables.TryGetVariableType(exportedSymbol, out Type declaredType) || declaredType != symbolType)
                {
                    publicVariables.RemoveVariable(exportedSymbol);
                    if (!publicVariables.TryAddVariable(CreateUdonVariable(exportedSymbol, GetPublicVariableDefaultValue(exportedSymbol, declaredType), symbolType)))
                    {
                        EditorGUILayout.LabelField($"Error drawing field for symbol '{exportedSymbol}'.");
                        continue;
                    }
                }

                if (!publicVariables.TryGetVariableValue(exportedSymbol, out object variableValue))
                {
                    variableValue = GetPublicVariableDefaultValue(exportedSymbol, declaredType);
                }

                variableValue = DrawPublicVariableField(exportedSymbol, variableValue, symbolType, ref dirty, true);
                if (!dirty)
                {
                    continue;
                }

                Undo.RecordObject(udonBehaviour, "Modify Public Variable");

                if (!publicVariables.TrySetVariableValue(exportedSymbol, variableValue))
                {
                    if (!publicVariables.TryAddVariable(CreateUdonVariable(exportedSymbol, variableValue, symbolType)))
                    {
                        Debug.LogError($"Failed to set public variable '{exportedSymbol}' value.");
                    }
                }

                EditorSceneManager.MarkSceneDirty(udonBehaviour.gameObject.scene);

                if (PrefabUtility.IsPartOfPrefabInstance(udonBehaviour))
                {
                    PrefabUtility.RecordPrefabInstancePropertyModifications(udonBehaviour);
                }
            }

            EditorGUI.indentLevel--;
        }