/// <summary>Makes a game object to represent currently dragging assembly.</summary> /// <remarks>It's a very expensive operation.</remarks> static void MakePointer() { DestroyPointer(); // Make pointer node transformations. if (pointerNodeTransform) { pointerNodeTransform.gameObject.DestroyGameObject(); } pointerNodeTransform = new GameObject("KISPointerPartNode").transform; // Deatch will decouple from the parent so, ask to ignore it when looking for the nodes. attachNodes = KIS_Shared.GetAvailableAttachNodes(partToAttach, ignoreAttachedPart: partToAttach.parent); if (!attachNodes.Any()) { //TODO: When there are no nodes try finding ones in the parent or in the children. // Ideally, the caller should have checked if this part has free nodes. Now the only // way is to pick *any* node. The surface one always exists so, it's a good // candidate. Though, for many details it may result in a weird representation. Logger.logError("Part {0} has no free nodes, use {1}", partToAttach, partToAttach.srfAttachNode); attachNodes.Add(partToAttach.srfAttachNode); } attachNodeIndex = 0; // Expect that first node is the best default. UpdatePointerAttachNode(); // Make pointer renderer. var combines = new List <CombineInstance>(); CollectMeshesFromAssembly(partToAttach, combines); // Create one filter per mesh in the hierarhcy. Simple combining all meshes into one // larger mesh may have weird representation artifacts on different video cards. pointer = new GameObject("KISPointer"); foreach (var combine in combines) { var mesh = new Mesh(); mesh.CombineMeshes(new[] { combine }); var childObj = new GameObject("KISPointerChildMesh"); var meshRenderer = childObj.AddComponent <MeshRenderer>(); meshRenderer.shadowCastingMode = ShadowCastingMode.Off; meshRenderer.receiveShadows = false; var filter = childObj.AddComponent <MeshFilter>(); filter.sharedMesh = mesh; childObj.transform.parent = pointer.transform; } allModelMr = pointer.GetComponentsInChildren <MeshRenderer>().ToList(); foreach (var mr in allModelMr) { mr.material = new Material(Shader.Find("Transparent/Diffuse")); } pointerNodeTransform.parent = pointer.transform; Logger.logInfo("New pointer created"); }
/// <summary>Sets possible attach nodes in <c>attachNodes</c>.</summary> /// <exception cref="InvalidOperationException"> /// If part has no valid attachment nodes. /// </exception> private static void MakePointerAttachNodes() { // Make node transformations. if (pointerNodeTransform) { Destroy(pointerNodeTransform); } pointerNodeTransform = new GameObject("KASPointerPartNode").transform; // Deatch will decouple from the parent so, ask to ignore it when looking for the nodes. attachNodes = KIS_Shared.GetAvailableAttachNodes(partToAttach, ignoreAttachedPart: partToAttach.parent); if (!attachNodes.Any()) { //TODO: When there are no nodes try finding ones in the parent or in the children. // Ideally, the caller should have checked if this part has free nodes. Now the only // way is to pick *any* node. The surface one always exists so, it's a good // candidate. Though, for many details it may result in a weird representation. Logger.logError("Part {0} has no free nodes, use {1}", partToAttach, partToAttach.srfAttachNode); attachNodes.Add(partToAttach.srfAttachNode); } attachNodeIndex = 0; // Expect that first node is the best default. UpdatePointerAttachNode(); }
/// <summary>Makes a game object to represent currently dragging assembly.</summary> /// <remarks>It's a very expensive operation.</remarks> static void MakePointer(Part rootPart) { DestroyPointer(); // Make pointer node transformations. if (pointerNodeTransform) { pointerNodeTransform.gameObject.DestroyGameObject(); } pointerNodeTransform = new GameObject("KISPointerPartNode").transform; // Deatch will decouple from the parent so, ask to ignore it when looking for the nodes. attachNodes = KIS_Shared.GetAvailableAttachNodes(rootPart, ignoreAttachedPart: rootPart.parent) .Select(AttachNode.Clone) .ToList(); if (!attachNodes.Any()) { //TODO: When there are no nodes try finding ones in the parent or in the children. // Ideally, the caller should have checked if this part has free nodes. Now the only // way is to pick *any* node. The surface one always exists so, it's a good // candidate. However, for many details it may result in a weird representation. DebugEx.Error( "Part {0} has no free nodes, use {1}", rootPart, rootPart.srfAttachNode); attachNodes.Add(AttachNode.Clone(rootPart.srfAttachNode)); } attachNodeIndex = 0; // Expect that first node is the best default. // Collect models from all the part in the assembly. pointer = new GameObject("KISPointer"); var model = KISAPI.PartUtils.GetSceneAssemblyModel(rootPart, keepColliders: true); var colliders = model.GetComponentsInChildren <Collider>().ToList(); CreateAutoOffsets(model, colliders); aboveAutoOffset = autoOffsets[attachNodeIndex]; foreach (var collider in colliders) { UnityEngine.Object.DestroyImmediate(collider); } model.transform.parent = pointer.transform; model.transform.position = Vector3.zero; model.transform.rotation = Quaternion.identity; allModelRenderers.Clear(); allModelRenderers.AddRange(pointer.GetComponentsInChildren <Renderer>()); foreach (var renderer in allModelRenderers) { renderer.material = new Material(Shader.Find("Transparent/Diffuse")); renderer.shadowCastingMode = ShadowCastingMode.Off; renderer.receiveShadows = false; } pointerNodeTransform.parent = pointer.transform; DebugEx.Fine("New pointer created"); }
static void OnMouseEnterPart(Part hoverPart) { if (hoverPart == partToAttach) { return; } if (allowMount) { ModuleKISPartMount pMount = hoverPart.GetComponent <ModuleKISPartMount>(); if (pMount) { // Set current attach node AttachNode an = attachNodes.Find(f => f.id == pMount.mountedPartNode); if (an != null) { attachNodeIndex = attachNodes.IndexOf(an); SetPointerVisible(false); } else { SetPointerVisible(true); } // Init attach node foreach (KeyValuePair <AttachNode, List <string> > mount in pMount.GetMounts()) { if (!mount.Key.attachedPart) { KIS_Shared.AssignAttachIcon(hoverPart, mount.Key, colorMountOk, "KISMount"); } } } } if (allowStack && currentAttachNode.nodeType != AttachNode.NodeType.Surface) { var variant = VariantsUtils.GetCurrentPartVariant(hoverPart); if (variant != null) { VariantsUtils.ApplyVariantOnAttachNodes(hoverPart, variant); } foreach (var an in KIS_Shared.GetAvailableAttachNodes(hoverPart, needSrf: false)) { KIS_Shared.AssignAttachIcon(hoverPart, an, colorStack); } } SendPointerState(pointerTarget, PointerState.OnMouseEnterPart, hoverPart, null); }