1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- public class DrawingMap : MonoBehaviour
- {
- [SerializeField]
- private Image colorImage;//颜色池
- private Texture2D temp_texture;
- void Start()
- {
- InitColor();
- }
- // Update is called once per frame
- void Update()
- {
-
- }
- private void InitColor()
- {
- temp_texture = this.colorImage.mainTexture as Texture2D;
- //CDebug.Log("texture.height" + texture.height + "texture.width" + texture.width);
- int addValue = (temp_texture.width - 1) / 3;
- Color value0 = (Color.green - Color.red) / addValue;
- Color value1 = (Color.blue - Color.green) / addValue;
- Color value2 = (Color.red - Color.blue) / addValue;
- for (int x = 0; x < temp_texture.width; x++)
- {
- for (int y = 0; y < temp_texture.height; y++)
- {
- if (x < addValue)
- {
- temp_texture.SetPixel(x, y, Color.red + value0 * x);
- }
- else if (x < addValue * 2)
- {
- temp_texture.SetPixel(x, y, Color.green + value1 * (x - addValue));
- }
- else
- {
- temp_texture.SetPixel(x, y, Color.blue + value2 * (x - addValue * 2));
- }
- }
- }
- // this.colorImage.sprite = Sprite.Create(temp_texture, new Rect(0, 0, 256f,128f), Vector2.zero);
- temp_texture.Apply();
- // this.colorImage.material.mainTexture = temp_texture;
- }
- public Color GetColorByPoint(Vector2 point)
- {
- return temp_texture.GetPixel((int) point.x, (int)point.y);
- }
- }
|