Exemplo n.º 1
0
        public override VisualElement CreatePropertyGUI(SerializedProperty property)
        {
            ScriptAttributeUtility.GetFieldInfoFromProperty(property, out var fieldType);

            var objectField = new UnityEditor.UIElements.ObjectField(property.displayName);
            var genericType = fieldType.GetGenericArguments()[0];

            objectField.objectType  = genericType;
            objectField.value       = property.objectReferenceValue;
            objectField.bindingPath = property.propertyPath;

            return(objectField);
        }
            void Rebind(VisualElement ROOT)
            {
                var instance = (StressTests)target;

                System.Action rebuild = () => {
                    instance.OnDisable();
                    instance.OnEnable();
                };

                var MATERIAL = new UnityEditor.UIElements.ObjectField("Material");

                MATERIAL.objectType = typeof(Material);
                MATERIAL.value      = instance._srcMaterial;
                MATERIAL.RegisterValueChangedCallback((ctx) => {
                    instance._srcMaterial = (Material)ctx.newValue;
                });
                ROOT.Add(MATERIAL);

                var NUM = new UnityEditor.UIElements.IntegerField("Num Segments");

                NUM.value = instance._numSegments;
                NUM.RegisterValueChangedCallback((ctx) => {
                    instance._numSegments = ctx.newValue;

                    // const int max = 100_000;
                    // if( instance._numSegments > max )
                    // {
                    //  instance._numSegments = max;
                    //  NUM.SetValueWithoutNotify( max );
                    // }

                    const int min = 1;
                    if (instance._numSegments < min)
                    {
                        instance._numSegments = min;
                        NUM.SetValueWithoutNotify(min);
                    }

                    // rebuild();
                    // ROOT.Clear();
                    // Rebind(ROOT);
                });
                ROOT.Add(NUM);

                var FREQ = new UnityEditor.UIElements.FloatField("Frequency");

                FREQ.value = instance._frequency;
                FREQ.RegisterValueChangedCallback((ctx) => {
                    instance._frequency = ctx.newValue;
                });
                ROOT.Add(FREQ);

                var LOOP = new Toggle("Every Frame");

                LOOP.value = instance._everyFrame;
                LOOP.RegisterValueChangedCallback((ctx) => {
                    instance._everyFrame = ctx.newValue;
                });
                ROOT.Add(LOOP);

                var BUTTON = new Button(() => {
                    rebuild();
                    ROOT.Clear();
                    Rebind(ROOT);
                });

                BUTTON.text = "Update batch";
                ROOT.Add(BUTTON);

                if (instance._segments != null)
                {
                    var LABEL = new Label("Batch data:");
                    LABEL.style.marginTop = LABEL.style.marginTop.value.value + 12f;
                    ROOT.Add(LABEL);

                    var MATERIAL_INSTANCE = new UnityEditor.UIElements.ObjectField("Material instance (copy)");
                    MATERIAL_INSTANCE.objectType = typeof(Material);
                    MATERIAL_INSTANCE.value      = instance._segments.material;
                    ROOT.Add(MATERIAL_INSTANCE);

                    var MESH_INSTANCE = new UnityEditor.UIElements.ObjectField("Mesh instance");
                    MESH_INSTANCE.objectType = typeof(Mesh);
                    MESH_INSTANCE.value      = instance._segments.mesh;
                    ROOT.Add(MESH_INSTANCE);
                }
                else
                {
                    var LABEL = new Label("( no batch data )");
                    LABEL.style.marginTop = LABEL.style.marginTop.value.value + 12f;
                    ROOT.Add(LABEL);
                }
            }