summaryrefslogtreecommitdiff
path: root/VRCSDK3Avatars/Assets/Resources/GestureManager/Scripts/Editor/Modules/Vrc3/Vrc3VisualRender.cs
blob: c2cadb9298123dbc702d4d02833c19d2cbb984f8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#if VRC_SDK_VRCSDK3
using UnityEngine;
using UnityEngine.UIElements;

namespace GestureManager.Scripts.Editor.Modules.Vrc3
{
    public abstract class Vrc3VisualRender : VisualElement
    {
        private bool _rendering;
        internal Rect Rect;

        public virtual void Render(VisualElement root, Rect rect)
        {
            if (Event.current.type != EventType.Layout && !root.Contains(this)) root.Add(this);
            _rendering = true;

            style.height = rect.height;
            style.width = rect.width;
            style.left = rect.x;
            style.top = rect.y;
        }

        internal void StopRendering()
        {
            if (!_rendering) return;
            _rendering = false;
            parent?.Remove(this);
        }

        protected abstract bool RenderCondition(ModuleVrc3 module, RadialMenu meu);

        public void CheckCondition(ModuleVrc3 module, RadialMenu menu)
        {
            if (!_rendering) return;
            if (!RenderCondition(module, menu)) StopRendering();
        }
    }
}
#endif