Ejemplo n.º 1
0
        /// <summary>
        /// Draws an equivalent to <see cref="OutlineMask"/>.
        /// </summary>
        /// <param name="texture"></param>
        /// <param name="xLeft"></param>
        /// <param name="xRight"></param>
        /// <param name="yBottom"></param>
        /// <param name="yTop"></param>
        /// <param name="maskCriteria"></param>
        /// <param name="maskColor"></param>
        /// <param name="lineOnly"></param>
        /// <param name="lineWidth"></param>
        public void DrawMask(ref UnityEngine.Texture2D texture, float xLeft, float xRight, float yBottom, float yTop, Func <float, bool> maskCriteria, UnityEngine.Color maskColor, bool lineOnly = true, int lineWidth = 1)
        {
            int width  = texture.width - 1;
            int height = texture.height - 1;

            float graphStepX = (xRight - xLeft) / width;
            float graphStepY = (yTop - yBottom) / height;

            for (int x = 0; x <= width; x++)
            {
                for (int y = 0; y <= height; y++)
                {
                    float xF = x * graphStepX + xLeft;
                    float yF = y * graphStepY + yBottom;

                    if (lineOnly)
                    {
                        float pixelValue = ValueAt(xF, yF);
                        bool  mask       = false;

                        if (!maskCriteria(pixelValue))
                        {
                            for (int w = 1; w <= lineWidth; w++)
                            {
                                if ((x >= w && maskCriteria(ValueAt((x - w) * graphStepX + xLeft, yF))) ||
                                    (x < width - w && maskCriteria(ValueAt((x + w) * graphStepX + xLeft, yF))) ||
                                    (y >= w && maskCriteria(ValueAt(xF, (y - w) * graphStepY + yBottom))) ||
                                    (y < height - w && maskCriteria(ValueAt(xF, (y + w) * graphStepY + yBottom))))
                                {
                                    mask = true;
                                    break;
                                }
                            }
                        }
                        if (mask)
                        {
                            texture.SetPixel(x, y, maskColor);
                        }
                        else
                        {
                            texture.SetPixel(x, y, UnityEngine.Color.clear);
                        }
                    }
                    else
                    {
                        if (!maskCriteria(ValueAt(xF, yF)) || xF < XMin || xF > XMax || yF < YMin || yF > YMax)
                        {
                            texture.SetPixel(x, y, maskColor);
                        }
                        else
                        {
                            texture.SetPixel(x, y, UnityEngine.Color.clear);
                        }
                    }
                }
            }

            texture.Apply();
        }
Ejemplo n.º 2
0
        public UnityEngine.Texture2D getTexture(int scale)
        {
            try
            {
                changed = false;
                if (scale <= 0)
                {
                    scale = 1;
                }

                scale = 1;

                UnityEngine.Texture2D tex =
                    new UnityEngine.Texture2D(760, 760);

                for (int x = 0; x <= 760 - 1; x++)
                {
                    for (int y = 0; y <= 760 - 1; y++)
                    {
                        tex.SetPixel(x, y, pixels[x, y].getColor());
                    }
                }
                tex.filterMode = UnityEngine.FilterMode.Point;
                tex.Apply();
                return(tex);
            }
            catch (Exception e)
            {
                UnityEngine.Debug.LogError("[kOS-Editor->Screen->getTexture] " + e.Message);
                return(new UnityEngine.Texture2D(760, 760));
            }
        }
        static int _m_SetPixel(RealStatePtr L)
        {
            try {
                ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);


                UnityEngine.Texture2D gen_to_be_invoked = (UnityEngine.Texture2D)translator.FastGetCSObj(L, 1);



                {
                    int _x = LuaAPI.xlua_tointeger(L, 2);
                    int _y = LuaAPI.xlua_tointeger(L, 3);
                    UnityEngine.Color _color; translator.Get(L, 4, out _color);

                    gen_to_be_invoked.SetPixel(_x, _y, _color);



                    return(0);
                }
            } catch (System.Exception gen_e) {
                return(LuaAPI.luaL_error(L, "c# exception:" + gen_e));
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Draws the object on the specified <see cref="UnityEngine.Texture2D"/>.
        /// </summary>
        /// <param name="texture">The texture on which to draw the object.</param>
        /// <param name="xLeft">The X axis lower bound.</param>
        /// <param name="xRight">The X axis upper bound.</param>
        /// <param name="yBottom">The Y axis lower bound.</param>
        /// <param name="yTop">The Y axis upper bound.</param>
        /// <param name="cMin">The color axis lower bound.</param>
        /// <param name="cMax">The color axis upper bound.</param>
        public void Draw(ref UnityEngine.Texture2D texture, float xLeft, float xRight, float yBottom, float yTop, float cMin, float cMax)
        {
            if (!Visible)
            {
                return;
            }
            int width  = texture.width - 1;
            int height = texture.height - 1;

            float graphStepX = (xRight - xLeft) / width;
            float graphStepY = (yTop - yBottom) / height;
            float cRange     = cMax - cMin;

            for (int x = 0; x <= width; x++)
            {
                for (int y = 0; y <= height; y++)
                {
                    float xF = x * graphStepX + xLeft;
                    float yF = y * graphStepY + yBottom;
                    if (xF < XMin || xF > XMax || yF < YMin || yF > YMax)
                    {
                        continue;
                    }
                    texture.SetPixel(x, y, this.Color[(ColorFunc(xF, yF, ValueAt(xF, yF)) - cMin) / cMax]);
                }
            }

            texture.Apply();
        }
        private void FeelingMonitorPanel(int id)
        {
            Dictionary <string, float> feelingValueMap = _connector.FeelingValueMap;

            if (feelingValueMap.Count == 0)
            {
                return;
            }

            _scrollPosition = UnityEngine.GUILayout.BeginScrollView(_scrollPosition);

            float feelingBarWidth = UnityEngine.Screen.width * 0.3f;

            _boxStyle = _panelSkin.box;
            lock (feelingValueMap)
            {
                int topOffset = 5;
                foreach (string feeling in feelingValueMap.Keys)
                {
                    if (!_isFeelingTextureMapInitialized)
                    {
                        float                 r = UnityEngine.Random.value;
                        float                 g = UnityEngine.Random.value;
                        float                 b = UnityEngine.Random.value;
                        UnityEngine.Color     c = new UnityEngine.Color(r, g, b, 0.6f);
                        UnityEngine.Texture2D t = new UnityEngine.Texture2D(1, 1);
                        t.SetPixel(0, 0, c);
                        t.Apply();
                        _feelingTextureMap[feeling] = t;
                    }
                    float value = feelingValueMap[feeling];

                    // Set the texture of background.
                    _boxStyle.normal.background = _feelingTextureMap[feeling];
                    UnityEngine.GUILayout.BeginHorizontal();
                    UnityEngine.GUILayout.Label(feeling + ": ", _panelSkin.label, UnityEngine.GUILayout.MaxWidth(_panel.width * 0.3f));
                    UnityEngine.GUILayout.Box("", _boxStyle, UnityEngine.GUILayout.Width(feelingBarWidth * value), UnityEngine.GUILayout.Height(16));
                    UnityEngine.GUILayout.EndHorizontal();
                    topOffset += 15;
                }
                // We only need to initialize the map at the first time.
                if (!_isFeelingTextureMapInitialized)
                {
                    _isFeelingTextureMapInitialized = true;
                }
            }

            UnityEngine.GUILayout.EndScrollView();
        }
        private void SetBackgroundColor(UnityEngine.GUIStyle style, UnityEngine.Color color)
        {
            var texture = new UnityEngine.Texture2D(1, 1);

            texture.SetPixel(0, 0, color);
            texture.Apply();
            style.active.background    = texture;
            style.focused.background   = texture;
            style.hover.background     = texture;
            style.normal.background    = texture;
            style.onActive.background  = texture;
            style.onFocused.background = texture;
            style.onHover.background   = texture;
            style.onNormal.background  = texture;
        }
Ejemplo n.º 7
0
    public static UIButton FactoryButton(IDagNodeValue <UnityEngine.Rect> dagRect, string localeKey, int depth, ClickEventHandler onClick)
    {
        DagNodeValue <int> dagDepth = new DagNodeValue <int>(depth);

        UnityEngine.GUIStyle style = new UnityEngine.GUIStyle();
        style.normal.background = UnityEngine.Texture2D.whiteTexture;
        UnityEngine.Texture2D texture = new UnityEngine.Texture2D(1, 1);
        texture.SetPixel(0, 0, new UnityEngine.Color(0.9f, 0.9f, 0.9f, 1.0f));
        texture.Apply();
        style.hover.background = texture;
        DagNodeValue <UnityEngine.GUIStyle> dagStyle = new DagNodeValue <UnityEngine.GUIStyle>(style);
        DagGUIContent dagGUIContent = DagGUIContent.FactoryLocale(localeKey);

        return(new UIButton(dagRect, dagGUIContent, dagStyle, dagDepth, onClick));
    }
Ejemplo n.º 8
0
            public AlphaPicker(int w, int h)
            {
                Alpha = 1;
                Size  = new Size(w, h);

                _image = new UnityEngine.Texture2D(w, h);
                for (int i = 0; i < w; i++)
                {
                    int   rgb          = (int)(((float)i / w) * 255);
                    Color currentColor = Color.FromArgb(rgb, rgb, rgb);
                    for (int k = 0; k < h; k++)
                    {
                        _image.SetPixel(i, k, currentColor.ToUColor());
                    }
                }
                _image.Apply();

                Owner.UpClick += Application_UpClick;
            }
Ejemplo n.º 9
0
            private void _UpdateImage()
            {
                double hue        = 0f;
                double saturation = .9f;
                double luminosity = .5f;

                for (int i = 0; i < _image.width; i++)
                {
                    for (int k = 0; k < _image.height; k++)
                    {
                        hue = (float)(_image.height - k - 1) / _image.height;

                        // HSL to RGB convertion.
                        Color pixelColor = GetColorFromHSL(hue, saturation, luminosity);
                        _image.SetPixel(i, k, pixelColor.ToUColor());
                    }
                    _image.Apply();
                }
            }
Ejemplo n.º 10
0
        private static void MenuItem_SaveBinaryWithAssetsPath()
        {
            //texture
            UnityEngine.Texture2D t_texture;
            {
                t_texture = new UnityEngine.Texture2D(32, 32);
                for (int xx = 0; xx < 32; xx++)
                {
                    for (int yy = 0; yy < 32; yy++)
                    {
                        t_texture.SetPixel(xx, yy, new UnityEngine.Color((float)xx / 32, (float)yy / 32, 0.0f, 1.0f));
                    }
                }
                t_texture.Apply();
            }

            //SaveAssetWithAssetsPath
            BlueBack.AssetLib.Editor.CreateDirectoryWithAssetsPath.Create("Out");
            BlueBack.AssetLib.Editor.SaveAssetWithAssetsPath.SaveConverter(t_texture, new BlueBack.AssetLib.PngConverterAssetToBinary(), "Out/test.png");
            BlueBack.AssetLib.Editor.RefreshAssetDatabase.Refresh();
        }
Ejemplo n.º 11
0
            private void _UpdateImage()
            {
                double hue        = _hueValue;
                double saturation = 0f;
                double luminosity = 1f;

                for (int i = 0; i < _image.width; i++)
                {
                    saturation = ((float)i / _image.width);

                    for (int k = 0; k < _image.height; k++)
                    {
                        luminosity = (float)k / _image.height;

                        // HSL to RGB convertion.
                        Color pixelColor = GetColorFromHSL(hue, saturation, luminosity);
                        _image.SetPixel(i, k, pixelColor.ToUColor());
                    }
                    _image.Apply();
                }
            }
        public static void Main(UnityEngine.Texture2D texture, int sampleCount = 5)
        {
            int width  = texture.width;
            int height = texture.height;

            Exten.r = new Random(0);
            //scene = random_scene();

            UnityEngine.Vector3 lookfrom = new UnityEngine.Vector3(3, 3, 2);
            UnityEngine.Vector3 lookat   = new UnityEngine.Vector3(0, 0, -1);
            float dist_to_focus          = (lookat - lookfrom).length();
            float aperture = 2.0f;


            Camera camera = new Camera(lookfrom, lookat, new UnityEngine.Vector3(0, 1, 0), 60, (float)(width) / (float)(height), aperture, dist_to_focus);

            //print("P3\n{0} {1}\n255\n", width, height);

            for (int i = height - 1; i >= 0; --i)
            {
                for (int j = 0; j < width; ++j)
                {
                    var c = new UnityEngine.Vector3(0, 0, 0);
                    for (int k = 0; k < sampleCount; ++k)
                    {
                        float x = (j + Exten.rand01()) / (float)width;
                        float y = (i + Exten.rand01()) / (float)height;
                        var   r = camera.GenRay(x, y);
                        Profiler.BeginSample("RayingRay");
                        c += RayTracing(r, 0);
                        Profiler.EndSample();
                    }
                    c /= sampleCount;
                    var c1 = c.gamma();
                    UnityEngine.Color outColor = new UnityEngine.Color(c1.x, c1.y, c1.z, 1);
                    texture.SetPixel(j, i, outColor);
                }
            }
        }
Ejemplo n.º 13
0
        public override void Draw(ref UnityEngine.Texture2D texture, float xLeft, float xRight, float yBottom, float yTop)
        {
            int width  = texture.width - 1;
            int height = texture.height - 1;

            float graphStepX = (xRight - xLeft) / width;
            float graphStepY = (yTop - yBottom) / height;

            for (int x = 0; x <= width; x++)
            {
                for (int y = 0; y <= height; y++)
                {
                    float xF = x * graphStepX + xLeft;
                    float yF = y * graphStepY + yBottom;
                    if (xF < XMin || xF > XMax || yF < YMin || yF > YMax)
                    {
                        continue;
                    }
                    texture.SetPixel(x, y, this.Color[ColorFunc(xF, yF, ValueAt(xF, yF) * ZAxisScaler)]);
                }
            }

            texture.Apply();
        }
Ejemplo n.º 14
0
	private void FeelingMonitorPanel(int id)
	{
		Dictionary<string, float> feelingValueMap = _connector.FeelingValueMap;
		if(feelingValueMap.Count == 0)
		{
			return;
		}

		_scrollPosition = UnityEngine.GUILayout.BeginScrollView(_scrollPosition);

		float feelingBarWidth = UnityEngine.Screen.width * 0.3f;

		_boxStyle = _panelSkin.box;
		lock(feelingValueMap)
		{
			int topOffset = 5;
			foreach(string feeling in feelingValueMap.Keys)
			{
				if(!_isFeelingTextureMapInitialized)
				{
					float r = UnityEngine.Random.value;
					float g = UnityEngine.Random.value;
					float b = UnityEngine.Random.value;
					UnityEngine.Color c = new UnityEngine.Color(r, g, b, 0.6f);
					UnityEngine.Texture2D t = new UnityEngine.Texture2D(1, 1);
					t.SetPixel(0, 0, c);
					t.Apply();
					_feelingTextureMap[feeling] = t;
				}
				float value = feelingValueMap[feeling];

				// Set the texture of background.
				_boxStyle.normal.background = _feelingTextureMap[feeling];
				UnityEngine.GUILayout.BeginHorizontal();
				UnityEngine.GUILayout.Label(feeling + ": ", _panelSkin.label, UnityEngine.GUILayout.MaxWidth(_panel.width * 0.3f));
				UnityEngine.GUILayout.Box("", _boxStyle, UnityEngine.GUILayout.Width(feelingBarWidth * value), UnityEngine.GUILayout.Height(16));
				UnityEngine.GUILayout.EndHorizontal();
				topOffset += 15;
			}
			// We only need to initialize the map at the first time.
			if(!_isFeelingTextureMapInitialized)
			{
				_isFeelingTextureMapInitialized = true;
			}
		}

		UnityEngine.GUILayout.EndScrollView();
	}
Ejemplo n.º 15
0
            public AlphaPicker(int w, int h)
            {
                Alpha = 1;
                Size = new Size(w, h);

                _image = new UnityEngine.Texture2D(w, h);
                for (int i = 0; i < w; i++)
                {
                    int rgb = (int)(((float)i / w) * 255);
                    Color currentColor = Color.FromArgb(rgb, rgb, rgb);
                    for (int k = 0; k < h; k++)
                    {
                        _image.SetPixel(i, k, currentColor.ToUColor());
                    }
                }
                _image.Apply();

                Owner.UpClick += Application_UpClick;
            }
Ejemplo n.º 16
0
 public override void SetPixel(int x, int y, Color color)
 {
     unityTexture.SetPixel(x, y, color);
 }
Ejemplo n.º 17
0
        /** [シングルトン]constructor
         */
        private Instantiate()
        {
            //Sprite のグラフィックスとして適用させるテクスチャ。
            UnityEngine.Texture2D t_texture = UnityEngine.Texture2D.whiteTexture;
            {
                t_texture = new UnityEngine.Texture2D(64, 64);
                for (int xx = 0; xx < t_texture.width; xx++)
                {
                    for (int yy = 0; yy < t_texture.height; yy++)
                    {
                        float t_value_x;
                        if (xx < (t_texture.width / 2))
                        {
                            t_value_x = xx;
                        }
                        else
                        {
                            t_value_x = t_texture.width - 1 - xx;
                        }

                        float t_value_y;
                        if (yy < (t_texture.height / 2))
                        {
                            t_value_y = yy;
                        }
                        else
                        {
                            t_value_y = t_texture.width - 1 - yy;
                        }

                        float t_value = UnityEngine.Mathf.Min(t_value_x, t_value_y);

                        t_value = UnityEngine.Mathf.Clamp01(t_value * 0.8f);
                        t_texture.SetPixel(xx, yy, new UnityEngine.Color(1.0f, 1.0f, 1.0f, t_value));
                    }
                }

                t_texture.filterMode = UnityEngine.FilterMode.Bilinear;
                t_texture.wrapMode   = UnityEngine.TextureWrapMode.Clamp;
                t_texture.Apply();
            }

            //Sprite に適用させるテクスチャの Rect 領域。
            UnityEngine.Rect t_rect = new UnityEngine.Rect(0.0f, 0.0f, t_texture.width, t_texture.height);

            //グラフィックスの Rect に対するピボット地点の相対位置。
            UnityEngine.Vector2 t_pivot = new UnityEngine.Vector2(t_texture.width / 2, t_texture.height / 2);

            //ワールド空間座標の 1 単位分に相当する、スプライトのピクセル数。
            const float t_pixels_per_unit = 100.0f;

            //スプライトメッシュが外側に拡張する量。
            const uint t_extrude = 0;

            //スプライトのために生成されるメッシュタイプの制御。
            //FullRect	: 矩形はメッシュと等しいユーザーが指定したスプライトサイズ。
            //Tight		: ピクセルのアルファ値を基にしたタイトなメッシュ。多くの余分なピクセルは可能な限りクロップされます。
            UnityEngine.SpriteMeshType t_mesh_type = UnityEngine.SpriteMeshType.FullRect;

            //スプライトのサイズ (X=左、Y=下、Z=右、W=上)。
            UnityEngine.Vector4 t_border = new UnityEngine.Vector4(0.0f, 0.0f, 0.0f, 0.0f);

            //Generates a default physics shape for the sprite.
            bool t_generate_fallback_physicsshape = true;

            //UnityEngine.Sprite.Create
            this.inputfield_sprite = UnityEngine.Sprite.Create(t_texture, t_rect, t_pivot, t_pixels_per_unit, t_extrude, t_mesh_type, t_border, t_generate_fallback_physicsshape);
        }
Ejemplo n.º 18
0
 public void SetPixel(int x, int y, Color c)
 {
     tex.SetPixel(x, y, c.innerColor);
 }
Ejemplo n.º 19
0
                /// <summary>
                /// Initializes the components of the image to the values specified by the strings.
                /// </summary>
                /// <param name="ID">The unique id (if any) of this object.</param>
                /// <param name="Src">The path (if any) to the image file to load.</param>
                /// <param name="Colour">The colour tint to apply to the image or the colour fill to use as the image.
                /// <list type="table">
                /// <listheader>
                /// <term>Src Value</term>
                /// <term>Colour Value</term>
                /// <term>Result</term>
                /// </listheader>
                /// <item>
                /// <term>Specified</term>
                /// <term>Specified</term>
                /// <term>Image is rendered with Colour tint</term>
                /// </item>
                /// <item>
                /// <term>Specified</term>
                /// <term>null or empty</term>
                /// <term>Image is rendered without tint</term>
                /// </item>
                /// <item>
                /// <term>null or empty</term>
                /// <term>Specified</term>
                /// <term>Colour is used as fill colour for image</term>
                /// </item>
                /// <item>
                /// <term>null or empty</term>
                /// <term>null or empty</term>
                /// <term>Invalid, exception thrown</term>
                /// </item>
                /// </list>
                /// </param>
                /// <param name="Scale">The scale mode used for rendering the image to the specicified unit rect dimensions:
                /// <list type="table">
                /// <listheader>
                /// <term>String Value</term>
                /// <term>Description</term>
                /// </listheader>
                /// <item>
                /// <term>null or empty</term>
                /// <term>Stretches the texture to fill the complete rectangle passed in to GUI.DrawTexture</term>
                /// </item>
                /// <item>
                /// <term>stretchToFill</term>
                /// <term>Stretches the texture to fill the complete rectangle passed in to GUI.DrawTexture</term>
                /// </item>
                /// <item>
                /// <term>scaleAndCrop</term>
                /// <term>Scales the texture, maintaining aspect ratio, so it completely covers the position rectangle passed to GUI.DrawTexture. If the texture is being draw to a rectangle with a different aspect ratio than the original, the image is cropped</term>
                /// </item>
                /// <item>
                /// <term>scaleToFit</term>
                /// <term>Scales the texture, maintaining aspect ratio, so it completely fits withing the position rectangle passed to GUI.DrawTexture</term>
                /// </item>
                /// </list>
                /// </param>
                /// <param name="X">The x positioning of the image relative to the parent as governed by the horizontal alignment as follows:
                /// <list type="table">
                /// <listheader>
                /// <term>Alignment</term>
                /// <term>X Position</term>
                /// </listheader>
                /// <item>
                /// <term>null or empty</term>
                /// <term>x units from parent's left edge</term>
                /// </item>
                /// <item>
                /// <term>Left</term>
                /// <term>x units from parent's left edge</term>
                /// </item>
                /// <item>
                /// <term>Center</term>
                /// <term>x position is ignored</term>
                /// </item>
                /// <item>
                /// <term>Right</term>
                /// <term>x units from parent's right edge</term>
                /// </item>
                /// </list>
                /// </param>
                /// <param name="Y">The y positioning of the image relative to the parent as governed by the vertical alignment as follows:
                /// <list type="table">
                /// <listheader>
                /// <term>Alignment</term>
                /// <term>Y Position</term>
                /// </listheader>
                /// <item>
                /// <term>null or empty</term>
                /// <term>y units from parent's top edge</term>
                /// </item>
                /// <item>
                /// <term>Top</term>
                /// <term>y units from parent's top edge</term>
                /// </item>
                /// <item>
                /// <term>Center</term>
                /// <term>y position is ignored</term>
                /// </item>
                /// <item>
                /// <term>Bottom</term>
                /// <term>y units from parent's bottom edge</term>
                /// </item>
                /// </list>
                /// </param>
                /// <param name="W">The width of the image as follows:
                /// <list type="table">
                /// <listheader>
                /// <term>W</term>
                /// <term>H</term>
                /// <term>Description</term>
                /// </listheader>
                /// <item>
                /// <term>null or empty</term>
                /// <term>null or empty</term>
                /// <term>The image's dimensions (in pixels) will be used</term>
                /// </item>
                /// <item>
                /// <term>null or empty</term>
                /// <term>Specified</term>
                /// <term>The width will be calculated according to the specified height and aspect ration of the image</term>
                /// </item>
                /// <item>
                /// <term>Specified</term>
                /// <term>-n/a-</term>
                /// <term>The specified width will be used</term>
                /// </item>
                /// </list>
                /// </param>
                /// <param name="H">THe height of the image as follows:
                /// <list type="table">
                /// <listheader>
                /// <term>H</term>
                /// <term>W</term>
                /// <term>Description</term>
                /// </listheader>
                /// <item>
                /// <term>null or empty</term>
                /// <term>null or empty</term>
                /// <term>The image's dimensions (in pixels) will be used</term>
                /// </item>
                /// <item>
                /// <term>null or empty</term>
                /// <term>Specified</term>
                /// <term>The height will be calculated according to the specified width and aspect ration of the image</term>
                /// </item>
                /// <item>
                /// <term>Specified</term>
                /// <term>-n/a-</term>
                /// <term>The specified height will be used</term>
                /// </item>
                /// </list>
                /// </param>
                /// <param name="HAlign">The horizontal alignemnt of the image within the parent rect as specified by the following values:
                /// <list type="table">
                /// <listheader>
                /// <term>String Value</term>
                /// <term>Alignment.Type</term>
                /// </listheader>
                /// <item>
                /// <term>null or empty</term>
                /// <term>null</term>
                /// </item>
                /// <item>
                /// <term>left</term>
                /// <term>Alignment.Type.Left</term>
                /// </item>
                /// <item>
                /// <term>center</term>
                /// <term>Alignment.Type.Center</term>
                /// </item>
                /// <item>
                /// <term>right</term>
                /// <term>Alignment.Type.Right</term>
                /// </item>
                /// </list>
                /// </param>
                /// <param name="VAlign">The horizontal alignemnt of the image within the parent rect  as specified by the following values:
                /// <list type="table">
                /// <listheader>
                /// <term>String Value</term>
                /// <term>Alignment.Type</term>
                /// </listheader>
                /// <item>
                /// <term>null or empty</term>
                /// <term>null</term>
                /// </item>
                /// <item>
                /// <term>top</term>
                /// <term>Alignment.Type.Top</term>
                /// </item>
                /// <item>
                /// <term>center</term>
                /// <term>Alignment.Type.Center</term>
                /// </item>
                /// <item>
                /// <term>bottom</term>
                /// <term>Alignment.Type.Bottom</term>
                /// </item>
                /// </list>
                /// </param>
                /// <example>
                /// Instantiate an image object with the id "myImage", the path "somePic", no colour tint, default scale, a width of 300 virtual pixels, a height calculated automatically, positioned 10 virtual units down and centered horizontally:
                /// <code>Image img = new Image("myImage", "somePic", null, 300, null, null, "10", "center", null);</code>
                /// Instantiate an image object no id, a solid colour fill, default scale, a width of 300 virtual pixels, a height calculated automatically, positioned 10 virtual units down and centered horizontally:
                /// <code>Image img = new Image(null, null, "rgb(255,0,255)", 300, null, null, "10", "center", null);</code>
                /// </example>
                public Image(string ID, string Src, string Colour, string Scale, string X, string Y, string W, string H, string HAlign, string VAlign, string Visible) : base(ID, X, Y, W, H, HAlign, VAlign, Visible)
                {
                    switch (Scale)
                    {
                    case "":

                        scale = UnityEngine.ScaleMode.StretchToFill;
                        break;

                    case null:

                        scale = UnityEngine.ScaleMode.StretchToFill;
                        break;

                    case "stretchToFill":

                        scale = UnityEngine.ScaleMode.StretchToFill;
                        break;

                    case "scaleAndCrop":

                        scale = UnityEngine.ScaleMode.ScaleAndCrop;
                        break;

                    case "scaleToFit":

                        scale = UnityEngine.ScaleMode.ScaleToFit;
                        break;

                    default:
                        throw new Exception("Image widget has unknow scale mode");
                    }

                    if ((Colour == null || Colour == "") && (Src == null || Src == ""))
                    {
                        throw new Exception("Image widget has empty or null src string and colour string");
                    }

                    rgba = TouchGUI.Colour.Parse(Colour);

                    // Build texture from colour
                    if ((Src == null || Src == "") && rgba != null)
                    {
                        img = new UnityEngine.Texture2D(1, 1);
                        img.SetPixel(0, 0, (UnityEngine.Color)rgba);
                        img.Apply();
                    }
                    // Load texture from file
                    else
                    {
                        img = UnityEngine.Resources.Load(Src) as UnityEngine.Texture2D;
                    }

                    if (img == null)
                    {
                        throw new Exception("Image widget couldn't load " + Src);
                    }

                    // If width and height are null, use the image dimensions
                    if (rect.dim.x.value == null && rect.dim.y.value == null)
                    {
                        rect.dim.x.type  = Unit.Type.Pixel;
                        rect.dim.x.value = img.width;

                        rect.dim.y.type  = Unit.Type.Pixel;
                        rect.dim.y.value = img.height;
                    }
                    // If width is null, set the width with the image aspect ratio according to the specified height
                    else if (rect.dim.x.value == null)
                    {
                        float aspect = (float)img.width / (float)img.height;

                        rect.dim.x.type  = rect.dim.y.type;
                        rect.dim.x.value = (float)rect.dim.y.value * aspect;
                    }
                    // If height is null, set the height with the image aspect ratio according to the specified width
                    else if (rect.dim.y.value == null)
                    {
                        float aspect = (float)img.height / (float)img.width;

                        rect.dim.y.type  = rect.dim.x.type;
                        rect.dim.y.value = (float)rect.dim.x.value * aspect;
                    }
                }