void BlockChanged(Vector3I p, BlockID old, BlockID now) { if (!Enabled) { return; } int index = (p.Y * length + p.Z) * width + p.X; BlockRaw nowB = (BlockRaw)now, oldB = (BlockRaw)old; if (nowB == Block.Air && IsEdgeWater(p.X, p.Y, p.Z)) { nowB = Block.StillWater; game.UpdateBlock(p.X, p.Y, p.Z, Block.StillWater); } if (nowB == Block.Air) { PhysicsAction delete = OnDelete[oldB]; if (delete != null) { delete(index, oldB); } } else { PhysicsAction place = OnPlace[nowB]; if (place != null) { place(index, nowB); } } ActivateNeighbours(p.X, p.Y, p.Z, index); }
void BlockChanged(object sender, BlockChangedEventArgs e) { if (!Enabled) { return; } Vector3I p = e.Coords; int index = (p.Y * length + p.Z) * width + p.X; BlockID block = e.Block; if (block == Block.Air && IsEdgeWater(p.X, p.Y, p.Z)) { block = Block.StillWater; game.UpdateBlock(p.X, p.Y, p.Z, Block.StillWater); } if (e.Block == 0) { PhysicsAction delete = OnDelete[e.OldBlock]; if (delete != null) { delete(index, e.OldBlock); } } else { PhysicsAction place = OnPlace[block]; if (place != null) { place(index, block); } } ActivateNeighbours(p.X, p.Y, p.Z, index); }
public static PhysicsAction GetSSAction(Vector3 target, float speed) { PhysicsAction action = ScriptableObject.CreateInstance <PhysicsAction>(); action.forces = target * speed; return(action); }
void TickRandomBlocks() { int xMax = width - 1, yMax = height - 1, zMax = length - 1; for (int y = 0; y < height; y += 16) { for (int z = 0; z < length; z += 16) { for (int x = 0; x < width; x += 16) { int lo = (y * length + z) * width + x; int hi = (Math.Min(yMax, y + 15) * length + Math.Min(zMax, z + 15)) * width + Math.Min(xMax, x + 15); // Inlined 3 random ticks for this chunk int index = rnd.Next(lo, hi); BlockRaw block = map.blocks1[index]; PhysicsAction tick = OnRandomTick[block]; //if (tick != null) tick(index, block); index = rnd.Next(lo, hi); block = map.blocks1[index]; tick = OnRandomTick[block]; //if (tick != null) tick(index, block); index = rnd.Next(lo, hi); block = map.blocks1[index]; tick = OnRandomTick[block]; //if (tick != null) tick(index, block); } } } }
public List <GameObject> GetUFOs(int round, ActionType type) { List <GameObject> ufos = new List <GameObject>(); var count = GetUFOCount(round); for (int i = 0; i < count; ++i) { var index = random.Next(3); var obj = factory.GetUFO(colors[index], type); obj.transform.position = GetRandomPosition(); var ufo = obj.GetComponent <UFO>(); ufo.score = GetScore(round, index); ufo.visible = true; var speed = GetSpeed(round); var direction = GetRandomDirection(type); if (type == ActionType.Kinematics) { KinematicsAction action = KinematicsAction.GetAction(direction, speed); actionManager.AddAction(obj, action); } else { PhysicsAction action = PhysicsAction.GetAction(direction, speed); actionManager.AddAction(obj, action); } ufos.Add(obj); } return(ufos); }
void BlockChanged(object sender, BlockChangedEventArgs e) { if (!Enabled) { return; } Vector3I p = e.Coords; int index = (p.Y * length + p.Z) * width + p.X; BlockRaw newB = (BlockRaw)e.Block, oldB = (BlockRaw)e.OldBlock; if (newB == Block.Air && IsEdgeWater(p.X, p.Y, p.Z)) { newB = Block.StillWater; game.UpdateBlock(p.X, p.Y, p.Z, Block.StillWater); } if (newB == Block.Air) { PhysicsAction delete = OnDelete[oldB]; if (delete != null) { delete(p, oldB); } } else { PhysicsAction place = OnPlace[newB]; if (place != null) { place(p, newB); } } ActivateNeighbours(p.X, p.Y, p.Z, index); }
public void flyUFO(GameObject disk, Vector3 target, float speed) { action = PhysicsAction.GetSSAction(target, speed); if (disk.GetComponent <Rigidbody>() == null) { disk.AddComponent <Rigidbody>(); disk.GetComponent <Rigidbody>().constraints = RigidbodyConstraints.FreezeRotationX | RigidbodyConstraints.FreezeRotationZ; } this.RunAction(disk, action, this); }
public static PhysicsAction GetAction(Vector3 direction, float speed) { PhysicsAction action = ScriptableObject.CreateInstance <PhysicsAction>(); action.direction = direction; action.speed = speed; action.destroy = false; action.enable = true; return(action); }
/// <summary> Activates the block at the particular packed coordinates. </summary> public void Activate(int index) { BlockID block = map.blocks[index]; PhysicsAction activate = OnActivate[block]; if (activate != null) { activate(index, block); } }
/// <summary> Activates the block at the particular packed coordinates. </summary> public void Activate(Vector3I pos) { BlockRaw block = (BlockRaw)map.SafeGetBlock(pos.X, pos.Y, pos.Z); PhysicsAction activate = OnActivate[block]; if (activate != null) { activate(pos, block); } }
private float power; // 控制飞碟速度的变量 public static PhysicsAction GetAction(Vector3 direction, float angle, float power) { // 初始化飞碟的初速度方向 PhysicsAction action = CreateInstance <PhysicsAction>(); if (direction.x == -1) { action.startDirection = Quaternion.Euler(new Vector3(0, 0, -angle)) * Vector3.left * power; } else { action.startDirection = Quaternion.Euler(new Vector3(0, 0, angle)) * Vector3.right * power; } action.power = power; return(action); }
public virtual void Dispose() { if (IsDisposed) { return; } Body = null; OnMove = null; OnStopMove = null; OnPhysicsUpdate = null; OnPhysicsLateUpdate = null; OnReceiveForce = null; OnReceiveImpulse = null; IsDisposed = true; }
public PhysicsAction physics; // 物理动作 // 管理飞行 public void Fly(GameObject disk, float angle, float power) { physics = PhysicsAction.GetAction(disk.GetComponent <DiskData>().direction, angle, power); this.RunAction(disk, physics, this); }