/// <summary>
 /// Returns whether the specified BrickButton is pressed
 /// </summary>
 /// <param name="button">Button on the face of the EV3 brick</param>
 /// <returns>Whether or not the button is pressed</returns>
 public Task <bool> IsBrickButtonPressedAsync(BrickButton button)
 {
     return(ExecuteDirectWithReplyAsync <bool>(1, 0, c => c.IsBrickButtonPressed(button, 0), data =>
     {
         return BitConverter.ToBoolean(data, 0);
     }));
 }
Esempio n. 2
0
    public override void OnInspectorGUI()
    {
        base.OnInspectorGUI();

        GUILayout.Space(10);

        if (GUILayout.Button("Generate icon"))
        {
            serializedObject.Update();

            BrickButton button = (BrickButton)target;

            var image = button.GetComponent <Image>();
            if (image != null)
            {
                //generate icon
                var    brick = Resources.Load(button.brickResourcePath) as GameObject;
                string path  = string.Format("Assets/Resources/Icons/{0}.png", brick.name);
                BrickUtils.GenerateIcon(brick.GetComponent <Brick>(), path, 256);

                //attache generated icon to button
//                AssetDatabase.ImportAsset(path);
//                Sprite sprite = AssetDatabase.LoadAssetAtPath<Sprite>(path);
//                image.sprite = sprite;
            }

            serializedObject.ApplyModifiedProperties();
        }
    }
        IsBrickButtonPressedAsync(BrickButton button)
        {
            return(IsBrickButtonPressedAsyncInternal(button)
#if WINRT
                   .AsAsyncOperation()
#endif
                   );
        }
Esempio n. 4
0
    /// <summary>
    /// Generate new brick button.
    /// </summary>
    /// <param name="file">Prefa file name.</param>
    /// <param name="number">Number added to name</param>
    /// <param name="parent">:arent node to new button.</param>
    void GenerateButton(string file, int number, Transform parent)
    {
        //create GameObject
        GameObject buttonObject = new GameObject();

        buttonObject.transform.SetParent(parent);
        buttonObject.name = string.Format("brick button {0}", number);

        //atache Image component
        Image image = buttonObject.AddComponent <Image>();

        //attach BrickButtonScript and configure it
        BrickButton button = buttonObject.AddComponent <BrickButton>();

        button.brickResourcePath = ExtractResourcesPath(file);

        //generate button icon
        GameObject    brickPrefab = (GameObject)EditorGUIUtility.Load(file);
        DragableBrick brick       = brickPrefab.GetComponent <DragableBrick>();
        var           s           = Path.DirectorySeparatorChar;
        string        iconPath    = string.Format(string.Concat("Assets", s, "Resources", s, "Icons", s, "{0}.png"), brick.name);

        BrickUtils.GenerateIcon(brick, iconPath, 256);

        //configure icon
        button.imageResourcePath = ExtractResourcesPath(iconPath);
        string standardIconPath = string.Concat("Assets", s, "Gfx", s, "UI", s, "Icons", s, "BrickButtonIcon.png");
        //AssetDatabase.ImportAsset(standardIconPath);
        Sprite sprite = AssetDatabase.LoadAssetAtPath <Sprite>(standardIconPath);

        image.sprite = sprite;

        //configure group
        if (file.Contains("AgaQ Lukowe Poziome i Pionowe STL"))
        {
            button.group = 1;
        }
        else if (file.Contains("AgaQ Prostopadłoscianowe STL"))
        {
            button.group = 2;
        }
        else if (file.Contains("AgaQ Rownolegloboczne poziome STL"))
        {
            button.group = 3;
        }
        else if (file.Contains("AgaQ Schodkowe STL"))
        {
            button.group = 4;
        }
        else if (file.Contains("AgaQ Skalowe przechodzace STL"))
        {
            button.group = 5;
        }
        else if (file.Contains("AgaQ Trapezowe STL"))
        {
            button.group = 6;
        }
    }
        internal async Task <bool> IsBrickButtonPressedAsyncInternal(BrickButton button)
        {
            Command c = new Command(CommandType.DirectReply, 1, 0);

            c.IsBrickButtonPressed(button, 0);
            await SendCommandAsyncInternal(c);

            return(false);
        }
Esempio n. 6
0
        /// <summary>
        /// Returns whether the specified BrickButton is pressed
        /// </summary>
        /// <param name="button">Button on the face of the EV3 brick</param>
        /// <returns>Whether or not the button is pressed</returns>
        public async Task <bool> IsBrickButtonPressedAsync(BrickButton button)
        {
            var c = new Command(CommandType.DirectReply, 1, 0);

            c.IsBrickButtonPressed(button, 0);
            await _brick.SendCommandAsyncInternal(c);

            return(false);        //TODO: Read value?
        }
Esempio n. 7
0
        /// <summary>
        /// Add the Is Brick Pressed command to an existing Command object
        /// </summary>
        /// <param name="c">The command.</param>
        /// <param name="button">Button to check</param>
        /// <param name="index">Index at which the data should be returned inside of the global buffer</param>
        /// <returns>The updated command.</returns>
        public static Command IsBrickButtonPressed(this Command c, BrickButton button, Index index)
        {
            ParameterHelper.VerifyIndexValid(index);

            c.AddOpcode(Opcode.UIButton_Pressed);
            c.AddParameter((byte)button);
            c.AddGlobalIndex((byte)index);

            return(c);
        }
Esempio n. 8
0
        /// <summary>
        /// Add the Is Brick Pressed command to an existing Command object
        /// </summary>
        /// <param name="button">Button to check</param>
        /// <param name="index">Index at which the data should be returned inside of the global buffer</param>
        public void IsBrickButtonPressed(BrickButton button, int index)
        {
            if (index > 1024)
            {
                throw new ArgumentException("Index cannot be greater than 1024", "index");
            }

            AddOpcode(Opcode.UIButton_Pressed);
            AddParameter((byte)button);
            AddGlobalIndex((byte)index);
        }
Esempio n. 9
0
 // Use this for initialization
 public override void Start()
 {
     base.Start();
     if (stage == null)
     {
         stage = GameObject.Find("Stage").transform;
     }
     m_parent      = transform.parent.GetComponent <BrickButton>();
     m_Render      = GetComponent <SpriteRenderer>();
     m_originColor = m_Render.color;
     m_pivot       = transform.position;
     m_isLine      = false;
 }
Esempio n. 10
0
    void throwButtonUpdate(string data)
    {
        string[] input = data.Split(',');

        if (input.Length == 2)
        {
            string buttonType  = input[0];
            string buttonState = input[1];

            BrickButton bb    = (BrickButton)System.Enum.Parse(typeof(BrickButton), buttonType);
            bool        state = bool.Parse(buttonState);

            if (ButtonUpdateEvent != null)
            {
                ButtonUpdateEvent(bb, state);
            }

            // print("Button: " + bb.ToString() + "," + state.ToString());
        }
    }
Esempio n. 11
0
 /// <summary>
 /// Returns whether the specified BrickButton is pressed
 /// </summary>
 /// <param name="button">Button on the face of the EV3 brick</param>
 /// <returns>Whether or not the button is pressed</returns>
 public Task <bool> IsBrickButtonPressedAsync(BrickButton button)
 {
     return(IsBrickButtonPressedAsyncInternal(button));
 }
Esempio n. 12
0
		/// <summary>
		/// Add the Is Brick Pressed command to an existing Command object
		/// </summary>
		/// <param name="button">Button to check</param>
		/// <param name="index">Index at which the data should be returned inside of the global buffer</param>
		public void IsBrickButtonPressed(BrickButton button, int index)
		{
			if(index > 1024)
				throw new ArgumentException("Index cannot be greater than 1024", "index");

			AddOpcode(Opcode.UIButton_Pressed);
			AddParameter((byte)button);
			AddGlobalIndex((byte)index);
		}
Esempio n. 13
0
		IsBrickButtonPressedAsync(BrickButton button)
		{
			return IsBrickButtonPressedAsyncInternal(button)
#if WINRT
			.AsAsyncOperation()
#endif
			;
		}
Esempio n. 14
0
		internal async Task<bool> IsBrickButtonPressedAsyncInternal(BrickButton button)
		{
			Command c = new Command(CommandType.DirectReply, 1, 0);
			c.IsBrickButtonPressed(button, 0);
			await _brick.SendCommandAsyncInternal(c);
			return false;
		}
Esempio n. 15
0
 private void EV3Manager_ButtonUpdateEvent(BrickButton button, bool state)
 {
     // throw new System.NotImplementedException();
 }