Newer
Older
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
public class RenderSettingApplier {
public void Apply(IRenderSettingPreset preset) {
foreach (VisualBlueprint b in preset.GetVisualBlueprints()) {
Apply(b);
}
}
public void Apply(VisualBlueprint blueprint) {
WJohnM18
committed
try {
GameObject[] allObjects = GameObject.FindGameObjectsWithTag(blueprint.GetName());
WJohnM18
committed
foreach (GameObject currObject in allObjects) {
if (currObject.activeInHierarchy) {
ReplaceVisualComponents(currObject, blueprint.GetBlueprintObject());
}
WJohnM18
committed
Debug.Log("Applying blueprint: " + blueprint.GetName() + " to object: " + currObject.name);
}
} catch (UnityEngine.UnityException e) {
Debug.Log("No objects in scene with tag: " + blueprint.GetName() + " exist");
WJohnM18
committed
}
/**
Replace the visual components of the target with those of the reference
**/
private void ReplaceVisualComponents(GameObject target, GameObject reference)
{
HashSet<System.Type> componentTypes = new HashSet<System.Type>();
componentTypes.Add(typeof(Collider));
componentTypes.Add(typeof(MeshFilter));
componentTypes.Add(typeof(Renderer));
foreach (System.Type t in componentTypes) {
Component targetComponent = target.GetComponent(t);
Undo.RecordObject(targetComponent, "Paste setting blueprint values");
EditorUtility.CopySerializedIfDifferent(reference.GetComponent(t), targetComponent);
EditorUtility.SetDirty(targetComponent);