Пример #1
0
        private static void DrawFloatField(ExtendedPropertyDrawer drawer, FieldInfo field, string label = null)
        {
            var range = field.GetCustomAttribute <RangeAttribute>();

            if (range != null)
            {
                field.SetValue(
                    objectReference,
                    EditorGUI.Slider(
                        drawer.position,
                        label ?? UnityApp.ToDisplayFormat(field.Name),
                        field.GetValue <float>(objectReference),
                        range.min,
                        range.max)
                    );
            }
            else
            {
                field.SetValue(
                    objectReference,
                    EditorGUI.FloatField(
                        drawer.position,
                        label ?? UnityApp.ToDisplayFormat(field.Name),
                        field.GetValue <float>(objectReference))
                    );
            }
        }
Пример #2
0
        protected T1 Field <T1>(string customLabel, SerializedProperty property, params string[] path)
        {
            property = FindProperty(property, path);

            EditorGUILayout.PropertyField(property, new GUIContent(UnityApp.ToDisplayFormat(customLabel)));
            return(property.GetValue <T1>());
        }
Пример #3
0
        private void Start()
        {
            // substring to remove proceeding "_"
            var filename = _dataType == DataType.Phosphene ? UnityApp.ToDisplayFormat(_layout) : "axons";

            _path = EditorUtility.SaveFilePanelInProject("Save data texture...", filename, "asset", "");

            if (_path == "")
            {
                return;
            }

            StartTimer();

            threadGroup = PreprocessedDataFactory.Create(_dataType, _headset, _pattern, _layout, _gpuAccel, _path);
            if (_gpuAccel)
            {
                LogTimer();
            }
            else
            {
                threadGroup.OnAllThreadsFinished += LogTimer;
                threadGroup.OnAllThreadsFinished += () => { cpuStarted = false; };
            }

            cpuStarted = !_gpuAccel;
        }
Пример #4
0
 private static void DrawEnumField(ExtendedPropertyDrawer drawer, FieldInfo field, string label = null)
 {
     field.SetValue(
         objectReference,
         EditorGUI.EnumPopup(
             drawer.position,
             label ?? UnityApp.ToDisplayFormat(field.Name),
             field.GetValue <Enum>(objectReference))
         );
 }
Пример #5
0
 private static void DrawObjectField(ExtendedPropertyDrawer drawer, FieldInfo field, string label = null)
 {
     field.SetValue(
         objectReference,
         EditorGUI.ObjectField(
             drawer.position,
             label ?? UnityApp.ToDisplayFormat(field.Name),
             field.GetValue <UnityEngine.Object>(objectReference),
             field.FieldType,
             false)
         );
 }
Пример #6
0
        public static void OnGUI(ExtendedPropertyDrawer drawer)
        {
            var dataProp = drawer.Property.FindPropertyRelative("data");

            dataProp.arraySize = arraySize;

            var i   = 0;
            var hfi = 0;
            var pfi = 0;

            foreach (var headset in Enumerate <HeadsetModel>())
            {
                var hfp = drawer.Property
                          .FindPropertyRelative("headsetFoldout")
                          .GetArrayElementAtIndex(hfi);

                hfp.boolValue      = EditorGUI.Foldout(drawer.position, hfp.boolValue, UnityApp.ToDisplayFormat(headset));
                drawer.position.y += 18;

                foreach (var pattern in Enumerate <ElectrodePattern>())
                {
                    EditorGUI.indentLevel++;

                    var pfp = drawer.Property
                              .FindPropertyRelative("patternFoldout")
                              .GetArrayElementAtIndex(pfi);

                    if (hfp.boolValue)
                    {
                        pfp.boolValue      = EditorGUI.Foldout(drawer.position, pfp.boolValue, UnityApp.ToDisplayFormat(pattern));
                        drawer.position.y += 18;
                    }

                    foreach (var layout in Enumerate <ElectrodeLayout>())
                    {
                        if (hfp.boolValue && pfp.boolValue)
                        {
                            var phosTex = dataProp.GetArrayElementAtIndex(i);
                            EditorGUI.ObjectField(drawer.position, phosTex, new GUIContent(UnityApp.ToDisplayFormat(layout)));
                            drawer.position.y += 18;
                        }

                        i++;
                    }

                    pfi++;

                    EditorGUI.indentLevel--;
                }

                if (hfp.boolValue)
                {
                    var axonTex = dataProp.GetArrayElementAtIndex(i);
                    EditorGUI.ObjectField(drawer.position, axonTex, new GUIContent("Axon"));
                    drawer.position.y += 18;
                }

                i++;
                hfi++;
            }
        }
Пример #7
0
        private static void DrawParameters(ExtendedPropertyDrawer drawer)
        {
            drawer.position.width = drawer.Area.width;

            EditorGUI.BeginChangeCheck();
            EditorGUI.indentLevel++;

            foreach (var field in objectType.GetFields(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public))
            {
                DrawDecorators(drawer, field);
                var label = field.GetCustomAttribute <CustomLabelAttribute>()?.label;

                drawer.position.y += drawer.FieldHeight;

                if (field.FieldType == typeof(int))
                {
                    DrawIntField(drawer, field, label);
                }
                else if (field.FieldType == typeof(float))
                {
                    DrawFloatField(drawer, field, label);
                }
                else if (field.FieldType == typeof(bool))
                {
                    DrawBoolField(drawer, field, label);
                }
                else if (field.FieldType.IsEnum)
                {
                    DrawEnumField(drawer, field, label);
                }
                else if (field.FieldType.IsSubclassOf(typeof(UnityEngine.Object)))
                {
                    DrawObjectField(drawer, field, label);
                }
                else
                {
                    EditorGUI.LabelField(drawer.position, UnityApp.ToDisplayFormat(field.Name), "[Select asset to edit]");
                }
            }

            EditorGUI.indentLevel--;

            var changed = EditorGUI.EndChangeCheck();

            if (changed && objectIsNotNull)
            {
                if (Application.isPlaying)
                {
                    Mirror.InvokeMethod(objectReference, "Update");

                    if (Settings.SaveRuntimeChangesAutomatically)
                    {
                        var target = objectReference as ImageRenderer;

                        target.CopyTo(target.original);
                        EditorUtility.SetDirty(target.original);
                    }
                }
                else
                {
                    EditorUtility.SetDirty(objectReference);
                }
            }
        }