Example #1
0
        static void CreateScrollPanel(MenuCommand menuCommand)
        {
            // Create a custom game object
            GameObject panelObj = new GameObject("Dialogue Scroll Panel");

            // Register the creation in the undo system
            Undo.RegisterCreatedObjectUndo(panelObj, "Create " + panelObj.name);
            // Cria um Canvas se ele nao existir
            Canvas canvas = FindObjectOfType <Canvas>();

            if (!canvas)
            {
                GameObject canvasObj = new GameObject("Canvas", typeof(CanvasScaler));
                Undo.RegisterCreatedObjectUndo(canvasObj, "Create " + canvasObj.name);
                canvas = canvasObj.GetComponent <Canvas>();
                CanvasScaler canvasScaler = canvasObj.GetComponent <CanvasScaler>();
                canvasScaler.uiScaleMode            = CanvasScaler.ScaleMode.ConstantPixelSize;
                canvasScaler.scaleFactor            = 1f;
                canvasScaler.referencePixelsPerUnit = 100f;
                canvas.renderMode               = RenderMode.ScreenSpaceCamera;
                canvas.worldCamera              = FindObjectOfType <Camera>();
                canvas.pixelPerfect             = true;
                canvas.sortingOrder             = 10;
                canvas.targetDisplay            = 0;
                canvas.planeDistance            = 100f;
                canvas.additionalShaderChannels = AdditionalCanvasShaderChannels.Normal | AdditionalCanvasShaderChannels.Tangent | AdditionalCanvasShaderChannels.TexCoord1;
            }
            // Adiciona o panel como filho do canvas e seta propriedades iniciais
            panelObj.transform.SetParent(canvas.transform);
            panelObj.AddComponent <DialogueScrollPanel>();
            panelObj.GetComponent <CanvasRenderer>().cullTransparentMesh = false;
            panelObj.GetComponent <Mask>().showMaskGraphic = true;
            Image img = panelObj.GetComponent <Image>();

            img.transform.localPosition = new Vector3(img.transform.localPosition.x, img.transform.localPosition.y, 0f);
            img.sprite        = AssetDatabase.GetBuiltinExtraResource <Sprite>("UI/Skin/Background.psd");
            img.color         = Color.white;
            img.material      = null;
            img.raycastTarget = true;
            img.type          = Image.Type.Sliced;
            img.fillCenter    = true;
            int count = 0;

            Debug.Log("count = " + (count++) + ":  posZ = " + img.transform.localPosition.z);
            img.rectTransform.pivot = new Vector2(0.5f, 0f);
            Debug.Log("count = " + (count++) + ":  posZ = " + img.transform.localPosition.z);
            img.rectTransform.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Right, 0f, 0);
            Debug.Log("count = " + (count++) + ":  posZ = " + img.transform.localPosition.z);
            img.rectTransform.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Left, 0f, 0);
            Debug.Log("count = " + (count++) + ":  posZ = " + img.transform.localPosition.z);
            img.rectTransform.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Bottom, 0f, 150f);
            Debug.Log("count = " + (count++) + ":  posZ = " + img.transform.localPosition.z);
            img.rectTransform.anchorMin = new Vector2(0f, 0f);
            img.rectTransform.anchorMax = new Vector2(1f, 0f);
            Debug.Log("count = " + (count++) + ":  posZ = " + img.transform.localPosition.z);
            //img.rectTransform.position = new Vector3(img.rectTransform.position.x, 0f, img.rectTransform.position.z);
            img.rectTransform.localScale = new Vector3(1f, 1f, 1f);
            // Adiciona o objeto de viewport como filho do panel
            GameObject viewObj = new GameObject("Viewport");

            Undo.RegisterCreatedObjectUndo(viewObj, "Create " + viewObj.name);
            viewObj.transform.SetParent(panelObj.transform);
            viewObj.AddComponent <Image>();
            viewObj.AddComponent <Mask>();
            img = viewObj.GetComponent <Image>();
            img.transform.localPosition = new Vector3(img.transform.localPosition.x, img.transform.localPosition.y, 0f);
            img.sprite        = AssetDatabase.GetBuiltinExtraResource <Sprite>("UI/Skin/Background.psd");
            img.color         = Color.white;
            img.material      = null;
            img.raycastTarget = true;
            img.type          = Image.Type.Sliced;
            img.fillCenter    = true;
            viewObj.GetComponent <Mask>().showMaskGraphic = false;
            viewObj.GetComponent <CanvasRenderer>().cullTransparentMesh = false;
            panelObj.GetComponent <DialogueScrollPanel>().viewport      = img.rectTransform;
            img.rectTransform.pivot = new Vector2(0f, 0f);
            img.rectTransform.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Left, 0f, 0f);
            img.rectTransform.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Right, 0f, 0f);
            img.rectTransform.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Bottom, 0f, 0f);
            img.rectTransform.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Top, 0f, 0f);
            img.rectTransform.anchorMin = new Vector2(0f, 0f);
            img.rectTransform.anchorMax = new Vector2(1f, 1f);
            img.rectTransform.sizeDelta = new Vector2(0f, 0f);
            //img.rectTransform.position = new Vector3(0f, 0f, 0f);
            img.rectTransform.localScale = new Vector3(1f, 1f, 1f);
            // Adiciona o objeto de content como filho do viewport
            // O content por padrao contem um TextMeshProGUI
            GameObject contentObj = new GameObject("Content");

            Undo.RegisterCreatedObjectUndo(contentObj, "Create " + contentObj.name);
            contentObj.transform.SetParent(viewObj.transform);
            contentObj.AddComponent <ContentSizeFitter>();
            contentObj.AddComponent <TMPro.TextMeshProUGUI>();
            contentObj.GetComponent <ContentSizeFitter>().horizontalFit = ContentSizeFitter.FitMode.Unconstrained;
            contentObj.GetComponent <ContentSizeFitter>().verticalFit   = ContentSizeFitter.FitMode.PreferredSize;
            TMPro.TextMeshProUGUI textMesh = contentObj.GetComponent <TMPro.TextMeshProUGUI>();
            textMesh.transform.localPosition = new Vector3(img.transform.localPosition.x, img.transform.localPosition.y, 0f);
            textMesh.font               = TMPro.TMP_FontAsset.defaultFontAsset;
            textMesh.fontSize           = 21;
            textMesh.color              = Color.black;
            textMesh.alignment          = TMPro.TextAlignmentOptions.TopJustified;
            textMesh.wordWrappingRatios = 0f;
            textMesh.overflowMode       = TMPro.TextOverflowModes.ScrollRect;
            textMesh.margin             = new Vector4(3, 20, 3, 1);
            panelObj.GetComponent <DialogueScrollPanel>().content = textMesh.rectTransform;
            textMesh.rectTransform.pivot = new Vector2(0f, 1f);
            textMesh.rectTransform.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Left, 0f, 0f);
            textMesh.rectTransform.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Right, 0f, 0f);
            textMesh.rectTransform.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Bottom, 0f, 0f);
            textMesh.rectTransform.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Top, 0f, 0f);
            textMesh.rectTransform.anchorMin  = new Vector2(0f, 1f);
            textMesh.rectTransform.anchorMax  = new Vector2(1f, 1f);
            textMesh.rectTransform.sizeDelta  = new Vector2(0f, 0f);
            textMesh.rectTransform.localScale = new Vector3(1f, 1f, 1f);
            // Configura o DialogueHandler da cena (cria se necessario)
            DialogueHandler handler = FindObjectOfType <DialogueHandler>();

            if (!handler)
            {
                GameObject go = new GameObject("Dialogue Handler", typeof(DialogueHandler));
                Undo.RegisterCreatedObjectUndo(go, "Create " + go.name);
                handler = go.GetComponent <DialogueHandler>();
            }
            handler.dialogueText     = textMesh;
            handler.useTitles        = true;
            handler.titleText        = textMesh;
            handler.dialogueBox      = panelObj.GetComponent <DialogueScrollPanel>();
            handler.useTypingEffect  = true;
            handler.fillInBeforeSkip = true;
            handler.isSingleton      = true;

            // Select newly created object
            panelObj.SetActive(false);
            Selection.activeObject = panelObj;
        }
 public void colorToWhite(TMPro.TextMeshProUGUI text)
 {
     text.color = Color.white;
 }
        public override void ShowGUI(Menu menu)
        {
            string apiPrefix = "(AC.PlayerMenus.GetElementWithName (\"" + menu.title + "\", \"" + title + "\") as AC.MenuLabel)";

            MenuSource source = menu.menuSource;

            EditorGUILayout.BeginVertical("Button");

            if (source != MenuSource.AdventureCreator)
            {
                                #if TextMeshProIsPresent
                uiText = LinkedUiGUI <TMPro.TextMeshProUGUI> (uiText, "Linked Text:", source);
                                #else
                uiText = LinkedUiGUI <Text> (uiText, "Linked Text:", source);
                                #endif

                EditorGUILayout.EndVertical();
                EditorGUILayout.BeginVertical("Button");
            }

            labelType = (AC_LabelType)CustomGUILayout.EnumPopup("Label type:", labelType, apiPrefix + ".labelType", "What kind of text the label displays");
            if (labelType == AC_LabelType.Normal)
            {
                label = CustomGUILayout.TextField("Label text:", label, apiPrefix + ".label", "The display text");
            }
            else if (source == MenuSource.AdventureCreator)
            {
                label = CustomGUILayout.TextField("Placeholder text:", label, apiPrefix + ".label");
            }

            if (labelType == AC_LabelType.GlobalVariable)
            {
                variableID = AdvGame.GlobalVariableGUI("Global Variable:", variableID, "The Global Variable whose value will be displayed");
            }
            else if (labelType == AC_LabelType.DialogueLine)
            {
                useCharacterColour = CustomGUILayout.Toggle("Use Character text colour?", useCharacterColour, apiPrefix + ".useCharacterColour", "If True, then the displayed subtitle text will use the speaking character's subtitle text colour");
                if (sizeType == AC_SizeType.Manual)
                {
                    autoAdjustHeight = CustomGUILayout.Toggle("Auto-adjust height to fit?", autoAdjustHeight, apiPrefix + ".autoAdjustHeight", "If True, then the label's height will adjust itself to fit the text within it");
                }
            }

            if (labelType == AC_LabelType.Hotspot || labelType == AC_LabelType.DialogueLine || labelType == AC_LabelType.DialogueSpeaker)
            {
                updateIfEmpty = CustomGUILayout.Toggle("Update if string is empty?", updateIfEmpty, apiPrefix + ".updateIfEmpty", "If True, then the display text buffer can be empty ");

                if (labelType == AC_LabelType.Hotspot)
                {
                    showPendingWhileMovingToHotspot = CustomGUILayout.ToggleLeft("Show pending Interaction while moving to Hotspot?", showPendingWhileMovingToHotspot, apiPrefix + ".showPendingWhileMovingToHotspot", "If True, then the label will not change while the player is moving towards a Hotspot in order to run an interaction");
                }
            }
            else if (labelType == AC_LabelType.InventoryProperty)
            {
                if (AdvGame.GetReferences().inventoryManager)
                {
                    if (AdvGame.GetReferences().inventoryManager.invVars != null && AdvGame.GetReferences().inventoryManager.invVars.Count > 0)
                    {
                        InvVar[]      invVars     = AdvGame.GetReferences().inventoryManager.invVars.ToArray();
                        List <string> invVarNames = new List <string>();

                        int itemPropertyNumber = 0;
                        for (int i = 0; i < invVars.Length; i++)
                        {
                            if (invVars[i].id == itemPropertyID)
                            {
                                itemPropertyNumber = i;
                            }
                            invVarNames.Add(invVars[i].id + ": " + invVars[i].label);
                        }

                        itemPropertyNumber = CustomGUILayout.Popup("Inventory property:", itemPropertyNumber, invVarNames.ToArray(), apiPrefix + ".itemPropertyNumber", "The inventory property to show");
                        itemPropertyID     = invVars[itemPropertyNumber].id;

                        inventoryPropertyType = (InventoryPropertyType)CustomGUILayout.EnumPopup("Inventory item source:", inventoryPropertyType, apiPrefix + ".inventoryPropertyType", "What kind of item to display properties for");
                    }
                    else
                    {
                        EditorGUILayout.HelpBox("No Inventory properties defined!", MessageType.Warning);
                    }
                }
                else
                {
                    EditorGUILayout.HelpBox("No Inventory Manager assigned!", MessageType.Warning);
                }
            }

            EditorGUILayout.EndVertical();

            base.ShowGUI(menu);
        }
 private void Awake()
 {
     textField = GetComponent <TMPro.TextMeshProUGUI>();
 }
Example #5
0
 private void Start()
 {
     m_text = GetComponentInChildren <TMPro.TextMeshProUGUI>();
 }
 /// <summary>
 /// Set text alignment.
 /// </summary>
 /// <param name="text">Text component.</param>
 /// <param name="alignment">Alignment.</param>
 protected static void SetTextAlignment(TMPro.TextMeshProUGUI text, TextAnchor alignment)
 {
     text.alignment = ConvertAlignment(alignment);
 }
Example #7
0
        private void Awake()
        {
            text = gameObject.GetComponent <TMPro.TextMeshProUGUI>();

            this.transform.SetAsFirstSibling();
        }
Example #8
0
 internal OnscreenMessageBox(Vector3Int?position, string speaker, int speakerLevel, MessageModeType mode, int messagesSize, TMPro.TextMeshProUGUI textMesh = null)
 {
     m_Position     = position;
     Speaker        = speaker;
     m_SpeakerLevel = speakerLevel;
     Mode           = mode;
     m_Messages     = new Utility.RingBuffer <OnscreenMessage>(messagesSize);
     m_TextMesh     = textMesh;
 }
Example #9
0
 private void Start()
 {
     container      = GetComponentInChildren <TMPro.TextMeshProUGUI>();
     container.text = "";
 }
    public void ReplaceGlobals(UnityEngine.GameObject newPlayerPrefab, UnityEngine.GameObject newEnemyPrefab, UnityEngine.GameObject newShotPrefab, TMPro.TextMeshProUGUI newEnemyCountText)
    {
        var index     = GameComponentsLookup.Globals;
        var component = (GlobalsComponent)CreateComponent(index, typeof(GlobalsComponent));

        component.playerPrefab   = newPlayerPrefab;
        component.enemyPrefab    = newEnemyPrefab;
        component.shotPrefab     = newShotPrefab;
        component.enemyCountText = newEnemyCountText;
        ReplaceComponent(index, component);
    }
Example #11
0
 private void OnEnable()
 {
     textMesh = GetComponent <TMPro.TextMeshProUGUI>();
     vJoyInterface.VJoyStatusChange.Listen(OnStatusChange);
     Refresh(vJoyInterface.vJoyStatus);
 }
    public void ReplaceGlobals(UnityEngine.GameObject newPlayerPrefab, UnityEngine.GameObject newEnemyPrefab, UnityEngine.GameObject newShotPrefab, TMPro.TextMeshProUGUI newEnemyCountText)
    {
        var entity = globalsEntity;

        if (entity == null)
        {
            entity = SetGlobals(newPlayerPrefab, newEnemyPrefab, newShotPrefab, newEnemyCountText);
        }
        else
        {
            entity.ReplaceGlobals(newPlayerPrefab, newEnemyPrefab, newShotPrefab, newEnemyCountText);
        }
    }
    public GameEntity SetGlobals(UnityEngine.GameObject newPlayerPrefab, UnityEngine.GameObject newEnemyPrefab, UnityEngine.GameObject newShotPrefab, TMPro.TextMeshProUGUI newEnemyCountText)
    {
        if (hasGlobals)
        {
            throw new Entitas.EntitasException("Could not set Globals!\n" + this + " already has an entity with GlobalsComponent!",
                                               "You should check if the context already has a globalsEntity before setting it or use context.ReplaceGlobals().");
        }
        var entity = CreateEntity();

        entity.AddGlobals(newPlayerPrefab, newEnemyPrefab, newShotPrefab, newEnemyCountText);
        return(entity);
    }
 private void OnEnable()
 {
     textMesh = GetComponent <TMPro.TextMeshProUGUI>();
     SteamVR_Events.Initialized.Listen(OnInitialize);
     Refresh();
 }
        /// <summary>
        /// Call this any time the title text has changed - this will make an attempt to update
        /// the contract window title.  We do this because otherwise the window will only ever read
        /// the title once.
        /// </summary>
        /// <param name="newTitle">New title to display</param>
        public void UpdateContractWindow(string newTitle)
        {
            // Get the cascading list for our contract
            if (text == null && ContractsApp.Instance != null)
            {
                UICascadingList.CascadingListItem list = TitleTrackerHelper.uiListMap.ContainsKey(parameter.Root.ContractGuid) ? TitleTrackerHelper.uiListMap[parameter.Root.ContractGuid] : null;

                if (list != null)
                {
                    foreach (KSP.UI.UIListItem item in list.items)
                    {
                        TMPro.TextMeshProUGUI textComponent = item.GetComponentsInChildren<TMPro.TextMeshProUGUI>(true).FirstOrDefault();
                        if (textComponent != null)
                        {
                            // Check for any string in titleTracker
                            foreach (string title in titles)
                            {
                                if (textComponent.text.EndsWith(">" + title + "</color>"))
                                {
                                    text = textComponent;
                                    layoutElement = item.GetComponentsInChildren<LayoutElement>(true).FirstOrDefault();
                                    break;
                                }
                            }

                            if (text != null)
                            {
                                break;
                            }
                        }
                    }
                }
            }

            if (text)
            {
                // Clear the titleTracker, and replace the text
                if (!text.text.Contains(">" + newTitle + "<"))
                {
                    float preHeight = text.preferredHeight;

                    titles.Clear();
                    text.text = text.text.Substring(0, text.text.IndexOf(">") + 1) + newTitle + "</color>";
                    titles.Add(newTitle);

                    float postHeight = text.preferredHeight;

                    if (preHeight != postHeight)
                    {
                        text.rectTransform.sizeDelta = new Vector2(text.rectTransform.sizeDelta.x, postHeight + 4f);
                        layoutElement.preferredHeight = postHeight + 6f;

                        // Force an update to the layout even when not active
                        if (!layoutElement.IsActive())
                        {
                            LayoutRebuilder.MarkLayoutForRebuild(layoutElement.transform as RectTransform);
                        }
                    }
                }
            }

            // Contracts Window + update
            ContractsWindow.SetParameterTitle(parameter, newTitle);
        }
Example #16
0
        /// <summary>
        /// 値の更新
        /// </summary>
        /// <param name="v">カーブからサンプリングした0−1で正規化された値</param>
        protected override void _UpdateValue(float v)
        {
            if (!_image && !_text && !_tmp && !_sprite_renderer && !_renderer)
            {
                _image           = GetComponent <Image>();
                _text            = GetComponent <Text>();
                _tmp             = GetComponent <TMPro.TextMeshProUGUI>();
                _sprite_renderer = GetComponent <SpriteRenderer>();
                _renderer        = GetComponent <Renderer>();
            }

            Color value;

            if (_image)
            {
                value = _image.color;
            }
            else if (_text)
            {
                value = _text.color;
            }
            else if (_tmp)
            {
                value = _tmp.color;
            }
            else if (_sprite_renderer)
            {
                value = _sprite_renderer.color;
            }
            else if (_renderer)
            {
                value = _renderer.material.color;
            }
            else
            {
                enabled = false;
                return;
            }

            if (!_option.HasFlag(eColorConstraints.Ignore_R))
            {
                value.r = _from.r * (1.0f - v) + _to.r * v;
            }
            if (!_option.HasFlag(eColorConstraints.Ignore_G))
            {
                value.g = _from.g * (1.0f - v) + _to.g * v;
            }
            if (!_option.HasFlag(eColorConstraints.Ignore_B))
            {
                value.b = _from.b * (1.0f - v) + _to.b * v;
            }
            if (!_option.HasFlag(eColorConstraints.Ignore_A))
            {
                value.a = _from.a * (1.0f - v) + _to.a * v;
            }

            if (_image)
            {
                _image.color = value;
            }
            else if (_text)
            {
                _text.color = value;
            }
            else if (_tmp)
            {
                _tmp.color = value;
            }
            else if (_sprite_renderer)
            {
                _sprite_renderer.color = value;
            }
            else if (_renderer)
            {
                _renderer.material.color = value;
            }
        }
Example #17
0
 /// <summary>
 /// Set text style.
 /// </summary>
 /// <param name="text">Text component.</param>
 /// <param name="style">Font style.</param>
 protected static void SetTextStyle(TMPro.TextMeshProUGUI text, FontStyle style)
 {
     text.fontStyle = ConvertStyle(style);
 }
Example #18
0
        /**
            TextMesh Proのレイアウトを決定して返す
            レイアウト、改行などの必要に応じて文字列を分割する。
         */
        private IEnumerator<ChildPos> DoTextMeshProComponentLayout(TagTree textTree, TMPro.TextMeshProUGUI textComponent, string text, ViewCursor textViewCursor, Func<InsertType, TagTree, ViewCursor> insertion = null)
        {
            // Debug.Log("DoTextMeshProComponentLayout text:" + text.Length + " textViewCursor:" + textViewCursor);
            textComponent.text = text;

            // textComponentに対してwidthをセットする必要がある。
            textComponent.rectTransform.sizeDelta = new Vector2(textViewCursor.viewWidth, float.PositiveInfinity);

            // このメソッドは、コンポーネントがgoにアタッチされてcanvasに乗っている場合のみ動作する。
            var textInfos = textComponent.GetTextInfo(text);

            // 各行の要素とパラメータを取得する。
            var tmGeneratorLines = textInfos.lineInfo;
            var lineSpacing = textComponent.lineSpacing;
            var tmLineCount = textInfos.lineCount;


            var onLayoutPresetX = (float)textTree.keyValueStore[HTMLAttribute._ONLAYOUT_PRESET_X];
            // Debug.Log("text:" + text + " textViewCursor.viewWidth:" + textViewCursor.viewWidth);

            // 1行以上のラインが画面内にある。

            var isStartAtZeroOffset = onLayoutPresetX == 0 && textViewCursor.offsetX == 0;
            var isMultilined = 1 < tmLineCount;


            // このコンテナの1行目を別のコンテナの結果位置 = 行中から書いた結果、この1行の幅が画面幅を超えている場合、全体を次の行に送る。
            // あ、この判定では無理だな、、分割されたコンテナの可能性が出てくる? 整列を下からではなく上からやる必要がある。
            if (!isStartAtZeroOffset && textViewCursor.viewWidth < tmGeneratorLines[0].length)
            {
                // 行なかで、1行目のコンテンツがまるきり入らなかった。
                // よって、改行を行なって次の行からコンテンツを開始する。
                // textTree.keyValueStore[HTMLAttribute._ONLAYOUT_PRESET_X] = 0.0f;
                insertion(InsertType.RetryWithNextLine, null);

                // テキストとサイズを空に戻す
                textComponent.text = string.Empty;
                textComponent.rectTransform.sizeDelta = Vector2.zero;

                yield break;
            }

            // 複数行存在するんだけど、2行目のスタートが0文字目の場合、1行目に1文字も入っていない。
            if (isMultilined && tmGeneratorLines[1].firstCharacterIndex == 0)
            {
                // 行頭でこれが起きる場合、コンテンツ幅が圧倒的に不足していて、一文字も入らないということが起きている。
                // 1文字ずつ切り分けて表示する。
                if (isStartAtZeroOffset)
                {
                    // 最初の1文字目を強制的にセットする
                    var bodyContent = text.Substring(0, 1);

                    // 内容の反映
                    textTree.keyValueStore[HTMLAttribute._CONTENT] = bodyContent;

                    // 最終行
                    var lastLineContent = text.Substring(1);

                    // 最終行を分割して送り出す。追加されたコンテンツを改行後に処理する。
                    var nextLineContent = new InsertedTree(textTree, lastLineContent, textTree.tagValue);
                    insertion(InsertType.InsertContentToNextLine, nextLineContent);


                    var charHeight = (tmGeneratorLines[0].lineHeight + lineSpacing);

                    // テキストとサイズを空に戻す
                    textComponent.text = string.Empty;
                    textComponent.rectTransform.sizeDelta = Vector2.zero;


                    yield return textTree.SetPos(textViewCursor.offsetX, textViewCursor.offsetY, textViewCursor.viewWidth, charHeight);
                    yield break;
                }

                // 行中からのコンテンツ追加で、複数行があるので、コンテンツ全体を次の行で開始させる。
                insertion(InsertType.RetryWithNextLine, null);

                // テキストとサイズを空に戻す
                textComponent.text = string.Empty;
                textComponent.rectTransform.sizeDelta = Vector2.zero;

                yield break;
            }

            if (isStartAtZeroOffset)
            {
                if (isMultilined)
                {
                    // Debug.LogError("行頭での折り返しのある複数行 text:" + text + " textViewCursor.offsetX:" + textViewCursor.offsetX + " tmLineCount:" + tmLineCount);
                    /*
                        TMProのtextInfo上のレイアウト指示と、実際にレイアウトした時に自動的に分割されるワードに差がある。
                        abc が a\nbcになることもあれば、レイアウト時には分割されずabcで入ってしまうこともある。
                        これは予知できないので、textInfoでの分割を正にする方向で対処する。
                        具体的に言うと、文章に人力で\nを入れる。
                     */

                    var bodyContent = string.Empty;
                    var lastLineContent = string.Empty;

                    for (var i = 0; i < tmLineCount; i++)
                    {
                        var lineInfo = tmGeneratorLines[i];
                        var lineText = text.Substring(lineInfo.firstCharacterIndex, lineInfo.lastCharacterIndex - lineInfo.firstCharacterIndex + 1);
                        if (i == tmLineCount - 1)
                        {
                            lastLineContent = lineText;
                            continue;
                        }

                        bodyContent += lineText;
                    }


                    // 内容の反映
                    textTree.keyValueStore[HTMLAttribute._CONTENT] = bodyContent;

                    // 最終行を分割して送り出す。追加されたコンテンツを改行後に処理する。
                    var nextLineContent = new InsertedTree(textTree, lastLineContent, textTree.tagValue);
                    insertion(InsertType.InsertContentToNextLine, nextLineContent);


                    // 最終行以外はハコ型に収まった状態なので、ハコとして出力する。
                    // 最終一つ前までの高さを出して、このコンテンツの高さとして扱う。
                    var totalHeight = 0f;
                    for (var i = 0; i < tmLineCount - 1; i++)
                    {
                        var line = tmGeneratorLines[i];
                        totalHeight += (line.lineHeight + lineSpacing);
                    }

                    // テキストとサイズを空に戻す
                    textComponent.text = string.Empty;
                    textComponent.rectTransform.sizeDelta = Vector2.zero;

                    // このビューのポジションをセット
                    yield return textTree.SetPos(textViewCursor.offsetX, textViewCursor.offsetY, textViewCursor.viewWidth, totalHeight);
                }
                else
                {
                    // Debug.LogError("行頭の単一行 text:" + text);
                    var currentLineWidth = textComponent.preferredWidth;
                    var currentLineHeight = (tmGeneratorLines[0].lineHeight + lineSpacing);

                    // 最終行かどうかの判断はここではできないので、単一行の入力が終わったことを親コンテナへと通知する。
                    insertion(InsertType.TailInsertedToLine, textTree);
                    textTree.keyValueStore[HTMLAttribute._IS_SINGLE_LINE] = true;

                    var childPos = textTree.SetPos(textViewCursor.offsetX, textViewCursor.offsetY, currentLineWidth, currentLineHeight);

                    // テキストとサイズを空に戻す
                    textComponent.text = string.Empty;
                    textComponent.rectTransform.sizeDelta = Vector2.zero;

                    yield return childPos;
                }
            }
            else
            {
                if (isMultilined)
                {
                    // Debug.LogError("行中追加での折り返しのある複数行 text:" + text);
                    var currentLineHeight = (tmGeneratorLines[0].lineHeight + lineSpacing);

                    // 複数行が途中から出ている状態で、まず折り返しているところまでを分離して、後続の文章を新規にstringとしてinsertする。
                    var currentLineContent = text.Substring(0, tmGeneratorLines[1].firstCharacterIndex);
                    textTree.keyValueStore[HTMLAttribute._CONTENT] = currentLineContent;
                    textTree.keyValueStore[HTMLAttribute._IS_SINGLE_LINE] = true;

                    // get preferredWidht of text from trimmed line.
                    textComponent.text = currentLineContent;

                    var currentLineWidth = textComponent.preferredWidth;

                    var restContent = text.Substring(tmGeneratorLines[1].firstCharacterIndex);
                    var nextLineContent = new InsertedTree(textTree, restContent, textTree.tagValue);

                    // 次のコンテンツを新しい行から開始する。
                    insertion(InsertType.InsertContentToNextLine, nextLineContent);

                    // テキストとサイズを空に戻す
                    textComponent.text = string.Empty;
                    textComponent.rectTransform.sizeDelta = Vector2.zero;

                    yield return textTree.SetPos(textViewCursor.offsetX, textViewCursor.offsetY, currentLineWidth, currentLineHeight);
                }
                else
                {
                    // Debug.LogError("行中追加の単一行 text:" + text);
                    var width = textComponent.preferredWidth;
                    var height = (tmGeneratorLines[0].lineHeight + lineSpacing);

                    // Debug.LogError("行中の単一行 text:" + text + " textViewCursor:" + textViewCursor);
                    // 最終行かどうかの判断はここでできないので、単一行の入力が終わったことを親コンテナへと通知する。
                    insertion(InsertType.TailInsertedToLine, textTree);
                    textTree.keyValueStore[HTMLAttribute._IS_SINGLE_LINE] = true;

                    // テキストとサイズを空に戻す
                    textComponent.text = string.Empty;
                    textComponent.rectTransform.sizeDelta = Vector2.zero;

                    yield return textTree.SetPos(textViewCursor.offsetX, textViewCursor.offsetY, width, height);
                }
            }
        }
        /// <summary>
        /// Call this any time the title text has changed - this will make an attempt to update
        /// the contract window title.  We do this because otherwise the window will only ever read
        /// the title once.
        /// </summary>
        /// <param name="newTitle">New title to display</param>
        public void UpdateContractWindow(string newTitle)
        {
            // Get the cascading list for our contract
            if (text == null && ContractsApp.Instance != null)
            {
                UICascadingList.CascadingListItem list = TitleTrackerHelper.uiListMap.ContainsKey(parameter.Root.ContractGuid) ? TitleTrackerHelper.uiListMap[parameter.Root.ContractGuid] : null;

                if (list != null)
                {
                    foreach (KSP.UI.UIListItem item in list.items)
                    {
                        TMPro.TextMeshProUGUI textComponent = item.GetComponentsInChildren <TMPro.TextMeshProUGUI>(true).FirstOrDefault();
                        if (textComponent != null)
                        {
                            // Check for any string in titleTracker
                            foreach (string title in titles)
                            {
                                if (textComponent.text.EndsWith(">" + title + "</color>"))
                                {
                                    text          = textComponent;
                                    layoutElement = item.GetComponentsInChildren <LayoutElement>(true).FirstOrDefault();
                                    break;
                                }
                            }

                            if (text != null)
                            {
                                break;
                            }
                        }
                    }
                }
            }

            if (text)
            {
                // Clear the titleTracker, and replace the text
                if (!text.text.Contains(">" + newTitle + "<"))
                {
                    float preHeight = text.preferredHeight;

                    titles.Clear();
                    text.text = text.text.Substring(0, text.text.IndexOf(">") + 1) + newTitle + "</color>";
                    titles.Add(newTitle);

                    float postHeight = text.preferredHeight;

                    if (preHeight != postHeight)
                    {
                        text.rectTransform.sizeDelta  = new Vector2(text.rectTransform.sizeDelta.x, postHeight + 4f);
                        layoutElement.preferredHeight = postHeight + 6f;

                        // Force an update to the layout even when not active
                        if (!layoutElement.IsActive())
                        {
                            LayoutRebuilder.MarkLayoutForRebuild(layoutElement.transform as RectTransform);
                        }
                    }
                }
            }

            // Contracts Window + update
            ContractsWindow.SetParameterTitle(parameter, newTitle);
        }
Example #20
0
 private static void SetWeapon(TMPro.TextMeshProUGUI ui, Color color, string text, params object[] augs)
 {
     ui.text  = augs.Length <= 0 ? text : new Text(text, augs).ToString();
     ui.color = color;
     ui.transform.parent.gameObject.SetActive(true);
 }
Example #21
0
        public override void ShowGUI(Menu menu)
        {
            string apiPrefix = "(AC.PlayerMenus.GetElementWithName (\"" + menu.title + "\", \"" + title + "\") as AC.MenuJournal)";

            MenuSource source = menu.menuSource;

            EditorGUILayout.BeginVertical("Button");

            journalType = (JournalType)CustomGUILayout.EnumPopup("Journal type:", journalType, apiPrefix + ".journalType", "What type of journal this is");
            if (journalType == JournalType.DisplayExistingJournal || journalType == JournalType.DisplayActiveDocument)
            {
                if (journalType == JournalType.DisplayExistingJournal)
                {
                    EditorGUILayout.HelpBox("This Journal will share pages from another Journal element in the same Menu.", MessageType.Info);
                    otherJournalTitle = CustomGUILayout.TextField("Existing element name:", otherJournalTitle, apiPrefix + ".otherJournalTitle", "The name of the Journal element within the same Menu that is used as reference");
                    pageOffset        = CustomGUILayout.IntField("Page offset #:", pageOffset, apiPrefix + ".pageOffset", "The difference in page index between this and the reference Journal");
                }

                if (pages == null || pages.Count != 1)
                {
                    pages.Clear();
                    pages.Add(new JournalPage());
                }

                showPage = 1;

                if (source == MenuSource.AdventureCreator)
                {
                    EditorGUILayout.BeginHorizontal();
                    EditorGUILayout.LabelField("Placeholder text:", GUILayout.Width(146f));
                    pages[0].text = CustomGUILayout.TextArea(pages[0].text, GUILayout.MaxWidth(370f), apiPrefix + ".pages[0].text");
                    EditorGUILayout.EndHorizontal();
                }
            }
            else if (journalType == JournalType.NewJournal)
            {
                if (pages == null)
                {
                    pages = new List <JournalPage>();
                    pages.Clear();
                    pages.Add(new JournalPage());
                }
                numPages = pages.Count;

                for (int i = 0; i < pages.Count; i++)
                {
                    EditorGUILayout.BeginHorizontal();

                    if (pages[i].lineID >= 0)
                    {
                        CustomGUILayout.LabelField("Page #" + (i + 1).ToString() + ", Text ID #" + pages[i].lineID + ":", apiPrefix + ".pages[" + i.ToString() + "].text");
                    }
                    else
                    {
                        CustomGUILayout.LabelField("Page #" + (i + 1).ToString() + ":", apiPrefix + ".pages[" + i.ToString() + "].text");
                    }

                    if (GUILayout.Button("", CustomStyles.IconCog))
                    {
                        sideMenu = i;
                        SideMenu();
                    }
                    EditorGUILayout.EndHorizontal();

                    pages[i].text = CustomGUILayout.TextArea(pages[i].text, GUILayout.MaxWidth(370f), apiPrefix + ".pages[" + i.ToString() + "].text");
                    GUILayout.Box("", GUILayout.ExpandWidth(true), GUILayout.Height(1));
                }

                if (GUILayout.Button("Create new page", EditorStyles.miniButton))
                {
                    Undo.RecordObject(this, "Create journal page");
                    pages.Add(new JournalPage());
                }

                numPages = pages.Count;

                EditorGUILayout.EndVertical();
                EditorGUILayout.BeginVertical("Button");

                if (numPages > 1)
                {
                    showPage      = CustomGUILayout.IntSlider("Preview page #:", showPage, 1, numPages, apiPrefix + ".showPage", "The index number of the current page being shown ");
                    startFromPage = CustomGUILayout.Toggle("Start from this page?", startFromPage, apiPrefix + ".startFromPage", "If True, then the page index above will be the first open when the game begins");
                }
                else if (numPages == 1)
                {
                    showPage = 1;
                }
                else
                {
                    showPage = 0;
                }
            }

            if (source == MenuSource.AdventureCreator)
            {
                anchor      = (TextAnchor)CustomGUILayout.EnumPopup("Text alignment:", anchor, apiPrefix + ".anchor", "The text alignment");
                textEffects = (TextEffects)CustomGUILayout.EnumPopup("Text effect:", textEffects, apiPrefix + ".textEffects", "The special FX applied to the text");
                if (textEffects != TextEffects.None)
                {
                    outlineSize = CustomGUILayout.Slider("Effect size:", outlineSize, 1f, 5f, apiPrefix + ".outlineSize", "The outline thickness");
                }
            }
            else
            {
                EditorGUILayout.EndVertical();
                EditorGUILayout.BeginVertical("Button");

                                #if TextMeshProIsPresent
                uiText = LinkedUiGUI <TMPro.TextMeshProUGUI> (uiText, "Linked Text:", source);
                                #else
                uiText = LinkedUiGUI <Text> (uiText, "Linked Text:", source);
                                #endif
            }

            if (journalType == JournalType.NewJournal)
            {
                actionListOnAddPage = (ActionListAsset)CustomGUILayout.ObjectField <ActionListAsset> ("ActionList on add page:", actionListOnAddPage, false, apiPrefix + ".actionListOnAddPage", "An ActionList to run whenever a new page is added");
            }

            EditorGUILayout.EndVertical();

            base.ShowGUI(menu);
        }
Example #22
0
 private void Awake()
 {
     m_Text = GetComponent <TMPro.TextMeshProUGUI>();
 }
Example #23
0
 void Awake()
 {
     tmpro = GetComponent <TMPro.TextMeshProUGUI>();
     CustomLog.OnLogUpdate += LogUpdate;
 }
Example #24
0
 public static void MutliText(this TMPro.TextMeshProUGUI text, string key)
 {
     text.text = WordDic.Get(key);
 }
Example #25
0
 // Start is called before the first frame update
 void Start()
 {
     songList  = SongLibrary.GetSongList();
     songLabel = GetComponent <TMPro.TextMeshProUGUI>();
     UpdateSong();
 }
Example #26
0
 protected override void Awake()
 {
     base.Awake();
     _text = GetComponentInChildren <TMPro.TextMeshProUGUI>();
 }
 public void colorToPurple(TMPro.TextMeshProUGUI text)
 {
     text.color = new Color(201, 0, 255);
 }
Example #28
0
 public UITextField(TMPro.TextMeshProUGUI textMeshProUGUI)
 {
     this.uiText          = null;
     this.textMeshProUGUI = textMeshProUGUI;
 }
 internal TextualEffectInstance CreateTextualEffect(int color, string value, TMPro.TextMeshProUGUI textMesh)
 {
     return(new TextualEffectInstance(color, value, textMesh));
 }
 // Start is called before the first frame update
 override protected void Awake()
 {
     text = this.GetComponentInChildren <TMPro.TextMeshProUGUI>();
     base.Awake();
     father = this.GetComponentInParent <UIDropDown>();
 }
        public virtual void UpdateText()
        {
            if (!started)
            {
                return;
            }
            var textTable = this.textTable;
            var language  = UILocalizationManager.instance.currentLanguage;

            // Skip if no text table or language set:
            if (textTable == null)
            {
                Debug.LogWarning("No localized text table is assigned to " + name + " or a UI Localized Manager component.", this);
                return;
            }

            if (!textTable.HasLanguage(language))
            {
                Debug.LogWarning("Text table " + textTable.name + " does not have a language '" + language + "'.", textTable);
                return;
            }

            // Make sure we have localizable UI components:
            if (text == null && dropdown == null)
            {
                text     = GetComponent <UnityEngine.UI.Text>();
                dropdown = GetComponent <UnityEngine.UI.Dropdown>();
            }
            var hasLocalizableComponent = text != null || dropdown != null;

#if TMP_PRESENT
            if (!m_lookedForTMP)
            {
                m_lookedForTMP  = true;
                textMeshProUGUI = GetComponent <TMPro.TextMeshProUGUI>();
            }
            hasLocalizableComponent = hasLocalizableComponent || textMeshProUGUI != null;
#endif
            if (!hasLocalizableComponent)
            {
                Debug.LogWarning("Localize UI didn't find a localizable UI component on " + name + ".", this);
                return;
            }

            // Get the original values to use as field lookups:
            if (string.IsNullOrEmpty(fieldName))
            {
                fieldName = (text != null) ? text.text : string.Empty;
            }
            if ((fieldNames.Count == 0) && (dropdown != null))
            {
                dropdown.options.ForEach(opt => fieldNames.Add(opt.text));
            }

            // Localize Text:
            if (text != null)
            {
                if (!textTable.HasField(fieldName))
                {
                    Debug.LogWarning("Text table " + textTable.name + " does not have a field '" + fieldName + "'.", textTable);
                }
                else
                {
                    text.text = GetLocalizedText(fieldName);
                }
            }

            // Localize Dropdown:
            if (dropdown != null)
            {
                for (int i = 0; i < dropdown.options.Count; i++)
                {
                    if (i < fieldNames.Count)
                    {
                        dropdown.options[i].text = GetLocalizedText(fieldNames[i]);
                    }
                }
                dropdown.captionText.text = GetLocalizedText(fieldNames[dropdown.value]);
            }

#if TMP_PRESENT
            if (!m_lookedForTMP)
            {
                m_lookedForTMP  = true;
                textMeshProUGUI = GetComponent <TMPro.TextMeshProUGUI>();
            }
            if (textMeshProUGUI != null)
            {
                if (string.IsNullOrEmpty(fieldName))
                {
                    fieldName = (textMeshProUGUI != null) ? textMeshProUGUI.text : string.Empty;
                }
                if (!textTable.HasField(fieldName))
                {
                    Debug.LogWarning("Text table " + textTable.name + " does not have a field '" + fieldName + "'.", textTable);
                }
                else
                {
                    textMeshProUGUI.text = GetLocalizedText(fieldName);
                }
            }
#endif
        }
 private void OnParameterChange(Contract c, ContractParameter p)
 {
     if (c == parameter.Root)
     {
         text = null;
     }
 }