Esempio n. 1
0
 private void OnEnable()
 {
     avatars    = GetAvatars();
     avatarKeys = avatars.Keys.ToArray();
     if (0 != avatars.Count)
     {
         _8TrackEditor        = new Avatar8TrackEditor(avatars[avatarKeys[0]]);
         expressionParameters = avatars[avatarKeys[0]].expressionParameters;
         expressionsMenu      = avatars[avatarKeys[0]].expressionsMenu;
     }
     else
     {
         _8TrackEditor = new Avatar8TrackEditor();
     }
 }
Esempio n. 2
0
        private bool VRC_Actions(string songLibrary, List <AudioClip> libAssets, Avatar8TrackEditor _8Track)
        {
            //--- --- VRC Expression Parameters --- ---
            if (null != expressionParameters)
            {
                VRCExpressionParameters.Parameter volumeParam = new VRCExpressionParameters.Parameter()
                {
                    name = _8Track.VolumeEPName, valueType = VRCExpressionParameters.ValueType.Float
                };
                VRCExpressionParameters.Parameter trackParam = new VRCExpressionParameters.Parameter()
                {
                    name = _8Track.TrackEPName, valueType = VRCExpressionParameters.ValueType.Int
                };

                VRCExpressionParameters.Parameter[] parameters = expressionParameters.parameters;
                bool hasTrack  = false;
                bool hasVolume = false;
                foreach (VRCExpressionParameters.Parameter parameter in parameters)
                {
                    if (parameter.name == _8TrackEditor.VolumeEPName)
                    {
                        hasVolume = true;
                    }
                    else if (parameter.name == _8TrackEditor.TrackEPName)
                    {
                        hasTrack = true;
                    }
                }

                if (!hasVolume)
                {
                    ArrayUtility.Add <VRCExpressionParameters.Parameter>(ref expressionParameters.parameters, volumeParam);
                }
                if (!hasTrack)
                {
                    ArrayUtility.Add <VRCExpressionParameters.Parameter>(ref expressionParameters.parameters, trackParam);
                }

                UnityEditor.EditorUtility.SetDirty(expressionParameters);
            }

            //--- --- VRC Expression Menu --- ---
            VRCExpressionsMenu mainMenu = new VRCExpressionsMenu()
            {
                name = _8Track._8TrackObject.name + " Menu"
            };

            mainMenu.controls.Add(new VRCExpressionsMenu.Control()
            {
                icon = _8Track.StopIcon, name = "Stop", parameter = new VRCExpressionsMenu.Control.Parameter()
                {
                    name = _8Track.TrackEPName
                }, type = VRCExpressionsMenu.Control.ControlType.Toggle, value = 0
            });
            mainMenu.controls.Add(new VRCExpressionsMenu.Control()
            {
                icon = _8Track.VolumeIcon, name = "Volume", subParameters = new VRCExpressionsMenu.Control.Parameter[] { new VRCExpressionsMenu.Control.Parameter()
                                                                                                                         {
                                                                                                                             name = _8Track.VolumeEPName
                                                                                                                         } }, type = VRCExpressionsMenu.Control.ControlType.RadialPuppet
            });

            VRCExpressionsMenu disk = new VRCExpressionsMenu()
            {
                name = "Disk " + 1
            };

            mainMenu.controls.Add(new VRCExpressionsMenu.Control()
            {
                icon = _8Track.DiskIcon, name = disk.name, type = VRCExpressionsMenu.Control.ControlType.SubMenu, subMenu = disk
            });

            int menuCount = 3;
            VRCExpressionsMenu        menu  = mainMenu;
            List <VRCExpressionsMenu> menus = new List <VRCExpressionsMenu>();

            int diskCount = 0;
            List <VRCExpressionsMenu> disks = new List <VRCExpressionsMenu>
            {
                disk
            };

            int trackNumber = 0;

            do
            {
                if (libAssets.Count <= trackNumber)
                {
                    break;
                }

                string trackName = libAssets[trackNumber].name;
                trackNumber++;

                if (diskCount == 8)
                {
                    VRCExpressionsMenu newDisk = new VRCExpressionsMenu()
                    {
                        name = "Disk " + (disks.Count + 1)
                    };

                    if (7 == menuCount && 0 < libAssets.Count - (trackNumber))
                    {
                        VRCExpressionsMenu newMenu = new VRCExpressionsMenu()
                        {
                            name = "More..."
                        };
                        menu.controls.Add(new VRCExpressionsMenu.Control()
                        {
                            icon = _8Track.FolderIcon, name = newMenu.name, type = VRCExpressionsMenu.Control.ControlType.SubMenu, subMenu = newMenu
                        });
                        menus.Add(newMenu);
                        menu      = newMenu;
                        menuCount = 0;
                    }
                    menu.controls.Add(new VRCExpressionsMenu.Control()
                    {
                        icon = _8Track.DiskIcon, name = newDisk.name, type = VRCExpressionsMenu.Control.ControlType.SubMenu, subMenu = newDisk
                    });
                    menuCount++;
                    disks.Add(newDisk);
                    disk      = newDisk;
                    diskCount = 0;
                }

                disk.controls.Add(new VRCExpressionsMenu.Control()
                {
                    icon = _8Track.TrackIcon, name = trackName, parameter = new VRCExpressionsMenu.Control.Parameter()
                    {
                        name = _8Track.TrackEPName
                    }, type = VRCExpressionsMenu.Control.ControlType.Toggle, value = trackNumber
                });
                diskCount++;
            } while(true);

            foreach (VRCExpressionsMenu d in disks)
            {
                CreateAsset(_8Track.AudioClip, d, d.name + ".asset");
                EditorUtility.SetDirty(d);
            }

            CreateAsset(_8Track.AudioClip, mainMenu, mainMenu.name + ".asset");
            EditorUtility.SetDirty(mainMenu);
            for (int i = 0; i < menus.Count; i++)
            {
                CreateAsset(_8TrackEditor.AudioClip, menus[i], _8Track._8TrackObject.name + " Menu " + i + ".asset");
            }

            if (null != expressionsMenu)
            {
                VRCExpressionsMenu.Control toggle = GetMenuControl();
                expressionsMenu.controls.Remove(toggle);
                expressionsMenu.controls.Add(new VRCExpressionsMenu.Control()
                {
                    icon = _8Track.FolderIcon, name = _8TrackEditor._8TrackObject.name, type = VRCExpressionsMenu.Control.ControlType.SubMenu, subMenu = mainMenu
                });
                EditorUtility.SetDirty(expressionsMenu);
            }
            EditorUtility.SetDirty(expressionParameters);
            AssetDatabase.SaveAssets();
            return(true);
        }