void OnTriggerEnter(Collider other) { // プレイヤーと自身とぶつかっても無視 if (other.GetComponentInParent <Player>() != null) { return; } if (other.isTrigger) { return; } Scaffolds scaffolds = other.transform.GetComponentInParent <Scaffolds>(); if (scaffolds == null && player.rideScaffolds != null && !player.isRide) { player.rideScaffolds = null; player.InitParent(); } }
/** * * \param remainingEdgesIndices list with indices which aren't touched by any scaffold, is not changed * \param scaffoldAppliedSuccessfull is true if an scaffold was applied successfull * \param scaffoldEdges contains all edges of the scaffold, valid only if the application was successful */ private void tryToApplyScaffoldToRemainingEdges(Datastructures.TreeNode graph, List<int> remainingEdgesIndices, out bool scaffoldAppliedSuccessfull, List<int> scaffoldEdges, out Scaffolds.Graph.GraphScaffoldInstanceData instanceData) { int startEdgeIndex; Scaffolds.Graph.GraphScaffold.EnumScaffoldIterationResult scaffoldIterationResult; int subsequentIterationsCount; // array which tells about remainingEdgesIndices which edges were either consumed or tried bool[] consumedEdgeIndex; consumedEdgeIndex = new bool[remainingEdgesIndices.Count]; scaffoldAppliedSuccessfull = false; scaffoldEdges.Clear(); // choose random edge and try to start scaffold from there startEdgeIndex = random.Next(remainingEdgesIndices.Count); instanceData = searchingScaffoldRoot.newInstanceData(); scaffoldIterationResult = searchingScaffoldRoot.firstIteration(instanceData, graph, startEdgeIndex, getVertexPositionByIndexDelegate); if( scaffoldIterationResult == Scaffolds.Graph.GraphScaffold.EnumScaffoldIterationResult.DOESNTMATCH ) { return; } consumedEdgeIndex[startEdgeIndex] = true; subsequentIterationsCount = 0; // is the index of the vertex which was on the last edge consumed int lastVertexIndex; // chose a random vertex of the first edge as our vantage point if( random.Next(2) == 0 ) { Datastructures.TreeNode edgeTreeNode; edgeTreeNode = graph.childNodes[GRAPHINDEXEDGES].childNodes[startEdgeIndex]; lastVertexIndex = edgeTreeNode.childNodes[0].value.valueInt; } else { Datastructures.TreeNode edgeTreeNode; edgeTreeNode = graph.childNodes[GRAPHINDEXEDGES].childNodes[startEdgeIndex]; lastVertexIndex = edgeTreeNode.childNodes[1].value.valueInt; } for(;;) { int edgeI; bool consumedEdge; // indicates if we have consumed an edge in this try consumedEdge = false; // search for a edge which wasn't consumed and contains the lastVertexIndex for( edgeI = 0; edgeI < consumedEdgeIndex.Length; edgeI++ ) { if( consumedEdgeIndex[edgeI] ) { continue; } // we are here if the edge was not jet consumed int edgeIndex; Datastructures.TreeNode edgeTreeNode; edgeIndex = remainingEdgesIndices[edgeI]; edgeTreeNode = graph.childNodes[GRAPHINDEXEDGES].childNodes[edgeIndex]; if( edgeTreeNode.childNodes[0].value.valueInt != lastVertexIndex && edgeTreeNode.childNodes[1].value.valueInt != lastVertexIndex ) { continue; } // we are here if this edge is connected with the last vertex consumedEdgeIndex[edgeI] = true; // we try to consume it with the scaffold scaffoldIterationResult = searchingScaffoldRoot.nextIteration(instanceData, graph, edgeIndex, getVertexPositionByIndexDelegate); if (scaffoldIterationResult == Scaffolds.Graph.GraphScaffold.EnumScaffoldIterationResult.DOESNTMATCH) { continue; } // we are here if we found an edge which the scaffold accepted // now we need to // * add it to the solution // * set the new lastVertexIndex scaffoldEdges.Add(edgeIndex); if (edgeTreeNode.childNodes[0].value.valueInt == lastVertexIndex ) { lastVertexIndex = edgeTreeNode.childNodes[1].value.valueInt; } else // edgeTreeNode.childNodes[1].value.valueInt == lastVertexIndex) { lastVertexIndex = edgeTreeNode.childNodes[0].value.valueInt; } consumedEdge = true; break; } // if we haven't consumed an edge we are done, because we don't have any other possibilities if( !consumedEdge ) { break; } subsequentIterationsCount++; } // if there was no subsequent application the scaffold was not really applied if( subsequentIterationsCount < 1 ) { return; } scaffoldAppliedSuccessfull = true; }