public override void SetVisible(bool newValue) { base.SetVisible(newValue); if (newValue) { partPropNames = wearablePartProps.Keys.ToArray(); List <WBIWearableProp> wearableProps = wearablePartProps[partPropNames[0]]; wearableProp = wearableProps[0]; selectedPropName = wearableProp.name; selectedProp = wearableProp.prop; setInitialOffsets(); } }
protected override void DrawWindowContents(int windowId) { GUILayout.BeginHorizontal(); GUILayout.BeginVertical(); // Current prop GUILayout.Label(selectedPropName); // Selectable props to edit scrollPos = GUILayout.BeginScrollView(scrollPos, propPanelOptions); List <WBIWearableProp> wearableProps; int count; WBIWearableProp partProp; for (int index = 0; index < partPropNames.Length; index++) { GUILayout.Label(string.Format("<color=white>{0:s}</color>", partPropNames[index])); wearableProps = wearablePartProps[partPropNames[index]]; count = wearableProps.Count; for (int propIndex = 0; propIndex < count; propIndex++) { partProp = wearableProps[propIndex]; if (GUILayout.Button(partProp.name)) { wearableProp = partProp; selectedPropName = wearableProp.name; selectedProp = wearableProp.prop; setInitialOffsets(); } } } GUILayout.EndScrollView(); GUILayout.EndVertical(); GUILayout.BeginVertical(); // Delta buttons buttonGroupIndex = GUILayout.SelectionGrid(buttonGroupIndex, buttonTexts, buttonTexts.Length); // Offsets bool updateNeeded = false; offsetXString = drawOffsetControls("#LOC_SUNKWORKS_OffsetX", offsetXString, ref offsetXDelta, ref updateNeeded); offsetYString = drawOffsetControls("#LOC_SUNKWORKS_OffsetY", offsetYString, ref offsetYDelta, ref updateNeeded); offsetZString = drawOffsetControls("#LOC_SUNKWORKS_OffsetZ", offsetZString, ref offsetZDelta, ref updateNeeded); offsetRollString = drawOffsetControls("#LOC_SUNKWORKS_OffsetRoll", offsetRollString, ref offsetRollDelta, ref updateNeeded); offsetPitchString = drawOffsetControls("#LOC_SUNKWORKS_OffsetPitch", offsetPitchString, ref offsetPitchDelta, ref updateNeeded); offsetYawString = drawOffsetControls("#LOC_SUNKWORKS_OffsetYaw", offsetYawString, ref offsetYawDelta, ref updateNeeded); // Update position offset positionOffset.x = offsetXDelta; positionOffset.y = offsetYDelta; positionOffset.z = offsetZDelta; // Update rotation offset rotationOffset.x = offsetRollDelta; rotationOffset.y = offsetPitchDelta; rotationOffset.z = offsetYawDelta; // Update the meshTransform's position and rotation. if (updateNeeded) { wearableProp.meshTransform.localPosition = positionOffset; wearableProp.meshTransform.localEulerAngles = rotationOffset; } // Copy offsets to clipboard button if (GUILayout.Button(Localizer.Format("#LOC_SUNKWORKS_copyOffsetsButton"))) { StringBuilder outputString = new StringBuilder(); outputString.AppendLine(string.Format("positionOffset = {0:n4}, {1:n4}, {2:n4}", offsetXDelta, offsetYDelta, offsetZDelta)); outputString.AppendLine(string.Format("rotationOffset = {0:n4}, {1:n4}, {2:n4}", offsetRollDelta, offsetPitchDelta, offsetYawDelta)); string offsetString = outputString.ToString(); if (kerbalEVA.ModuleInventoryPartReference.ContainsPart(WBIWearablesController.kJetpackPartName)) { offsetString = offsetString.Replace("positionOffset", "positionOffsetJetpack"); } GUIUtility.systemCopyBuffer = offsetString; } GUILayout.EndVertical(); GUILayout.EndHorizontal(); }
private void setupWearableParts() { List <AvailablePart> cargoParts = PartLoader.Instance.GetAvailableAndPurchaseableCargoParts(); AvailablePart availablePart; List <WBIWearableItem> wearableItems; WBIWearableItem wearableItem; int count = cargoParts.Count; int itemCount; Transform anchorTransform; GameObject prefab; GameObject prop; Transform attachTransform; Collider[] colliders; WBIWearableProp wearableProp; List <WBIWearableProp> wearableProps; wearablePartProps = new Dictionary <string, List <WBIWearableProp> >(); wearablePartModules = new Dictionary <string, string[]>(); for (int index = 0; index < count; index++) { availablePart = cargoParts[index]; if (availablePart.partPrefab.HasModuleImplementing <WBIWearableItem>()) { wearableItems = availablePart.partPrefab.FindModulesImplementing <WBIWearableItem>(); // Setup our wearable props for this part. wearableProps = new List <WBIWearableProp>(); wearablePartProps.Add(availablePart.name, wearableProps); // Setup the props- Special thanks to Vali and Issac for showing the way how! itemCount = wearableItems.Count; for (int itemIndex = 0; itemIndex < itemCount; itemIndex++) { wearableItem = wearableItems[itemIndex]; // Create new wearable prop instance. wearableProp = new WBIWearableProp(); wearableProp.name = wearableItem.moduleID; wearableProp.partName = availablePart.name; wearableProp.bodyLocation = wearableItem.bodyLocation; wearableProp.positionOffset = wearableItem.positionOffset; wearableProp.positionOffsetJetpack = wearableItem.positionOffsetJetpack; wearableProp.rotationOffset = wearableItem.rotationOffset; // Setup part module names if (!string.IsNullOrEmpty(wearableItem.evaModules)) { string[] evaModules = wearableItem.evaModules.Split(new char[] { ';' }); wearablePartModules.Add(availablePart.name, evaModules); } // Get the attachment transform attachTransform = getAttachTransform(wearableItem.bodyLocation); // Get the anchor transform and prefab anchorTransform = availablePart.partPrefab.FindModelTransform(wearableItem.anchorTransform); if (anchorTransform == null) { continue; } prefab = anchorTransform.gameObject; // Create instance prop = Instantiate(prefab, attachTransform.position, attachTransform.rotation, kerbalEVA.transform); prop.name = wearableItem.moduleID; wearableProp.prop = prop; // Add the TrackingRigObject. The tracking rig moves the prop (GameObject) associated with the anchorTransform. TrackRigObject trackRig = prop.AddComponent <TrackRigObject>(); trackRig.target = attachTransform; trackRig.keepInitialOffset = false; trackRig.trackingMode = TrackRigObject.TrackMode.LateUpdate; // Now we need the child mesh that we'll apply the position and rotation offsets to. Transform meshTransform = prop.transform.Find(wearableItem.meshTransform); wearableProp.meshTransform = meshTransform; /* * meshTransform.localEulerAngles = wearableItem.rotationOffset; * if (wearableItem.bodyLocation != BodyLocations.backOrJetpack) * meshTransform.localPosition = wearableItem.positionOffset; * else * meshTransform.localPosition = inventory.ContainsPart(kJetpackPartName) ? wearableItem.positionOffsetJetpack : wearableItem.positionOffset; */ // Remove colliders colliders = prop.GetComponentsInChildren <Collider>(true); for (int colliderIndex = 0; colliderIndex < colliders.Length; colliderIndex++) { DestroyImmediate(colliders[colliderIndex]); } // Hide the prop for now. prop.SetActive(false); // Add the wearable prop to our list. wearablePartProps[availablePart.name].Add(wearableProp); } } } }