コード例 #1
0
        public static string WriteHeader(string name, ColorMode mode, int W, int H)
        {
            string result = "";

            result += $"#ifndef _bitmap_{name}_h_\n";
            result += $"#define _bitmap_{name}_h_\n\n";
            result += "#include \"../bitmapinfo.h\"\n\n";
            result += $"const PROGMEM uint8_t bitmap_{name}_data[] = \n{{\n";
            result += $"    //Color model: {mode.ToString()}";
            if (mode == ColorMode.Default)
            {
                result += $" ({ColorMode.Color_565})";
            }
            result += $"\n    //Bitmap size {W} x {H}\n";
            result += $"    {"0x" + ((byte)mode).ToString("x").ToUpper()}, ";

            var bytes = BitConverter.GetBytes((short)W);

            result += $"{"0x" + (bytes[0]).ToString("x").ToUpper()}, ";
            result += $"{"0x" + (bytes[1]).ToString("x").ToUpper()}, ";

            bytes   = BitConverter.GetBytes((short)H);
            result += $"{"0x" + (bytes[0]).ToString("x").ToUpper()}, ";
            result += $"{"0x" + (bytes[1]).ToString("x").ToUpper()},\n\n";

            return(result);
        }
コード例 #2
0
    public void ChangeToColorMode(ColorMode mode)
    {
        currentMode = mode;
        PlayerPrefs.SetString(COLOR_MODE, currentMode.ToString());

        UpdateSignResourceStrgColors();         // First update colors because some delegate listeners use it for simplicity
        ColorChangeEvent(mode, changeDuration); // Call delaegateategateggatagegatge
    }
コード例 #3
0
 public static Format ConvertToFormat(ColorMode mode)
 {
     switch (mode)
     {
         case ColorMode.Bit16:
             return Format.A4R4G4B4;
         case ColorMode.Bit32:
             return Format.A8R8G8B8;
         default:
             throw new NotImplementedException(mode.ToString());
     }
 }
コード例 #4
0
 public static Format ConvertToFormat(ColorMode mode)
 {
     switch (mode)
     {
         case ColorMode.Bit16:
             throw new NotSupportedException();
         case ColorMode.Bit32:
             return Format.R8G8B8A8_UNorm;
         default:
             throw new NotImplementedException(mode.ToString());
     }
 }
コード例 #5
0
        public static Material GetOrGenerateMaterialVariant(Shader shader, ToneMode tone, ColorMode color, BlurMode blur)
        {
            if (!shader)
            {
                return(null);
            }

            Material mat = GetMaterial(shader, tone, color, blur);

            if (!mat)
            {
                Debug.Log("Generate material : " + GetVariantName(shader, tone, color, blur));
                mat = new Material(shader);

                if (0 < tone)
                {
                    mat.EnableKeyword("UI_TONE_" + tone.ToString().ToUpper());
                }
                if (0 < color)
                {
                    mat.EnableKeyword("UI_COLOR_" + color.ToString().ToUpper());
                }
                if (0 < blur)
                {
                    mat.EnableKeyword("UI_BLUR_" + blur.ToString().ToUpper());
                }

                mat.name       = GetVariantName(shader, tone, color, blur);
                mat.hideFlags |= HideFlags.NotEditable;

#if UIEFFECT_SEPARATE
                bool   isMainAsset  = true;
                string dir          = Path.GetDirectoryName(GetDefaultMaterialPath(shader));
                string materialPath = Path.Combine(Path.Combine(dir, "Separated"), mat.name + ".mat");
#else
                bool   isMainAsset  = (0 == tone) && (0 == color) && (0 == blur);
                string materialPath = GetDefaultMaterialPath(shader);
#endif
                if (isMainAsset)
                {
                    Directory.CreateDirectory(Path.GetDirectoryName(materialPath));
                    AssetDatabase.CreateAsset(mat, materialPath);
                    AssetDatabase.SaveAssets();
                }
                else
                {
                    mat.hideFlags |= HideFlags.HideInHierarchy;
                    AssetDatabase.AddObjectToAsset(mat, materialPath);
                }
            }
            return(mat);
        }
コード例 #6
0
        public static Format ConvertToFormat(ColorMode mode)
        {
            switch (mode)
            {
            case ColorMode.Bit16:
                return(Format.A4R4G4B4);

            case ColorMode.Bit32:
                return(Format.A8R8G8B8);

            default:
                throw new NotImplementedException(mode.ToString());
            }
        }
コード例 #7
0
        public static Format ConvertToFormat(ColorMode mode)
        {
            switch (mode)
            {
            case ColorMode.Bit16:
                throw new NotSupportedException();

            case ColorMode.Bit32:
                return(Format.R8G8B8A8_UNorm);

            default:
                throw new NotImplementedException(mode.ToString());
            }
        }
コード例 #8
0
        public static string WriteFooter(string name, int W, int H, ColorMode mode)
        {
            string result = "";

            result += "};\n\n";
            result += $"BMP_IFNO bitmap_{name}(void)\n";
            result += "{\n";
            result += "     BMP_IFNO bmp;";
            result += $"    width = {W};";
            result += $"    height = {H};";
            result += $"    colorMode = {mode.ToString()};";
            result += "     return bmp;";
            result += "}\n\n";
            result += "#endif\n";
            return(result);
        }
コード例 #9
0
    protected override void DoGUI()
    {
        if (currentMaterial.HasProperty("_FaceColor"))
        {
            base.DoGUI();
        }
        else
        {
            if (BeginCommonPanel("Sprite", true))
            {
                EditorGUI.indentLevel++;
                DoTexture2D("_MainTex", "Texture");
                DoColor("_Color", "Color");
                EditorGUI.indentLevel--;
            }
            EndCommonPanel();
        }

        if (BeginCommonPanel("Dissolve", true))
        {
            EditorGUI.indentLevel++;
            DoTexture2D("_NoiseTex", "Texture");

            ColorMode color =
                currentMaterial.IsKeywordEnabled("ADD") ? ColorMode.Add
                                                : currentMaterial.IsKeywordEnabled("SUBTRACT") ? ColorMode.Subtract
                                                : currentMaterial.IsKeywordEnabled("FILL") ? ColorMode.Fill
                                                : ColorMode.Multiply;

            var newColor = (ColorMode)EditorGUILayout.EnumPopup("Color Mode", color);
            if (color != newColor)
            {
                currentMaterial.DisableKeyword(color.ToString().ToUpper());
                if (newColor != ColorMode.Multiply)
                {
                    currentMaterial.EnableKeyword(newColor.ToString().ToUpper());
                }
            }
            EditorGUI.indentLevel--;
        }
        EndCommonPanel();
    }
コード例 #10
0
    protected override void DoGUI()
    {
        if (material.HasProperty("_FaceColor"))
        {
            base.DoGUI();
        }
        else if (DoPanelHeader(spritePanel))
        {
            EditorGUI.indentLevel += 1;
            DoTexture2D("_MainTex", "Texture");
            DoColor("_Color", "Color");
            EditorGUI.indentLevel -= 1;
        }

        if (DoPanelHeader(dissolvePanel))
        {
            EditorGUI.indentLevel += 1;
            DoTexture2D("_NoiseTex", "Texture");

            ColorMode color =
                material.IsKeywordEnabled("ADD") ? ColorMode.Add
                                                : material.IsKeywordEnabled("SUBTRACT") ? ColorMode.Subtract
                                                : material.IsKeywordEnabled("FILL") ? ColorMode.Fill
                                                : ColorMode.Multiply;

            var newColor = (ColorMode)EditorGUILayout.EnumPopup("Color Mode", color);
            if (color != newColor)
            {
                material.DisableKeyword(color.ToString().ToUpper());
                if (newColor != ColorMode.Multiply)
                {
                    material.EnableKeyword(newColor.ToString().ToUpper());
                }
            }
            EditorGUI.indentLevel -= 1;
        }
    }
コード例 #11
0
        protected void DrawPreview()
        {
            GUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();
            Rect rect = GUILayoutUtility.GetRect(_previewWidth, _previewHeight, GUI.skin.box);

            if (_previewTexture != null)
            {
                //RTEditorGUI.DrawTexture(_previewTexture, _previewWidth, GUI.skin.box);
                //GUI.BeginGroup(rect);
                GUI.color = _textureSequenceId == _nextSequenceId ? Color.white : new Color(1.0f, 1.0f, 1.0f, 0.25f);
                GUI.DrawTexture(rect, _previewTexture, ScaleMode.ScaleToFit, true);
                GUI.color = Color.white;
                //GUI.EndGroup();
            }

            GUILayout.FlexibleSpace();
            GUILayout.EndHorizontal();

            using (var horizontalScope = new GUILayout.HorizontalScope("box"))
            {
                GUILayout.FlexibleSpace();
                const float sz = 70.0f;
                PreviewLeft   = RTEditorGUI.FloatField("Left", PreviewLeft, GUILayout.Width(sz));
                PreviewRight  = RTEditorGUI.FloatField("Right", PreviewRight, GUILayout.Width(sz));
                PreviewTop    = RTEditorGUI.FloatField("Top", PreviewTop, GUILayout.Width(sz));
                PreviewBottom = RTEditorGUI.FloatField("Bottom", PreviewBottom, GUILayout.Width(sz));
                GUILayout.FlexibleSpace();
            }
            PreviewSeamless = RTEditorGUI.Toggle(PreviewSeamless, "Seamless");

#if UNITY_EDITOR
            Colorization = (ColorMode)UnityEditor.EditorGUILayout.EnumPopup(new GUIContent("ColorMode", "Colorization method for preview"), Colorization);
#else
            GUILayout.Label(new GUIContent("Colorization: " + Colorization.ToString(), "Quality Mode for noise"));
#endif
        }
コード例 #12
0
ファイル: EV3ColorSensor.cs プロジェクト: gitter-badger/iot-1
 /// <summary>
 /// Selected mode
 /// </summary>
 /// <returns>String representing selected mode</returns>
 public string SelectedMode()
 {
     return(ColorMode.ToString());
 }
コード例 #13
0
        private void UpdateShaderInternal()
        {
            foreach (var localRenderer in gameObject.GetComponentsInChildren <Renderer>())
            {
                localRenderer.enabled = Enabled;
                if (!Enabled)
                {
                    continue;
                }

                var transparent = Visibility.ToString("f");
                var colorBy     = _colorBy.ToString("f");
                var lit         = _lit.ToString("f");
                var side        = _side.ToString("f");

                var materials = localRenderer.sharedMaterials;

                if (Visibility == VisibilityMode.Disabled)
                {
                    localRenderer.enabled = false;
                }
                else
                {
                    // Object switches have precedence in enabling / disabling the renderer
                    var switchBase = GetComponentInParent <ObjectSwitchBase>();
                    if (switchBase)
                    {
                        switchBase.SetActiveChild(switchBase.ActiveChild);
                    }
                    else
                    {
                        localRenderer.enabled = true;
                    }

                    if (materials.Length == 0)
                    {
                        materials = new Material[1];
                    }
                    if (materials.Length != 2 && _side == SideMode.TwoSided)
                    {
                        materials = new Material[2];
                    }

                    switch (materials.Length)
                    {
                    case 1:
                        var matName = transparent + colorBy + lit + side;
                        var mat     = Resources.Load("Materials/" + matName, typeof(Material)) as Material;
                        if (mat == null)
                        {
                            Debug.LogWarning(gameObject.name + ": Material " + matName + " not found.");
                        }
                        materials[0] = mat;
                        break;

                    case 2:
                        var matNameFront = transparent + colorBy + lit + SideMode.Front.ToString("f");
                        var matNameBack  = transparent + colorBy + lit + SideMode.Back.ToString("f");
                        var matFront     = Resources.Load("Materials/" + matNameFront, typeof(Material)) as Material;
                        var matBack      = Resources.Load("Materials/" + matNameBack, typeof(Material)) as Material;
                        materials[0] = matFront;
                        materials[1] = matBack;
                        if (Side != SideMode.TwoSided)
                        {
                            var newMaterials = new Material[1];
                            if (Side == SideMode.Front)
                            {
                                newMaterials[0] = materials[0];
                            }
                            else
                            {
                                newMaterials[0] = materials[1];
                            }

                            materials = newMaterials;
                        }
                        break;
                    }
                }
                if (Application.isPlaying)
                {
                    localRenderer.materials = materials;
                }
                else
                {
                    localRenderer.sharedMaterials = materials;
                }
                _materials = materials;
            }
        }
コード例 #14
0
    public static Material MakeCustomMaterial(ColorMode colorMode, bool transparent = false)
    {
        Material material = null;

        switch (colorMode)
        {
        case ColorMode.MATTE:
            material = new Material(Shader.Find("Standard"));
            material.SetFloat("_Glossiness", 0.0f);
            material.SetFloat("_Metallic", 0.0f);
            break;

        case ColorMode.GLOSSY:
            material = new Material(Shader.Find("Standard"));
            material.SetFloat("_Glossiness", 0.9f);
            material.SetFloat("_Metallic", 0.0f);
            break;

        case ColorMode.METAL:
            material = new Material(Shader.Find("Standard"));
            material.SetFloat("_Glossiness", 0.95f);
            material.SetFloat("_Metallic", 1.0f);
            break;

        case ColorMode.UNLIT:
            if (transparent)
            {
                material = new Material(Shader.Find("Unlit/UnlitColorTransparent"));
            }
            else
            {
                material = new Material(Shader.Find("Unlit/Color"));
            }
            break;

        case ColorMode.GLASS:
            material = new Material(Shader.Find("Standard"));
            material.SetFloat("_Glossiness", 0.973f);
            material.SetFloat("_Metallic", 0.273f);
            break;

        case ColorMode.ADD:
            material = new Material(Shader.Find("Unlit/UnlitAdd"));
            break;

        case ColorMode.MULTIPLY:
            material = new Material(Shader.Find("Unlit/UnlitMultiply"));
            break;
        }
        material.name = "Custom:" + colorMode.ToString() + ":" + System.Guid.NewGuid();

        if (transparent)
        {
            material.renderQueue = 3000;
            if (material.shader.name == "Standard")
            {
                material.SetFloat("_Mode", 3); // transparent
                // http://answers.unity.com/answers/1265884/view.html
                material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One);
                material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha);
                material.SetInt("_ZWrite", 0);
                material.DisableKeyword("_ALPHATEST_ON");
                material.DisableKeyword("_ALPHABLEND_ON");
                material.EnableKeyword("_ALPHAPREMULTIPLY_ON");
            }
        }
        return(material);
    }