Пример #1
0
        // Converts a NamedAudioClip into a AudioMateClip and creates the necessary UI to display the clip
        // in the clip library
        private AudioMateClip CreateClip(NamedAudioClip sourceClip)
        {
            var clip    = new AudioMateClip(sourceClip);
            var clipUID = GetClipObjectName(clip);
            var go      = new GameObject(clipUID);

            go.transform.SetParent(_content, false);
            var gridLayout = go.AddComponent <HorizontalLayoutGroup>();

            gridLayout.spacing = 10f;
            gridLayout.childForceExpandWidth  = false;
            gridLayout.childControlWidth      = true;
            gridLayout.childForceExpandHeight = true;
            gridLayout.childControlHeight     = false;
            gridLayout.padding = new RectOffset(5, 5, -20, -20);
            var buttonGroup   = gridLayout.gameObject.AddComponent <HorizontalButtonGroup>();
            var previewButton = buttonGroup.CreateButton("\u25B6", Styles.Success, () =>
            {
                clip.SourceClip.Test();
                Cursor.Clip  = clip;
                Cursor.Index = Clips.IndexOf(clip);
                RefreshUI();
            }, false, 10f);

            var toggleButton = buttonGroup.CreateButton(clip.DisplayName, Styles.Disabled, () =>
            {
                clip.ToggleState();
                if (clip.IsInActiveCollection)
                {
                    _collections.AddClipToActiveCollection(clip);
                }
                else
                {
                    _collections.RemoveClipFromActiveCollection(clip);
                }

                RefreshUI();
            }, true, 100f);

            clip.UI.PreviewButton = previewButton;
            clip.UI.ToggleButton  = toggleButton;
            clip.RefreshUI();

            return(clip);
        }
Пример #2
0
 private static string GetClipObjectName(AudioMateClip clip)
 {
     return($"AudioMateClip{clip.SourceClip.uid}");
 }