// ReSharper disable once InconsistentNaming // ReSharper disable once UnusedMember.Global public void OnGUI() { EditorContent.Space(); EditorContent.BeginObjectChanged(); _tabMode = (TabMode) EditorContent.Tab((int) _tabMode, "Create Preset", "Apply Preset"); if (EditorContent.IsObjectChanged()) { _gameObject = null; _enabledComponents.Clear(); _configurations.Clear(); _preset = null; } EditorContent.Space(); switch (_tabMode) { case TabMode.Save: CreatePresetLayout(); break; case TabMode.Restore: ApplyPresetLayout(); break; } }
// ReSharper disable once UnusedMember.Local // ReSharper disable once InconsistentNaming private void OnGUI() { EditorContent.BeginObjectChanged(); _sourceGameObject = EditorContent.ObjectPicker <GameObject>("Source GameObject", _sourceGameObject, true); if (EditorContent.IsObjectChanged()) { _projections.Clear(); } if (_sourceGameObject == null) { EditorContent.Label("Select the GameObject that you want to project the Component."); return; } _components = _sourceGameObject.GetComponents <Component>(); EditorContent.Label("Components:"); foreach (var component in _components) { var instanceId = component.GetInstanceID(); if (!_projections.ContainsKey(instanceId)) { _projections.Add(instanceId, false); } _projections[instanceId] = EditorContent.Checkbox(ObjectNames.GetInspectorTitle(component), _projections[instanceId]); } EditorContent.Space(); _destinationGameObject = EditorContent.ObjectPicker <GameObject>("Destination GameObject", _destinationGameObject, true); using (EditorContent.DisabledGroup(_destinationGameObject == null || _projections.All(w => !w.Value))) { if (EditorContent.Button("Projection")) { foreach (var sourceComponent in _components.Where(w => _projections[w.GetInstanceID()])) { // ReSharper disable once PossibleNullReferenceException var destComponent = _destinationGameObject.AddComponent(sourceComponent.GetType()); using (var sourceProperties = new SerializedObject(sourceComponent)) using (var destProperties = new SerializedObject(destComponent)) { var iterator = sourceProperties.GetIterator(); while (iterator.NextVisible(true)) { destProperties.CopyFromSerializedProperty(iterator); } destProperties.ApplyModifiedProperties(); } } } } }