Esempio n. 1
0
    public void DisplayPick(GameObject[] pickables, Transform plyr, Collider clckdObj)     //wyświetlenie okna z lootem
    {
        int i = 0;

        pick.GetComponent <LootPick>().Refresh();       //usuń poprzednie obiekty z gui_pick

        foreach (GameObject p in pickables)
        {
            if (p != null)
            {
                pick.GetComponent <LootPick>().itemButtons[i].GetComponent <ItemButton>().item         = p;
                pick.GetComponent <LootPick>().itemButtons[i].GetComponent <ItemButton>().interactable = clckdObj.transform;
                pick.GetComponent <LootPick>().itemButtons[i].SetActive(true);
                i++;
            }
        }
        if (i != 0)                                                    // jeśli był jakikolwiek przedmiot do wyświetlenia
        {
            pick.rectTransform.anchoredPosition = Input.mousePosition; //pozycja okna taka jak pozycja kursora
            pick.gameObject.SetActive(true);
        }
        else
        {
            clckdObj.enabled = false;             // wyłącza interakcję z obiektem
            DisplayInfo("Brak przedmiotów do zebrania");
        }
    }
    // ================================================================ //

    // 创建残余数量的图标
    protected UnityEngine.UI.Image  create_stock_icon(float x, float y)
    {
        UnityEngine.UI.Image icon = GameObject.Instantiate(this.uiStockIconPrefab).GetComponent <UnityEngine.UI.Image>();

        icon.GetComponent <RectTransform>().SetParent(this.uiCanvas.GetComponent <RectTransform>());
        icon.GetComponent <RectTransform>().localPosition = new Vector3(x, y, 0.0f);

        return(icon);
    }
Esempio n. 3
0
    public void updateWeather(WeatherController.weatherList weather)
    {
        switch ((int)weather)
        {
        case 0:
            weatherText.text = "Acid Rain";
            weatherImg.GetComponent <UnityEngine.UI.Image>().sprite = acidRainSprite;
            //weatherImg.GetComponent<UnityEngine.UI.Image>().color = Color.green;
            //weatherBackgroundImg.GetComponent<UnityEngine.UI.Image>().color = Color.green;
            break;

        case 1:
            weatherText.text = "Sand Storm";
            weatherImg.GetComponent <UnityEngine.UI.Image>().sprite = sandStormSprite;
            //weatherImg.GetComponent<UnityEngine.UI.Image>().color = Color.cyan;
            //weatherBackgroundImg.GetComponent<UnityEngine.UI.Image>().color = Color.cyan;
            break;

        case 2:
            weatherText.text = "High Temp";
            weatherImg.GetComponent <UnityEngine.UI.Image>().sprite = highTempSprite;
            //weatherImg.GetComponent<UnityEngine.UI.Image>().color = Color.red;
            //weatherBackgroundImg.GetComponent<UnityEngine.UI.Image>().color = Color.red;
            break;

        case 3:
            weatherText.text = "Cold";
            weatherImg.GetComponent <UnityEngine.UI.Image>().sprite = coldSprite;
            //weatherImg.GetComponent<UnityEngine.UI.Image>().color = Color.blue;
            //weatherBackgroundImg.GetComponent<UnityEngine.UI.Image>().color = Color.blue;
            break;

        case 4:
            weatherText.text = "Normal";
            weatherImg.GetComponent <UnityEngine.UI.Image>().sprite = normalSprite;
            //weatherImg.GetComponent<UnityEngine.UI.Image>().color = Color.white;
            //weatherBackgroundImg.GetComponent<UnityEngine.UI.Image>().color = Color.white;
            break;

        default:
            break;
        }

        intensityText.text = "";
        for (int i = 0; i < myWeatherController.getWeatherLevel(); ++i)
        {
            intensityText.text += "I";
        }

        weatherChangeAnimator.SetTrigger("Play");
    }
    public void CreateTape()
    {
        if (!MatchRegex(inputField.text))
        {
            invalidInput.GetComponent <Animator>().Play("InvalidInput");
            this.SoundObject.GetComponent <AudioSource>().PlayOneShot(Resources.Load("Audio/G1_invalidInput") as AudioClip);
            return;
        }
        //setting initial state
        state = GetInitialState();
        //setting finalstate
        finalState = GetFinalState();
        //play sound on create tape
        SoundObject.GetComponent <AudioSource>().PlayOneShot(Resources.Load("Audio/G1_createTapeSound") as AudioClip);
        //getting input string
        string text = "Δ" + inputField.text + "ΔΔ";

        //setting x to leftMostX
        x = leftMostX;
        for (int i = 0; i < text.Length; i++)
        {
            CreateObjectNode(x, text[i].ToString());
            x = x + difference;
        }
        RightMostX = x - difference;
        //setting x for camera to right of left delta or start of string node.
        x = leftMostX + difference;
        //hiding inputField gameobject
        inputField.gameObject.SetActive(false);
        createBtn.gameObject.SetActive(false);
        gotoMainMenu.gameObject.SetActive(false);
    }
    public void SetRotation(Quaternion aRotation)
    {
        RectTransform r = GetComponent <RectTransform>();

        r.rotation = aRotation;
        mImage.GetComponent <RectTransform>().localRotation = Quaternion.Inverse(aRotation);
    }
Esempio n. 6
0
    private void Awake()
    {
        m_SliderRectTransform          = m_ShotSlider.GetComponent <RectTransform>();
        m_PerfectPowerBarRectTransform = m_PerfectPowerBar.GetComponent <RectTransform>();

        m_SliderHeight = m_SliderRectTransform.sizeDelta.y;
    }
Esempio n. 7
0
    void    Update()
    {
        // 잔여 표시.

        int remain = m_gameCtrl.GetRetryRemain();

        if (m_remainImages.Count < remain)
        {
            for (int i = m_remainImages.Count; i < remain; i++)
            {
                UnityEngine.UI.Image remain_image = this.create_remain_image();

                float x = -Screen.width / 2.0f + PLAYER_IMAGE_WIDTH + i * PLAYER_IMAGE_WIDTH;
                float y = Screen.height / 2.0f - 48.0f;

                remain_image.GetComponent <RectTransform>().localPosition = new Vector3(x, y, 0.0f);

                m_remainImages.Add(remain_image);
            }
        }
        else if (m_remainImages.Count > remain)
        {
            for (int i = m_remainImages.Count - 1; i > remain - 1; i--)
            {
                GameObject.Destroy(m_remainImages[i].gameObject);
            }

            m_remainImages.RemoveRange(remain, m_remainImages.Count - remain);
        }
    }
Esempio n. 8
0
    private void Awake()
    {
        m_reticleTransform = ReticleImage.GetComponent <Transform>();

        // Store the original scale and rotation.
        m_originalScale    = m_reticleTransform.localScale;
        m_originalRotation = m_reticleTransform.localRotation;
    }
Esempio n. 9
0
    // ================================================================ //

    // 잔여 아이콘을 만든다.
    protected UnityEngine.UI.Image  create_remain_image()
    {
        UnityEngine.UI.Image remain_image = GameObject.Instantiate(this.m_uiRemainImagePrefab).GetComponent <UnityEngine.UI.Image>();

        remain_image.GetComponent <RectTransform>().SetParent(this.m_uiCanvas.GetComponent <RectTransform>());

        return(remain_image);
    }
Esempio n. 10
0
    public void Start()
    {
        canvasTransform = canvas.GetComponent <RectTransform>();
        player          = GameObject.FindGameObjectWithTag("MainCamera");
        text.text       = String.Format("(Space) Interact with {0}", StringUtils.SpaceCase(itemType.ToString()));
        RectTransform textRectTransform  = text.GetComponent <RectTransform>();
        RectTransform imageRectTransform = image.GetComponent <RectTransform>();

        imageRectTransform.sizeDelta = new Vector2(text.preferredWidth + 10f, imageRectTransform.rect.height);
    }
    private IEnumerator Respawn(float time)
    {
        yield return(new WaitForSeconds(time));

        keysEnabled = true;
        gameOverText.gameObject.SetActive(false);

        Vector3 respawn = GameObject.Find("RespawnPoint").transform.position;

        gameObject.transform.position = new Vector3(respawn.x, respawn.y, transform.position.z);

        life = 3;

        heart1.GetComponent <UnityEngine.UI.Image>().sprite = HeartSprite;
        heart2.GetComponent <UnityEngine.UI.Image>().sprite = HeartSprite;
        heart3.GetComponent <UnityEngine.UI.Image>().sprite = HeartSprite;

        changeForm(forms.Water);
    }
Esempio n. 12
0
    private IEnumerator Respawn(float time)
    {
        yield return(new WaitForSeconds(time));

        changeForm(startForm);
        rigidBody.isKinematic = false;

        keysEnabled = true;
        gameOverText.gameObject.SetActive(false);
        gameOverText.transform.parent.transform.GetChild(0).GetComponent <Timer>().continueTimer();

        Vector3 respawn = GameObject.Find("RespawnPoint").transform.position;

        gameObject.transform.position = new Vector3(respawn.x, respawn.y, transform.position.z);

        life = 3;

        heart1.GetComponent <UnityEngine.UI.Image>().sprite = HeartSprite;
        heart2.GetComponent <UnityEngine.UI.Image>().sprite = HeartSprite;
        heart3.GetComponent <UnityEngine.UI.Image>().sprite = HeartSprite;
    }
Esempio n. 13
0
 private void Start()
 {
     if (selectionBox != null)
     {
         //We need to reset anchors and pivot to ensure proper positioning
         _rt           = selectionBox.GetComponent <RectTransform>();
         _rt.pivot     = Vector2.one * .5f;
         _rt.anchorMin = Vector2.one * .5f;
         _rt.anchorMax = Vector2.one * .5f;
         selectionBox.gameObject.SetActive(false);
     }
 }
Esempio n. 14
0
 static public void initCanvas()
 {
     mainCanvas = GameObject.Find("canvas");
     mainCanvas.GetComponent <Canvas>().renderMode  = RenderMode.ScreenSpaceCamera;
     mainCanvas.GetComponent <Canvas>().worldCamera = Camera.main;
     mainCanvas.GetComponent <UnityEngine.UI.CanvasScaler>().uiScaleMode         = UnityEngine.UI.CanvasScaler.ScaleMode.ScaleWithScreenSize;
     mainCanvas.GetComponent <UnityEngine.UI.CanvasScaler>().referenceResolution = new Vector2(1920, 1080);
     mainCanvas.GetComponent <UnityEngine.UI.CanvasScaler>().matchWidthOrHeight  = 1.0f;
     outputImage = GameObject.Find("canvas/image").GetComponent <UnityEngine.UI.Image>();
     outputImage.material.mainTexture = outputTexture;
     outputImage.type = UnityEngine.UI.Image.Type.Simple;
     outputImage.GetComponent <RectTransform>().sizeDelta = new Vector2(1080, 1080);
 }
Esempio n. 15
0
 public void DisplayInventory(GameObject player)
 {
     if (!inventory.gameObject.activeInHierarchy)
     {
         int          i     = 0;
         GameObject[] items = player.GetComponent <inventory>().slots;
         foreach (GameObject x in items)
         {
             if (x != null)
             {
                 inventory.GetComponent <InventoryWindow>().itemButtons[i].GetComponent <ItemButton>().item = x;
                 inventory.GetComponent <InventoryWindow>().itemButtons[i].SetActive(true);
             }
             i++;
         }
         inventory.gameObject.SetActive(true);
     }
     else
     {
         inventory.gameObject.SetActive(false);
     }
 }
Esempio n. 16
0
        private void SetHealthBar(Text healthBarPercent, Image healthBar, int healthValue, int totalHealthValue)
        {
            int healthPercent = (int)(((float)healthValue / (float)totalHealthValue) * 100);
            healthBarPercent.text = (healthPercent.ToString() + "%");

            float width = (float)healthPercent;
            float height = healthBar.GetComponent<RectTransform>().rect.height;

            width = Mathf.Clamp(width, 0.0f, 100.0f);
            healthBar.GetComponent<RectTransform>().sizeDelta = new Vector2(width, height);

            if (healthPercent >= 80)
                SetColor(healthBar, colorVeryHighHealth);
            else if (healthPercent >= 60)
                SetColor(healthBar, colorHighHealth);
            else if (healthPercent >= 40)
                SetColor(healthBar, colorMediumHealth);
            else if (healthPercent >= 20)
                SetColor(healthBar, colorLowHealth);
            else
                SetColor(healthBar, colorVeryLowHealth);
        }
Esempio n. 17
0
    void GameOver()
    {
        //GameOverText.enabled = true;
        GameOverScreen.GetComponent <Animation>().Play();
        hitbox.enabled  = false;
        rb.gravityScale = 0;
        _dead           = true;

        ResetAllAnimation();
        an.SetBool("Dead", true);
        //Time.timeScale = 0f;

        //Destroy(gameObject); // TODO
    }
    private void AnalyseFrame()
    {
        if (frame != null)
        {
            frame.Dispose();
        }
        frame = capture.QueryFrame();
        if (frame != null)
        {
            GameObject.Destroy(cameraTex);
            cameraTex = TextureConvert.ImageToTexture2D <Bgr, byte>(frame, true);
            Sprite.DestroyImmediate(CameraImageUI.GetComponent <UnityEngine.UI.Image>().sprite);
            CameraImageUI.sprite = Sprite.Create(cameraTex, new Rect(0, 0, cameraTex.width, cameraTex.height), new Vector2(0.5f, 0.5f));
        }
        if (true)
        //if (!processingFrame)
        {
            processingFrame = true;

            board = ImageTools.ReadFromFrame(frame.Clone(), filteringParameters);

            if (lookupImage != null)
            {
                lookupImage.Dispose();
            }

            if (board != null)
            {
                lookupImage = ImageTools.DrawRooms(320, 240, board.Grid);
            }
            else
            {
                lookupImage = new Image <Bgr, byte>(320, 240, new Bgr(0, 0, 0));
            }

            if (lookupImage != null)
            {
                GameObject.Destroy(lookupTex);
                lookupTex = TextureConvert.ImageToTexture2D <Bgr, byte>(lookupImage, true);
                Sprite.DestroyImmediate(LookupUI.GetComponent <UnityEngine.UI.Image>().sprite);
                LookupUI.sprite = Sprite.Create(lookupTex, new Rect(0, 0, lookupTex.width, lookupTex.height), new Vector2(0.5f, 0.5f));
            }
            processingFrame = false;
        }
    }
Esempio n. 19
0
    // Update is called once per frame

    void Update()
    {
        if (bar != null)
        {
            _sliderVal = Mathf.MoveTowards(_sliderVal, targetSliderVal, Time.deltaTime * Mathf.Abs(targetSliderVal - _sliderVal) * 10.0f);
            RectTransform bt = bar.GetComponent <RectTransform>();
            Vector2       r  = bt.sizeDelta;
            RectTransform tt = GetComponent <RectTransform>();
            if (horizontal)
            {
                r.x = tt.sizeDelta.x * _sliderVal;
            }
            else
            {
                r.y = tt.sizeDelta.y * _sliderVal;
            }
            bt.sizeDelta = r;
        }
    }
Esempio n. 20
0
    public void initialize()
    {
        mainCanvas = GameObject.Find("Canvas");
        mainCanvas.GetComponent <Canvas>().renderMode  = RenderMode.ScreenSpaceCamera;
        mainCanvas.GetComponent <Canvas>().worldCamera = Camera.main;
        mainCanvas.GetComponent <UnityEngine.UI.CanvasScaler>().uiScaleMode         = UnityEngine.UI.CanvasScaler.ScaleMode.ScaleWithScreenSize;
        mainCanvas.GetComponent <UnityEngine.UI.CanvasScaler>().referenceResolution = new Vector2(1024, 1024);

        if (Screen.width > Screen.height)
        {
            mainCanvas.GetComponent <UnityEngine.UI.CanvasScaler>().matchWidthOrHeight = 0.0f;
        }
        else
        {
            mainCanvas.GetComponent <UnityEngine.UI.CanvasScaler>().matchWidthOrHeight = 1.0f;
        }

        outputImage       = GameObject.Find("Canvas/Image").GetComponent <UnityEngine.UI.Image>();
        outputImage.color = new Color(1, 1, 1, 1);
        outputImage.type  = UnityEngine.UI.Image.Type.Simple;
        outputImage.GetComponent <RectTransform>().sizeDelta = new Vector2(1024, 1024);
    }
 public static void PlayInsufficientMoneyAnim()
 {
     moneyPanel.GetComponent <Animation>().Play();
 }
Esempio n. 22
0
 public void SetBackground()
 {
     image.sprite = spriteToSet;
     image.GetComponent <UnityEngine.Video.VideoPlayer>().enabled = false;
 }
Esempio n. 23
0
 private void Start()
 {
     Health = MaxHealth;
     healthBar.GetComponent <UnityEngine.UI.Image>().color = new Color(Mathf.Clamp((1 - (float)Health / (float)MaxHealth), 0, 1), Mathf.Clamp(((float)Health / (float)MaxHealth), 0, 1), 0, 0.5f);
     transform.position = nodeManager.SetPosition(gameObject.GetComponent <Enemy>(), Column, Row);
 }
 public void OnPointerEnter(UnityEngine.UI.Image image)
 {
     image.gameObject.SetActive(true);
     image.GetComponent <Animator>().Play("languageImage");
 }
Esempio n. 25
0
 private void set_highlight_position(float pos_y)
 {
     highlight.GetComponent <RectTransform>().localPosition = new Vector3(0, pos_y, 0);
     current_highlight_position = pos_y;
 }
		private void fitImageInView(Image image)
		{
			var rect = image.GetComponent<RectTransform>();
			float width = image.mainTexture.width / (float)Screen.width, height = image.mainTexture.height / (float)Screen.height;
			var size = MathUtilities.FitInView(width, height, 1, 1);
			rect.anchorMin = new Vector2(-(size.x*.5f) + .5f, -(size.y*.5f) + .5f);
			rect.anchorMax = new Vector2(-(size.x*.5f) + .5f + size.x, -(size.y*.5f) + .5f + size.y);
			rect.offsetMin = Vector2.zero;
			rect.offsetMax = Vector2.zero;
		}
Esempio n. 27
0
        /// <summary>
        /// Sets an image or gif/apng from a resource path
        /// </summary>
        /// <param name="image">Image component to set the image to</param>
        /// <param name="location">Resource path, file path, or url of image. Can prefix with # to find and use a base game sprite. May need to prefix resource paths with 'AssemblyName:'</param>
        /// <param name="loadingAnimation">Whether a loading animation is shown as a placeholder until the image is loaded</param>
        /// <param name="scaleOptions">If the image should be downscaled and what it should be downscaled to</param>
        /// <param name="callback">Method to call once SetImage has finished</param>
        public static void SetImage(this Image image, string location, bool loadingAnimation, ScaleOptions scaleOptions, Action callback)
        {
            AnimationStateUpdater oldStateUpdater = image.GetComponent <AnimationStateUpdater>();

            if (oldStateUpdater != null)
            {
                MonoBehaviour.DestroyImmediate(oldStateUpdater);
            }

            if (location.Length > 1 && location[0] == '#')
            {
                string imgName = location.Substring(1);
                image.sprite = Utilities.FindSpriteCached(imgName);
                if (image.sprite == null)
                {
                    Logger.log.Error($"Could not find Sprite with image name {imgName}");
                }

                return;
            }


            bool isURL = Uri.TryCreate(location, UriKind.Absolute, out Uri uri);

            if (IsAnimated(location) || isURL && IsAnimated(uri.LocalPath))
            {
                AnimationStateUpdater stateUpdater = image.gameObject.AddComponent <AnimationStateUpdater>();
                stateUpdater.image = image;
                if (loadingAnimation)
                {
                    stateUpdater.controllerData = AnimationController.instance.loadingAnimation;
                }

                if (AnimationController.instance.RegisteredAnimations.TryGetValue(location, out AnimationControllerData animControllerData))
                {
                    stateUpdater.controllerData = animControllerData;
                }
                else
                {
                    Utilities.GetData(location, (byte[] data) =>
                    {
                        AnimationLoader.Process(
                            (location.EndsWith(".gif", StringComparison.OrdinalIgnoreCase) ||
                             (isURL && uri.LocalPath.EndsWith(".gif", StringComparison.OrdinalIgnoreCase))) ? AnimationType.GIF : AnimationType.APNG,

                            data, (Texture2D tex, Rect[] uvs, float[] delays, int width, int height) =>
                        {
                            AnimationControllerData controllerData = AnimationController.instance.Register(location, tex, uvs, delays);
                            stateUpdater.controllerData            = controllerData;
                            callback?.Invoke();
                        });
                    });
                    return;
                }
            }
            else
            {
                AnimationStateUpdater stateUpdater = image.gameObject.AddComponent <AnimationStateUpdater>();
                stateUpdater.image = image;
                if (loadingAnimation)
                {
                    stateUpdater.controllerData = AnimationController.instance.loadingAnimation;
                }

                Utilities.GetData(location, async(byte[] data) =>
                {
                    if (stateUpdater != null)
                    {
                        GameObject.DestroyImmediate(stateUpdater);
                    }

                    if (scaleOptions.ShouldScale)
                    {
                        var imageBytes = await Task.Run(() => DownScaleImage(data, scaleOptions)).ConfigureAwait(false);
                        _ = UnityMainThreadTaskScheduler.Factory.StartNew(() =>
                        {
                            image.sprite = Utilities.LoadSpriteRaw(imageBytes);
                            image.sprite.texture.wrapMode = TextureWrapMode.Clamp;
                        });
                    }
                    else
                    {
                        image.sprite = Utilities.LoadSpriteRaw(data);
                        image.sprite.texture.wrapMode = TextureWrapMode.Clamp;
                    }

                    callback?.Invoke();
                });
                return;
            }
            callback?.Invoke();
        }
Esempio n. 28
0
    private void CreateInventoryLayout()
    {
        int     columns  = slots / rows;
        Vector3 slotSize = slotPrefab.GetComponent <RectTransform>().rect.size;

        inventoryW = (slotSize.x + leftPad) * columns + outPading * 2 - leftPad;
        inventoryH = (slotSize.y + topPad) * rows + outPading * 2 - topPad;

        RectTransform inventoryRect = this.GetComponent <RectTransform>();

        inventoryRect.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, inventoryW);
        inventoryRect.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, inventoryH);

        float orgX = -inventoryW / 2;
        float orgY = inventoryH / 2;

        for (int row = 0; row < rows; row++)
        {
            for (int column = 0; column < columns; column++)
            {
                Slot slot = Instantiate(slotPrefab);
                slot.transform.SetParent(this.gameObject.transform);
                slot.transform.localScale = oneSize;
                slot.GetComponent <RectTransform>().localPosition = new Vector3(orgX + outPading + (leftPad + slotSize.x) * column, orgY - outPading - (topPad + slotSize.y) * row, 0);
                slotsList.Add(slot);
                emptySlots++;
            }
        }

        //Equipment Panel
        equipment = Instantiate(equipmentPrefab);
        equipment.transform.SetParent(this.transform);
        equipment.transform.localScale = oneSize;

        float equipmentW = slotSize.x * 2 + outPading * 5;

        RectTransform equipmentRect = equipment.GetComponent <RectTransform>();

        equipmentRect.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, equipmentW);
        equipmentRect.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, inventoryH);

        equipmentRect.localPosition = new Vector3(-inventoryW + equipmentW / 2, 0, 0);

        //InventoryBar
        inventoryBar = Instantiate(equipmentPrefab);
        inventoryBar.transform.SetParent(this.transform);
        inventoryBar.transform.localScale = oneSize;

        float barW = equipmentW + inventoryW + leftPad;

        RectTransform barRect = inventoryBar.GetComponent <RectTransform>();

        barRect.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, barW);
        barRect.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, 36);

        barRect.localPosition = new Vector3(-(equipmentW + outPading) / 2, (inventoryH + 36) / 2, 0);

        close.transform.SetParent(inventoryBar.transform);
        close.transform.localScale = oneSize;
        RectTransform closeRect = close.GetComponent <RectTransform>();

        closeRect.localPosition = new Vector3(barW / 2 - closeRect.sizeDelta.x - leftPad, 0, 0);

        //StatsPanel
        RectTransform statsRect = statsPanel.GetComponent <RectTransform>();

        statsRect.transform.SetParent(this.transform);
        statsRect.localPosition = new Vector3(inventoryW / 2, 0, 0);

        statsText = statsPanel.GetComponentInChildren <Text>();

        //Equipment Slots
        orgX = -equipmentW / 2;

        //Head slot
        Slot helmetSlot = Instantiate(slotPrefab);

        helmetSlot.transform.SetParent(equipment.transform);
        helmetSlot.transform.localScale = oneSize;
        helmetSlot.AddSpecialization(ItemType.Head);
        helmetSlot.GetComponent <RectTransform>().localPosition = new Vector3(orgX + outPading * 2.5f + slotSize.x / 2, orgY - outPading * 2, 0);
        equipmentSlots.Add(helmetSlot);

        //Weapon slot
        Slot weaponSlot = Instantiate(slotPrefab);

        weaponSlot.transform.SetParent(equipment.transform);
        weaponSlot.transform.localScale = oneSize;
        weaponSlot.AddSpecialization(ItemType.Weapon);
        weaponSlot.GetComponent <RectTransform>().localPosition = new Vector3(orgX + outPading * 2, orgY - outPading * 2 - slotSize.y - outPading, 0);
        equipmentSlots.Add(weaponSlot);

        //Shield slot
        Slot shieldSlot = Instantiate(slotPrefab);

        shieldSlot.transform.SetParent(equipment.transform);
        shieldSlot.transform.localScale = oneSize;
        shieldSlot.AddSpecialization(ItemType.Shield);
        shieldSlot.GetComponent <RectTransform>().localPosition = new Vector3(orgX + outPading * 3 + slotSize.x, orgY - outPading * 2 - slotSize.y - outPading, 0);
        equipmentSlots.Add(shieldSlot);

        //Armor slot
        Slot armorSlot = Instantiate(slotPrefab);

        armorSlot.transform.SetParent(equipment.transform);
        armorSlot.transform.localScale = oneSize;
        armorSlot.AddSpecialization(ItemType.Armor);
        armorSlot.GetComponent <RectTransform>().localPosition = new Vector3(orgX + outPading * 2, orgY - outPading * 2 - (slotSize.y + outPading) * 2, 0);
        equipmentSlots.Add(armorSlot);

        //Hands slot
        Slot hadsSlot = Instantiate(slotPrefab);

        hadsSlot.transform.SetParent(equipment.transform);
        hadsSlot.transform.localScale = oneSize;
        hadsSlot.AddSpecialization(ItemType.Gloves);
        hadsSlot.GetComponent <RectTransform>().localPosition = new Vector3(orgX + outPading * 3 + slotSize.x, orgY - outPading * 2 - (slotSize.y + outPading) * 2, 0);
        equipmentSlots.Add(hadsSlot);

        //Shoes slot
        Slot shoesSlot = Instantiate(slotPrefab);

        shoesSlot.transform.SetParent(equipment.transform);
        shoesSlot.transform.localScale = oneSize;
        shoesSlot.AddSpecialization(ItemType.Boots);
        shoesSlot.GetComponent <RectTransform>().localPosition = new Vector3(orgX + outPading * 2.5f + slotSize.x / 2, orgY - outPading * 2 - (slotSize.y + outPading) * 3, 0);
        equipmentSlots.Add(shoesSlot);

        //Set final inventory position (centered)
        Rect canvasRect = canvas.GetComponent <RectTransform>().rect;

        this.transform.position = new Vector3(canvasRect.width / 2, canvasRect.height / 2, 0);
    }
        public UINode DrawLayer(Layer layer, UINode parent)
        {
            UINode node = PSDImportUtility.InstantiateItem(PSDImporterConst.PREFAB_PATH_SLIDER, layer.name, parent); //GameObject.Instantiate(temp) as UnityEngine.UI.Slider;

            UnityEngine.UI.Slider slider = node.GetComponent <UnityEngine.UI.Slider>();
            string type = layer.arguments[0].ToUpper();

            switch (type)
            {
            case "R":
                slider.direction = Slider.Direction.RightToLeft;
                break;

            case "L":
                slider.direction = Slider.Direction.LeftToRight;
                break;

            case "T":
                slider.direction = Slider.Direction.TopToBottom;
                break;

            case "B":
                slider.direction = Slider.Direction.BottomToTop;
                break;

            default:
                break;
            }
            bool haveHandle = false;

            for (int i = 0; i < layer.images.Length; i++)
            {
                Image  image               = layer.images[i];
                string lowerName           = image.name.ToLower();
                UnityEngine.UI.Image graph = null;

                if (lowerName.StartsWith("b_"))
                {
                    graph = slider.transform.Find("Background").GetComponent <UnityEngine.UI.Image>();
                    PSDImportUtility.SetRectTransform(image, slider.GetComponent <RectTransform>());
                    slider.name = layer.name;
                }
                else if (lowerName.StartsWith("f_"))
                {
                    graph = slider.fillRect.GetComponent <UnityEngine.UI.Image>();
                }
                else if (lowerName.StartsWith("h_"))
                {
                    graph = slider.handleRect.GetComponent <UnityEngine.UI.Image>();
                    RectTransform rect = graph.GetComponent <RectTransform>();
                    rect.name             = image.name;
                    rect.sizeDelta        = new Vector2(image.size.width, 0);
                    rect.anchoredPosition = Vector2.zero;
                    haveHandle            = true;
                }

                if (graph == null)
                {
                    continue;
                }

                PSDImportUtility.SetPictureOrLoadColor(image, graph);
            }

            if (!haveHandle)
            {
                UnityEngine.Object.DestroyImmediate(slider.handleRect.parent.gameObject);
            }
            return(node);
        }
Esempio n. 30
0
 void Start()
 {
     //assign health bar and thirst bar x coordinates to max health at first
     currentThirstX = thirstBarEmpty.GetComponent <RectTransform>().anchoredPosition.x;
     healthScript   = GetComponent <Health>();
 }
Esempio n. 31
0
 void Start()
 {
     //assign health bar x coordinate to max health at first
     currentX = healthBarEmpty.GetComponent <RectTransform>().anchoredPosition.x;
 }
Esempio n. 32
0
 public void DisplayItemMenu(int index)
 {
     itemMenu.GetComponent <ItemMenu>().itemIndex = index;
     itemMenu.rectTransform.anchoredPosition      = Input.mousePosition;   //pozycja okna taka jak pozycja kursora
     itemMenu.gameObject.SetActive(true);
 }