Skip to content

Instantly share code, notes, and snippets.

@DomDomHaas
Created February 16, 2017 09:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save DomDomHaas/518d60d388bc593b2ffa5975abb9172b to your computer and use it in GitHub Desktop.
Save DomDomHaas/518d60d388bc593b2ffa5975abb9172b to your computer and use it in GitHub Desktop.
Unity C# Script to change all the ColorPalettes in a scene. (Is only working with the ColorPalettes u3d.as/bFr extension)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace MrWhaleGames.ColorPalette
{
[ExecuteInEditMode]
public class ScenePaletteSwitcher : MonoBehaviour
{
public PaletteData PaletteData;
public void SwitchAllPalettes()
{
Palette[] paletteObjs = GameObject.FindObjectsOfType<Palette> ();
if (paletteObjs != null) {
foreach (var item in paletteObjs) {
item.Data = this.PaletteData;
#if UNITY_EDITOR
// is need to mark the object as changed
UnityEditor.EditorUtility.SetDirty (item);
#endif
}
}
PaletteImporter[] paletteImporterObjs = GameObject.FindObjectsOfType<PaletteImporter> ();
if (paletteImporterObjs != null) {
foreach (var item in paletteImporterObjs) {
item.Data = this.PaletteData;
#if UNITY_EDITOR
// is need to mark the object as changed
UnityEditor.EditorUtility.SetDirty (item);
#endif
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment