- Home /
Question by
Eldh · Mar 18, 2015 at 12:34 PM ·
serializationcustom editorcustom-inspectorserialize
How to save sprite color change on custom inspector ?
CLass code :
using UnityEngine; using System.Collections;
//[ExecuteInEditMode]
//[System.Serializable]
public class TileData : MonoBehaviour {
// public Color color;
public SpriteRenderer spr;
//[SerializeField]
public enum Type
{
clear,
building,
}
//[SerializeField]
public Type type;
public bool guarded;
public Color buildingColor;
public Color clearColor;
public void ChangeType()
{
switch (type)
{
case Type.building :
spr.color = buildingColor;
break;
case Type.clear :
spr.color = clearColor;
break;
}
}
}
And custom inspector :
using UnityEngine;
using System.Collections;
using UnityEditor;
[CanEditMultipleObjects,CustomEditor(typeof(TileData))]
public class tileEditor : Editor {
//Color color = new Color();
public override void OnInspectorGUI()
{
DrawDefaultInspector();
TileData tileDataScript = (TileData)target;
if(GUI.changed)
{
//EditorUtility.SetDirty(target);
//EditorUtility.SetDirty(tileDataScript);
tileDataScript.ChangeType();
SceneView.RepaintAll();
}
if(GUILayout.Button("update"))
{
tileDataScript.ChangeType();
SceneView.RepaintAll();
}
}
}
So i just want some script to only be executed in the editor. So i created a custom editor. When i enter play mode everything is saved except the color of my sprites which reset to default. I can't figure out how to save the color change. Can someone help me ?
EDIT : So it seems that every change i make on my spriteRenderer spr ( child of my prefab assigned manually in the inspector) is not saved.
Comment