Esempio n. 1
0
        public void PerformClickShouldExecuteCommand()
        {
            var clicked = false;
            var command = new Command<string>(
                p =>
                {
                    Assert.Null( p );
                    clicked = true;
                } );
            var target = new ClickableItem<string>( "test", command );

            target.PerformClick();
            Assert.True( clicked );

            clicked = false;
            command = new Command<string>(
                p =>
                {
                    Assert.Equal( "test2", p );
                    clicked = true;
                } );
            target = new ClickableItem<string>( "test", command );
            target.PerformClick( "test2" );
            Assert.True( clicked );
        }
Esempio n. 2
0
 private void RefreshButton(ClickableItem button, ButtonItem buttonItem)
 {
     if (button.IsEnabledFunction != null)
     {
         buttonItem.Enabled = button.IsEnabledFunction();
     }
 }
Esempio n. 3
0
 // Use this for initialization
 void Start()
 {
     cam         = GetComponent <Camera>();
     clickedItem = null;
     canGrab     = true;
     itemInUse   = false;
 }
Esempio n. 4
0
    public void DoTrigger(ClickableItem item)
    {
        if (triggerTimes >= 0 && currentTriggerTimes >= triggerTimes)
        {
            //触发完成
            return;
        }

        if (!NeedFlags.All(f => Stage.Instance.HasFlag(f)))
        {
            Debug.Log("缺少前置条件");
            return;
        }

        if (WithOutFlags.Any(f => Stage.Instance.HasFlag(f)))
        {
            Debug.Log("含有不能有的flag");
            return;
        }

        currentTriggerTimes++;
        //这里把监听器作为一个额外的判断条件或者功能
        foreach (var listener in TriggerListeners)
        {
            if (listener != null && !listener.OnTrigger(this))
            {
                return;
            }
        }

        DoTriggerEffect(item);
    }
    // Update is called once per frame
    void Update()
    {
        RaycastHit hit;
        Ray        ray = cameraVR.ViewportPointToRay(screenCenterVector);

        Debug.DrawRay(ray.origin, ray.direction * 100, Color.red);

        bool raycast = Physics.Raycast(ray, out hit, Mathf.Infinity, ~(1 << 8));

        //bool raycast = Physics.Raycast(ray, out hit);

        if (!raycast)
        {
            return;
        }

        marker.transform.position = hit.point;
        if (hit.distance > maxDistance)
        {
            MarkerScript.SetSelectedItemType(SelectedItemType.Other);
            return;
        }

        GameObject    hitObject     = hit.transform.gameObject;
        ClickableItem ClickableItem = hitObject.GetComponent <ClickableItem>();

        if (ClickableItem != null)
        {
            MarkerScript.SetSelectedItemType(SelectedItemType.ClickableItem);
            if (OVRInput.GetDown(OVRInput.Button.One))
            {
                //ewentualne wracanie do norm koloru
                CheckReturnToInitialColor();
                ClickableItem.Click(hit);
            }
            else
            {
                //podswietlenie itemu
                //jesli byl jakis inny podswitlony to wrocic go do norm koloru
                if (hitObject != lastFrameHitObject)
                {
                    //ewentualne wracanie poprzedniego do normalnego koloru
                    CheckReturnToInitialColor();
                    //podswietlenie nowego
                    if (ClickableItem.HighLightMaterial(hit.distance))
                    {
                        lastFrameHitObject = hitObject;
                    }
                }
            }
        }
        else //not clickable item
        {
            MarkerScript.SetSelectedItemType(SelectedItemType.Other);
            //ewentualne wracanie do norm koloru
            CheckReturnToInitialColor();
        }
    }
Esempio n. 6
0
    private void OnTriggerExit2D(Collider2D collision)
    {
        ClickableItem clickable = collision.gameObject.GetComponent <ClickableItem>();

        if (clickable == clickableItem)
        {
            clickableItem = null;
        }
    }
Esempio n. 7
0
    // Update is called once per frame
    void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            Ray        ray = Camera.main.ScreenPointToRay(new Vector3((cam.pixelWidth - 1) / 2, (cam.pixelHeight - 1) / 2, 0));
            GameObject itm = null;

            if (Physics.Raycast(ray, out hit, FPCRange))
            {
                itm = hit.collider.gameObject;
                //Debug.DrawRay(cam.ViewportToWorldPoint(new Vector3(0.5f, 0.5f, 0f)), itm.transform.position, Color.green, 3.0f, false);
                //Debug.DrawRay(ray, itm.transform.position, Color.green, 3.0f, false);
                clickedItem = itm.GetComponentInParent <ClickableItem>();
                if (clickedItem != null)
                {
                    //TODO: Shader stuff here?
                    Debug.Log("Hit a clickable item");
                    clickedItem.OnPlayerClick(hit.collider.gameObject.name);
                }

                if (itm.tag == "Grabbable")
                {
                    if (!grabbedObject)
                    {
                        grabbedObject = itm;
                    }
                    if (!canGrab)
                    {
                        ThrowDrop();
                        grabbedObject = itm;                         //Reset 'cause ThrowDrop() nulls out grabbedObject
                        Pickup();
                    }
                    else
                    {
                        Pickup();
                    }
                }

                if (itm.tag == "UseSpot")
                {
                    if (!canGrab && grabbedObject && clickedItem.CanBeUsed())
                    {
                        Debug.Log("Clicked UseSpot");
                        Use(itm.transform);
                    }
                }
            }
        }

        if (!canGrab && grabbedObject)
        {
            grabbedObject.transform.position = guide.position;
            //grabbedObject.transform.rotation = guide.rotation;
        }
    }
Esempio n. 8
0
        public override void RefreshButtonStatus(ClickableItem button)
        {
            var control = ((Control)Buttons[button].ContainerControl);

            if (control.InvokeRequired)
            {
                control.Invoke(new MethodInvoker(RefreshButtonStatus));
                return;
            }

            RefreshButton(button, Buttons[button]);
        }
Esempio n. 9
0
        public void ConstructorShouldSetExpectedProperties()
        {
            var command = new Command<string>( Console.WriteLine );
            var target = new ClickableItem<string>( "test", command );

            Assert.Equal( "test", target.Value );
            Assert.IsType<CommandInterceptor<object>>( target.Click );

            target = new ClickableItem<string>( "test", command, EqualityComparer<string>.Default );
            Assert.Equal( "test", target.Value );
            Assert.IsType<CommandInterceptor<object>>( target.Click );
        }
Esempio n. 10
0
        /// <summary>
        /// Carrega todas as skills ativas do heroi que está em seu turno no menu de skills.
        /// </summary>
        /// <param name="skills"> Lista com todas as skills do heroi. </param>
        public void UpdateSkillsContent(List <Skill> skills)
        {
            // Deleta todos os itens previamente alocados no content
            foreach (SkillElement element in skillsContent.GetComponentsInChildren <SkillElement>())
            {
                Destroy(element.gameObject);
            }

            // Variável auxiliar para a ordenação dos itens
            AxisInteractableItem lastItem = null;

            // Passa por todas as skills da lista, adicionando as ativas no menu e as ordenando
            foreach (PlayerSkill skill in skills)
            {
                if (skill.active)
                {
                    // Instancia um novo item e o coloca no content
                    GameObject newSkill = Instantiate(skillObject, skillsContent);
                    newSkill.GetComponent <SkillElement>().skill = skill;

                    newSkill.GetComponent <Image>().sprite = skill.skillImage;

                    // Define este script como responsável pelo item criado
                    SkillListItem newSkillListItem = newSkill.GetComponent <SkillListItem>();
                    newSkillListItem.skillList = this;

                    // Adiciona a decisão de clique no item criado
                    ClickableItem newClickableItem = newSkill.GetComponent <ClickableItem>();
                    newClickableItem.BCD = clickDecision;

                    // Adiciona a skill no item que a ativará
                    SkillItem newSkillItem = newSkill.GetComponent <SkillItem>();
                    newSkillItem.skill = skill;

                    // Ordena o item na lista
                    AxisInteractableItem newItem = newSkill.GetComponent <AxisInteractableItem>();
                    if (lastItem != null)
                    {
                        newItem.upItem    = lastItem;
                        lastItem.downItem = newItem;
                    }
                    else
                    {
                        manager.firstItem = newItem;
                    }
                    lastItem = newItem;
                }
            }
            manager.Active();
        }
Esempio n. 11
0
    void ShowClickableInfo(RaycastHit2D clickableHit)
    {
        ClickableItem clicked = clickableHit.transform.GetComponent <ClickableItem>();

        if (clicked)
        {
            clicked.OnItemClick();
        }
        ClickableFloor floor = clickableHit.transform.GetComponent <ClickableFloor>();

        if (floor)
        {
            Debug.Log("hitting floor");
            FindObjectOfType <ClickableCharacter>().MoveCharacter(clickableHit.point);
        }

        /*if (furniture)
         * {
         *  Debug.Log(furniture.Name);
         *  Debug.Log(furniture.description);
         *  nameText.text = furniture.Name;
         *  descriptionText.text = furniture.description;
         *  priceText.text = furniture.price.ToString();
         *  if (furniture.purchased)
         *  {
         *      Debug.Log("purchased");
         *  }
         *  else
         *  {
         *      Debug.Log("not purchased");
         *  }
         * }
         * else if (character)
         * {
         *  Debug.Log(character.name);
         *  Debug.Log(character.level);
         *
         * }else /_if (floor)
         * {
         *  Debug.Log("hitting floor");
         *  FindObjectOfType<ClickableCharacter>().MoveCharacter(clickableHit.point);
         * }else if (door)
         * {
         *  door.Activate();
         * }*/
    }
Esempio n. 12
0
    public void DoTriggerEffect(ClickableItem item)
    {
        switch (triggerType)
        {
        case TriggerType.PickUp:
            //拾取
            Inventory.Instance.AddItem(item);
            break;

        case TriggerType.Dialog:
            //对话
            switch (triggerTarget)
            {
            case "对话.一幅彩色的画":
                item.girlBalloon?.ShowMessage("一幅彩色的画");
                break;
            }

            if (!string.IsNullOrEmpty(flag))
            {
                Stage.Instance.AddFlag(flag);
            }

            break;

        case TriggerType.Open:
            //打开游戏
            CloseUpView.Instance.OpenMiniGame(triggerTarget);

            break;

        case TriggerType.None:

            if (!string.IsNullOrEmpty(flag))
            {
                Stage.Instance.AddFlag(flag);
            }

            break;
        }
        OnSuccessTrigger?.Invoke();
    }
Esempio n. 13
0
        public void EqualsShouldReturnExpectedResult()
        {
            var target = new ClickableItem<string>( "test", new Command<string>( Console.WriteLine ) );

            Assert.True( target == new ClickableItem<string>( "test", new Command<string>( Console.WriteLine ) ) );
            Assert.True( target != new ClickableItem<string>( "test1", new Command<string>( Console.WriteLine ) ) );
            Assert.True( target.Equals( new ClickableItem<string>( "test", new Command<string>( Console.WriteLine ) ) ) );
            Assert.False( target.Equals( new ClickableItem<string>( "test1", new Command<string>( Console.WriteLine ) ) ) );
            Assert.True( target.Equals( (object) new ClickableItem<string>( "test", new Command<string>( Console.WriteLine ) ) ) );
            Assert.False( target.Equals( (object) new ClickableItem<string>( "test1", new Command<string>( Console.WriteLine ) ) ) );

            target = new ClickableItem<string>( "test", new Command<string>( Console.WriteLine ), StringComparer.OrdinalIgnoreCase );

            Assert.True( target == new ClickableItem<string>( "TEST", new Command<string>( Console.WriteLine ) ) );
            Assert.True( target != new ClickableItem<string>( "TEST1", new Command<string>( Console.WriteLine ) ) );
            Assert.True( target.Equals( new ClickableItem<string>( "TEST", new Command<string>( Console.WriteLine ) ) ) );
            Assert.False( target.Equals( new ClickableItem<string>( "TEST1", new Command<string>( Console.WriteLine ) ) ) );
            Assert.True( target.Equals( (object) new ClickableItem<string>( "TEST", new Command<string>( Console.WriteLine ) ) ) );
            Assert.False( target.Equals( (object) new ClickableItem<string>( "TEST1", new Command<string>( Console.WriteLine ) ) ) );
        }
Esempio n. 14
0
    public void AddItem(ClickableItem citem, bool anim = true)
    {
        citem.transform.DOComplete();
        var rawItem = citem.item;

        if (anim)
        {
            var item = Render(rawItem);
            item.Hide();
            citem.GetComponent <MaskableGraphic>().DOFade(0, 0.05f).SetDelay(0.20f);
            citem.transform.DOMove(item.transform.position, 0.3f).OnComplete(() =>
            {
                item.Show();
                citem.Hide();
            });
        }
        else
        {
            Render(rawItem);
        }
    }
		public AddItemToMixerEvent(ClickableItem item)
		{
			itemToAdd = item;
		}
Esempio n. 16
0
    IEnumerator Start()
    {
        raycaster = gameObject.AddComponent <GraphicRaycaster>();
        while (InventoryManager.GetInventoryManager == null)
        {
            yield return(null);
        }
        inventoryBackground = GetComponent <Image>();
        casesParent         = new GameObject("inventoryCases");
        RectTransform rcParent = casesParent.AddComponent <RectTransform>();

        casesParent.transform.SetParent(transform);
        rcParent.sizeDelta               = Vector2.one;
        rcParent.pivot                   = Vector2.up;
        rcParent.anchorMax               = Vector2.up;
        rcParent.anchorMin               = Vector2.up;
        rcParent.anchoredPosition        = Vector2.zero;
        casesParent.transform.localScale = Vector3.one;

        //Create all cases with images and buttons
        cases = new Image[InventoryManager.GetInventoryManager.NbColumns, InventoryManager.GetInventoryManager.NbLines];
        Button button;

        for (int i = 0; i < InventoryManager.GetInventoryManager.NbColumns; i++)
        {
            for (int j = 0; j < InventoryManager.GetInventoryManager.NbLines; j++)
            {
                GameObject tmp    = new GameObject("Case " + i + " : " + j);
                Vector2    tmpPos = Vector2.zero;
                tmp.transform.parent = casesParent.transform;
                tmpPos.x            += i * (sizeCase.x + offset.x) + offset.x + offsetBorder.x;
                tmpPos.y            -= j * (sizeCase.y + offset.y) + offset.y + offsetBorder.y;
                cases[i, j]          = tmp.AddComponent <Image>();
                RectTransform tmpRect = tmp.GetComponent <RectTransform>();
                tmpRect.pivot            = Vector2.up;
                tmpRect.sizeDelta        = sizeCase;
                tmpRect.anchoredPosition = tmpPos;
                tmpRect.localScale       = Vector3.one;

                cases[i, j].sprite = caseSprite;
                cases[i, j].color  = Color.white;

                GameObject tmp2 = Instantiate(tmp);
                tmp2.transform.SetParent(tmp.transform);

                cases[i, j]       = tmp2.GetComponent <Image>();
                cases[i, j].color = Color.white;

                ClickableItem clickableItem = tmp2.AddComponent <ClickableItem>();
                clickableItem.onLeftClick += ChangeItemFromInventoryToTrade;
                button = tmp2.AddComponent <Button>();
                int index = i + j * InventoryManager.GetInventoryManager.NbColumns;
                clickableItem.id = index;
                button.onClick.AddListener(() => SelectItem(index));
                tmpRect                  = tmp2.GetComponent <RectTransform>();
                tmpRect.pivot            = new Vector2(0.5f, 0.5f);
                tmpRect.anchoredPosition = Vector2.zero;
                tmpRect.sizeDelta        = sizeCase * 0.75f;
                tmpRect.localScale       = Vector3.one;
            }
        }
        itemsSpriteHud = SpriteManager.GetSpriteManager.ItemsSpriteHud;


        //Create ItemInHand image
        canvas = GameObject.Find("CanvasInGame");
        GameObject itemInHandGameObject = new GameObject("ItemInHand");

        itemInHandGameObject.transform.SetParent(canvas.transform);
        itemInHand = itemInHandGameObject.AddComponent <Image>();
        itemInHand.rectTransform.anchorMin  = Vector2.zero;
        itemInHand.rectTransform.anchorMax  = Vector2.zero;
        itemInHand.rectTransform.sizeDelta  = sizeCase;
        itemInHand.raycastTarget            = false;
        itemInHand.rectTransform.localScale = Vector3.one;

        //add methods to delegate of inventoryManager
        InventoryManager.GetInventoryManager.InventoryOpen     += EnableInventoryHud;
        InventoryManager.GetInventoryManager.InventoryClose    += DisableInventoryHud;
        InventoryManager.GetInventoryManager.InventoryIsUpdate += UpdateInventoryHud;

        Vector2 newSize = new Vector2();

        newSize.x = InventoryManager.GetInventoryManager.NbColumns * (sizeCase.x + offset.x) + offset.x + offsetBorder.x * 2f;
        newSize.y = InventoryManager.GetInventoryManager.NbLines * (sizeCase.y + offset.y) + offset.y + offsetBorder.y * 2f;
        GetComponent <RectTransform>().sizeDelta = newSize;

        DisableInventoryHud();
        isInitialize = true;
    }
 public bool ContainsItem(ClickableItem item)
 {
     return(items.Contains(item));
 }
 public void AddInventoryItem(ClickableItem item)
 {
     items.Add(item);
     item.OnAddedToInventory();
     inventoryUI.UpdateInventory();
 }
		public bool ContainsItem(ClickableItem item)
		{
			return items.Contains(item);
		}
		public void AddInventoryItem(ClickableItem item)
		{
			items.Add(item);
			item.OnAddedToInventory();
			inventoryUI.UpdateInventory();
		}
 public AddItemToMixerEvent(ClickableItem item)
 {
     itemToAdd = item;
 }