Get mesh vertex colors

I use Probuilder & Polybrush with vertex colors for all the art in VThree. Keeping track of all the colors can be a chore, and if I lose one figuring out which it is visually is impossible. So I whipped this up quickly this evening. It’ll print all the colors on your mesh (if you’re using vertex colors) to the console.

Right click on an object in the hierarchy and choose “Get Vertex Colors”

Hopefully useful for someone.

using System;
using System.Linq;
using UnityEngine;
using UnityEditor;

public class NWZGetMeshColors : MonoBehaviour {
    [MenuItem("GameObject/Get Vertex Colors", false, 0)]
	private static void GetVertexColors(){
		Debug.Log("Getting mesh colors for " + Selection.activeTransform.gameObject.name);
		Mesh mesh = Selection.activeTransform.gameObject.GetComponent<MeshFilter>().sharedMesh;
        Vector3[] vertices = mesh.vertices;
		Color[] colors = new Color[vertices.Length];
		int i = 0;

		foreach (Color c in mesh.colors){
			if(!colors.Contains(c)){
				colors[i] = c;
				i++;
			}
        }

		Color[] uniqueColors = new Color[i];
		Array.Copy(colors, uniqueColors, uniqueColors.Length);

		foreach (Color c in uniqueColors){
			Debug.Log("<color=" + ToRGBHex(c) + ">▉</color> " + ToRGBHex(c));
        }
	}

	public static string ToRGBHex(Color c){
		return string.Format("#{0:X2}{1:X2}{2:X2}", ToByte(c.r), ToByte(c.g), ToByte(c.b));
	}
 
	private static byte ToByte(float f){
		f = Mathf.Clamp01(f);
		return (byte)(f * 255);
	}
}

C9McEc-U0AAKSZt

C9McIvWVYAAY3f1

First Huldra’s Path In Game Screen

Huldra’s Path is progressing along nicely, and so it’s time to show off a glimpse at the word I’m creating for it.

Still a long way to go, but having finally nailed down the visuals feels amazing.

hel-final-preanimation

How To: Second Clock in Unity

I’ve been asked more than you’d think on how to build a second timer in Unity. It’s straght forward, and involves only a few lines of code.

#pragma strict

var startedAt 		: float;
var clockTime 		: int;
var lastClockTime 	: int;

function Awake(){
	startedAt = Time.time;
}

function Update (){
	var offsetTime : float = Time.time - startedAt;
	clockTime = offsetTime % 60;

	if(clockTime > lastClockTime){
		lastClockTime = clockTime;
		print(clockTime);
	}
}

The way this works is we store Time.time at Awake() so that we account for whatever time passes before our timer starts. On update we subtract that amount from the current time, and then we store the result of the remainder on the clockTime variable.

Finally we check to see if clockTime is different from lastClockTime, and if it is, we update lastClockTime and print the result. We do this to avoid unnecessarily updating the GUI or, in this example’s case, printing the result of the update. This keeps the overhead as low as possible.

Local Coop Test for Tiny Kleptos

Testing out the two player on a pair of XBOX 360 controllers. Seems to work well, though has some health / damage bugs, and for some reason the players sometimes collide with each other. It’s a controller / coop test though, and that works great.

Sadly, being almost 1AM I had to play both players myself so they move one at a time. Nighttime crush.