コード例 #1
0
        override protected void DrawInspectorGUI()
        {
            UIInputField tTarget = target as UIInputField;

            EditorGUILayout.Separator();                // 少し区切りスペース

            //-------------------------------------------------------------------

            FontFilter tFontFilter = EditorGUILayout.ObjectField("Font Filter", tTarget.fontFilter, typeof(FontFilter), false) as FontFilter;

            if (tFontFilter != tTarget.fontFilter)
            {
                Undo.RecordObject(tTarget, "UIInputField : Font Filter Change ");                       // アンドウバッファに登録
                tTarget.fontFilter = tFontFilter;
                EditorUtility.SetDirty(tTarget);
            }

            string tFontAlternateCodeOld = "" + tTarget.fontAlternateCode;
            string tFontAlternateCodeNew = EditorGUILayout.TextField("Font Alternate Code", tFontAlternateCodeOld);

            if (string.IsNullOrEmpty(tFontAlternateCodeNew) == false && (tFontAlternateCodeNew[0] != tFontAlternateCodeOld[0]))
            {
                Undo.RecordObject(tTarget, "UIInputField : Font Alternate Code Change ");                       // アンドウバッファに登録
                tTarget.fontAlternateCode = tFontAlternateCodeNew[0];
                EditorUtility.SetDirty(tTarget);
            }
        }
コード例 #2
0
        //-------------------------------------------------------------------------------------------

        // 各派生クラスでの初期化処理を行う(メニューまたは AddView から生成される場合のみ実行れる)
        override protected void OnBuild(string tOption = "")
        {
            InputFieldPlus tInputField = _inputField;

            if (tInputField == null)
            {
                tInputField = gameObject.AddComponent <InputFieldPlus>();
            }
            if (tInputField == null)
            {
                // 異常
                return;
            }

            Image tImage = _image;

            if (tImage != null)
            {
                tInputField.targetGraphic = tImage;
            }

            //-------------------------------

            bool tIsMultiLine = false;

            if (string.IsNullOrEmpty(tOption) == false && tOption.ToLower() == "multiline")
            {
                // マルチ
                tIsMultiLine = true;
            }


            Vector2 tSize = GetCanvasSize();

            int tFontSize = 16;

            if (tSize.x > 0 && tSize.y > 0)
            {
                if (tIsMultiLine == false)
                {
                    // シングル
                    SetSize(tSize.y * 0.5f, tSize.y * 0.1f);
                }
                else
                {
                    // マルチ
                    SetSize(tSize.y * 0.5f, tSize.y * 0.5f);
                }

                tFontSize = ( int )(tSize.y * 0.1f * 0.6f);
            }

            // Image
            tImage.sprite = Resources.Load <Sprite>("uGUIHelper/Textures/UIDefaultFrame");
            tImage.type   = Image.Type.Sliced;

            if (isCanvasOverlay == true)
            {
                tImage.material = Resources.Load <Material>("uGUIHelper/Shaders/UI-Overlay-Default");
            }

            ResetRectTransform();

            // Text
            UIText tTextComponent = AddView <UIText>("Text", "SIMPLE");

            tTextComponent.isContentSizeFitter = false;
            tTextComponent.fontSize            = tFontSize;
            tTextComponent.supportRichText     = false;
            tTextComponent.color = new Color32(50, 50, 50, 255);
            tTextComponent.SetAnchorToStretch();
            tTextComponent.SetMargin(12, 12, 12, 12);
//			tText.position = new Vector2( 0, -2 ) ;
//			tText.SetSize( -24, -28 ) ;
//			tText.resizeTextForBestFit = true ;
            tInputField.textComponent = tTextComponent._text;
            if (tIsMultiLine == false)
            {
                tTextComponent.alignment = TextAnchor.MiddleLeft;
            }
            else
            {
                tTextComponent.alignment = TextAnchor.UpperLeft;
            }

            if (isCanvasOverlay == true)
            {
                tTextComponent.material = Resources.Load <Material>("uGUIHelper/Shaders/UI-Overlay-Default");
            }

            // TextColorModifier
            tTextComponent.AddComponent <TextColorModifier>();

            // Placeholder
            UIText tPlaceholder = AddView <UIText>("Placeholder", "SIMPLE");

            tPlaceholder.fontSize  = tFontSize;
            tPlaceholder.fontStyle = FontStyle.Italic;
            tPlaceholder.text      = "Enter text...";
            tPlaceholder.color     = new Color32(50, 50, 50, 128);
            tPlaceholder.SetAnchorToStretch();
            tPlaceholder.SetMargin(12, 12, 12, 12);
//			tPlaceholder.position = new Vector2( 0, -2 ) ;
//			tPlaceholder.SetSize( -24, -28 ) ;
//			tPlaceholder.resizeTextForBestFit = true ;
            tInputField.placeholder = tPlaceholder._text;
            if (tIsMultiLine == false)
            {
                tPlaceholder.alignment = TextAnchor.MiddleLeft;
            }
            else
            {
                tPlaceholder.alignment = TextAnchor.UpperLeft;
            }

            if (isCanvasOverlay == true)
            {
                tPlaceholder.material = Resources.Load <Material>("uGUIHelper/Shaders/UI-Overlay-Default");
            }


            if (tIsMultiLine == true)
            {
                // マルチラインで生成する
                tInputField.lineType = InputFieldPlus.LineType.MultiLineNewline;
                tInputField.textComponent.horizontalOverflow = HorizontalWrapMode.Wrap;
            }

            tInputField.caretWidth       = 4;
            tInputField.customCaretColor = true;
            tInputField.caretColor       = Color.blue;

            //----------------------------------------------------------

            FontFilter tFontFilter        = null;
            char       tFontAlternateCode = '?';

#if UNITY_EDITOR
            if (Application.isPlaying == false)
            {
                // メニューから操作した場合のみ自動設定を行う
                DefaultSettings tDS = Resources.Load <DefaultSettings>("uGUIHelper/DefaultSettings");
                if (tDS != null)
                {
                    tFontFilter        = tDS.fontFilter;
                    tFontAlternateCode = tDS.fontAlternateCode;
                }
            }
#endif
            if (tFontFilter == null)
            {
            }
            else
            {
                fontFilter = tFontFilter;
            }

            if (tFontAlternateCode == 0)
            {
                fontAlternateCode = '?';
            }
            else
            {
                fontAlternateCode = tFontAlternateCode;
            }
        }
コード例 #3
0
        // レイアウトを描画する
        private void OnGUI()
        {
            string tPath = null;

            string[] tId = AssetDatabase.FindAssets("FontFilter");
            if (tId != null)
            {
                int i, l = tId.Length;
                for (i = 0; i < l; i++)
                {
                    tPath = AssetDatabase.GUIDToAssetPath(tId[i]);

                    if (Directory.Exists(tPath) == true)
                    {
                        break;
                    }
                }

                if (i >= l)
                {
                    tPath = null;
                }
            }

            if (string.IsNullOrEmpty(tPath) == true)
            {
                EditorGUILayout.HelpBox("状態が異常です", MessageType.Warning);
                return;
            }

            tPath = tPath + "/Resources/uGUIHelper";
            if (Directory.Exists(tPath) == false)
            {
                EditorGUILayout.HelpBox("保存フォルダが存在しません", MessageType.Warning);
                return;
            }

            FontFilter tFF = null;

            tPath = tPath + "/FontFilter.asset";
            if (File.Exists(tPath) == false)
            {
                // ファイルが存在しない
                tFF      = ScriptableObject.CreateInstance <FontFilter>();
                tFF.name = "FontFilter";

                AssetDatabase.CreateAsset(tFF, tPath);
                AssetDatabase.Refresh();
            }
            else
            {
                // ファイルが存在する
                tFF = AssetDatabase.LoadAssetAtPath <FontFilter>(tPath);
            }

            Selection.activeObject = tFF;

            //----------------------------------------------------------

            bool tDirty = false;


            // フォント
            Font tFont = EditorGUILayout.ObjectField("Font", m_Font, typeof(Font), false) as Font;

            if (tFont != m_Font)
            {
                m_Font = tFont;
            }

            if (m_Font != null)
            {
                if (GUILayout.Button("Create Or Update") == true)
                {
                    tPath = AssetDatabase.GetAssetPath(m_Font.GetInstanceID());

                    TrueTypeFontImporter tFontData = ( TrueTypeFontImporter )AssetImporter.GetAtPath(tPath);

                    FontTextureCase tOldFontTextureCase = tFontData.fontTextureCase;

                    if (tFontData.fontTextureCase != FontTextureCase.Unicode)
                    {
                        tFontData.fontTextureCase = FontTextureCase.Unicode;
                        tFontData.SaveAndReimport();
                    }

                    //--------------------------------------------------------------------

                    if (tFF.flag == null || tFF.flag.Length < 8192)
                    {
                        tFF.flag = new byte[8192];
                    }

                    int           v = 0;
                    byte          f;
                    CharacterInfo tCI;
                    bool          e;
                    char          c;
                    int           i, j, l = 65536;
                    for (i = 0; i < l; i = i + 8)
                    {
                        f = 0;
                        for (j = 0; j < 8; j++)
                        {
                            c = ( char )(i + j);

                            e = true;
                            if (c != ' ' && c != ' ')
                            {
                                if (m_Font.HasCharacter(c) == true)
                                {
                                    if (m_Font.GetCharacterInfo(c, out tCI, 16) == true)
                                    {
                                        if (tCI.advance <= 0)
                                        {
                                            e = false;
                                        }
                                    }
                                    else
                                    {
                                        e = false;
                                    }
                                }
                                else
                                {
                                    e = false;
                                }
                            }

                            if (e == true)
                            {
                                f = ( byte )(f | (1 << j));
                                v++;
                            }
                        }

                        tFF.flag[i >> 3] = f;
                    }

                    //--------------------------------------------------------------------

                    if (tOldFontTextureCase != FontTextureCase.Unicode)
                    {
                        tFontData.fontTextureCase = tOldFontTextureCase;
                        tFontData.SaveAndReimport();
                    }

                    //--------------------------------------------------------------------

                    tDirty = true;

                    EditorUtility.DisplayDialog("Font Filter", "Completed !! -> " + v, "OK");
                }
            }

            //----------------------------------

            // 更新判定
            if (tDirty == true)
            {
                EditorUtility.SetDirty(tFF);                    // 更新実行
//				AssetDatabase.Refresh() ;
            }
        }
コード例 #4
0
        // レイアウトを描画する
        private void OnGUI()
        {
            string tPath = null;

            string[] tId = AssetDatabase.FindAssets("DefaultSettings");
            if (tId != null)
            {
                int i, l = tId.Length;
                for (i = 0; i < l; i++)
                {
                    tPath = AssetDatabase.GUIDToAssetPath(tId[i]);

                    if (Directory.Exists(tPath) == true)
                    {
                        break;
                    }
                }

                if (i >= l)
                {
                    tPath = null;
                }
            }

            if (string.IsNullOrEmpty(tPath) == true)
            {
                EditorGUILayout.HelpBox("状態が異常です", MessageType.Warning);
                return;
            }

            tPath = tPath + "/Resources/uGUIHelper";
            if (Directory.Exists(tPath) == false)
            {
                EditorGUILayout.HelpBox("保存フォルダが存在しません", MessageType.Warning);
                return;
            }

            DefaultSettings tDS = null;

            tPath = tPath + "/DefaultSettings.asset";
            if (File.Exists(tPath) == false)
            {
                // ファイルが存在しない
                tDS      = ScriptableObject.CreateInstance <DefaultSettings>();
                tDS.name = "DefaultSettings";

                AssetDatabase.CreateAsset(tDS, tPath);
                AssetDatabase.Refresh();
            }
            else
            {
                // ファイルが存在する
                tDS = AssetDatabase.LoadAssetAtPath <DefaultSettings>(tPath);
            }

            Selection.activeObject = tDS;

            //----------------------------------------------------------

            bool tDirty = false;

            // ボタンの下地
            Sprite tButtonFrame = EditorGUILayout.ObjectField("Button", tDS.buttonFrame, typeof(Sprite), false) as Sprite;

            if (tButtonFrame != tDS.buttonFrame)
            {
                tDS.buttonFrame = tButtonFrame;
                tDirty          = true;
            }

            // ボタン無効化時の色
            Color c;

            c.r = tDS.buttonDisabledColor.r;
            c.g = tDS.buttonDisabledColor.g;
            c.b = tDS.buttonDisabledColor.b;
            c.a = tDS.buttonDisabledColor.a;
            tDS.buttonDisabledColor = EditorGUILayout.ColorField("Button Disabled Color", tDS.buttonDisabledColor);
            if (tDS.buttonDisabledColor.Equals(c) == false)
            {
                tDirty = true;
            }

            // ボタンラベルのフォントサイズ
            int tButtonLabelFontSize = EditorGUILayout.IntField("Button Label Font Size", tDS.buttonLabelFontSize);

            if (tButtonLabelFontSize != tDS.buttonLabelFontSize)
            {
                tDS.buttonLabelFontSize = tButtonLabelFontSize;
                tDirty = true;
            }

            // ボタンラベルの色
            c.r = tDS.buttonLabelColor.r;
            c.g = tDS.buttonLabelColor.g;
            c.b = tDS.buttonLabelColor.b;
            c.a = tDS.buttonLabelColor.a;
            tDS.buttonLabelColor = EditorGUILayout.ColorField("Button Label Color", tDS.buttonLabelColor);
            if (tDS.buttonLabelColor.Equals(c) == false)
            {
                tDirty = true;
            }

            bool tButtonLabelShadow = EditorGUILayout.Toggle("Button Label Shadow", tDS.buttonLabelShadow);

            if (tButtonLabelShadow != tDS.buttonLabelShadow)
            {
                tDS.buttonLabelShadow = tButtonLabelShadow;
                tDirty = true;
            }

            bool tButtonLabelOutline = EditorGUILayout.Toggle("Button Label Outline", tDS.buttonLabelOutline);

            if (tButtonLabelOutline != tDS.buttonLabelOutline)
            {
                tDS.buttonLabelOutline = tButtonLabelOutline;
                tDirty = true;
            }

            //----------------------------------

            // プログレスバーの下地
            Sprite tProgressbarFrame = EditorGUILayout.ObjectField("ProgressbarFrame", tDS.progressbarFrame, typeof(Sprite), false) as Sprite;

            if (tProgressbarFrame != tDS.progressbarFrame)
            {
                tDS.progressbarFrame = tProgressbarFrame;
                tDirty = true;
            }

            // プログレスバーの前景
            Sprite tProgressbarThumb = EditorGUILayout.ObjectField("ProgressbarThumb", tDS.progressbarThumb, typeof(Sprite), false) as Sprite;

            if (tProgressbarThumb != tDS.progressbarThumb)
            {
                tDS.progressbarThumb = tProgressbarThumb;
                tDirty = true;
            }

            //----------------------------------

            // テキストの色
            c.r           = tDS.textColor.r;
            c.g           = tDS.textColor.g;
            c.b           = tDS.textColor.b;
            c.a           = tDS.textColor.a;
            tDS.textColor = EditorGUILayout.ColorField("Text Color", tDS.textColor);
            if (tDS.textColor.Equals(c) == false)
            {
                tDirty = true;
            }

            // フォント
            Font tFont = EditorGUILayout.ObjectField("Font", tDS.font, typeof(Font), false) as Font;

            if (tFont != tDS.font)
            {
                tDS.font = tFont;
                tDirty   = true;
            }

            // フォントサイズ
            int tFontSize = EditorGUILayout.IntField("Font Size", tDS.fontSize);

            if (tFontSize != tDS.fontSize)
            {
                tDS.fontSize = tFontSize;
                tDirty       = true;
            }

            //----------------------------------

            // インプットフィールド関係
            FontFilter tFontFilter = EditorGUILayout.ObjectField("Font Filter", tDS.fontFilter, typeof(FontFilter), false) as FontFilter;

            if (tFontFilter != tDS.fontFilter)
            {
                tDS.fontFilter = tFontFilter;
                tDirty         = true;
            }

            string tFontAlternateCodeOld = "" + tDS.fontAlternateCode;
            string tFontAlternateCodeNew = EditorGUILayout.TextField("Font Alternate Code", tFontAlternateCodeOld);

            if (string.IsNullOrEmpty(tFontAlternateCodeNew) == false && (tFontAlternateCodeNew[0] != tFontAlternateCodeOld[0]))
            {
                tDS.fontAlternateCode = tFontAlternateCodeNew[0];
                tDirty = true;
            }

            //----------------------------------

            // 更新判定
            if (tDirty == true)
            {
                EditorUtility.SetDirty(tDS);                    // 更新実行
//				AssetDatabase.Refresh() ;
            }
        }