//Will search for all fields on a component, encapsulate them in a TransferableField instance and return them as list private void ObtainFields(TransferableType transferableType) { var fields = GetFieldsForType(transferableType.ComponentType); transferableType.Fields = fields.Select(f => new TransferableField() { Field = f, IsActivated = true }).ToList(); }
//Transfers all selected values from an old object's component to the corresponding new component private void TransferSingleComponent(TransferableType type, GameObject oldObject, GameObject newlyCreatedPrefab) { Component oldComponent = GameObjectHelper.GetComponentInAllChildren(oldObject, type.ComponentType); Component newComponent = GameObjectHelper.GetComponentInAllChildren(newlyCreatedPrefab, type.ComponentType); try { type.Fields.Where(f => f.IsActivated).Select(fi => fi.Field).ToList().ForEach(mf => mf.SetValue(newComponent, mf.GetValue(oldComponent))); } catch { Debug.LogWarning("An error occurred when transfering values for " + type.ComponentType.Name); } }