本文整理汇总了C#中Block.GetComponent方法的典型用法代码示例。如果您正苦于以下问题:C# Block.GetComponent方法的具体用法?C# Block.GetComponent怎么用?C# Block.GetComponent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Block
的用法示例。
在下文中一共展示了Block.GetComponent方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddBlockToMap
/// <summary>
///Add a block to the desired map
/// </summary>
/// <param name="map">
/// The map to which you wish to add a block
/// </param>
/// <param name="b">
/// The instantiated Block object that you wish to add to the map (if null, will add an EmptyBlock object)
/// </param>
/// <param name="randomise">
/// Randomise the variant of this Block upon addition to the map?
/// </param>
/// <param name="variation">
/// If not randomising, feel free to pass through the index of the variation you wish to display
/// </param>
/// <param name="refreshUponAddition">
/// Refresh the surrounding blocks upon addition to the map?
/// </param>
/// <param name="x">
/// The target x coordinate
/// </param>
/// <param name="y">
/// The target y coordinate
/// </param>
/// <param name="depth">
/// The depth to which to add the block
/// </param>
/// <param name="destroyExistingImmediate">
/// Use DestroyImmediate or Destroy when removing the existing block? (You must use immediate from within the Editor, and cannot use it once physics collisions)
/// </param>
/// <param name="addEmptyWhenNull">
/// When passing 'null', should we add an empty block, or should we simply destroy the space and leave it?
/// </param>
public static void AddBlockToMap(BlockMap map, Block b, bool randomise, int variation, bool refreshUponAddition, int x, int y, int depth, bool destroyExistingImmediate, bool addEmptyWhenNull){
if(b == null && addEmptyWhenNull){
b = GetEmptyBlock(map);
}
MapChunk m = map.GetChunkForBlockCoordinate(x,y,depth);
if(m == null){
int mx = 0;
mx = (int)((float)x / (float)map.chunkWidth);
int my = 0;
my = (int)((float)y / (float)map.chunkHeight);
MapChunk mc = GetChunkPrefab();
map.Editor_AddChunkAt(mx,my,depth,mc,true);
if(destroyExistingImmediate){
GameObject.DestroyImmediate(mc.gameObject);
}
else{
GameObject.Destroy(mc.gameObject);
}
m = map.GetChunkForBlockCoordinate(x,y,depth);
Block[] cb = new Block[map.chunkWidth * map.chunkHeight];
m.Editor_InitializeChunk(cb);
}
//Block eb = map.GetBlockAt(x,y,depth);
map.SetBlockAt(x,y,depth,null,destroyExistingImmediate);
map.SetBlockAt(x,y,depth,b,destroyExistingImmediate);
if(randomise && b != null){
b.RandomiseVariant();
}
else if(b != null && variation != 0){
b.SetVariant(variation);
}
if(refreshUponAddition){
RefreshBlock(map,x,y,depth);
}
if(b != null && !b.retainCollider){
Collider c = b.GetComponent<Collider>();
if(c != null){
if(addEmptyWhenNull){
c.isTrigger = true;
}
else{
if(destroyExistingImmediate){
GameObject.DestroyImmediate(c);
}
else{
//.........这里部分代码省略.........
示例2: SetupSlide
void SetupSlide(Block block, BlockSlider.SlideDirection direction)
{
// Save off the state of the block that this one will swap with
Block targetBlock = null;
if (direction == BlockSlider.SlideDirection.Left)
{
targetBlock = board.Blocks [block.X - 1, block.Y];
}
if (direction == BlockSlider.SlideDirection.Right)
{
targetBlock = board.Blocks [block.X + 1, block.Y];
}
BlockSlider slider = block.GetComponent<BlockSlider>();
slider.TargetState = targetBlock.State;
slider.TargetType = targetBlock.Type;
}
示例3: Update
void Update ()
{
mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
Vector3 worldPoint = Camera.main.ScreenToWorldPoint(Input.mousePosition);
RaycastHit2D hit;
if (Input.GetMouseButtonDown(0))
{
hit = Physics2D.Raycast(new Vector2(worldPoint.x, worldPoint.y), Vector3.forward, Mathf.Infinity);
if(hit.transform != null)
{
block = hit.transform.GetComponent<Block>();
if (block != null) {
if (block.Interactive)
{
var hitRb = hit.transform.GetComponent<Rigidbody2D>();
var vol = 0.05f;// + hitRb.mass / 50f;
var pitch = 1.0f - hitRb.mass/20f;
Debug.Log("Rb: " + vol + " " + pitch);
AudioManager.Instance.Play(GrabClip, GrabMixer, vol, vol, pitch, pitch);
spawnedPrefab = Instantiate(mousePointPrefab, hit.point, Quaternion.identity) as GameObject;
GrabbedBlock = hit.transform.gameObject;
joint = GrabbedBlock.GetComponent<SpringJoint2D>();
coll = GrabbedBlock.GetComponent<Collider2D> ();
grabbedRB = GrabbedBlock.GetComponent<Rigidbody2D>();
joint.enabled = true;
coll.isTrigger = false;
GrabbedBlock.layer = 0;
grabbedRB.isKinematic = false;
if (block.IsNew) {
Vector2 dist = hit.point - (Vector2)block.transform.position;
dist /= SpawnBlock.SpawnSize;
block.transform.position = hit.point - dist;
block.transform.localScale = block.GetComponent<Block>().OriginalScale;
}
joint.connectedBody = spawnedPrefab.GetComponent<Rigidbody2D>();
joint.anchor = GrabbedBlock.transform.InverseTransformPoint(spawnedPrefab.transform.position);
}
}
}
}
if (Input.GetMouseButtonUp (0) && !inSpawn) {
if (spawnedPrefab != null) {
if (block.IsNew) {
usedBlocks++;
block.inPlay = true;
GrabbedBlock.tag = "Block";
SpawnBlock.instance.BlockSpawn ();
}
joint.enabled = false; // this fixing a major bug (I guess we won't need it anyway?)
block.IsNew = false;
if (GameManager.Instance.LockOldBlockInput) {
block.Interactive = false;
}
GrabbedBlock.transform.parent = null;
GrabbedBlock = null;
Destroy (spawnedPrefab.gameObject);
}
}
if (Input.GetMouseButtonUp (0) && inSpawn && block.IsNew) {
GrabbedBlock.transform.localScale = Vector3.one;
GrabbedBlock.transform.localScale *= SpawnBlock.SpawnSize;
coll.isTrigger = true;
GrabbedBlock.layer = 7;
grabbedRB.isKinematic = true;
Destroy (spawnedPrefab.gameObject);
joint.anchor = new Vector2(0f,0f);
joint.connectedBody = null;
GrabbedBlock.transform.eulerAngles = new Vector3(0, 0, GrabbedBlock.GetComponent<Block>().SpawnAngle);
GrabbedBlock.transform.rotation = Quaternion.identity;
GrabbedBlock.transform.position = mainSpawnPoint.transform.position;
}
}