浏览代码

Add menu item to re-place all multi-materials in the oppened scene.

/Yibing-Project-2
Remy 7 年前
当前提交
0ba87b81
共有 2 个文件被更改,包括 33 次插入24 次删除
  1. 11
      Tests/GraphicsTests/RenderPipeline/HDRenderPipeline/CommonAssets/Scripts/Editor/GraphicTestTools.cs
  2. 46
      Tests/GraphicsTests/RenderPipeline/HDRenderPipeline/CommonAssets/Scripts/Editor/MultiMaterialPlacerEditor.cs

11
Tests/GraphicsTests/RenderPipeline/HDRenderPipeline/CommonAssets/Scripts/Editor/GraphicTestTools.cs


}
}
}
[MenuItem("GraphicTest Tools/Update All Material Placers")]
public static void UpdateAllPlacers()
{
MultiMaterialPlacer[] placers = Object.FindObjectsOfType<MultiMaterialPlacer>();
for (int i=0; i<placers.Length; ++i)
{
MultiMaterialPlacerEditor.PlaceObjects(placers[i]);
}
}
}

46
Tests/GraphicsTests/RenderPipeline/HDRenderPipeline/CommonAssets/Scripts/Editor/MultiMaterialPlacerEditor.cs


base.OnInspectorGUI();
if ( GUILayout.Button("Place") )
{
foreach ( Object obj in targets)
foreach (object obj in targets)
MultiMaterialPlacer m = obj as MultiMaterialPlacer;
Material[] materials = PlaceObjects(m);
if (materials != null)
{
foreach (Material mat in materials)
{
UnityEditor.Experimental.Rendering.HDPipeline.HDEditorUtils.ResetMaterialKeywords(mat);
}
}
PlaceObjects(obj as MultiMaterialPlacer);
}
}

}
}
public Material[] PlaceObjects(MultiMaterialPlacer _target)
public static void PlaceObjects(MultiMaterialPlacer _target)
{
//clear hierarchy
for (int i=_target.transform.childCount-1; i>=0; --i)

}
if (_target.prefabObject == null) return null;
if (_target.prefabObject == null) return;
List<Material> outMats = new List<Material>(); ;
List<Material> materials = new List<Material>();
Renderer refObject = Instantiate(_target.prefabObject.gameObject).GetComponent<Renderer>();
if (_target.material != null)

if (_target.is2D)
{
if (_target.instanceParameters.Length < 2) return null;
if (!(_target.instanceParameters[0].multi && _target.instanceParameters[1].multi)) return null;
if (_target.instanceParameters.Length < 2) return;
if (!(_target.instanceParameters[0].multi && _target.instanceParameters[1].multi)) return;
for (int i = 0; i < _target.instanceParameters[0].count; i++)
{

tmp.gameObject.name = _target.prefabObject.name+"_"+ ApplyParameterToMaterial(tmp.sharedMaterial, _target.instanceParameters[0], i);
tmp.gameObject.name += "_"+ApplyParameterToMaterial(tmp.sharedMaterial, _target.instanceParameters[1], j);
outMats.Add(tmp.sharedMaterial);
materials.Add(tmp.sharedMaterial);
y -= _target.offset;
}
x += _target.offset;

{
Renderer tmp = CopyObject(refObject, x, y, _target.transform, _target);
tmp.gameObject.name = _target.prefabObject.name + "_" + ApplyParameterToMaterial(tmp.sharedMaterial, _target.instanceParameters[i]);
outMats.Add(tmp.sharedMaterial);
materials.Add(tmp.sharedMaterial);
}
else
{

Renderer tmp = CopyObject(refObject, x, y, _target.transform, _target);
tmp.gameObject.name = _target.prefabObject.name + "_" + ApplyParameterToMaterial(tmp.sharedMaterial, _target.instanceParameters[i], j);
outMats.Add(tmp.sharedMaterial);
materials.Add(tmp.sharedMaterial);
}
}
}

tmp.gameObject.name = _target.prefabObject.name + "_" + ApplyParameterToMaterial(tmp.sharedMaterial, _target.instanceParameters[i]);
outMats.Add(tmp.sharedMaterial);
materials.Add(tmp.sharedMaterial);
}
}

DestroyImmediate(refObject.gameObject);
return outMats.ToArray();
if (materials != null)
{
foreach (Material mat in materials)
{
UnityEditor.Experimental.Rendering.HDPipeline.HDEditorUtils.ResetMaterialKeywords(mat);
}
}
Renderer CopyObject( Renderer _target, float _x, float _y, Transform _parent, MultiMaterialPlacer _placer )
public static Renderer CopyObject( Renderer _target, float _x, float _y, Transform _parent, MultiMaterialPlacer _placer )
{
Renderer o = Instantiate(_target.gameObject).GetComponent<Renderer>();
o.sharedMaterial = Instantiate(_target.sharedMaterial);

return o;
}
string ApplyParameterToMaterial(Material _mat, MaterialParameterVariation _param)
public static string ApplyParameterToMaterial(Material _mat, MaterialParameterVariation _param)
{
if (_param.multi) return null;
string o = _param.parameter + "_";

return o;
}
string ApplyParameterToMaterial(Material _mat, MaterialParameterVariation _param, int _num)
public static string ApplyParameterToMaterial(Material _mat, MaterialParameterVariation _param, int _num)
{
if (!_param.multi) return null;
if (_param.paramType == MaterialParameterVariation.ParamType.Texture) return null;

正在加载...
取消
保存