本文整理汇总了C#中UnityEditor.SerializedObject.UpdateIfDirtyOrScript方法的典型用法代码示例。如果您正苦于以下问题:C# SerializedObject.UpdateIfDirtyOrScript方法的具体用法?C# SerializedObject.UpdateIfDirtyOrScript怎么用?C# SerializedObject.UpdateIfDirtyOrScript使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UnityEditor.SerializedObject
的用法示例。
在下文中一共展示了SerializedObject.UpdateIfDirtyOrScript方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BuildAllSource
public void BuildAllSource(MB3_TextureBaker mom)
{
SerializedObject tbr = new SerializedObject(mom);
SerializedProperty resultMaterials = tbr.FindProperty("resultMaterials");
MB3_TextureBakerEditorInternal.ConfigureMutiMaterialsFromObjsToCombine (mom,resultMaterials,tbr);
tbr.UpdateIfDirtyOrScript();
}
示例2: ConfigureMutiMaterialsFromObjsToCombine
public static void ConfigureMutiMaterialsFromObjsToCombine(MB3_TextureBaker mom, SerializedProperty resultMaterials, SerializedObject textureBaker){
if (mom.GetObjectsToCombine().Count == 0){
Debug.LogError("You need to add some objects to combine before building the multi material list.");
return;
}
if (resultMaterials.arraySize > 0){
Debug.LogError("You already have some source to combined material mappings configured. You must remove these before doing this operation.");
return;
}
if (mom.textureBakeResults == null){
Debug.LogError("Material Bake Result asset must be set before using this operation.");
return;
}
Dictionary<Shader,List<Material>> shader2Material_map = new Dictionary<Shader, List<Material>>();
Dictionary<Material,Mesh> obUVobject2material_map = new Dictionary<Material,Mesh>();
//validate that the objects to be combined are valid
for (int i = 0; i < mom.GetObjectsToCombine().Count; i++){
GameObject go = mom.GetObjectsToCombine()[i];
if (go == null) {
Debug.LogError("Null object in list of objects to combine at position " + i);
return;
}
Renderer r = go.GetComponent<Renderer>();
if (r == null || (!(r is MeshRenderer) && !(r is SkinnedMeshRenderer))){
Debug.LogError("GameObject at position " + i + " in list of objects to combine did not have a renderer");
return;
}
if (r.sharedMaterial == null){
Debug.LogError("GameObject at position " + i + " in list of objects to combine has a null material");
return;
}
}
//first pass put any meshes with obUVs on their own submesh if not fixing OB uvs
if (!mom.fixOutOfBoundsUVs){
for (int i = 0; i < mom.GetObjectsToCombine().Count; i++){
GameObject go = mom.GetObjectsToCombine()[i];
Mesh m = MB_Utility.GetMesh(go);
Rect dummy = new Rect();
MB_Utility.MeshAnalysisResult dummyMar = new MB_Utility.MeshAnalysisResult();
Renderer r = go.GetComponent<Renderer>();
for (int j = 0; j < r.sharedMaterials.Length; j++){
if (MB_Utility.hasOutOfBoundsUVs(m, ref dummy, ref dummyMar, j)){
if (!obUVobject2material_map.ContainsKey(r.sharedMaterials[j])){
Debug.LogWarning("Object " + go + " submesh " + j + " uses UVs outside the range 0,0..1,1 to generate tiling. This object has been mapped to its own submesh in the combined mesh. It can share a submesh with other objects that use different materials if you use the fix out of bounds UVs feature which will bake the tiling");
obUVobject2material_map.Add(r.sharedMaterials[j],m);
}
}
}
}
}
//second pass put other materials without OB uvs in a shader to material map
for (int i = 0; i < mom.GetObjectsToCombine().Count; i++){
Renderer r = mom.GetObjectsToCombine()[i].GetComponent<Renderer>();
for (int j = 0; j < r.sharedMaterials.Length; j++){
if (!obUVobject2material_map.ContainsKey(r.sharedMaterials[j])) {
if (r.sharedMaterials[j] == null) continue;
List<Material> matsThatUseShader = null;
if (!shader2Material_map.TryGetValue(r.sharedMaterials[j].shader, out matsThatUseShader)){
matsThatUseShader = new List<Material>();
shader2Material_map.Add(r.sharedMaterials[j].shader, matsThatUseShader);
}
if (!matsThatUseShader.Contains(r.sharedMaterials[j])) matsThatUseShader.Add(r.sharedMaterials[j]);
}
}
}
if (shader2Material_map.Count == 0 && obUVobject2material_map.Count == 0) Debug.LogError("Found no materials in list of objects to combine");
mom.resultMaterials = new MB_MultiMaterial[shader2Material_map.Count + obUVobject2material_map.Count];
string pth = AssetDatabase.GetAssetPath(mom.textureBakeResults);
string baseName = Path.GetFileNameWithoutExtension(pth);
string folderPath = pth.Substring(0,pth.Length - baseName.Length - 6);
int k = 0;
foreach(Shader sh in shader2Material_map.Keys){
List<Material> matsThatUse = shader2Material_map[sh];
MB_MultiMaterial mm = mom.resultMaterials[k] = new MB_MultiMaterial();
mm.sourceMaterials = matsThatUse;
string matName = folderPath + baseName + "-mat" + k + ".mat";
Material newMat = new Material(Shader.Find("Diffuse"));
if (matsThatUse.Count > 0 && matsThatUse[0] != null){
MB3_TextureBaker.ConfigureNewMaterialToMatchOld(newMat, matsThatUse[0]);
}
AssetDatabase.CreateAsset(newMat, matName);
mm.combinedMaterial = (Material) AssetDatabase.LoadAssetAtPath(matName,typeof(Material));
k++;
}
foreach(Material m in obUVobject2material_map.Keys){
MB_MultiMaterial mm = mom.resultMaterials[k] = new MB_MultiMaterial();
mm.sourceMaterials = new List<Material>();
mm.sourceMaterials.Add(m);
string matName = folderPath + baseName + "-mat" + k + ".mat";
Material newMat = new Material(Shader.Find("Diffuse"));
MB3_TextureBaker.ConfigureNewMaterialToMatchOld(newMat,m);
AssetDatabase.CreateAsset(newMat, matName);
mm.combinedMaterial = (Material) AssetDatabase.LoadAssetAtPath(matName,typeof(Material));
k++;
}
textureBaker.UpdateIfDirtyOrScript();
//.........这里部分代码省略.........
示例3: OnInspectorGUI
public override void OnInspectorGUI() {
serializedObject.UpdateIfDirtyOrScript();
MadGUI.PropertyField(draggable, "Draggable", MadGUI.ObjectIsSet);
MadGUI.PropertyField(startDepth, "Start Depth", "Depth value of first layer added. "
+ "Every next layer will receive +1 to it's depth value.");
MadGUI.PropertyField(ignoreXMovement, "Ignore X Movement");
MadGUI.PropertyField(ignoreYMovement, "Ignore Y Movement");
serializedObject.ApplyModifiedProperties();
MadGUI.Info("Add new layers, then select them to edit properties for each layer.");
var arrayList = new MadGUI.ArrayList<MadLevelBackgroundLayer>(script.layers, (layer) => {
if (layer == null) {
return null;
}
var so = new SerializedObject(layer);
so.UpdateIfDirtyOrScript();
var texture = so.FindProperty("texture");
EditorGUILayout.BeginHorizontal();
MadGUI.PropertyField(texture, "");
MadGUI.ConditionallyEnabled(CanMoveUp(layer), () => {
if (GUILayout.Button("Up")) {
MoveUp(layer);
}
});
MadGUI.ConditionallyEnabled(CanMoveDown(layer), () => {
if (GUILayout.Button("Down")) {
MoveDown(layer);
}
});
GUI.color = Color.yellow;
if (GUILayout.Button("Select")) {
Selection.activeGameObject = layer.gameObject;
}
GUI.color = Color.white;
EditorGUILayout.EndHorizontal();
if (so.ApplyModifiedProperties()) {
layer.SetDirty();
}
return layer;
});
arrayList.addLabel = "Add Layer";
arrayList.emptyLabel = "There are currently no layers.";
arrayList.createFunctionGeneric = () => {
var layer = MadTransform.CreateChild<MadLevelBackgroundLayer>(script.transform, "layer (empty)");
layer.GetComponent<MadSprite>().hideFlags = HideFlags.HideInInspector;
return layer;
};
arrayList.onRemove = (layer) => layer.Cleanup();
arrayList.beforeAdd = () => {
MadUndo.RecordObject(script, "Add Background Layer");
MadUndo.LegacyRegisterSceneUndo("Add Background Layer");
};
arrayList.beforeRemove = (arg) => {
MadUndo.RecordObject(script, "Remove Background Layer");
MadUndo.LegacyRegisterSceneUndo("Remove Background Layer");
};
if (arrayList.Draw()) {
EditorUtility.SetDirty(script);
}
EditorGUI.BeginChangeCheck();
if (EditorGUI.EndChangeCheck()) {
// changed
}
}