/// <summary>
 /// Sets the ObjectPreview to display the tracked object for the trial.
 /// </summary>
 /// <param name="settings">The tracked object's settings.</param>
 public void SetUI(BasicTrialManager.BouncingObjectSettings settings)
 {
     Preview.SetImage(BouncingObject.GetObjectSprite(settings.Shape), settings.Color.GetColor());
     StartButton.interactable = false;
     ActivationTimer          = 0;
     gameObject.SetActive(true);
 }
示例#2
0
 /// <summary>
 /// Unifys the speed/scale settings of all the BouncingObjects.
 /// </summary>
 public void UnifyObjectSettings()
 {
     BasicTrialManager.BouncingObjectSettings settings = BounceObjectList [0].GetObjectSettings();
     foreach (BounceObjectUI ui in BounceObjectList)
     {
         ui.SetSpeedScale(settings.Speed, settings.Scale);
     }
 }
示例#3
0
    /// <summary>
    /// Adds a BounceObjectUI to the display based on the passed in BouncingObjectSettings.
    /// </summary>
    /// <param name="bouncingObject">The object to add to the UI display.</param>
    public void AddTrialObject(BasicTrialManager.BouncingObjectSettings bouncingObject)
    {
        if (BounceObjectList == null)
        {
            BounceObjectList = new List <BounceObjectUI> ();
        }
        BounceObjectUI bounceUI = GameObject.Instantiate <BounceObjectUI> (BouncingObjectUIPrefab);

        bounceUI.InitializeUI(this, bouncingObject);
        bounceUI.GetComponent <RectTransform> ().SetParent(ObjectDisplayLayout.transform, false);
        BounceObjectList.Add(bounceUI);
    }
示例#4
0
    /// <summary>
    /// Sets the UI to reflect the BouncingObjectSettings as passed in.
    /// </summary>
    /// <param name="settings">The BouncingObjectSettings to display.</param>
    public void SetUI(BasicTrialManager.BouncingObjectSettings settings)
    {
        Speed.text      = settings.Speed.ToString();
        Scale.text      = settings.Scale.ToString();
        NumSpawned.text = settings.NumberToSpawn.ToString();
        ColorPicker.SetJSONColor(settings.Color);
        Tracked.isOn = settings.bTrackedObject;
        Shape.value  = (int)settings.Shape;
        Path.value   = (int)settings.Path;

        SetPreviewImage();
        SetPreviewColor();
    }
示例#5
0
    /// <summary>
    /// Collects the BouncingObjectSettings as designed in the UI.
    /// </summary>
    /// <returns>A BouncingObjectSettings representing the BouncingObject.</returns>
    public BasicTrialManager.BouncingObjectSettings GetObjectSettings()
    {
        BasicTrialManager.BouncingObjectSettings settings = new BasicTrialManager.BouncingObjectSettings
        {
            bTrackedObject = Tracked.isOn,
            Scale          = float.Parse(Scale.text),
            Speed          = float.Parse(Speed.text),
            NumberToSpawn  = int.Parse(NumSpawned.text),
            Color          = ColorPicker.GetJSONColor(),
            Shape          = (BouncingObject.ObjectShapes)Shape.value,
            Path           = (BouncingObject.ObjectPaths)Path.value
        };

        return(settings);
    }
示例#6
0
    /// <summary>
    /// Sets the objects settings based upon the passed in BouncingObjectSettings. Initializes all
    /// customizable variables and prepares for test start.
    /// </summary>
    /// <param name="settings">The BouncingObjectSettings to use.</param>
    /// <param name="camera">The camera used for the test, to determine screen area.</param>
    public void SetObjectSettings(BasicTrialManager.BouncingObjectSettings settings, Camera camera)
    {
        bool    isIntersecting = true;
        Vector2 position       = Vector2.zero;
        //Gets bounds to bounce off of.
        float screenAspect = (float)Screen.width / (float)Screen.height;
        float cameraHeight = camera.orthographicSize * 2;

        CameraBounds = new Bounds(camera.transform.position, new Vector3(cameraHeight * screenAspect, cameraHeight, 0));

        Settings     = settings;
        Rigidbody2D  = GetComponent <Rigidbody2D> ();
        ObjectSprite = GetComponent <SpriteRenderer> ();
        BoxCollider  = GetComponent <BoxCollider2D> ();

        ObjectSprite.sprite = GetObjectSprite(settings.Shape);
        ObjectSprite.color  = Settings.Color.GetColor();

        float objectScale = BASE_SIZE / ObjectSprite.sprite.rect.width;

        transform.localScale = new Vector3(objectScale, objectScale, 1) * Settings.Scale;

        float cameraY = CameraBounds.min.y;
        float cameraX = CameraBounds.min.x;

        Vector3 objSize = BoxCollider.bounds.size;

        while (isIntersecting)
        {
            position = new Vector2(Random.Range(-cameraX + cameraX / 4, cameraX - cameraX / 4),
                                   Random.Range(-cameraY + cameraY / 4, cameraY - cameraY / 4));
            Collider2D hitObject = Physics2D.OverlapBox(position, objSize, 0);
            if (hitObject == null)
            {
                isIntersecting = false;
            }
        }

        Vector2 velocity = Vector2.zero;

        switch (Settings.Path)
        {
        case ObjectPaths.Diagonal:
            velocity = DiagonalSpeeds [Random.Range(0, DiagonalSpeeds.Length)] * Settings.Speed * OBJECT_BASE_SPEED;
            break;

        case ObjectPaths.Straight:
            velocity = StraightSpeeds [Random.Range(0, StraightSpeeds.Length)] * Settings.Speed * OBJECT_BASE_SPEED;
            break;
        }

        if (Settings.bTrackedObject)
        {
            if (position.x > 0 && velocity.x > 0 || position.x < 0 && velocity.x < 0)
            {
                velocity = new Vector2(velocity.x * -1, velocity.y);
            }
            if (position.y > 0 && velocity.y > 0 || position.y < 0 && velocity.y < 0)
            {
                velocity = new Vector2(velocity.x, velocity.y * -1);
            }
        }

        transform.position   = position;
        Rigidbody2D.velocity = velocity;
    }
示例#7
0
 /// <summary>
 /// Initializes the UI with both BouncingObjectSettings and the parent BasicTrialObjectDesignUI
 /// </summary>
 /// <param name="parentUI">The BasicTrialObjectDesignUI parent.</param>
 /// <param name="settings">The beginning settings of the object.</param>
 public void InitializeUI(BasicTrialObjectDesignUI parentUI, BasicTrialManager.BouncingObjectSettings settings)
 {
     RemoveButton.onClick.AddListener(delegate { parentUI.RemoveTrialObject(this); });
     Tracked.onValueChanged.AddListener(delegate { parentUI.Highlight(false); });
     SetUI(settings);
 }