Exemple #1
0
        /// <summary>
        /// OnInspectorGUI.
        /// </summary>
        public override void OnInspectorGUI()
        {
            EditorGUILayout.ObjectField("Script", MonoScript.FromMonoBehaviour(mScript), typeof(MyImageStyle), false);

            serializedObject.Update();

            EditorGUI.BeginChangeCheck();

            mStyle.enumValueIndex = (int)(MyImageStyleManager.EStyle)EditorGUILayout.EnumPopup("Style", (MyImageStyleManager.EStyle)mStyle.enumValueIndex);

            if (EditorGUI.EndChangeCheck())
            {
                serializedObject.ApplyModifiedProperties();
                mScript.Refresh();
            }

            MyImageStyleManager.MyImageStyleInfo info = MyImageStyleManager.Instance.GetInfo((MyImageStyleManager.EStyle)mStyle.enumValueIndex);
            EditorGUILayout.LabelField("Your Note", info != null ? info.Note : string.Empty);
        }
Exemple #2
0
        /// <summary>
        /// Refresh.
        /// </summary>
        public void Refresh()
        {
            MyImageStyleManager.MyImageStyleInfo info = MyImageStyleManager.Instance.GetInfo(mStyle);
            if (info == null)
            {
                return;
            }

            if (mImage == null)
            {
                mImage = gameObject.GetComponent <Image>();
            }

            if (info.Image != null)
            {
                mImage.sprite = info.Image;
            }

            if (info.Material != null)
            {
                mImage.material = info.Material;
            }

            mImage.color = info.Color;

            if (info.Size.x > 0 && info.Size.y > 0)
            {
                if (mRectTransform == null)
                {
                    mRectTransform = gameObject.GetComponent <RectTransform>();
                }
                if (mRectTransform != null)
                {
                    mRectTransform.sizeDelta = info.Size;
                }
            }

            switch (info.Type)
            {
            case MyImageStyleManager.EImageType.SIMPLE:
            {
                mImage.type           = Image.Type.Simple;
                mImage.preserveAspect = false;
            }
            break;

            case MyImageStyleManager.EImageType.SIMPLE_PRESERVE_ASPECT:
            {
                mImage.type           = Image.Type.Simple;
                mImage.preserveAspect = true;
            }
            break;

            case MyImageStyleManager.EImageType.SLICED:
            {
                mImage.type       = Image.Type.Sliced;
                mImage.fillCenter = false;
            }
            break;

            case MyImageStyleManager.EImageType.SLICED_FILL_CENTER:
            {
                mImage.type       = Image.Type.Sliced;
                mImage.fillCenter = true;
            }
            break;
            }
        }