private void Copy() { var scaleProp = RelProp(Target, _layerMaskScaleProperty); var offsetProp = RelProp(Target, _layerMaskOffsetProperty); var data = new CopyPasteData( scaleProp == null ? (Vector2?)null : scaleProp.vector2Value, offsetProp == null ? (Vector2?)null : offsetProp.vector2Value, _channel1.Copy(RelProp(Target, _channel1Property)), _channel2.Copy(RelProp(Target, _channel2Property)), _channel3.Copy(RelProp(Target, _channel3Property)), _channel4.Copy(RelProp(Target, _channel4Property)) ); EditorGUIUtility.systemCopyBuffer = JsonUtility.ToJson(data, true); }
public static void Copy(object c) { clipboard.Clear(); if (c == null) { return; } if ((c as MochaInterface.Component).myType == "CScript") { MochaInterface.CScript cscript = MochaEditor.CastingHelper.CastTo <MochaInterface.CScript>((MochaInterface.Component)c); MochaScriptSystem.BoundScript bs = MochaScriptSystem.ScriptSubsystemManaged.getInstance().GetBoundScriptFromCScript(cscript); stored_type = bs.scriptObject.GetType(); foreach (var pi in bs.scriptObject.GetType().GetProperties()) { if (pi.Name == "gameObject") { continue; //do not copy the gameObject this is bound to } if (pi.GetCustomAttribute <MochaDoNotShow>() != null) { continue; } CopyPasteData pd = new CopyPasteData() { name = pi.Name, value = pi.GetValue(bs.scriptObject) }; clipboard.Add(pd); } return; } stored_type = c.GetType(); MochaEditor.PropertyValueConverter pvc = new MochaEditor.PropertyValueConverter(); foreach (MochaEditor.PropertyValueConverter.PropertyInfo pi in (ObservableCollection <MochaEditor.PropertyValueConverter.PropertyInfo>)pvc.Convert(c, null, "Component", null)) { CopyPasteData pd = new CopyPasteData() { name = pi.PropertyName, value = pi.PropertyValue }; clipboard.Add(pd); } }
static string SerializeGraphElementsImplementation(IEnumerable <GraphElement> elements) { List <ScriptableObject> data = new List <ScriptableObject>(); foreach (var element in elements) { if (element.userData is MathNode mathNode) { data.Add(mathNode); } else if (element.userData is MathPlacemat mathPlacemat) { data.Add(mathPlacemat); } } CopyPasteData <ScriptableObject> copyPasteData = new CopyPasteData <ScriptableObject>(data); return(m_SerializedDataMimeType + " " + JsonUtility.ToJson(copyPasteData)); }
public void Test_DuplicateCommand_OneNode([Values] TestingMode mode) { GraphModel.CreateNode <Type0FakeNodeModel>("Node0", Vector2.zero); TestPrereqCommandPostreq(mode, () => { Assert.That(GetNodeCount(), Is.EqualTo(1)); var nodeModel = GetNode(0); Assert.That(nodeModel, Is.TypeOf <Type0FakeNodeModel>()); CopyPasteData copyPasteData = CopyPasteData.GatherCopiedElementsData(new List <IGraphElementModel> { nodeModel }); return(new PasteSerializedDataCommand("Duplicate", Vector2.one, copyPasteData)); }, () => { Assert.That(GetNodeCount(), Is.EqualTo(2)); Assert.That(GraphModel.NodeModels.Count(n => n == null), Is.Zero); }); }
public static void Copy(object c) { clipboard.Clear(); if (c == null) return; if ((c as MochaInterface.Component).myType == "CScript") { MochaInterface.CScript cscript = MochaEditor.CastingHelper.CastTo<MochaInterface.CScript>((MochaInterface.Component)c); MochaScriptSystem.BoundScript bs = MochaScriptSystem.ScriptSubsystemManaged.getInstance().GetBoundScriptFromCScript(cscript); stored_type = bs.scriptObject.GetType(); foreach (var pi in bs.scriptObject.GetType().GetProperties()) { if (pi.Name == "gameObject") continue; //do not copy the gameObject this is bound to if (pi.GetCustomAttribute<MochaDoNotShow>() != null) continue; CopyPasteData pd = new CopyPasteData() { name = pi.Name, value = pi.GetValue(bs.scriptObject) }; clipboard.Add(pd); } return; } stored_type = c.GetType(); MochaEditor.PropertyValueConverter pvc = new MochaEditor.PropertyValueConverter(); foreach (MochaEditor.PropertyValueConverter.PropertyInfo pi in (ObservableCollection<MochaEditor.PropertyValueConverter.PropertyInfo>)pvc.Convert(c, null, "Component", null)) { CopyPasteData pd = new CopyPasteData() { name = pi.PropertyName, value = pi.PropertyValue }; clipboard.Add(pd); } }
void UnserializeAndPasteImplementation(string operationName, string serializedData) { CopyPasteData <ScriptableObject> data = JsonUtility.FromJson <CopyPasteData <ScriptableObject> >(serializedData.Substring(m_SerializedDataMimeType.Length + 1)); if (data != null) { // Come up with top left most element's position to find the delta we're going to compute from the mouse position var placemats = data.GetPlacemats(); //.Select(e => e.position.position); var topLeftPosition = Vector2.positiveInfinity; var delta = s_CopyOffset; foreach (var placemat in placemats) { var position = placemat.position; if (position.x < topLeftPosition.x) { topLeftPosition = position.position; delta = s_CopyOffset + position.size; } } var ids = new Dictionary <string, string>(); if (data.GetNodes().Any()) { foreach (MathNode mathNode in data.GetNodes()) { string oldID = mathNode.nodeID.ToString(); ids[oldID] = mathNode.RewriteID().ToString(); m_SimpleGraphViewWindow.AddNode(mathNode); mathNode.m_Position += delta; } // Remap ids foreach (MathNode mathNode in data.GetNodes()) { mathNode.RemapReferences(ids); } } if (data.GetPlacemats().Any()) { // ZOrder is 1 based. var nextZ = m_SimpleGraphViewWindow.mathBook.placemats.Count + 1; foreach (MathPlacemat mathPlacemat in data.GetPlacemats().OrderBy(e => e.zOrder)) { string oldID = mathPlacemat.identification; ids[oldID] = mathPlacemat.RewriteID(); mathPlacemat.position = new Rect(mathPlacemat.position.x + delta.x, mathPlacemat.position.y + delta.y, mathPlacemat.position.width, mathPlacemat.position.height); // Put new placemats on top. mathPlacemat.zOrder = nextZ++; } foreach (MathPlacemat mathPlacemat in data.GetPlacemats()) { mathPlacemat.RemapReferences(ids); m_SimpleGraphViewWindow.AddPlacemat(mathPlacemat); } } Reload(data.GetNodes(), data.GetPlacemats(), null, ids); } }