C# 为什么脚本只使用渲染器组件为某些对象着色? 使用System.Linq; 使用UnityEditor; 使用UnityEngine; //改编自Unity3DCollege YouTube视频教程https://www.youtube.com/watch?v=pdDrY8Mc2lU [初始化加载] 公共类CustomHierarchy:单行为 { 专用静态向量2偏移=新向量2(0,2); 公共静态颜色gameObjectFontColor=Color.black; 公共静态颜色=Color.black; 公共静态颜色=Color.white; 公共静态颜色不活动颜色=新颜色(0.01f、0.4f、0.25f); 静态CustomHierarchy() { EditorApplication.hierarchyWindowItemOnGUI+=HandleHierarchyWindowItemOnGUI; } 私有静态void HandleHierarchyWindowItemOnGUI(int-instanceID,Rect-selectionRect) { Color fontColor=游戏对象fontColor; 颜色背景颜色=新颜色(.76f、.76f、.76f); FontStyleFont=FontStyle.Normal; var obj=EditorUtility.InstanceIDToObject(instanceID); GameObject gameObj=EditorUtility.InstanceIDToObject(instanceID)作为GameObject; if(Selection.instanceID.Contains(instanceID)) { 背景色=新颜色(0.24f、0.48f、0.90f); } 如果(obj!=null) { var prefactType=prefactUtility.getPrefactType(obj); if(gameObj.activeInHierarchy==false) { 背景颜色=不活动颜色; } if(gameObj.GetComponent()==true) { fontColor=Color.yellow; } if(prefableType==prefableType.prefableInstance) { styleFont=FontStyle.Bold; PropertyModification[]PrefactMods=PrefactUtility.GetPropertyModifications(obj); foreach(PrefactMods中的PropertyModification PrefactMod) { if(PrefactMod.propertyPath.ToString()!=“m_Name”&&PrefactMod.propertyPath.ToString()!=“m_LocalPosition.x”&&PrefactMod.propertyPath.ToString()!=“m_LocalPosition.y”&&PrefactMod.propertyPath.ToString()!=“m_LocalPosition.z”&&PrefactMod.propertyPath.ToString()!=“m(LocalRotation.x”&&PrefactMod.propertyPath.ToString()!=“m(LocalRotation.y”&&PrefactMod.propertyPath.ToString()!=“m_LocalRotation.z”&&PrefactMod.propertyPath.ToString()!=“m_LocalRotation.w”&&PrefactMod.propertyPath.ToString()!=“m_RootOrder”&&PrefactMod.propertyPath.ToString()!=“m_IsActive”) { fontColor=fontColor; 打破 } } 如果(fontColor!=PrefactModFontColor)fontColor=PrefactOrgFontColor; } Rect offsetRect=new Rect(selectionRect.position+offset,selectionRect.size); EditorGUI.DrawRect(selectionRect,backgroundColor); EditorGUI.LabelField(offsetRect,obj.name,新GUIStyle()) { normal=new GUIStyleState(){textColor=fontColor}, fontStyle=styleFont } ); } } }
我添加了以下部分:C# 为什么脚本只使用渲染器组件为某些对象着色? 使用System.Linq; 使用UnityEditor; 使用UnityEngine; //改编自Unity3DCollege YouTube视频教程https://www.youtube.com/watch?v=pdDrY8Mc2lU [初始化加载] 公共类CustomHierarchy:单行为 { 专用静态向量2偏移=新向量2(0,2); 公共静态颜色gameObjectFontColor=Color.black; 公共静态颜色=Color.black; 公共静态颜色=Color.white; 公共静态颜色不活动颜色=新颜色(0.01f、0.4f、0.25f); 静态CustomHierarchy() { EditorApplication.hierarchyWindowItemOnGUI+=HandleHierarchyWindowItemOnGUI; } 私有静态void HandleHierarchyWindowItemOnGUI(int-instanceID,Rect-selectionRect) { Color fontColor=游戏对象fontColor; 颜色背景颜色=新颜色(.76f、.76f、.76f); FontStyleFont=FontStyle.Normal; var obj=EditorUtility.InstanceIDToObject(instanceID); GameObject gameObj=EditorUtility.InstanceIDToObject(instanceID)作为GameObject; if(Selection.instanceID.Contains(instanceID)) { 背景色=新颜色(0.24f、0.48f、0.90f); } 如果(obj!=null) { var prefactType=prefactUtility.getPrefactType(obj); if(gameObj.activeInHierarchy==false) { 背景颜色=不活动颜色; } if(gameObj.GetComponent()==true) { fontColor=Color.yellow; } if(prefableType==prefableType.prefableInstance) { styleFont=FontStyle.Bold; PropertyModification[]PrefactMods=PrefactUtility.GetPropertyModifications(obj); foreach(PrefactMods中的PropertyModification PrefactMod) { if(PrefactMod.propertyPath.ToString()!=“m_Name”&&PrefactMod.propertyPath.ToString()!=“m_LocalPosition.x”&&PrefactMod.propertyPath.ToString()!=“m_LocalPosition.y”&&PrefactMod.propertyPath.ToString()!=“m_LocalPosition.z”&&PrefactMod.propertyPath.ToString()!=“m(LocalRotation.x”&&PrefactMod.propertyPath.ToString()!=“m(LocalRotation.y”&&PrefactMod.propertyPath.ToString()!=“m_LocalRotation.z”&&PrefactMod.propertyPath.ToString()!=“m_LocalRotation.w”&&PrefactMod.propertyPath.ToString()!=“m_RootOrder”&&PrefactMod.propertyPath.ToString()!=“m_IsActive”) { fontColor=fontColor; 打破 } } 如果(fontColor!=PrefactModFontColor)fontColor=PrefactOrgFontColor; } Rect offsetRect=new Rect(selectionRect.position+offset,selectionRect.size); EditorGUI.DrawRect(selectionRect,backgroundColor); EditorGUI.LabelField(offsetRect,obj.name,新GUIStyle()) { normal=new GUIStyleState(){textColor=fontColor}, fontStyle=styleFont } ); } } },c#,unity3d,C#,Unity3d,我添加了以下部分: using System.Linq; using UnityEditor; using UnityEngine; //Adapted from Unity3DCollege YouTube Video Tutorial https://www.youtube.com/watch?v=pdDrY8Mc2lU [InitializeOnLoad] public class CustomHierarchy : MonoBehaviour { private static V
using System.Linq;
using UnityEditor;
using UnityEngine;
//Adapted from Unity3DCollege YouTube Video Tutorial https://www.youtube.com/watch?v=pdDrY8Mc2lU
[InitializeOnLoad]
public class CustomHierarchy : MonoBehaviour
{
private static Vector2 offset = new Vector2(0, 2);
public static Color gameObjectFontColor = Color.black;
public static Color prefabOrgFontColor = Color.black;
public static Color prefabModFontColor = Color.white;
public static Color inActiveColor = new Color(0.01f, 0.4f, 0.25f);
static CustomHierarchy()
{
EditorApplication.hierarchyWindowItemOnGUI += HandleHierarchyWindowItemOnGUI;
}
private static void HandleHierarchyWindowItemOnGUI(int instanceID, Rect selectionRect)
{
Color fontColor = gameObjectFontColor;
Color backgroundColor = new Color(.76f, .76f, .76f);
FontStyle styleFont = FontStyle.Normal;
var obj = EditorUtility.InstanceIDToObject(instanceID);
GameObject gameObj = EditorUtility.InstanceIDToObject(instanceID) as GameObject;
if (Selection.instanceIDs.Contains(instanceID))
{
backgroundColor = new Color(0.24f, 0.48f, 0.90f);
}
if (obj != null)
{
var prefabType = PrefabUtility.GetPrefabType(obj);
if (gameObj.activeInHierarchy == false)
{
backgroundColor = inActiveColor;
}
if(gameObj.GetComponent<Renderer>() == true)
{
fontColor = Color.yellow;
}
if (prefabType == PrefabType.PrefabInstance)
{
styleFont = FontStyle.Bold;
PropertyModification[] prefabMods = PrefabUtility.GetPropertyModifications(obj);
foreach (PropertyModification prefabMod in prefabMods)
{
if (prefabMod.propertyPath.ToString() != "m_Name" && prefabMod.propertyPath.ToString() != "m_LocalPosition.x" && prefabMod.propertyPath.ToString() != "m_LocalPosition.y" && prefabMod.propertyPath.ToString() != "m_LocalPosition.z" && prefabMod.propertyPath.ToString() != "m_LocalRotation.x" && prefabMod.propertyPath.ToString() != "m_LocalRotation.y" && prefabMod.propertyPath.ToString() != "m_LocalRotation.z" && prefabMod.propertyPath.ToString() != "m_LocalRotation.w" && prefabMod.propertyPath.ToString() != "m_RootOrder" && prefabMod.propertyPath.ToString() != "m_IsActive")
{
fontColor = prefabModFontColor;
break;
}
}
if (fontColor != prefabModFontColor) fontColor = prefabOrgFontColor;
}
Rect offsetRect = new Rect(selectionRect.position + offset, selectionRect.size);
EditorGUI.DrawRect(selectionRect, backgroundColor);
EditorGUI.LabelField(offsetRect, obj.name, new GUIStyle()
{
normal = new GUIStyleState() { textColor = fontColor },
fontStyle = styleFont
}
);
}
}
}
if(gameObj.GetComponent()==true)
{
fontColor=Color.yellow;
}
但是在层次中,大多数带有网格渲染器的对象都是黑色的,只有一些是黄色的
我想把层次结构中的所有游戏对象用黄色涂成网格渲染器或渲染器组件。可能所有没有渲染器组件的游戏对象都是红色的。我认为预设的颜色会变成黑色,即使它有渲染器,因为 如果(fontColor!=PrefactModFontColor)fontColor=PrefactOrgFontColor 也许试试这样的
if(gameObj.GetComponent<Renderer>() == true)
{
fontColor = Color.yellow;
}
if(fontColor!=fontColor)
{
if(gameObj.GetComponent()==true)
fontColor=Color.yellow;
其他的
fontColor=fontColor;
}
正在工作。我不得不在其他地方添加一些IF/ELSE,但它起作用了。谢谢
if (fontColor != prefabModFontColor)
{
if(gameObj.GetComponent<Renderer>() == true)
fontColor = Color.yellow;
else
fontColor = prefabOrgFontColor;
}