Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- // For List
- using System.Collections.Generic;
- //
- // To use, import a texture with the following settings:
- // Texture Type = Advanced
- // Read/Write Enabled = true
- // Filter Mode = Point
- // Format = ARGB 32 bit
- // Don't forget to press Apply :)
- //
- // When creating the texture, I tested using a 32 bit png saved from Paint.NET
- //
- public class ColorFetcherScript : MonoBehaviour {
- // The texture we're going to read from
- public Texture2D textureToRead;
- // whether or not we want to prepend Alpha of 1.0 (for paint.net solid colors, yes we do)
- public bool prefixFF = true;
- // List of format <hex value (string)>
- private List<string> colorList;
- // Use this for initialization
- void Start(){
- if(!textureToRead){
- Debug.LogError("Cannot read texture!");
- }
- colorList = new List<string>();
- getColors();
- }
- private void getColors(){
- Color[] texColors = textureToRead.GetPixels();
- string tempHex = "";
- Debug.Log("Reading Colors...");
- for(int i = 0; i < texColors.Length; i++){
- tempHex = ((Color32)texColors[i]).r.ToString("X2") + ((Color32)texColors[i]).g.ToString("X2") + ((Color32)texColors[i]).b.ToString("X2");
- if(!colorList.Contains(tempHex)){
- //Debug.Log("Found new color: " + tempHex);
- if(prefixFF){
- colorList.Add("FF" + tempHex);
- }else{
- colorList.Add(tempHex);
- }
- }
- }
- Debug.Log("Done! Found " +colorList.Count+ " unique colors.");
- Debug.Log("=======PRINTING LIST========");
- string printedList = "";
- foreach(string s in colorList){
- printedList += s + "\n";
- }
- Debug.Log(printedList);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement