public override void RenderCloneOverlay(InstanceState instanceState, ref Matrix4x4 matrix4x, Vector3 deltaPosition, float deltaAngle, Vector3 center, bool followTerrain, RenderManager.CameraInfo cameraInfo, Color toolColor) { //if (MoveItTool.m_isLowSensitivity) return; BuildingState state = instanceState as BuildingState; BuildingInfo buildingInfo = state.Info.Prefab as BuildingInfo; Vector3 newPosition = matrix4x.MultiplyPoint(state.position - center); newPosition.y = state.position.y + deltaPosition.y; if (followTerrain) { newPosition.y = newPosition.y - state.terrainHeight + TerrainManager.instance.SampleOriginalRawHeightSmooth(newPosition); } float newAngle = state.angle + deltaAngle; buildingInfo.m_buildingAI.RenderBuildOverlay(cameraInfo, toolColor, newPosition, newAngle, default); BuildingTool.RenderOverlay(cameraInfo, buildingInfo, state.length, newPosition, newAngle, toolColor, false); if (buildingInfo.m_subBuildings != null && buildingInfo.m_subBuildings.Length != 0) { Matrix4x4 subMatrix4x = default; subMatrix4x.SetTRS(newPosition, Quaternion.AngleAxis(newAngle * Mathf.Rad2Deg, Vector3.down), Vector3.one); for (int i = 0; i < buildingInfo.m_subBuildings.Length; i++) { BuildingInfo buildingInfo2 = buildingInfo.m_subBuildings[i].m_buildingInfo; Vector3 position = subMatrix4x.MultiplyPoint(buildingInfo.m_subBuildings[i].m_position); float angle = buildingInfo.m_subBuildings[i].m_angle * 0.0174532924f + newAngle; buildingInfo2.m_buildingAI.RenderBuildOverlay(cameraInfo, toolColor, position, angle, default); BuildingTool.RenderOverlay(cameraInfo, buildingInfo2, 0, position, angle, toolColor, true); } } }
// For Deletion Undo public override Instance Clone(InstanceState instanceState, Dictionary <ushort, ushort> clonedNodes) { BuildingState state = instanceState as BuildingState; MoveableBuilding cloneInstance = null; BuildingInfo info = state.Info.Prefab as BuildingInfo; if (BuildingManager.instance.CreateBuilding(out ushort clone, ref SimulationManager.instance.m_randomizer, info, state.position, state.angle, state.length, SimulationManager.instance.m_currentBuildIndex)) { SimulationManager.instance.m_currentBuildIndex++; InstanceID cloneID = default; cloneID.Building = clone; cloneInstance = new MoveableBuilding(cloneID); buildingBuffer[clone].m_flags = state.flags; if (info.m_subBuildings != null && info.m_subBuildings.Length != 0) { Matrix4x4 subMatrix4x = default; subMatrix4x.SetTRS(state.position, Quaternion.AngleAxis(state.angle * Mathf.Rad2Deg, Vector3.down), Vector3.one); for (int i = 0; i < info.m_subBuildings.Length; i++) { BuildingInfo subInfo = info.m_subBuildings[i].m_buildingInfo; Vector3 subPosition = subMatrix4x.MultiplyPoint(info.m_subBuildings[i].m_position); float subAngle = info.m_subBuildings[i].m_angle * 0.0174532924f + state.angle; if (BuildingManager.instance.CreateBuilding(out ushort subClone, ref SimulationManager.instance.m_randomizer, subInfo, subPosition, subAngle, 0, SimulationManager.instance.m_currentBuildIndex)) { SimulationManager.instance.m_currentBuildIndex++; if (info.m_subBuildings[i].m_fixedHeight) { buildingBuffer[subClone].m_flags = buildingBuffer[subClone].m_flags | Building.Flags.FixedHeight; } } if (clone != 0 && subClone != 0) { buildingBuffer[clone].m_subBuilding = subClone; buildingBuffer[subClone].m_parentBuilding = clone; buildingBuffer[subClone].m_flags = buildingBuffer[subClone].m_flags | Building.Flags.Untouchable; clone = subClone; } } } cloneInstance.ResetSubInstances(); } return(cloneInstance); }
public override void ReplaceInstance(Instance instance) { base.ReplaceInstance(instance); MoveableNode node = instance as MoveableNode; if (pillarState != null) { pillarState.instance = node.Pillar; if (pillarState.instance == null) { pillarState = null; } } }
public override InstanceState SaveToState(bool integrate = true) { BuildingState state = new BuildingState { instance = this, Info = Info, position = buildingBuffer[id.Building].m_position, angle = buildingBuffer[id.Building].m_angle, flags = buildingBuffer[id.Building].m_flags, length = buildingBuffer[id.Building].Length, isSubInstance = isSubInstance, isHidden = isHidden, isCustomContent = Info.Prefab.m_isCustomContent }; state.terrainHeight = TerrainManager.instance.SampleOriginalRawHeightSmooth(state.position); List <InstanceState> subStates = new List <InstanceState>(); foreach (Instance subInstance in subInstances) { if (subInstance != null && subInstance.isValid) { if (subInstance.id.Building > 0) { subStates.Add(((MoveableBuilding)subInstance).SaveToState()); } else { subStates.Add(subInstance.SaveToState()); } } } if (subStates.Count > 0) { state.subStates = subStates.ToArray(); } //state.SaveIntegrations(integrate); return(state); }
public override Instance Clone(InstanceState instanceState, ref Matrix4x4 matrix4x, float deltaHeight, float deltaAngle, Vector3 center, bool followTerrain, Dictionary <ushort, ushort> clonedNodes, Action action) { BuildingState state = instanceState as BuildingState; Vector3 newPosition = matrix4x.MultiplyPoint(state.position - center); newPosition.y = state.position.y + deltaHeight; float terrainHeight = TerrainManager.instance.SampleOriginalRawHeightSmooth(newPosition); if (followTerrain) { newPosition.y = newPosition.y + terrainHeight - state.terrainHeight; } MoveableBuilding cloneInstance = null; BuildingInfo info = state.Info.Prefab as BuildingInfo; float newAngle = state.angle + deltaAngle; if (BuildingManager.instance.CreateBuilding(out ushort clone, ref SimulationManager.instance.m_randomizer, info, newPosition, newAngle, state.length, SimulationManager.instance.m_currentBuildIndex)) { SimulationManager.instance.m_currentBuildIndex++; InstanceID cloneID = default; cloneID.Building = clone; cloneInstance = new MoveableBuilding(cloneID); if ((state.flags & Building.Flags.Completed) != Building.Flags.None) { buildingBuffer[clone].m_flags = buildingBuffer[clone].m_flags | Building.Flags.Completed; } if ((state.flags & Building.Flags.FixedHeight) != Building.Flags.None) { buildingBuffer[clone].m_flags = buildingBuffer[clone].m_flags | Building.Flags.FixedHeight; } if ((state.flags & Building.Flags.Historical) != Building.Flags.None) { buildingBuffer[clone].m_flags = buildingBuffer[clone].m_flags | Building.Flags.Historical; } if ((state.flags & Building.Flags.Hidden) != Building.Flags.None) { buildingBuffer[clone].m_flags = buildingBuffer[clone].m_flags | Building.Flags.Hidden; } if (Mathf.Abs(terrainHeight - newPosition.y) > 0.01f) { AddFixedHeightFlag(clone); } else { RemoveFixedHeightFlag(clone); } if (info.m_subBuildings != null && info.m_subBuildings.Length != 0) { Matrix4x4 subMatrix4x = default; subMatrix4x.SetTRS(newPosition, Quaternion.AngleAxis(newAngle * Mathf.Rad2Deg, Vector3.down), Vector3.one); for (int i = 0; i < info.m_subBuildings.Length; i++) { BuildingInfo subInfo = info.m_subBuildings[i].m_buildingInfo; Vector3 subPosition = subMatrix4x.MultiplyPoint(info.m_subBuildings[i].m_position); float subAngle = info.m_subBuildings[i].m_angle * 0.0174532924f + newAngle; if (BuildingManager.instance.CreateBuilding(out ushort subClone, ref SimulationManager.instance.m_randomizer, subInfo, subPosition, subAngle, 0, SimulationManager.instance.m_currentBuildIndex)) { SimulationManager.instance.m_currentBuildIndex++; if (info.m_subBuildings[i].m_fixedHeight) { buildingBuffer[subClone].m_flags = buildingBuffer[subClone].m_flags | Building.Flags.FixedHeight; } } if (clone != 0 && subClone != 0) { buildingBuffer[clone].m_subBuilding = subClone; buildingBuffer[subClone].m_parentBuilding = clone; buildingBuffer[subClone].m_flags = buildingBuffer[subClone].m_flags | Building.Flags.Untouchable; clone = subClone; } } } cloneInstance.ResetSubInstances(); } return(cloneInstance); }
public override void Transform(InstanceState instanceState, ref Matrix4x4 matrix4x, float deltaHeight, float deltaAngle, Vector3 center, bool followTerrain) { BuildingState state = instanceState as BuildingState; Vector3 newPosition = matrix4x.MultiplyPoint(state.position - center); newPosition.y = state.position.y + deltaHeight; float terrainHeight = TerrainManager.instance.SampleOriginalRawHeightSmooth(newPosition); bool isFixed = GetFixedHeightFlag(id.Building); if (!isFixed) { AddFixedHeightFlag(id.Building); } if (followTerrain) { newPosition.y = newPosition.y + terrainHeight - state.terrainHeight; } AddFixedHeightFlag(id.Building); Move(newPosition, state.angle + deltaAngle); Matrix4x4 matrixSub = default; matrixSub.SetTRS(Vector3.zero, Quaternion.AngleAxis(deltaAngle * Mathf.Rad2Deg, Vector3.down), Vector3.one); if (state.subStates != null) { foreach (InstanceState subState in state.subStates) { Vector3 subOffset = (subState.position - center) - (state.position - center); Vector3 subPosition = TransformPosition + matrixSub.MultiplyPoint(subOffset); subPosition.y = subState.position.y - state.position.y + newPosition.y; subState.instance.Move(subPosition, subState.angle + deltaAngle); if (subState.instance is MoveableNode mn) { if (mn.Pillar != null) { mn.Pillar.Move(subPosition, subState.angle + deltaAngle); } } if (subState is BuildingState bs) { if (bs.subStates != null) { foreach (InstanceState subSubState in bs.subStates) { Vector3 subSubOffset = (subSubState.position - center) - (state.position - center); Vector3 subSubPosition = TransformPosition + matrixSub.MultiplyPoint(subSubOffset); subSubPosition.y = subSubState.position.y - state.position.y + newPosition.y; subSubState.instance.Move(subSubPosition, subSubState.angle + deltaAngle); if (subSubState.instance is MoveableNode mn2) { if (mn2.Pillar != null) { mn2.Pillar.Move(subSubPosition, subSubState.angle + deltaAngle); } } } } } } } if (!isFixed && Mathf.Abs(terrainHeight - newPosition.y) < 0.01f) { RemoveFixedHeightFlag(id.Building); } }
public void MoveCall(Vector3 newPosition, float angle) { Bounds originalBounds = GetBounds(false); Vector3 oldPosition = this.position; float oldAngle = this.angle; float terrainHeight = TerrainManager.instance.SampleOriginalRawHeightSmooth(newPosition); bool isFixed = GetFixedHeightFlag(id.Building); AddFixedHeightFlag(id.Building); BuildingState state = SaveToState() as BuildingState; Move(newPosition, angle); Vector3 center = oldPosition; float deltaAngle = angle - oldAngle; Matrix4x4 matrixSub = default; matrixSub.SetTRS(Vector3.zero, Quaternion.AngleAxis(deltaAngle * Mathf.Rad2Deg, Vector3.down), Vector3.one); if (state.subStates != null) { foreach (InstanceState subState in state.subStates) { Vector3 subOffset = (subState.position - center) - (state.position - center); Vector3 subPosition = TransformPosition + matrixSub.MultiplyPoint(subOffset); subPosition.y = subState.position.y - state.position.y + newPosition.y; subState.instance.Move(subPosition, subState.angle + deltaAngle); if (subState.instance is MoveableNode mn) { if (mn.Pillar != null) { mn.Pillar.Move(subPosition, subState.angle + deltaAngle); } } if (subState is BuildingState bs) { if (bs.subStates != null) { foreach (InstanceState subSubState in bs.subStates) { Vector3 subSubOffset = (subSubState.position - center) - (state.position - center); Vector3 subSubPosition = TransformPosition + matrixSub.MultiplyPoint(subSubOffset); subSubPosition.y = subSubState.position.y - state.position.y + newPosition.y; subSubState.instance.Move(subSubPosition, subSubState.angle + deltaAngle); if (subSubState.instance is MoveableNode mn2) { if (mn2.Pillar != null) { mn2.Pillar.Move(subSubPosition, subSubState.angle + deltaAngle); } } } } } } } if (!isFixed && Mathf.Abs(terrainHeight - newPosition.y) < 0.01f) { RemoveFixedHeightFlag(id.Building); } Bounds fullbounds = GetBounds(false); MoveItTool.UpdateArea(originalBounds, true); MoveItTool.UpdateArea(fullbounds, true); }