public void SnapToSlot(BuildingSnapSlot source_slot, BuildingSnapSlot target_slot) { if (snaped_slot_count == 0) { //暂时放弃控制权。 transform.SetParent(GameFacade.Instance.GetWorldManager().building_root); BuildingObject target_bo = target_slot.building_owner; //rotation float y = target_bo.transform.eulerAngles.y; float this_y = transform.eulerAngles.y; float delta_y = y - this_y; while (delta_y > 90) { delta_y -= 90; } while (delta_y < -90) { delta_y += 90; } Rotate(delta_y); //position Vector3 delta = target_slot.transform.position - source_slot.transform.position; transform.position += delta; transform.localScale = Vector3.one; old_snap_pos = detector_transform.position; } snaped_slot_count++; Debug.Log("Current Snaped Count is " + snaped_slot_count); }
void OnTriggerEnter(Collider other) { ////冲突状态,不要进行吸附,放置两个物块重叠! //LocalPlayer lp = GameFacade.Instance.GetLocalPlayer(); //if (lp.operation_state == EOperationState.Building_Confict) //{ // return; //} //已经放好的,就不要在吸附了,被吸附就可以了 if (building_owner.BuildingBlockState == EPlaceableObjectState.Normal) { return; } if (other.gameObject.tag == "Slot") { BuildingSnapSlot temp_target = other.gameObject.GetComponent <BuildingSnapSlot>(); //不接受的部件,不要进行吸附 if (temp_target.Accept(this)) { this.building_owner.SnapToSlot(this, temp_target); } } }
public bool Accept(BuildingSnapSlot target) { BuildingSnapLimitCondition bsc = limit_conditions.Find(x => x.slot_type == target.output_type); if (bsc != null) { switch (bsc.limit_type) { case EBuildingSnapLimitType.Unlimit: return(true); case EBuildingSnapLimitType.Unique_Slot_Check: Debug.Log("BeginSlotCheck : Unique_Slot_Check pos " + (transform.position + bsc.check_position_shift) + " dir " + bsc.check_direction); LineRenderer lr = GetComponent <LineRenderer>(); if (lr != null) { lr.SetPosition(0, transform.position + bsc.check_position_shift); lr.SetPosition(1, transform.position + bsc.check_position_shift + bsc.check_direction * bsc.check_distance); } RaycastHit result; Physics.Raycast( transform.position + bsc.check_position_shift, bsc.check_direction, out result, bsc.check_distance, LayerMask.GetMask(buildings_mask), QueryTriggerInteraction.Ignore); Debug.Log("snap test " + result.collider); if (result.collider == null) { return(true); } break; } } return(false); }