Skip to content

Instantly share code, notes, and snippets.

@jasoncg
Last active October 24, 2018 11:30
Show Gist options
  • Select an option

  • Save jasoncg/093dae755b4bb96c4ed74076d4f9e99a to your computer and use it in GitHub Desktop.

Select an option

Save jasoncg/093dae755b4bb96c4ed74076d4f9e99a to your computer and use it in GitHub Desktop.
Voxeland build progress in Unity Hierarchy
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEditor;
using UnityEngine;
using Voxeland5;
/// <summary>
/// jasoncg
/// 2018-08-11
/// Based on
/// https://gist.github.com/ilkinulas/802c993bb6bcdb3a45bfbdd01c2f3718
/// </summary>
[InitializeOnLoad]
public class VoxelandHierarchyView {
static VoxelandHierarchyView() {
EditorApplication.hierarchyChanged += EditorApplication_hierarchyChanged;
EditorApplication.hierarchyWindowItemOnGUI += HierarchyWindowItemOnGUI;
}
private static void EditorApplication_hierarchyChanged () {
RemoveStale();
}
private static Dictionary<GameObject, Voxeland> _voxelandObjects = new Dictionary<GameObject, Voxeland>();
private static List<GameObject> temp = new List<GameObject>();
private static void RemoveStale() {
temp.AddRange(_voxelandObjects.Keys);
foreach(var key in temp) {
if(key == null)
_voxelandObjects.Remove(key);
}
temp.Clear();
}
private static void HierarchyWindowItemOnGUI (int instanceID, Rect selectionRect) {
GameObject gameObject = EditorUtility.InstanceIDToObject(instanceID) as GameObject;
if(gameObject == null)
return;
Voxeland voxeland = null;
if(!_voxelandObjects.TryGetValue(gameObject, out voxeland)) {
_voxelandObjects[gameObject] = gameObject.GetComponent<Voxeland>();
}
if(voxeland == null)
return;
Rect r = new Rect(selectionRect);
float areaWidth = Mathf.Min(240, r.width*0.75f);
r.x += r.width - areaWidth;
if(ThreadWorker.IsWorking("Voxeland")) {
//Rect r = new Rect(selectionRect);
float calculatedSum; float completeSum; float totalSum;
ThreadWorker.GetProgresByTag("VoxelandChunk", out totalSum, out calculatedSum, out completeSum);
if(totalSum > 0) {
GUI.Label(r, $"Building ({(calculatedSum / totalSum)}) ({(completeSum / totalSum)})");
var calculated = (calculatedSum / totalSum);
var complete = (completeSum / totalSum);
r.width = areaWidth; // / 2.0f;
EditorGUI.ProgressBar(r, complete, $"{completeSum} / {totalSum}");
EditorApplication.RepaintHierarchyWindow();
} else {
GUI.Label(r, "Rebuilding...");
}
} else {
r.width = areaWidth / 2.0f;
if(GUI.Button(r, "Rebuild")) {
voxeland.Rebuild();
}
r.x += areaWidth / 2.0f;
//r.width = areaWidth-r.x;
if(GUI.Button(r, "Force Generate")) {
voxeland.Generate(true);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment