public Quaternion CalculatePreviewRotation(StructureItem structure) { rotationIndex = rotationIndex % structure.availableRotations.Length; Vector3 euler = structure.availableRotations[rotationIndex].rotation; return(Quaternion.Euler(euler)); }
/// <summary> /// Get a the gradient color definition /// </summary> private static List <GradientColorStop> GetGradientColor(StructureDescriptor descriptor, GradientColor gradientColor) { StructureItem item = null; if (descriptor.Items.TryGetValue(ref item, "Angl")) { var anglDesc = (StructureUnitFloat)item; gradientColor.Angle = anglDesc.Value; } if (descriptor.Items.TryGetValue(ref item, "Rvrs")) { var rvrsDesc = (StructureBool)item; gradientColor.IsReverse = rvrsDesc.Value; } if (descriptor.Items.TryGetValue(ref item, "Scl")) { var sclDesc = (StructureUnitFloat)item; gradientColor.Scale = sclDesc.Value; } else { gradientColor.Scale = 100; } var gradDesc = (StructureDescriptor)descriptor.Items["Grad"]; var intrDescriptor = (StructureDouble)gradDesc.Items["Intr"]; gradientColor.MaxPosition = intrDescriptor.Value; var clrsDesc = (StructureList)gradDesc.Items["Clrs"]; List <GradientColorStop> stops = new List <GradientColorStop>(); foreach (var clrtItem in clrsDesc.Items) { var clrtDesc = (StructureDescriptor)clrtItem; GradientColorStop stop = new GradientColorStop(); stops.Add(stop); var colorDescriptor = (StructureDescriptor)clrtDesc.Items["Clr"]; stop.Color = GetColor(colorDescriptor); var positionDescriptor = (StructureLong)clrtDesc.Items["Lctn"]; stop.Position = positionDescriptor.Value; var mdpnDescriptor = (StructureLong)clrtDesc.Items["Mdpn"]; stop.MiddlePoint = mdpnDescriptor.Value; } return(stops); }
public Vector3 CalculatePreviewPosition(StructureItem structure, Vector3 headPosition, Vector3 lookDirection) { Vector3 inFront = headPosition + lookDirection * structure.previewDistance; inFront.x = RoundToGrid(inFront.x, structure.gridResolution); inFront.y = RoundToGrid(inFront.y, structure.gridResolution); inFront.z = RoundToGrid(inFront.z, structure.gridResolution); rotationIndex = rotationIndex % structure.availableRotations.Length; Vector3 offset = structure.availableRotations[rotationIndex].positionOffset; return(inFront + offset); }
void Update() { if (!isLocalPlayer) { return; } StructureItem structure = GetCurrentStructure(); if (structure != null) { if (preview != null && preview.name != structure.structurePrefab.name) { Destroy(preview); } if (preview == null || preview.name != structure.structurePrefab.name) { preview = Instantiate(structure.structurePrefab, CalculatePreviewPosition(structure, look.headPosition, look.lookDirectionRaycasted), CalculatePreviewRotation(structure)); preview.name = structure.structurePrefab.name; Behaviour[] behaviours = preview.GetComponentsInChildren <Behaviour>(); for (int i = behaviours.Length - 1; i >= 0; --i) { if (!(behaviours[i] is NetworkIdentity)) { Destroy(behaviours[i]); } } foreach (Collider co in preview.GetComponentsInChildren <Collider>()) { Destroy(co); } } preview.transform.position = CalculatePreviewPosition(structure, look.headPosition, look.lookDirectionRaycasted); preview.transform.rotation = CalculatePreviewRotation(structure); if (Input.GetKeyDown(rotationKey)) { int newIndex = (rotationIndex + 1) % structure.availableRotations.Length; CmdSetRotationIndex(newIndex); } Bounds bounds = preview.GetComponentInChildren <Renderer>().bounds; bool canBuild = structure.CanBuildThere(look.headPosition, bounds, look.raycastLayers); foreach (Renderer renderer in preview.GetComponentsInChildren <Renderer>()) { renderer.material.color = canBuild ? canBuildColor : cantBuildColor; } } else if (preview != null) { Destroy(preview); } }
void OnDrawGizmos() { if (preview != null) { StructureItem structure = GetCurrentStructure(); Bounds bounds = preview.GetComponentInChildren <Renderer>().bounds; Gizmos.color = Color.gray; Gizmos.DrawWireCube(bounds.center, bounds.size); Gizmos.color = Color.black; Gizmos.DrawWireCube(bounds.center, bounds.size * (1 - structure.buildToleranceCollision)); Gizmos.color = Color.white; Gizmos.DrawWireCube(bounds.center, bounds.size * (1 + structure.buildToleranceAir)); } }
public StructureItem TransformStructure(swgemurpcserver.rpc.SWGEmuCharacterStructureItem charStructItem) { var item = new StructureItem() { display_name = charStructItem.DisplayName, object_id = charStructItem.ObjectId, object_name = charStructItem.ObjectName }; if (StringDetails != null) { item.resolved_object_name = StringDetails.Get(charStructItem.ObjectName); } return(item); }