示例#1
0
 private void UnHoverLastSelectable()
 {
     if (lastSelectable == null)
     {
         return;
     }
     lastSelectable.UnHover();
     lastSelectable = null;
 }
示例#2
0
 private void HoverSelection(SelectableEntity selectable)
 {
     if (lastSelectable != selectable)
     {
         UnHoverLastSelectable();
         lastSelectable = selectable;
         selectable.Hover();
     }
 }
    //private void objectUnselection(int gameObjectInstanceId) {
    private void objectUnselection(GameObject go)
    {
        SelectableEntity selectable = go.GetComponent <SelectableEntity>();

        if (selectable.selectionVisual != null)
        {
            GameObjectManager.setGameObjectState(selectable.selectionVisual, false);
        }
    }
    private void unSelectAll(SelectorEntity selector)
    {
        foreach (GameObject selectableObject in _selectableGO)
        {
            SelectableEntity selectable = selectableObject.GetComponent <SelectableEntity>();
            selectable.isSelected = false;
            GameObjectManager.setGameObjectTag(selectableObject, "Unselected");
        }

        selector.hasSelected = false;
    }
示例#5
0
 private void ClickOnSelectable()
 {
     if (lastSelectable == null)
     {
         HudService.CloseMenu();
     }
     else
     {
         lastSelectable.Click();
         lastSelectable = null;
     }
 }
    //Awake.
    void Awake()
    {
        //Detect whether the materials can be found. If not, report an error.
        if (shapeMaterial == null || pillowAndGlowMeshMaterial == null || pillowAndGlowRenderTextureMaterial == null)
        {
            Debug.LogError("At least one of the material properties on this Vector Sprites instance have been removed. The materials need to be assigned in " +
                           "order to create the sprites. Please re-assign them to this Vector Sprites instance (you may need to comment out the [HideInInspector] " +
                           "attributes on the material properties in \"VectorSprites.cs\" in order to assign them again).");
            return;
        }

        //Clear the sprites dictionary.
        sprites.Clear();

        //If the version is not up to date, don't do anything.
        if (!vectorSpritesProperties.updateVersion())
        {
            return;
        }

        //Set all meshes to dirty to ensure they are re-generated (the game quality might not match the editor quality).
        for (int i = 0; i < vectorSpritesProperties.shapeGroups.Count; i++)
        {
            for (int j = 0; j < vectorSpritesProperties.shapeGroups[i].shapes.Count; j++)
            {
                vectorSpritesProperties.shapeGroups[i].shapes[j].resetAllMeshes();
            }
        }

        //Create a Vector Sprites Renderer game object so the Vector Sprites can be rendered to textures.
        GameObject vectorSpritesRendererGameObject = new GameObject("Vector Sprites Renderer");

        vectorSpritesRendererGameObject.hideFlags = HideFlags.HideAndDontSave;
        VectorSpritesRenderer vectorSpritesRenderer = vectorSpritesRendererGameObject.AddComponent <VectorSpritesRenderer>();

        vectorSpritesRenderer.createdFromVectorSpritesInstance.flag = true;

        //Store the old selection so it can be restored after the sprites are generated.
        SelectableEntity oldSelectedEntity             = vectorSpritesProperties.selectedEntity;
        List <int>       oldSelectedEntityPrimaryIDs   = new List <int>();
        List <int>       oldSelectedEntitySecondaryIDs = new List <int>();

        for (int i = 0; i < vectorSpritesProperties.selectedEntities.Count; i++)
        {
            oldSelectedEntityPrimaryIDs.Add(vectorSpritesProperties.selectedEntities[i].primaryID);
            oldSelectedEntitySecondaryIDs.Add(vectorSpritesProperties.selectedEntities[i].secondaryID);
        }

        //Create the array of sprites, one for each Vector Sprite and loop over them in order to create them.
        for (int i = 0; i < vectorSpritesProperties.vectorSprites.Count; i++)
        {
            //Work out the sprite's scale.
            Vector2 meshScale = new Vector2(2, 2);
            if (vectorSpritesProperties.vectorSprites[i].spriteRectangleTransform == SpriteRectangleTransform.Crop)
            {
                if (vectorSpritesProperties.vectorSprites[i].width > vectorSpritesProperties.vectorSprites[i].height)
                {
                    meshScale.y *= (float)vectorSpritesProperties.vectorSprites[i].width / vectorSpritesProperties.vectorSprites[i].height;
                }
                else
                {
                    meshScale.x *= (float)vectorSpritesProperties.vectorSprites[i].height / vectorSpritesProperties.vectorSprites[i].width;
                }
            }

            //Render the sprite to a render texture. Double the size of the render texture if anti-aliasing is enabled (so it can be scaled back down).
            RenderTexture renderTexture = new RenderTexture(vectorSpritesProperties.vectorSprites[i].width *
                                                            (vectorSpritesProperties.vectorSprites[i].antialias ? 2 : 1), vectorSpritesProperties.vectorSprites[i].height *
                                                            (vectorSpritesProperties.vectorSprites[i].antialias ? 2 : 1), 16, RenderTextureFormat.ARGB32);
            renderTexture.hideFlags = HideFlags.HideAndDontSave;
            vectorSpritesProperties.selectedEntity = SelectableEntity.Sprite;
            vectorSpritesProperties.selectedEntities.Clear();
            vectorSpritesProperties.selectedEntities.Add(new SelectedEntity(i));
            vectorSpritesRenderer.render(vectorSpritesProperties, shapeMaterial, pillowAndGlowMeshMaterial, pillowAndGlowRenderTextureMaterial, renderTexture,
                                         meshScale, false);

            //Get the texture directly from the render texture.
            RenderTexture.active = renderTexture;
            Texture2D texture = new Texture2D(renderTexture.width, renderTexture.height, TextureFormat.ARGB32, false);
            texture.wrapMode = TextureWrapMode.Clamp;
            texture.ReadPixels(new Rect(0, 0, renderTexture.width, renderTexture.height), 0, 0, false);
            texture.Apply();
            RenderTexture.active = null;
            DestroyImmediate(renderTexture);

            //Copy the texture to the master texture, scaling down for anti-aliasing purposes if required.
            if (vectorSpritesProperties.vectorSprites[i].antialias)
            {
                renderTexture = new RenderTexture(vectorSpritesProperties.vectorSprites[i].width, vectorSpritesProperties.vectorSprites[i].height, 16,
                                                  RenderTextureFormat.ARGB32);
                renderTexture.hideFlags = HideFlags.HideAndDontSave;
                Graphics.Blit(texture, renderTexture);
                DestroyImmediate(texture);
                texture = new Texture2D(vectorSpritesProperties.vectorSprites[i].width, vectorSpritesProperties.vectorSprites[i].height, TextureFormat.ARGB32,
                                        false);
                RenderTexture.active = renderTexture;
                texture.ReadPixels(new Rect(0, 0, vectorSpritesProperties.vectorSprites[i].width, vectorSpritesProperties.vectorSprites[i].height), 0, 0,
                                   false);
                RenderTexture.active = null;
                DestroyImmediate(renderTexture);
                texture.Apply();
            }

            //Create the sprite.
            vectorSpritesProperties.vectorSprites[i].sprite = Sprite.Create(texture, new Rect(0, 0, vectorSpritesProperties.vectorSprites[i].width,
                                                                                              vectorSpritesProperties.vectorSprites[i].height), new Vector2(0.5f, 0.5f));

            //Add the sprite to the dictionary if it doesn't contain one with the same name.
            if (!sprites.ContainsKey(vectorSpritesProperties.vectorSprites[i].name))
            {
                sprites.Add(vectorSpritesProperties.vectorSprites[i].name, vectorSpritesProperties.vectorSprites[i].sprite);
            }
        }

        //Restore the previous selected entity.
        vectorSpritesProperties.selectedEntity = oldSelectedEntity;
        vectorSpritesProperties.selectedEntities.Clear();
        for (int i = 0; i < oldSelectedEntityPrimaryIDs.Count; i++)
        {
            vectorSpritesProperties.selectedEntities.Add(new VectorSprites.SelectedEntity(oldSelectedEntityPrimaryIDs[i], oldSelectedEntitySecondaryIDs[i]));
        }

        //Reset all shapes' meshes and render textures now that it has been rendered.
        for (int i = 0; i < vectorSpritesProperties.shapeGroups.Count; i++)
        {
            for (int j = 0; j < vectorSpritesProperties.shapeGroups[i].shapes.Count; j++)
            {
                vectorSpritesProperties.shapeGroups[i].shapes[j].resetAllMeshes();
            }
        }

        //Destroy the temporary Vector Sprites Renderer game object.
        Destroy(vectorSpritesRendererGameObject);
    }
        public void Configure(SelectableEntity <MedicineReminder> selectableReminder, bool isEditing = false)
        {
            this.selectableReminder = selectableReminder;
            UpdateDesignForNormalState();

            if (isEditing)
            {
                SelectCheckBox.Hidden = false;
                ViewLeadingConstraintToCheckBox.Active = true;
                ViewLeadingConstraint.Active           = false;

                SelectCheckBox.SelectionChanged -= SelectCheckBox_SelectionChanged;
                SelectCheckBox.Selected          = selectableReminder.IsSelected;
                SelectCheckBox.SelectionChanged += SelectCheckBox_SelectionChanged;
            }
            else
            {
                SelectCheckBox.Hidden                  = true;
                ViewLeadingConstraint.Active           = true;
                ViewLeadingConstraintToCheckBox.Active = false;
            }

            var atttibuted = new NSMutableAttributedString();

            atttibuted.Append(new NSAttributedString(selectableReminder.Entity.Medicine.Name, Fonts.GetBoldFont(18), Colors.LoginHelpTextColor));
            atttibuted.Append(new NSAttributedString($" {selectableReminder.Entity.Medicine.Strength}", Fonts.GetNormalFont(14), Colors.LoginHelpTextColor));

            MedicineNameLabel.AttributedText = atttibuted;

            var reminder = selectableReminder.Entity.Reminder;

            if (reminder != null)
            {
                List <String> frequency      = new List <string>();
                var           attributedText = new NSMutableAttributedString();

                attributedText.Append(new NSAttributedString($"{"General.View.Next".Translate()}: ", Fonts.GetMediumFont(15), Colors.DateSelectionLabelTextColor));
                String dayText;
                if (reminder.NextReminderDay.GetDay() == Day.Today)
                {
                    dayText   = "Today".Translate();
                    frequency = reminder.GetNextFrequencies();
                }
                else if (reminder.NextReminderDay.GetDay() == Day.Tomorrow)
                {
                    dayText = "Tomorrow".Translate();
                }
                else
                {
                    dayText = reminder.NextReminderDay.ToString().Translate();
                }

                attributedText.Append(new NSAttributedString(dayText, Fonts.GetMediumFont(15), Colors.DateSelectionLabelTextColor));
                attributedText.Append(new NSAttributedString($" {"General.View.TimePrefix".Translate()} ", Fonts.GetMediumFont(15), Colors.TitleTextColor));

                if (frequency.Count < 1)
                {
                    frequency = reminder.FrequencyPerDay;
                }

                var alarmText = String.Join(", ", frequency);
                attributedText.Append(new NSAttributedString(alarmText, Fonts.GetMediumFont(15), UIColor.Black));

                MedicineReminderLabel.AttributedText = attributedText;

                AlarmImageView.Hidden        = false;
                MedicineReminderLabel.Hidden = false;
            }
            else
            {
                AlarmImageView.Hidden        = true;
                MedicineReminderLabel.Hidden = true;
            }
        }
 private bool CanDepositEntity(SelectableEntity entity)
 {
     return(ValidRotationForDeposit(entity.direction) && (!RequiresAvailableAmountToDeposit() || GetAvailableAmount(entity.tag) > 0f) && AdditionalCanDepositTest());
 }
 

 public void Configure(SelectableEntity <MedicineInfo> medicine) 

 {
     
            this.selectableMedicine = medicine; 
 var atttibuted = new NSMutableAttributedString(); 
 atttibuted.Append(new NSAttributedString(medicine.Entity.Name, Fonts.GetBoldFont(18), Colors.LoginHelpTextColor)); 
 atttibuted.Append(new NSAttributedString($" {medicine.Entity.Strength}, {medicine.Entity.Form}", Fonts.GetNormalFont(14), Colors.LoginHelpTextColor)); 

 MedicineName.AttributedText = atttibuted; 

 SelectCheckBox.SelectionChanged -= SelectCheckBox_SelectionChanged; 
 SelectCheckBox.Selected = medicine.IsSelected; 
 SelectCheckBox.SelectionChanged += SelectCheckBox_SelectionChanged; 

 }
示例#10
0
 /// <summary>
 /// Предоставляет экземпляр класса EntityType, готовый к употреблению
 /// </summary>
 /// <param name="entity">Тип сущности, зарегистрированный в DialogService</param>
 public EntityType(SelectableEntity entity)
 {
     Entity = entity;
 }
    // Use to process your families.
    protected override void onProcess(int familiesUpdateCount)
    {
        GameObject go = _selectorGO.First();

        if (go != null)
        {
            SelectorEntity selector = go.GetComponent <SelectorEntity>();

            bool isOnBuyable = false;
            foreach (GameObject buyable in _buyableSelectableGO)
            {
                if (Input.GetMouseButtonDown(0))
                {
                    unSelectAll(selector);

                    SelectableEntity selectable = buyable.GetComponent <SelectableEntity>();

                    selectable.isSelected = true;
                    GameObjectManager.setGameObjectTag(buyable, "Selected");

                    isOnBuyable = true;
                    break;
                }
            }

            if (!isOnBuyable)
            {
                // If we press the right mouse button, move selected units or buy unit
                if (Input.GetMouseButtonDown(1) && !selector.isSelecting && _selectedGO.Count > 0)
                {
                    foreach (GameObject selectedObject in _selectedGO)
                    {
                        Move move = null;

                        if (selector.hasSelected)
                        {
                            //Case : unit selected -> move the unit
                            move = selectedObject.GetComponent <Move>();
                        }
                        else
                        {
                            //Case : buyable object selected -> buy
                            UIUnit     ui       = selectedObject.GetComponent <UIUnit>();
                            GameObject playerGO = _playerGO.First();

                            if (ui != null && ui.prefab != null && playerGO != null)
                            {
                                Player player = playerGO.GetComponent <Player>();

                                Energy  playerEnergy = playerGO.GetComponent <Energy>();
                                Buyable buyable      = ui.prefab.GetComponent <Buyable>();

                                //Check if we have enough "money"
                                if (buyable != null && buyable.energyPrice <= playerEnergy.energyPoints)
                                {
                                    playerEnergy.energyPoints -= buyable.energyPrice;

                                    //Spawn
                                    List <Vector3> spawnArea = TilemapUtils.getAllWorldPosition(player.spawnArea);
                                    Vector3        position  = Vector3.zero;
                                    if (spawnArea.Count > 0)
                                    {
                                        position = spawnArea[Random.Range(0, spawnArea.Count)];
                                    }

                                    GameObject myNewUnit = Object.Instantiate <GameObject>(ui.prefab, position, Quaternion.Euler(0f, 0f, Random.Range(0f, 360f)));
                                    GameObjectManager.bind(myNewUnit);

                                    move = myNewUnit.GetComponent <Move>();
                                }

                                //unSelectAll();
                            }
                        }

                        //Move the unit
                        if (move != null)
                        {
                            move.targetPosition    = Camera.main.ScreenToWorldPoint(Input.mousePosition);
                            move.newTargetPosition = true;
                            move.forcedTarget      = true;
                        }
                    }
                }

                // If we press the left mouse button, begin selection and remember the location of the mouse
                if (Input.GetMouseButtonDown(0))
                {
                    selector.isSelecting    = true;
                    selector.mousePosition1 = Input.mousePosition;

                    unSelectAll(selector);
                }

                // If we let go of the left mouse button, end selection
                if (Input.GetMouseButtonUp(0))
                {
                    List <GameObject> selectedObjects = new List <GameObject>();

                    foreach (GameObject selectableObject in _selectableGO)
                    {
                        if (IsWithinSelectionBounds(selectableObject, selector))
                        {
                            SelectableEntity selectable = selectableObject.GetComponent <SelectableEntity>();
                            selectable.isSelected = false;
                            GameObjectManager.setGameObjectTag(selectableObject, "Selected");

                            selectedObjects.Add(selectableObject);
                        }
                    }

                    var sb = new StringBuilder();
                    sb.AppendLine(string.Format("Selecting [{0}] Units", selectedObjects.Count));
                    foreach (GameObject selectedObject in selectedObjects)
                    {
                        sb.AppendLine("-> " + selectedObject.name);
                    }
                    Debug.Log(sb.ToString());

                    selector.isSelecting = false;
                    if (selectedObjects.Count > 0)
                    {
                        selector.hasSelected = true;
                    }
                }

                // Highlight all objects within the selection box
                foreach (GameObject selectableObject in _selectableGO)
                {
                    Renderer r = selectableObject.GetComponentInChildren <Renderer>();
                    if (IsWithinSelectionBounds(selectableObject, selector))
                    {
                        if (r != null)
                        {
                            r.material.color = Color.green;
                        }
                    }
                    else
                    {
                        if (r != null)
                        {
                            r.material.color = Color.white;
                        }
                    }
                }
            }

            if (Input.GetMouseButtonDown(0))
            {
                //Update infos
                Ray          ray   = Camera.main.ScreenPointToRay(Input.mousePosition);
                RaycastHit2D hit2d = Physics2D.GetRayIntersection(ray, Mathf.Infinity, LayerMask.GetMask("Ignore Raycast"));

                if (hit2d.collider != null)
                {
                    GameObject collideGO = hit2d.collider.gameObject;

                    if (collideGO != null)
                    {
                        Info infos = collideGO.GetComponent <Info>();

                        if (infos != null)
                        {
                            foreach (GameObject infoPanelGo in _infoPanelGO)
                            {
                                UIUnit ui = infoPanelGo.GetComponent <UIUnit>();

                                if (ui.image != null)
                                {
                                    SpriteRenderer sr = collideGO.GetComponentInChildren <SpriteRenderer>();

                                    if (sr != null)
                                    {
                                        ui.image.sprite = sr.sprite;
                                        ui.image.color  = sr.color;
                                    }
                                    else
                                    {
                                        ui.image.sprite = Resources.Load <Sprite>("Icons/placeholder");
                                        ui.image.color  = Color.white;
                                    }
                                }

                                if (ui.text != null)
                                {
                                    ui.text.text = infos.myName.Replace("\\n", "\n");;
                                }

                                if (ui.description != null)
                                {
                                    StringBuilder sb = new StringBuilder();

                                    Prey prey = collideGO.GetComponent <Prey>();
                                    if (prey != null)
                                    {
                                        sb.AppendLine("Type : " + prey.myType);
                                    }

                                    Predator predator = collideGO.GetComponent <Predator>();
                                    if (predator != null)
                                    {
                                        sb.AppendLine("Targets : " + string.Join(" / ", predator.myPreys) + "\n");
                                    }

                                    sb.AppendLine(infos.myDescription);

                                    ui.description.text = sb.ToString().Replace("\\n", "\n");;

                                    RectTransform rtInfoPanel       = (RectTransform)ui.gameObject.transform;
                                    RectTransform rtDescriptionText = (RectTransform)ui.description.GetComponent <ContentSizeFitter>().transform;
                                    LayoutRebuilder.ForceRebuildLayoutImmediate(rtDescriptionText);

                                    float posy = -10 - rtDescriptionText.rect.height / 2;

                                    rtDescriptionText.anchoredPosition = new Vector2(rtDescriptionText.anchoredPosition.x, posy);
                                    rtInfoPanel.sizeDelta = new Vector2(rtInfoPanel.sizeDelta.x, rtDescriptionText.rect.height);
                                }

                                if (ui.button != null)
                                {
                                    ui.button.onClick.RemoveAllListeners();
                                    ButtonSystem_wrapper b = Object.FindObjectOfType <ButtonSystem_wrapper>();

                                    if (infos.moreInfoUrl != null && infos.moreInfoUrl != "" && b != null)
                                    {
                                        ui.button.onClick.AddListener(delegate { b.openURL(infos.moreInfoUrl); });
                                        GameObjectManager.setGameObjectState(ui.button.gameObject, true);
                                    }
                                    else
                                    {
                                        GameObjectManager.setGameObjectState(ui.button.gameObject, false);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }