|
|
|
|
|
|
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; |
|
|
|