Esempio n. 1
0
 public RobotMoveToInstruction()
 {
     component2 = new InstructionComponent("POS")
     {
         OnComponentClicked = onClicked
     };
 }
Esempio n. 2
0
        private Text CreateTextObject(InstructionComponent component, string name = "text")
        {
            var prefab = Resources.Load <GameObject>("Prefabs/Instructions/InstructionTextUI");
            var go     = Instantiate(prefab);

            go.name = name;
            go.GetComponent <RectTransform>().SetParent(transform, false);

            var text = go.GetComponent <Text>();

            text.text  = component.Text;
            text.color = TextColor;

            if (component.OnComponentClicked != null)
            {
                var collider = go.AddComponent <BoxCollider2D>();
                collider.size    = new Vector2(text.preferredWidth, text.preferredHeight);
                collider.enabled = component.OnComponentClicked != null;
                var eventHandler = go.AddComponent <ClickEventEmitter>();
                eventHandler.EventHandler += () => component.OnComponentClicked(null);
                eventHandler.Enabled       = component.OnComponentClicked != null;
            }

            return(text);
        }
Esempio n. 3
0
        public void Update()
        {
            // Handle mouse movement
            if (Input.GetMouseButtonDown(0) && !mouseDebounce && trackMouse)
            {
                trackMouse = false;

                var isoRay = Isometric.MouseToIsoRay();

                //do an isometric raycast on left mouse click
                if (Input.GetMouseButtonDown(0))
                {
                    IsoRaycastHit isoRaycastHit;

                    if (IsoPhysics.Raycast(isoRay, out isoRaycastHit))
                    {
                        selectedObj = isoRaycastHit.IsoTransform;

                        // Update instruction text
                        component2 =
                            new InstructionComponent("X: " + selectedObj.Position.x + " Z: " + selectedObj.Position.z)
                        {
                            OnComponentClicked = onClicked
                        };
                        targetPos = new Vector3(selectedObj.Position.x, 1, selectedObj.Position.z);
                        instructionRenderer.Render();
                    }
                }

                if (instructionRenderer != null)
                {
                    instructionRenderer.BackgroundColor = instructionRenderer.DefaultBackgroundColor;
                }
            }

            mouseDebounce = false;
        }