public void Export(string fileName) { ExtraData extraData = GetComponent <ExtraData>(); if (extraData == null) { return; } var position = transform.position; Body body = new Body(extraData, name, position.x, position.y, transform.eulerAngles.z); Collider2D[] colliders = GetComponents <Collider2D>(); foreach (Collider2D collider in colliders) { if (collider is PolygonCollider2D polyCol) { Polygon polygon = new Polygon(); foreach (Vector2 p in polyCol.points) { var localScale = transform.localScale; polygon.AddNode(p.x * localScale.x, p.y * localScale.y); } body.AddShape(polygon); } else if (collider is CircleCollider2D circleCol) { var localScale = transform.localScale; var offset = circleCol.offset; Circle circle = new Circle(offset.x * localScale.x, offset.y * localScale.y, circleCol.radius); body.AddShape(circle); } else if (collider is EdgeCollider2D chainCol) { Chain chain = new Chain(); foreach (Vector2 p in chainCol.points) { var localScale = transform.localScale; chain.AddNode(p.x * localScale.x, p.y * localScale.y); } body.AddShape(chain); } } string bodyData = JsonConvert.SerializeObject(body); StreamWriter streamWriter = new StreamWriter("Assets/Maps/" + fileName + ".txt"); streamWriter.Write(bodyData); streamWriter.Close(); #if UNITY_EDITOR AssetDatabase.ImportAsset("Assets/Maps/" + fileName + ".txt"); #endif }
void ObjectHandler(GameObject o) { ExtraData extraData = o.GetComponent <ExtraData>(); if (extraData == null) { return; } var position = o.transform.position; Body body = new Body(extraData, o.name, position.x, position.y, o.transform.eulerAngles.z); Collider2D[] colliders = o.GetComponents <Collider2D>(); foreach (Collider2D collider in colliders) { if (collider is PolygonCollider2D polyCol) { Polygon polygon = new Polygon(); foreach (Vector2 p in polyCol.points) { var localScale = o.transform.localScale; polygon.AddNode(p.x * localScale.x, p.y * localScale.y); } body.AddShape(polygon); } else if (collider is CircleCollider2D circleCol) { var localScale = o.transform.localScale; var offset = circleCol.offset; Circle circle = new Circle(offset.x * localScale.x, offset.y * localScale.y, circleCol.radius); body.AddShape(circle); } else if (collider is EdgeCollider2D chainCol) { Chain chain = new Chain(); foreach (Vector2 p in chainCol.points) { var localScale = o.transform.localScale; chain.AddNode(p.x * localScale.x, p.y * localScale.y); } body.AddShape(chain); } } _map.AddBody(body); }
//Sending back the parent chain object //Every node that has a branch is identified by looping through and checking Branches.count //Every branch that is listed will be a side chain from the parent chain public Molecule FindLongestChain(List <Node> nodesIn) { Chain parentChain = new Chain(); List <Chain> unsortedChains = GetStartingChains(GetStartingNodes(nodesIn)); List <Chain> parentSegment = new List <Chain>(); List <Chain> sideChains = new List <Chain>(); int sideChainsFound = 0; while (ParentChainsUnfound(parentSegment)) { for (int i = 0; i < unsortedChains.Count; i++) { if (IsUnclassified(unsortedChains[i])) { Chain c = unsortedChains[i]; Node previousNode = c.CurrentNode; Node cn = c.CurrentNode = c.FindNextNode(); if (cn.NodeTag != null) { if (cn.Next) { c.AddNode(cn); } } else { c.CurrentNode = previousNode; cn = c.FindBranchLink(); c.Side = true; cn.AddBranch(c); sideChainsFound++; } previousNode.Checked = true; } if (!SideChainsToFind(sideChainsFound, unsortedChains.Count)) { foreach (Chain c in unsortedChains) { if (c.Parent == false && c.Side == false) { c.Parent = true; parentSegment.Add(c); } } } } } bool finished = false; while (finished == false) { if (parentSegment[0].CurrentNode != parentSegment[1].CurrentNode) { Node nextNode = parentSegment[0].FindNextNode(); if (parentSegment[1].CurrentNode != nextNode) { if (nextNode.HasNeighbor(parentSegment[1].CurrentNode)) { finished = true; } parentSegment[0].AddNode(nextNode); parentSegment[0].CurrentNode = nextNode; } else if (parentSegment[1].CurrentNode == nextNode) { finished = true; } } } parentSegment[0].AddChain(parentSegment[1]); numberParentSegment(parentSegment[0]); Molecule mol = new Molecule(); mol.ParentChain = parentSegment[0]; mol.SideChains = new List <Chain>(); foreach (Chain c in unsortedChains) { if (c.Side) { mol.SideChains.Add(c); } } return(mol); }
public IChain <MessageInfo, LinkInfo <T> > Analize(Assembly[] assemblies, Type[] attributes, Func <Type, bool> messageTypeFilter = null) { var result = new Chain <MessageInfo, LinkInfo <T> >(); if (attributes == null) { throw new ArgumentNullException(nameof(attributes)); //attributes = Core.Defaults.GetAvailableAttributes(); } foreach (var assembly in assemblies) { var types = assembly.GetTypes(); if (messageTypeFilter != null) { types = types.Where(messageTypeFilter).ToArray(); } var messages = types.Where(t => attributes.Any(a => CompilerUtils.MessageTypeHasAttribute(t, a))) .ToArray(); if (messages.Any()) { foreach (var message in messages) { result.AddNode(new ChainNode <MessageInfo>(message.FullName, new MessageInfo() { Type = message, Attributes = CompilerUtils.GetAttributes(message), Interfaces = RemoveBaseTypes(CompilerUtils.GetLinks(message)) })); } } } foreach (var assembly in assemblies) { var types = assembly.GetTypes(); if (messageTypeFilter != null) { types = types.Where(messageTypeFilter).ToArray(); } var messages = types.Where(t => attributes.Any(a => CompilerUtils.MessageTypeHasAttribute(t, a))) .ToArray(); if (messages.Any()) { foreach (var message in messages) { var interfaces = CompilerUtils.GetLinks(message); interfaces = RemoveBaseTypes(interfaces); var msgAttributes = CompilerUtils.GetAttributes(message); var links = _theme.GetThemedLinks(message, msgAttributes, interfaces, result); if (links == null || links.Length == 0) { continue; } foreach (var linkMetadata in links) { result.AddDirectedEdge(result[message.FullName], result[linkMetadata.ToMessage.FullName], linkMetadata.Link); } } } } return(result); }