public void Update() { if (CameraManager.Instance.currentCameraMode != CameraManager.CameraMode.IVA) { if (_lastCameraMode == CameraManager.CameraMode.IVA) { // Switching away from IVA. //InputLockManager.RemoveControlLock("FreeIVA"); // Return the kerbal to its original seat. TargetedSeat = ActiveKerbal.seat; Buckle(); } } else { // In IVA. if (_lastCameraMode != CameraManager.CameraMode.IVA) { // Switching to IVA. FreeIva.EnableInternals(); SetCameraToSeat(); InternalCollider.HideAllColliders(); } GetInput(); } _lastCameraMode = CameraManager.Instance.currentCameraMode; }
public void Update() { if (CameraManager.Instance.currentCameraMode != CameraManager.CameraMode.IVA) { if (_lastCameraMode == CameraManager.CameraMode.IVA) // Switching away from IVA. { InputLockManager.RemoveControlLock("FreeIVA"); // Return the kerbal to its original seat. TargetedSeat = ActiveKerbal.seat; if (!buckled) { Buckle(); } } } else { // In IVA. if (_lastCameraMode != CameraManager.CameraMode.IVA) { // Switching to IVA. FreeIva.EnableInternals(); UpdateActiveKerbal();//false); SetCameraToSeat(); InternalCollider.HideAllColliders(); } // Check if we're changing crew member using the 'V' key. if (GameSettings.CAMERA_NEXT.GetKeyDown()) { _changingCurrentIvaCrew = true; } else { if (_changingCurrentIvaCrew) { UpdateActiveKerbal();//false); _changingCurrentIvaCrew = false; } } // TODO: Doesn't get mouse input when in FixedUpdate. // Split this out to flags set in Update and acted upon in FixedUpdate. GetInput(); /*FreeIva.InitialPart.Events.Clear(); * if (_transferStart != 0 && Planetarium.GetUniversalTime() > (0.25 + _transferStart)) * { * FlightGlobals.ActiveVessel.SpawnCrew(); * GameEvents.onVesselChange.Fire(FlightGlobals.ActiveVessel); * InternalCamera.Instance.transform.parent = ActiveKerbal.KerbalRef.eyeTransform; * _transferStart = 0; * }*/ } _lastCameraMode = CameraManager.Instance.currentCameraMode; }
public Hatch(string name, string attachNodeId, Vector3 localPosition, Vector3 scale, Quaternion rotation, List <KeyValuePair <Vector3, string> > hideWhenOpen, InternalCollider collider) { Name = name; AttachNodeId = attachNodeId; LocalPosition = localPosition; Scale = scale; Rotation = rotation; HideWhenOpen = hideWhenOpen; Collider = collider; }
public PropHatch(string name, string attachNodeId, Vector3 localPosition, Vector3 scale, Quaternion rotation, List <KeyValuePair <Vector3, string> > hideWhenOpen, InternalCollider collider, string closedPropName, string openPropName, int closedPropIndex) { Name = name; AttachNodeId = attachNodeId; LocalPosition = localPosition; Scale = scale; Rotation = rotation; HideWhenOpen = hideWhenOpen; Collider = collider; ClosedPropName = closedPropName; OpenPropName = openPropName; ClosedPropIndex = closedPropIndex; }
/*public override void OnSave(ConfigNode node) * { * Debug.Log("# OnSave " + node); * return; * base.OnSave(node); * Debug.Log("# Saving hatches"); * ConfigNode hatchNode = new ConfigNode("Hatch"); * foreach (Hatch h in Hatches) * { * hatchNode.AddValue("attachNodeId", h.AttachNodeId); * hatchNode.AddValue("position", h.Position.x + ", " + h.Position.y + ", " + h.Position.z); * hatchNode.AddValue("scale", h.Scale.x + ", " + h.Scale.y + ", " + h.Scale.z); * } * Debug.Log("# Adding hatch node " + hatchNode); * node.AddNode(hatchNode); * }*/ public override void OnLoad(ConfigNode node) { if (node.HasValue("CanIva")) { CanIva = bool.Parse(node.GetValue("CanIva")); } if (node.HasNode("Hatch")) { ConfigNode[] hatchNodes = node.GetNodes("Hatch"); foreach (var hn in hatchNodes) { Hatch h = ParseHatch(hn); if (h != null) { Hatches.Add(h); if (h.Collider != null) { InternalColliders.Add(h.Collider); } } } PersistenceManager.instance.AddHatches(part.name, Hatches); } Debug.Log("# Hatches loaded from config for part " + part.name + ": " + Hatches.Count); if (node.HasNode("InternalCollider")) { ConfigNode[] colliderNodes = node.GetNodes("InternalCollider"); foreach (var cn in colliderNodes) { InternalCollider ic = ParseInternalCollider(cn); if (ic != null) { InternalColliders.Add(ic); } } PersistenceManager.instance.AddInternalColliders(part.name, InternalColliders); Debug.Log("# Internal colliders loaded from config for part " + part.name + ": " + InternalColliders.Count); } }
//static bool _initialised = false; public static void EnableInternals() { try { //if (_initialised) return; foreach (Part p in FlightGlobals.ActiveVessel.parts) { if (p.internalModel == null) { p.CreateInternalModel(); } if (p.internalModel != null) { p.internalModel.SetVisible(true); PropHatch.AddPropHatches(p.internalModel); //PrintInternals(p); } } // TODO InternalCollider.HideAllColliders(); // TODO Hatch.InitialiseAllHatchesClosed(); //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! // Colliders, hatches and hatch props are all unhidden by this. //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! //_initialised = true; } catch (Exception ex) { Debug.LogError("[FreeIVA] Error enabling internals: " + ex.Message + ", " + ex.StackTrace); } }
private static void ColliderGui() { // TODO: Automatically add colliders to selected props using renderer bounds? if (GUILayout.Button((showColliderGui ? "Hide" : "Show") + " collider configuration")) showColliderGui = !showColliderGui; if (!showColliderGui) { InternalCollider.HideAllColliders(); return; } GUILayout.BeginHorizontal(); KerbalIva.KerbalCollider.collider.enabled = !GUILayout.Toggle(!KerbalIva.KerbalCollider.collider.enabled, "NoClip"); bool helmet = KerbalIva.WearingHelmet; KerbalIva.WearingHelmet = GUILayout.Toggle(KerbalIva.WearingHelmet, "Helmet"); if (helmet != KerbalIva.WearingHelmet) { } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); if (GUILayout.Button("Print collision layers")) { StringBuilder sb = new StringBuilder(); sb.Append(" 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 3 3"); sb.Append("0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1"); for (int i = 0; i < 32; i++) { sb.Append("\r\n"); if (i < 10) sb.Append(" "); sb.Append(i).Append("\t"); for (int j = 0; j < 32; j++) sb.Append(Physics.GetIgnoreLayerCollision(i, j) ? "T " : "F "); } Debug.Log(sb.ToString()); } if (GUILayout.Button("Create new collider")) { InternalCollider col = new InternalCollider(); col.Scale = new Vector3(0.5f, 0.5f, 0.5f); col.Instantiate(CurrentPart, _primitiveType); col.IvaGameObject.name = "Test collider"; CurrentModuleFreeIva.InternalColliders.Add(col); _colliderIndex = CurrentModuleFreeIva.InternalColliders.Count - 1; } if (GUILayout.Button("Stop all movement")) { foreach (var col in CurrentModuleFreeIva.InternalColliders) { col.IvaGameObject.rigidbody.velocity = Vector3.zero; col.IvaGameObject.rigidbody.angularVelocity = Vector3.zero; } } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); if (GUILayout.Toggle(_primitiveType == PrimitiveType.Sphere, "Sphere")) _primitiveType = PrimitiveType.Sphere; if (GUILayout.Toggle(_primitiveType == PrimitiveType.Capsule, "Capsule")) _primitiveType = PrimitiveType.Capsule; if (GUILayout.Toggle(_primitiveType == PrimitiveType.Cylinder, "Cylinder")) _primitiveType = PrimitiveType.Cylinder; if (GUILayout.Toggle(_primitiveType == PrimitiveType.Cube, "Cube")) _primitiveType = PrimitiveType.Cube; if (GUILayout.Toggle(_primitiveType == PrimitiveType.Plane, "Plane")) _primitiveType = PrimitiveType.Plane; if (GUILayout.Toggle(_primitiveType == PrimitiveType.Quad, "Quad")) _primitiveType = PrimitiveType.Quad; GUILayout.EndHorizontal(); InternalCollider c = null; if (CurrentModuleFreeIva.InternalColliders.Count == 0) { GUILayout.Label("No colliders"); } else { GUILayout.BeginHorizontal(); if (GUILayout.Button("Previous collider")) _colliderIndex--; if (GUILayout.Button("Next collider")) _colliderIndex++; GUILayout.EndHorizontal(); if (_colliderIndex >= CurrentModuleFreeIva.InternalColliders.Count) _colliderIndex = 0; if (_colliderIndex < 0) _colliderIndex = CurrentModuleFreeIva.InternalColliders.Count - 1; GuiUtils.label("Current collider", _colliderIndex + 1); c = CurrentModuleFreeIva.InternalColliders[_colliderIndex]; GuiUtils.label("Collider (" + (_colliderIndex + 1) + "/" + CurrentModuleFreeIva.InternalColliders.Count + ")", c.Name); } if (c == null) return; if (GUILayout.Button("Destroy collider")) { CurrentModuleFreeIva.InternalColliders.Remove(c); c.IvaGameObject.DestroyGameObject(); } GUILayout.BeginHorizontal(); c.IvaGameObject.collider.enabled = GUILayout.Toggle(c.IvaGameObject.collider.enabled, "Enabled"); bool wasVisible = c.Visible; bool v = GUILayout.Toggle(wasVisible, "Visible"); if (v != wasVisible) c.Visible = v; GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("Position X"); float xPos = float.Parse(GUILayout.TextField(c.LocalPosition.x.ToString())); GUILayout.Label("Position Y"); float yPos = float.Parse(GUILayout.TextField(c.LocalPosition.y.ToString())); GUILayout.Label("Position Z"); float zPos = float.Parse(GUILayout.TextField(c.LocalPosition.z.ToString())); if (xPos != c.LocalPosition.x || yPos != c.LocalPosition.y || zPos != c.LocalPosition.z) { //currentJoint = c.IvaGameObject.GetComponent<FixedJoint>(); //if (currentJoint != null) Destroy(currentJoint); c.LocalPosition = new Vector3(xPos, yPos, zPos); //currentJoint = c.IvaGameObject.AddComponent<FixedJoint>(); //currentJoint.connectedBody = CurrentPart.collider.rigidbody; c.IvaGameObject.rigidbody.velocity = Vector3.zero; c.IvaGameObject.rigidbody.angularVelocity = Vector3.zero; } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("Scale X"); float xSc = float.Parse(GUILayout.TextField(c.Scale.x.ToString())); GUILayout.Label("Scale Y"); float ySc = float.Parse(GUILayout.TextField(c.Scale.y.ToString())); GUILayout.Label("Scale Z"); float zSc = float.Parse(GUILayout.TextField(c.Scale.z.ToString())); if (xSc != c.Scale.x || ySc != c.Scale.y || zSc != c.Scale.z) { //currentJoint = c.IvaGameObject.GetComponent<FixedJoint>(); //if (currentJoint != null) Destroy(currentJoint); c.Scale = new Vector3(xSc, ySc, zSc); //currentJoint = c.IvaGameObject.AddComponent<FixedJoint>(); //currentJoint.connectedBody = CurrentPart.collider.rigidbody; c.IvaGameObject.rigidbody.velocity = Vector3.zero; c.IvaGameObject.rigidbody.angularVelocity = Vector3.zero; } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("Rotation X"); float xRot = float.Parse(GUILayout.TextField(c.Rotation.eulerAngles.x.ToString())); GUILayout.Label("Rotation Y"); float yRot = float.Parse(GUILayout.TextField(c.Rotation.eulerAngles.y.ToString())); GUILayout.Label("Rotation Z"); float zRot = float.Parse(GUILayout.TextField(c.Rotation.eulerAngles.z.ToString())); if (xRot != c.Rotation.eulerAngles.x || yRot != c.Rotation.eulerAngles.y || zRot != c.Rotation.eulerAngles.z) { //currentJoint = c.IvaGameObject.GetComponent<FixedJoint>(); //if (currentJoint != null) Destroy(currentJoint); c.Rotation = Quaternion.Euler(xRot, yRot, zRot); //currentJoint = c.IvaGameObject.AddComponent<FixedJoint>(); //currentJoint.connectedBody = CurrentPart.collider.rigidbody; c.IvaGameObject.rigidbody.velocity = Vector3.zero; c.IvaGameObject.rigidbody.angularVelocity = Vector3.zero; } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GuiUtils.label("Velocity", c.IvaGameObject.rigidbody.velocity.magnitude); GuiUtils.label("Angular velocity", c.IvaGameObject.rigidbody.angularVelocity.magnitude); GUILayout.EndHorizontal(); }
private InternalCollider ParseInternalCollider(ConfigNode node) { Vector3 position = Vector3.zero; if (!node.HasValue("type")) { Debug.LogWarning("[FreeIVA] InternalCollider type not found: Skipping collider."); return(null); } InternalCollider internalCollider = new InternalCollider(); internalCollider.ColliderType = (PrimitiveType)Enum.Parse(typeof(PrimitiveType), node.GetValue("type")); if (node.HasValue("name")) { internalCollider.Name = node.GetValue("name"); } if (node.HasValue("alwaysVisible")) { internalCollider.AlwaysVisible = bool.Parse(node.GetValue("alwaysVisible")); } if (node.HasValue("position")) { string posString = node.GetValue("position"); string[] p = posString.Split(_splitChars, StringSplitOptions.RemoveEmptyEntries); if (p.Length != 3) { Debug.LogWarning("[FreeIVA] Invalid collider position definition \"" + posString + "\": Must be in the form x, y, z."); return(null); } else { internalCollider.LocalPosition = new Vector3(float.Parse(p[0]), float.Parse(p[1]), float.Parse(p[2])); } } else { Debug.LogWarning("[FreeIVA] Collider position not found: Skipping collider."); return(null); } if (node.HasValue("scale")) { string scaleString = node.GetValue("scale"); string[] s = scaleString.Split(_splitChars, StringSplitOptions.RemoveEmptyEntries); if (s.Length != 3) { Debug.LogWarning("[FreeIVA] Invalid collider scale definition \"" + scaleString + "\": Must be in the form x, y, z."); return(null); } else { internalCollider.Scale = new Vector3(float.Parse(s[0]), float.Parse(s[1]), float.Parse(s[2])); } } else { Debug.LogWarning("[FreeIVA] Collider scale not found: Skipping collider."); return(null); } if (node.HasValue("rotation")) { string rotationString = node.GetValue("rotation"); string[] s = rotationString.Split(_splitChars, StringSplitOptions.RemoveEmptyEntries); if (s.Length != 3) { Debug.LogWarning("[FreeIVA] Invalid collider rotation definition \"" + rotationString + "\": Must be in the form x, y, z."); return(null); } else { internalCollider.Rotation = Quaternion.Euler(float.Parse(s[0]), float.Parse(s[1]), float.Parse(s[2])); } } else { Debug.LogWarning("[FreeIVA] Collider rotation not found: Skipping collider."); return(null); } return(internalCollider); }
public static PropHatch LoadPropHatchFromCfg(ConfigNode node) { Vector3 position = Vector3.zero; Vector3 scale = Vector3.one; if (!node.HasValue("closedPropIndex")) { Debug.LogWarning("[FreeIVA] Prop hatch closedPropIndex not found: Skipping hatch."); return(null); } PropHatch propHatch = new PropHatch(); propHatch.ClosedPropIndex = int.Parse(node.GetValue("closedPropIndex")); if (node.HasValue("closedPropName")) { propHatch.ClosedPropName = node.GetValue("closedPropName"); } if (node.HasValue("openPropName")) { propHatch.OpenPropName = node.GetValue("openPropName"); } if (node.HasValue("attachNodeId")) { propHatch.AttachNodeId = node.GetValue("attachNodeId"); } if (node.HasValue("position")) { string posString = node.GetValue("position"); string[] p = posString.Split(Utils.CfgSplitChars, StringSplitOptions.RemoveEmptyEntries); if (p.Length != 3) { Debug.LogWarning("[FreeIVA] Invalid prop hatch position definition \"" + posString + "\": Must be in the form x, y, z."); return(null); } else { propHatch.LocalPosition = new Vector3(float.Parse(p[0]), float.Parse(p[1]), float.Parse(p[2])); } } else { Debug.LogWarning("[FreeIVA] PropHatch does not have a position"); } Debug.Log("# PropHatch position: " + propHatch.LocalPosition); if (node.HasValue("scale")) { string scaleString = node.GetValue("scale"); string[] s = scaleString.Split(Utils.CfgSplitChars, StringSplitOptions.RemoveEmptyEntries); if (s.Length != 3) { Debug.LogWarning("[FreeIVA] Invalid prop hatch scale definition \"" + scaleString + "\": Must be in the form x, y, z."); return(null); } else { propHatch.Scale = new Vector3(float.Parse(s[0]), float.Parse(s[1]), float.Parse(s[2])); } } if (node.HasValue("rotation")) { string rotationString = node.GetValue("rotation"); string[] s = rotationString.Split(Utils.CfgSplitChars, StringSplitOptions.RemoveEmptyEntries); if (s.Length != 3) { Debug.LogWarning("[FreeIVA] Invalid prop hatch rotation definition \"" + rotationString + "\": Must be in the form x, y, z."); return(null); } else { propHatch.Rotation = Quaternion.Euler(float.Parse(s[0]), float.Parse(s[1]), float.Parse(s[2])); } } if (node.HasValue("HatchOpenSoundFile")) { propHatch.HatchOpenSoundFile = node.GetValue("HatchOpenSoundFile"); } if (node.HasValue("HatchCloseSoundFile")) { propHatch.HatchCloseSoundFile = node.GetValue("HatchCloseSoundFile"); } if (node.HasNode("HideWhenOpen")) { ConfigNode[] hideNodes = node.GetNodes("HideWhenOpen"); foreach (var hideNode in hideNodes) { if (!hideNode.HasValue("name")) { Debug.LogWarning("[FreeIVA] HideWhenOpen name not found."); continue; } string propName = hideNode.GetValue("name"); if (hideNode.HasValue("position")) { string posString = hideNode.GetValue("position"); string[] p = posString.Split(Utils.CfgSplitChars, StringSplitOptions.RemoveEmptyEntries); if (p.Length != 3) { Debug.LogWarning("[FreeIVA] Invalid HideWhenOpen position definition \"" + posString + "\": Must be in the form x, y, z."); continue; } else { Vector3 propPos = new Vector3(float.Parse(p[0]), float.Parse(p[1]), float.Parse(p[2])); propHatch.HideWhenOpen.Add(new KeyValuePair <Vector3, string>(propPos, propName)); } } } } if (node.HasNode("InternalCollider")) { ConfigNode hatchColliderNode = node.GetNode("InternalCollider"); if (hatchColliderNode != null) { propHatch.Collider = InternalCollider.LoadFromCfg(hatchColliderNode); } } return(propHatch); }
private static void ColliderGui() { // TODO: Automatically add colliders to selected props using renderer bounds? if (GUILayout.Button((showColliderGui ? "Hide" : "Show") + " collider configuration")) { showColliderGui = !showColliderGui; } if (!showColliderGui) { InternalCollider.HideAllColliders(); return; } GUILayout.BeginHorizontal(); KerbalIva.KerbalCollider.collider.enabled = !GUILayout.Toggle(!KerbalIva.KerbalCollider.collider.enabled, "NoClip"); bool helmet = KerbalIva.WearingHelmet; KerbalIva.WearingHelmet = GUILayout.Toggle(KerbalIva.WearingHelmet, "Helmet"); if (helmet != KerbalIva.WearingHelmet) { } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); if (GUILayout.Button("Print collision layers")) { StringBuilder sb = new StringBuilder(); sb.Append(" 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 3 3"); sb.Append("0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1"); for (int i = 0; i < 32; i++) { sb.Append("\r\n"); if (i < 10) { sb.Append(" "); } sb.Append(i).Append("\t"); for (int j = 0; j < 32; j++) { sb.Append(Physics.GetIgnoreLayerCollision(i, j) ? "T " : "F "); } } Debug.Log(sb.ToString()); } if (GUILayout.Button("Create new collider")) { InternalCollider col = new InternalCollider(); col.Scale = new Vector3(0.5f, 0.5f, 0.5f); col.Instantiate(CurrentPart, _primitiveType); col.IvaGameObject.name = "Test collider"; CurrentModuleFreeIva.InternalColliders.Add(col); _colliderIndex = CurrentModuleFreeIva.InternalColliders.Count - 1; } if (GUILayout.Button("Stop all movement")) { foreach (var col in CurrentModuleFreeIva.InternalColliders) { col.IvaGameObject.rigidbody.velocity = Vector3.zero; col.IvaGameObject.rigidbody.angularVelocity = Vector3.zero; } } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); if (GUILayout.Toggle(_primitiveType == PrimitiveType.Sphere, "Sphere")) { _primitiveType = PrimitiveType.Sphere; } if (GUILayout.Toggle(_primitiveType == PrimitiveType.Capsule, "Capsule")) { _primitiveType = PrimitiveType.Capsule; } if (GUILayout.Toggle(_primitiveType == PrimitiveType.Cylinder, "Cylinder")) { _primitiveType = PrimitiveType.Cylinder; } if (GUILayout.Toggle(_primitiveType == PrimitiveType.Cube, "Cube")) { _primitiveType = PrimitiveType.Cube; } if (GUILayout.Toggle(_primitiveType == PrimitiveType.Plane, "Plane")) { _primitiveType = PrimitiveType.Plane; } if (GUILayout.Toggle(_primitiveType == PrimitiveType.Quad, "Quad")) { _primitiveType = PrimitiveType.Quad; } GUILayout.EndHorizontal(); InternalCollider c = null; if (CurrentModuleFreeIva.InternalColliders.Count == 0) { GUILayout.Label("No colliders"); } else { GUILayout.BeginHorizontal(); if (GUILayout.Button("Previous collider")) { _colliderIndex--; } if (GUILayout.Button("Next collider")) { _colliderIndex++; } GUILayout.EndHorizontal(); if (_colliderIndex >= CurrentModuleFreeIva.InternalColliders.Count) { _colliderIndex = 0; } if (_colliderIndex < 0) { _colliderIndex = CurrentModuleFreeIva.InternalColliders.Count - 1; } GuiUtils.label("Current collider", _colliderIndex + 1); c = CurrentModuleFreeIva.InternalColliders[_colliderIndex]; GuiUtils.label("Collider (" + (_colliderIndex + 1) + "/" + CurrentModuleFreeIva.InternalColliders.Count + ")", c.Name); } if (c == null) { return; } if (GUILayout.Button("Destroy collider")) { CurrentModuleFreeIva.InternalColliders.Remove(c); c.IvaGameObject.DestroyGameObject(); } GUILayout.BeginHorizontal(); c.IvaGameObject.collider.enabled = GUILayout.Toggle(c.IvaGameObject.collider.enabled, "Enabled"); bool wasVisible = c.Visible; bool v = GUILayout.Toggle(wasVisible, "Visible"); if (v != wasVisible) { c.Visible = v; } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("Position X"); float xPos = float.Parse(GUILayout.TextField(c.LocalPosition.x.ToString())); GUILayout.Label("Position Y"); float yPos = float.Parse(GUILayout.TextField(c.LocalPosition.y.ToString())); GUILayout.Label("Position Z"); float zPos = float.Parse(GUILayout.TextField(c.LocalPosition.z.ToString())); if (xPos != c.LocalPosition.x || yPos != c.LocalPosition.y || zPos != c.LocalPosition.z) { //currentJoint = c.IvaGameObject.GetComponent<FixedJoint>(); //if (currentJoint != null) Destroy(currentJoint); c.LocalPosition = new Vector3(xPos, yPos, zPos); //currentJoint = c.IvaGameObject.AddComponent<FixedJoint>(); //currentJoint.connectedBody = CurrentPart.collider.rigidbody; c.IvaGameObject.rigidbody.velocity = Vector3.zero; c.IvaGameObject.rigidbody.angularVelocity = Vector3.zero; } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("Scale X"); float xSc = float.Parse(GUILayout.TextField(c.Scale.x.ToString())); GUILayout.Label("Scale Y"); float ySc = float.Parse(GUILayout.TextField(c.Scale.y.ToString())); GUILayout.Label("Scale Z"); float zSc = float.Parse(GUILayout.TextField(c.Scale.z.ToString())); if (xSc != c.Scale.x || ySc != c.Scale.y || zSc != c.Scale.z) { //currentJoint = c.IvaGameObject.GetComponent<FixedJoint>(); //if (currentJoint != null) Destroy(currentJoint); c.Scale = new Vector3(xSc, ySc, zSc); //currentJoint = c.IvaGameObject.AddComponent<FixedJoint>(); //currentJoint.connectedBody = CurrentPart.collider.rigidbody; c.IvaGameObject.rigidbody.velocity = Vector3.zero; c.IvaGameObject.rigidbody.angularVelocity = Vector3.zero; } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("Rotation X"); float xRot = float.Parse(GUILayout.TextField(c.Rotation.eulerAngles.x.ToString())); GUILayout.Label("Rotation Y"); float yRot = float.Parse(GUILayout.TextField(c.Rotation.eulerAngles.y.ToString())); GUILayout.Label("Rotation Z"); float zRot = float.Parse(GUILayout.TextField(c.Rotation.eulerAngles.z.ToString())); if (xRot != c.Rotation.eulerAngles.x || yRot != c.Rotation.eulerAngles.y || zRot != c.Rotation.eulerAngles.z) { //currentJoint = c.IvaGameObject.GetComponent<FixedJoint>(); //if (currentJoint != null) Destroy(currentJoint); c.Rotation = Quaternion.Euler(xRot, yRot, zRot); //currentJoint = c.IvaGameObject.AddComponent<FixedJoint>(); //currentJoint.connectedBody = CurrentPart.collider.rigidbody; c.IvaGameObject.rigidbody.velocity = Vector3.zero; c.IvaGameObject.rigidbody.angularVelocity = Vector3.zero; } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GuiUtils.label("Velocity", c.IvaGameObject.rigidbody.velocity.magnitude); GuiUtils.label("Angular velocity", c.IvaGameObject.rigidbody.angularVelocity.magnitude); GUILayout.EndHorizontal(); }
private InternalCollider ParseInternalCollider(ConfigNode node) { Vector3 position = Vector3.zero; if (!node.HasValue("type")) { Debug.LogWarning("[FreeIVA] InternalCollider type not found: Skipping collider."); return null; } InternalCollider internalCollider = new InternalCollider(); internalCollider.ColliderType = (PrimitiveType)Enum.Parse(typeof(PrimitiveType), node.GetValue("type")); if (node.HasValue("name")) { internalCollider.Name = node.GetValue("name"); } if (node.HasValue("alwaysVisible")) { internalCollider.AlwaysVisible = bool.Parse(node.GetValue("alwaysVisible")); } if (node.HasValue("position")) { string posString = node.GetValue("position"); string[] p = posString.Split(_splitChars, StringSplitOptions.RemoveEmptyEntries); if (p.Length != 3) { Debug.LogWarning("[FreeIVA] Invalid collider position definition \"" + posString + "\": Must be in the form x, y, z."); return null; } else internalCollider.LocalPosition = new Vector3(float.Parse(p[0]), float.Parse(p[1]), float.Parse(p[2])); } else { Debug.LogWarning("[FreeIVA] Collider position not found: Skipping collider."); return null; } if (node.HasValue("scale")) { string scaleString = node.GetValue("scale"); string[] s = scaleString.Split(_splitChars, StringSplitOptions.RemoveEmptyEntries); if (s.Length != 3) { Debug.LogWarning("[FreeIVA] Invalid collider scale definition \"" + scaleString + "\": Must be in the form x, y, z."); return null; } else internalCollider.Scale = new Vector3(float.Parse(s[0]), float.Parse(s[1]), float.Parse(s[2])); } else { Debug.LogWarning("[FreeIVA] Collider scale not found: Skipping collider."); return null; } if (node.HasValue("rotation")) { string rotationString = node.GetValue("rotation"); string[] s = rotationString.Split(_splitChars, StringSplitOptions.RemoveEmptyEntries); if (s.Length != 3) { Debug.LogWarning("[FreeIVA] Invalid collider rotation definition \"" + rotationString + "\": Must be in the form x, y, z."); return null; } else internalCollider.Rotation = Quaternion.Euler(float.Parse(s[0]), float.Parse(s[1]), float.Parse(s[2])); } else { Debug.LogWarning("[FreeIVA] Collider rotation not found: Skipping collider."); return null; } return internalCollider; }
public override void OnLoad(ConfigNode node) { if (node.HasNode("Hatch")) { ConfigNode[] hatchNodes = node.GetNodes("Hatch"); foreach (var hn in hatchNodes) { IHatch h = Hatch.LoadFromCfg(hn); if (h != null) { Hatches.Add(h); } } PersistenceManager.instance.AddHatches(part.name, Hatches); } Debug.Log("# Hatches loaded from config for part " + part.name + ": " + Hatches.Count); if (node.HasNode("PropHatch")) { ConfigNode[] propHatchNodes = node.GetNodes("PropHatch"); foreach (var phn in propHatchNodes) { PropHatch ph = PropHatch.LoadPropHatchFromCfg(phn); if (ph != null) { Hatches.Add(ph); } } PersistenceManager.instance.AddHatches(part.name, Hatches); } if (node.HasNode("MeshHatch")) { ConfigNode[] meshHatchNodes = node.GetNodes("MeshHatch"); foreach (var mhn in meshHatchNodes) { MeshHatch mh = MeshHatch.LoadMeshHatchFromCfg(mhn); if (mh != null) { Hatches.Add(mh); } } PersistenceManager.instance.AddHatches(part.name, Hatches); } //if (node.HasNode("PropHatchAnimated")) //{ // ConfigNode[] propHatchAnimatedNodes = node.GetNodes("PropHatchAnimated"); // foreach (var phan in propHatchAnimatedNodes) // { // PropHatchAnimated pha = PropHatchAnimated.LoadPropHatchFromCfg(phan); // if (pha != null) // { // Hatches.Add(pha); // if (pha.Collider != null) // InternalColliders.Add(pha.Collider); // } // } // PersistenceManager.instance.AddHatches(part.name, Hatches); //} Debug.Log("# Hatches loaded from config for part " + part.name + ": " + Hatches.Count); if (node.HasNode("InternalCollider")) { ConfigNode[] colliderNodes = node.GetNodes("InternalCollider"); foreach (var cn in colliderNodes) { InternalCollider ic = InternalCollider.LoadFromCfg(cn); if (ic != null) { InternalColliders.Add(ic); } } PersistenceManager.instance.AddInternalColliders(part.name, InternalColliders); Debug.Log("# Internal colliders loaded from config for part " + part.name + ": " + InternalColliders.Count); } else if (InternalColliders != null && InternalColliders.Count > 0) { PersistenceManager.instance.AddInternalColliders(part.name, InternalColliders); Debug.Log("# Internal colliders loaded from config for part " + part.name + ": " + InternalColliders.Count); } }