- Home /
(Custom WIndow) Access class color from another script and override it
Hello,
after days of not finding an answer to my problem i finaly have to ask here myself.
I want a custom window for applying new colors to an array of colors depending on the rule.
Example script with the list:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class List : MonoBehaviour {
public MyClass[] myClass;
}
[System.Serializable]
public class MyClass
{
public int rule;
public Color color;
}
My thought was that i just drag and drop the object into an object field so i can access the class. depending on the "rule" variable i would apply the new colors.
Example here: using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEditor;
public class ChangeClassColorEditor : EditorWindow {
public GameObject targetObject = null;
public Color setColor1;
public Color setColor2;
public Color setColor3;
[MenuItem("Window/Test/Change Color Tool")]
public static void ShowWindow()
{
GetWindow<ChangeClassColorEditor> ("Change Color Tool");
}
public void OnGUI()
{
targetObject = (GameObject)EditorGUILayout.ObjectField (targetObject, typeof(Object), true);
setColor1 = EditorGUILayout.ColorField ("Rule 1 color", setColor1);
setColor2 = EditorGUILayout.ColorField ("Rule 2 color", setColor2);
setColor3 = EditorGUILayout.ColorField ("Rule 3 color", setColor3);
if (GUILayout.Button("Set color"))
{
Debug.Log ("Set color pressed");
SetColor ();
}
}
private void SetColor ()
{
if (targetObject != null)
{/*
if (rule = 1)
{
color = SetColor1;
}
if (rule = 2)
{
color = SetColor1;
}
if (rule = 3)
{
color = SetColor1;
}*/
}
else
{
Debug.LogWarning ("Objectfield is empty !");
}
}
Question now is: Is it possible what i want to do? if yes how do i do it?
Your answer
![](https://koobas.hobune.stream/wayback/20220612160239im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Show a dropdown for C# classes in inspector. 2 Answers
Make custom editor for generic class to apply to all current and future child classes 1 Answer
Updating Public Class Array Not Updating Inspector 1 Answer
Editor Script for selecting class property for saving 1 Answer
Setting color with a public enum and displaying the change in editor? 1 Answer