Esempio n. 1
0
    public GameObject CreateButtonWithoutText(GameObject parentCanvas, UiInformation information, Sprite sprite)
    {
        var buttonObj = new GameObject("Button", typeof(Button))
        {
            layer = LayerMask.NameToLayer("UI")
        };

        buttonObj.transform.SetParent(parentCanvas.transform);

        // set size of button
        var rectTransform = buttonObj.AddComponent <RectTransform>();

        rectTransform.sizeDelta = new Vector2(information.Width, information.Height);
        rectTransform.anchorMin = information.AnchorMin;
        rectTransform.anchorMax = information.AnchorMax;
        rectTransform.pivot     = new Vector2(0.5f, 0.5f);

        // TODO : Use CImage
        var imgComp = buttonObj.AddComponent <Image>();

        imgComp.sprite = sprite;
        imgComp.color  = _sDefaultSelectableColor;
        imgComp.type   = Image.Type.Simple;

        buttonObj.GetComponent <Button> ().targetGraphic = imgComp;

        // this should always be in end.
        var deltaPosX = information.DeltaPosFromAnchor.x;
        var deltaPosY = information.DeltaPosFromAnchor.y;

        rectTransform.anchoredPosition = new Vector2(deltaPosX, deltaPosY);

        return(buttonObj);
    }
Esempio n. 2
0
    /// <summary>
    /// Reads the text file.
    /// </summary>
    /// <param name="textAsset">Text asset.</param>
    public static List <UiInformation> ReadTextFile(TextAsset textAsset)
    {
        var informationList = new List <UiInformation> ();

        var dataLines = textAsset.text.Split('\n');

        for (var index = 0; index < dataLines.Length; index++)
        {
            var line = dataLines[index];
            if (line.Contains("#") || string.IsNullOrEmpty(line))
            {
                continue;
            }

            var lineSplits = line.Split(',');

            // get the anchor and name of object from one string
            var anchorName = lineSplits[0].Split('_');
            var anchor     = GetAnchorFromString(anchorName[0].Trim());
            var name       = anchorName[1].Trim();
            var uiType     = GetUiTypeFromString(anchorName[2].Trim());

            var left   = float.Parse(lineSplits[1].Trim());
            var top    = float.Parse(lineSplits[2].Trim());
            var right  = float.Parse(lineSplits[3].Trim());
            var bottom = float.Parse(lineSplits[4].Trim());

            //Debug.Log(anchor + " " + name + " " + uiType + " " + left + " " + top + " " + right + " " + bottom);
            var information = new UiInformation(anchor, name, uiType, left, top, right, bottom);
            informationList.Add(information);
        }

        return(informationList);
    }
Esempio n. 3
0
    public void CreateText(GameObject panelCanvas, UiInformation information)
    {
        var textObj = new GameObject("Text", typeof(Text))
        {
            layer = LayerMask.NameToLayer("UI")
        };

        textObj.transform.SetParent(panelCanvas.transform);

        // set anchor and pivot
        var rectTransform = textObj.GetComponent <RectTransform>();

        rectTransform.anchorMin = information.AnchorMin;
        rectTransform.anchorMax = information.AnchorMax;
        rectTransform.pivot     = new Vector2(0.5f, 0.5f);

        textObj.GetComponent <Text> ().text      = information.Name;
        textObj.GetComponent <Text> ().alignment = TextAnchor.MiddleCenter;

        // this should always be in end.
        var deltaPosX = information.DeltaPosFromAnchor.x;
        var deltaPosY = information.DeltaPosFromAnchor.y;

        rectTransform.anchoredPosition = new Vector2(deltaPosX, deltaPosY);
    }
Esempio n. 4
0
    IEnumerator ShowMessage(float waitTime, MessageLableType _message, CellDoomstock _worldPosition, string iconToGet = null)
    {
        yield return(new WaitForSeconds(waitTime));

        UiInformation info = Instantiate(uiInformationPrefab,
                                         new Vector3(_worldPosition.GetWorldPosition().x,
                                                     _worldPosition.GetWorldPosition().y,
                                                     _worldPosition.GetWorldPosition().z + 0.5f), this.transform.rotation);

        info.cell = _worldPosition;
        switch (_message)
        {
        case MessageLableType.FoodProduction:
        case MessageLableType.FaithProduction:
        case MessageLableType.WoodProduction:
        case MessageLableType.SpiritProduction:
        case MessageLableType.StoneProduction:
        case MessageLableType.Death:
        case MessageLableType.Birth:
        case MessageLableType.RemovePopulation:
        case MessageLableType.AddPopulation:
        case MessageLableType.Reparing:
        case MessageLableType.Destroing:
        case MessageLableType.Miracle:
            info.ShowMessagePop_up(_message, iconToGet);
            info.MessageType = "PopUp";
            break;

        case MessageLableType.LimitFood:
        case MessageLableType.LimitFaith:
        case MessageLableType.LimitWood:
        case MessageLableType.LimitSpirit:
        case MessageLableType.LimitStone:
        case MessageLableType.LimitPopulation:
        case MessageLableType.GetMacerie:
            info.ShowMessageStuck(_message);
            info.MessageType = "Stuck";
            break;

        default:
            break;
        }
    }