- Home /
How to enable "Contribute Global" by script on Editor?
I created a script to enable/disable lighting options in children objects of a specific GameObject on Editor. I'm trying to access "Contribute Global" option
to turn ON:
But i dont know how. Which methods i nee to use?
My script:
using UnityEngine;
using UnityEditor;
using Object = UnityEngine.Object;
public class LightingToggle : EditorWindow
{
public Object source;
[MenuItem("Window/LightingToggle"), MenuItem("Tools/LightingToggle")]
public static void Enable(){
LightingToggle window = (LightingToggle)GetWindow(typeof(LightingToggle));
window.titleContent = new GUIContent("LightingToggle");
}
private void TurnOffLight() {
GameObject go = GameObject.Find(source.name);
foreach (MeshRenderer filter in go.gameObject.GetComponentsInChildren<MeshRenderer>()){
filter.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off;
filter.receiveShadows = false;
}
}
private void TurnOnLight(){
GameObject go = GameObject.Find(source.name);
foreach (MeshRenderer filter in go.gameObject.GetComponentsInChildren<MeshRenderer>()){
filter.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.On;
filter.receiveShadows = true;
}
}
void OnGUI(){
EditorGUILayout.Space();
if (GUILayout.Button("Turn Lighting Options Off")){
TurnOffLight();
}
EditorGUILayout.Space();
if (GUILayout.Button("Turn Lighting Options On")){
TurnOnLight();
}
EditorGUILayout.Space();
source = EditorGUILayout.ObjectField(source, typeof(Object), true);
}
}
Answer by FIFTYTWO · May 14, 2021 at 04:51 PM
It can be manipulated by GameObjectUtility.GetStaticEditorFlags() & GameObjectUtility.SetStaticEditorFlags() https://docs.unity3d.com/ScriptReference/GameObjectUtility.html
So, the flag belongs to GameObject but rendered in MeshRenderer's inspector
Your answer
Follow this Question
Related Questions
Turn on Shuriken "Simulate" from script in Edit mode? 1 Answer
I can't create tiles,Why can't I create tiles 0 Answers
keep gameObject in hierarchy folded when not selected 3 Answers
Editor window doesn't open 2 Answers
List of all editor attributes? 1 Answer