Пример #1
0
 public void Setup()
 {
     App = new UnityApp(
         ConfigureApp.Android.ApkFile(APK_PATH).StartApp(),
         PHONE_IP
         );
 }
Пример #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 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))
                    );
            }
        }
Пример #5
0
        // Update the live tile
        private void UpdateLiveTile()
        {
            UnityApp.BeginInvoke(() =>
            {
                var gameManager = GameManager.Instance; // Get our GameManager class from Unity

                if (gameManager == null)
                {
                    Debug.WriteLine("Gamemanager not found in Unity project");
                    return;
                }

                var score = GameManager.Instance.GetScore();

                ShellTile oTile = ShellTile.ActiveTiles.FirstOrDefault();
                if (oTile != null)
                {
                    var backContent     = "Score : " + score;
                    var wideBackContent = "Score : " + score;

                    var tileData = new FlipTileData()
                    {
                        BackTitle           = "Score",
                        BackContent         = backContent,
                        Count               = 0,
                        WideBackContent     = wideBackContent,
                        WideBackgroundImage = new Uri("/Assets/Tiles/FlipCycleTileLarge.png", UriKind.Relative),
                        BackgroundImage     = new Uri("/Assets/Tiles/FlipCycleTileMedium.png", UriKind.Relative)
                    };
                    oTile.Update(tileData);
                }
            });
        }
Пример #6
0
 public void Setup()
 {
     App = new UnityApp(
         ConfigureApp.iOS.AppBundle(APP_PATH).StartApp(),
         PHONE_IP
         );
 }
Пример #7
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))
         );
 }
Пример #8
0
 private void ShowNextExposure()
 {
     exposureId++;
     if (exposureId < exposures.Length)
     {
         ShowExposure();
     }
     else
     {
         UnityApp.Quit();
     }
 }
Пример #9
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)
         );
 }
Пример #10
0
        private static void CheckPathField(MonoBehaviour behaviour, FieldInfo field)
        {
            var attribute = field.GetCustomAttribute <PathAttribute>();
            var value     = field.GetValue <string>(behaviour);
            var path      = attribute.isRelative ? UnityApp.MakeAbsolute(value) : value;
            var exists    = attribute.isFile ? File.Exists(path) : Directory.Exists(path);

            if (exists == false && Settings.QuitForInvalidPaths)
            {
                Debug.LogError($"Invalid path \"{path}\" on the GameObject ({behaviour.name}).");
                UnityApp.Quit();
            }
        }
        private bool DrawInspectorSection(UnityApp unityApp)
        {
            EditorGUILayout.LabelField("", GUI.skin.horizontalSlider);
            var inspectedServiceDisplayName = string.IsNullOrEmpty(m_InspectedServiceName) ? "<nothing>" : m_InspectedServiceName;

            EditorGUILayout.LabelField($"Inspecting {inspectedServiceDisplayName}", EditorStyles.boldLabel);
            var ret = false;

            if (m_InspectedServiceType != m_LastInspectedServiceType)
            {
                if (m_LastInspectedServiceType != null &&
                    m_Inspectors.TryGetValue(m_LastInspectedServiceName, out var serviceInspector))
                {
                    serviceInspector.OnHide();
                }
            }

            if (m_InspectedServiceType != m_LastInspectedServiceType && m_InspectedServiceType != null)
            {
                var bindingData = unityApp.Container.GetBindingData(m_InspectedServiceName);
                if (!m_Inspectors.TryGetValue(m_InspectedServiceName, out var serviceInspector) &&
                    !m_TriedToCreateInspectorTypes.Contains(bindingData.ImplType))
                {
                    serviceInspector = CreateInspectorOrNull(bindingData);
                    m_TriedToCreateInspectorTypes.Add(bindingData.ImplType);
                    if (serviceInspector != null)
                    {
                        m_Inspectors[m_InspectedServiceName] = serviceInspector;
                    }
                }

                serviceInspector?.OnShow(m_InspectedServiceInstance);
            }

            if (m_InspectedServiceType != null)
            {
                m_Inspectors.TryGetValue(m_InspectedServiceName, out var serviceInspector);
                if (serviceInspector != null)
                {
                    EditorGUILayout.BeginVertical();
                    ret = serviceInspector.DrawContent(m_InspectedServiceInstance);
                    EditorGUILayout.EndVertical();
                }
            }

            m_LastInspectedServiceType = m_InspectedServiceType;
            m_LastInspectedServiceName = m_InspectedServiceName;
            return(ret);
        }
        private void DrawSingletonSection(UnityApp unityApp)
        {
            m_ShowSingletonSection = EditorGUILayout.Foldout(m_ShowSingletonSection, "Instances", EditorStyles.foldoutHeader);
            if (!m_ShowSingletonSection)
            {
                return;
            }

            EditorGUI.indentLevel++;
            bool clickedAnyInspect  = false;
            bool lastInstanceExists = false;

            foreach (var kv in unityApp.Container.GetSingletons())
            {
                var serviceName     = kv.Key;
                var serviceInstance = kv.Value;
                EditorGUILayout.BeginHorizontal();
                {
                    EditorGUILayout.LabelField(serviceName);
                    if (GUILayout.Button("Inspect", GUILayout.MaxWidth(80f)))
                    {
                        m_InspectedServiceName     = serviceName;
                        m_InspectedServiceType     = serviceInstance.GetType();
                        m_InspectedServiceInstance = serviceInstance;
                        clickedAnyInspect          = true;
                    }
                }

                if (!clickedAnyInspect && serviceInstance == m_InspectedServiceInstance)
                {
                    lastInstanceExists = true;
                }

                EditorGUILayout.EndHorizontal();
            }

            if (!clickedAnyInspect && !lastInstanceExists)
            {
                m_InspectedServiceName     = null;
                m_InspectedServiceType     = null;
                m_InspectedServiceInstance = null;
            }

            EditorGUI.indentLevel--;
        }
Пример #13
0
        public void EndTrial(int numCorrect)
        {
            // safety check
            if (_trialStarted == false)
            {
                return;
            }

            _trialStarted = false;

            // add trial
            _trial.endtime    = Time.time;
            _trial.timeTaken  = _trial.endtime - _trial.startTime;
            _trial.numCorrect = numCorrect;

            // misc stuff
            //speakers.PlayOneShot(startSound);
            HideWords();

            // save data
            _csv.AppendRow(_trial.participant, _trial.session, _trial.trialId, _trial.strategy, _trial.startTime, _trial.endtime, _trial.timeTaken, _trial.numCorrect);
            _csv.SaveWStream(path + $"Fad_Cnd_Res_{_trialId}_{participant}{session}.csv");

            // save rot and eye
            FindObjectOfType <RotationRecorder>().Save(_trialId);
            FindObjectOfType <EyeRecorder>().Save(_trialId);

            Debug.Log($"Trial {_trialId} ending. Participant got {numCorrect} correct.");

            // incr
            _trialId++;

            // if that was the last trial
            if (_trialId == _strategies.Length)
            {
                // stop the study
                UnityApp.Quit();
            }
            else
            {
                // otherwise, start next trial in 2 seconds
                Invoke(nameof(StartTrial), 2);
            }
        }
Пример #14
0
        static void CheckPaths()
        {
            var monoBehaviours = UnityApp.FindAllObjectsOfType <MonoBehaviour>();

            foreach (var behaviour in monoBehaviours)
            {
                if (behaviour == null)
                {
                    continue;
                }

                var fields = behaviour.GetType()
                             .GetFields(BINDING_FLAGS)
                             .Where((f) => f.HasCustomAttribute <PathAttribute>());

                foreach (var field in fields)
                {
                    CheckPathField(behaviour, field);
                }
            }
        }
        private void DrawContainerStatusSection(UnityApp unityApp)
        {
            m_ShowContainerStatusSection = EditorGUILayout.Foldout(m_ShowContainerStatusSection, "Container Status", EditorStyles.foldoutHeader);
            if (!m_ShowContainerStatusSection)
            {
                return;
            }

            EditorGUI.indentLevel++;

            var container = unityApp.Container;

            if (container == null)
            {
                EditorGUILayout.LabelField("Container doesn't exist.");
                return;
            }

            EditorGUILayout.BeginVertical();
            {
                EditorGUILayout.LabelField($"Type: {container.GetType()}");
                EditorGUILayout.LabelField($"Is Disposing: {container.IsDisposing}");
                EditorGUILayout.LabelField($"Is Disposed: {container.IsDisposed}");
                if (!container.IsDisposing && !container.IsDisposed)
                {
                    var rect = EditorGUILayout.BeginHorizontal();
                    // TODO: Unity bug or I use it wrongly? Why do I have to do the indentation by hand?
                    var indentedRect = EditorGUI.IndentedRect(rect);
                    EditorGUILayout.Space(indentedRect.xMin - rect.xMin, false);
                    if (GUILayout.Button("Dispose"))
                    {
                        container.Dispose();
                    }

                    EditorGUILayout.EndHorizontal();
                }
            }
            EditorGUILayout.EndVertical();
            EditorGUI.indentLevel--;
        }
        private void DrawBindingDataSection(UnityApp unityApp)
        {
            m_ShowBindingDataSection = EditorGUILayout.Foldout(m_ShowBindingDataSection, "Bindings", EditorStyles.foldoutHeader);
            if (!m_ShowBindingDataSection)
            {
                return;
            }

            EditorGUI.indentLevel++;
            foreach (var kv in unityApp.Container.GetBindingDatas())
            {
                var serviceName = kv.Key;
                var bindingData = kv.Value;
                var oldFoldout  = m_BindingDataFoldoutFlags.Contains(serviceName);
                var newFoldout  = EditorGUILayout.Foldout(oldFoldout, serviceName);
                if (newFoldout != oldFoldout)
                {
                    if (newFoldout)
                    {
                        m_BindingDataFoldoutFlags.Add(serviceName);
                    }
                    else
                    {
                        m_BindingDataFoldoutFlags.Remove(serviceName);
                    }
                }

                if (newFoldout)
                {
                    EditorGUI.indentLevel++;
                    EditorGUILayout.LabelField("Interface:", bindingData.InterfaceType?.ToString() ?? "<null>");
                    EditorGUILayout.LabelField("Impl:", bindingData.ImplType?.ToString() ?? "<null>");
                    EditorGUILayout.LabelField("Life Cycle Managed:", bindingData.LifeCycleManaged.ToString());
                    EditorGUI.indentLevel--;
                }
            }

            EditorGUI.indentLevel--;
        }
Пример #17
0
        public override void OnGUI(Rect rect, SerializedProperty property, GUIContent label)
        {
            BeginGUI(rect, property, label);

            var path   = attribute.isRelative ? UnityApp.MakeAbsolute(property.stringValue) : property.stringValue;
            var exists = attribute.isFile ? File.Exists(path) : Directory.Exists(path);

            Rect textRect, buttonRect;

            SplitFromRight(28, out textRect, out buttonRect);

            var prevCol = SetColour(exists ? Pastel.Green : Pastel.Red);

            EditorGUI.PropertyField(textRect, property, Label);
            SetColour(prevCol);

            if (GUI.Button(buttonRect, "..."))
            {
                path = exists ? path : UnityApp.DataPath;

                if (attribute.isFile)
                {
                    path = EditorUtility.OpenFilePanel("Select file...", path, "");
                }
                else
                {
                    path = EditorUtility.OpenFolderPanel("Select folder...", path, "") + "/";
                }

                if (path == "" || path == "/")
                {
                    return;
                }

                property.stringValue = attribute.isRelative ? UnityApp.MakeRelative(path, false) : path;
            }

            EndGUI();
        }
Пример #18
0
 private static void Awake()
 {
     UnityApp.StartCoroutine(Coroutine_Update());
 }
Пример #19
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);
                }
            }
        }
Пример #20
0
 /// <summary>
 /// Invoke until function returns false
 /// </summary>
 public static void InvokeUntil(Func <bool> callback)
 {
     UnityApp.StartCoroutine(Coroutine_Until(0, callback, null));
 }
Пример #21
0
 /// <summary>
 /// Invoke until function returns false. Ends with a final action
 /// </summary>
 public static void InvokeUntil(float delay, Func <bool> callback, Action final)
 {
     UnityApp.StartCoroutine(Coroutine_Until(delay, callback, final));
 }
Пример #22
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++;
            }
        }
Пример #23
0
        /*
         * Public methods
         */

        /// <summary>
        /// Invoke the callback with a delay
        /// </summary>
        public static void InvokeOnce(float delay, Action callback)
        {
            UnityApp.StartCoroutine(Coroutine_Invoke(delay, callback));
        }