Esempio n. 1
0
        public static void AddPodInventories(Part part, int crewCapacity)
        {
            for (var i = 0; i < crewCapacity; i++)
            {
                var moduleInventory =
                    part.AddModule(typeof(ModuleKISInventory).Name) as ModuleKISInventory;
                KIS_Shared.AwakePartModule(moduleInventory);
                moduleInventory.invType = ModuleKISInventory.InventoryType.Pod;
                DebugEx.Fine("{0}: Add pod inventory to match the capacity", part);
            }
            var podInventories = part.Modules.OfType <ModuleKISInventory>()
                                 .Where(m => m.invType == ModuleKISInventory.InventoryType.Pod)
                                 .ToArray();

            for (var i = 0; i < podInventories.Length; i++)
            {
                try {
                    var baseFields = new BaseFieldList(podInventories[i]);
                    baseFields.Load(evaInventory);
                    podInventories[i].podSeat = i;
                    DebugEx.Fine("{0}: Pod inventory for seat {1} loaded successfully", part, i);
                } catch {
                    DebugEx.Error("{0}: Pod inventory module for seat {1} can't be loaded!", part, i);
                }
            }
        }
Esempio n. 2
0
 public void Unequip()
 {
     if (!prefabModule)
     {
         return;
     }
     if (equipMode == EquipMode.Model)
     {
         UnityEngine.Object.Destroy(equippedGameObj);
         if (prefabModule.equipRemoveHelmet)
         {
             inventory.SetHelmet(true);
         }
     }
     if (equipMode == EquipMode.Part || equipMode == EquipMode.Physic)
     {
         Logger.logInfo("Update config node of equipped part: {0}", availablePart.title);
         partNode.ClearData();
         KIS_Shared.PartSnapshot(equippedPart).CopyTo(partNode);
         equippedPart.Die();
     }
     evaTransform    = null;
     equippedPart    = null;
     equippedGameObj = null;
     equipped        = false;
     PlaySound(prefabModule.moveSndPath);
     prefabModule.OnUnEquip(this);
 }
Esempio n. 3
0
 private void UpdateKey()
 {
     if (isRunning)
     {
         if (
             Input.GetKeyDown(KeyCode.Escape) ||
             Input.GetKeyDown(KeyCode.Return)
             )
         {
             KIS_Shared.DebugLog("Cancel key pressed, stop eva attach mode");
             StopPointer();
             SendPointerClick(PointerTarget.Nothing, Vector3.zero, Quaternion.identity, null, null);
         }
         if (GameSettings.Editor_toggleSymMethod.GetKeyDown())
         {
             if (pointerTarget != PointerTarget.PartMount)
             {
                 if (pointer)
                 {
                     UnityEngine.Object.Destroy(pointer);
                 }
                 attachNodeIndex++;
                 if (attachNodeIndex > (attachNodes.Count - 1))
                 {
                     attachNodeIndex = 0;
                 }
                 ResetMouseOver();
                 SendPointerState(pointerTarget, PointerState.OnChangeAttachNode, null, null);
             }
         }
     }
 }
Esempio n. 4
0
 public static void StopPointer()
 {
     KIS_Shared.DebugLog("StopPointer(pointer)");
     running = false;
     ResetMouseOver();
     InputLockManager.RemoveControlLock("KISpointer");
 }
Esempio n. 5
0
 /// <summary>Handles keyboard input.</summary>
 private void UpdateKey()
 {
     if (isRunning)
     {
         if (KIS_Shared.IsKeyUp(KeyCode.Escape) || KIS_Shared.IsKeyDown(KeyCode.Return))
         {
             Debug.Log("Cancel key pressed, stop eva attach mode");
             StopPointer(unlockUI: false);
             SendPointerClick(PointerTarget.Nothing, Vector3.zero, Quaternion.identity, null, null);
             // Delay unlocking to not let ESC be handled by the game.
             AsyncCall.CallOnEndOfFrame(this, UnlockUI);
         }
         if (GameSettings.Editor_toggleSymMethod.GetKeyDown()) // "R" by default.
         {
             if (pointerTarget != PointerTarget.PartMount && attachNodes.Count() > 1)
             {
                 attachNodeIndex++;
                 if (attachNodeIndex > (attachNodes.Count - 1))
                 {
                     attachNodeIndex = 0;
                 }
                 Debug.LogFormat("Attach node index changed to: {0}", attachNodeIndex);
                 UpdatePointerAttachNode();
                 ResetMouseOver();
                 SendPointerState(pointerTarget, PointerState.OnChangeAttachNode, null, null);
             }
             else
             {
                 ScreenMessaging.ShowInfoScreenMessage("This part has only one attach node!");
                 audioBipWrong.Play();
             }
         }
     }
 }
Esempio n. 6
0
 /// <summary>Handles keyboard input.</summary>
 private void UpdateKey()
 {
     if (isRunning)
     {
         if (KIS_Shared.IsKeyUp(KeyCode.Escape) || KIS_Shared.IsKeyDown(KeyCode.Return))
         {
             DebugEx.Fine("Cancel key pressed, stop eva attach mode");
             CancelPointer(this);
         }
         if (GameSettings.Editor_toggleSymMethod.GetKeyDown()) // "R" by default.
         {
             if (pointerTarget != PointerTarget.PartMount && attachNodes.Count() > 1)
             {
                 if (attachNodeIndex < attachNodes.Count - 1)
                 {
                     attachNodeIndex++;
                 }
                 else
                 {
                     attachNodeIndex = 0;
                 }
                 DebugEx.Fine("Attach node index changed to: {0}", attachNodeIndex);
                 ResetMouseOver();
                 SendPointerState(pointerTarget, PointerState.OnChangeAttachNode, null, null);
             }
             else
             {
                 ScreenMessaging.ShowInfoScreenMessage(OnlyOneAttachNodeMsg);
                 UISounds.PlayBipWrong();
             }
         }
     }
 }
Esempio n. 7
0
        private void MoveAttach(Part tgtPart, Vector3 pos, Quaternion rot, string srcAttachNodeID = null, AttachNode tgtAttachNode = null)
        {
            KIS_Shared.DebugLog("Move part & attach");
            KIS_Shared.SendKISMessage(movingPart, KIS_Shared.MessageAction.AttachStart, KISAddonPointer.GetCurrentAttachNode(), tgtPart, tgtAttachNode);
            KIS_Shared.DecoupleFromAll(movingPart);
            movingPart.transform.position = pos;
            movingPart.transform.rotation = rot;

            ModuleKISItem moduleItem            = movingPart.GetComponent <ModuleKISItem>();
            bool          useExternalPartAttach = false;

            if (moduleItem)
            {
                if (moduleItem.useExternalPartAttach)
                {
                    useExternalPartAttach = true;
                }
            }
            if (tgtPart && !useExternalPartAttach)
            {
                KIS_Shared.CouplePart(movingPart, tgtPart, srcAttachNodeID, tgtAttachNode);
            }
            KIS_Shared.SendKISMessage(movingPart, KIS_Shared.MessageAction.AttachEnd, KISAddonPointer.GetCurrentAttachNode(), tgtPart, tgtAttachNode);
            KISAddonPointer.StopPointer();
            movingPart  = null;
            draggedItem = null;
            draggedPart = null;
        }
Esempio n. 8
0
        public void OnKISAction(BaseEventData baseEventData)
        {
            if (allowStaticAttach == ItemAttachMode.Disabled || useExternalStaticAttach)
            {
                return;
            }
            string action  = baseEventData.GetString("action");
            Part   tgtPart = (Part)baseEventData.Get("targetPart");

            //FIXME: use enum values
            if (action == KIS_Shared.MessageAction.Store.ToString() ||
                action == KIS_Shared.MessageAction.DropEnd.ToString() ||
                action == KIS_Shared.MessageAction.AttachStart.ToString())
            {
                GroundDetach();
                var modulePickup = KISAddonPickup.instance.GetActivePickupNearest(this.transform.position);
                if (modulePickup)
                {
                    KIS_Shared.PlaySoundAtPoint(modulePickup.detachStaticSndPath, this.transform.position);
                }
            }
            if (action == KIS_Shared.MessageAction.AttachEnd.ToString() && tgtPart == null)
            {
                GroundAttach();
                var modulePickup = KISAddonPickup.instance.GetActivePickupNearest(this.transform.position);
                if (modulePickup)
                {
                    KIS_Shared.PlaySoundAtPoint(modulePickup.attachStaticSndPath, this.transform.position);
                }
            }
        }
Esempio n. 9
0
 public void Unequip(ActorType actorType = ActorType.API)
 {
     if (!prefabModule)
     {
         return;
     }
     // This must be firts thing to happen to prevent other handlers to trigger.
     equipped = false;
     if (equipMode == EquipMode.Model)
     {
         UnityEngine.Object.Destroy(equippedGameObj);
         if (prefabModule.equipRemoveHelmet)
         {
             inventory.SetHelmet(true);
         }
     }
     if (equipMode == EquipMode.Part || equipMode == EquipMode.Physic)
     {
         Debug.LogFormat("Update config node of equipped part: {0}", availablePart.title);
         partNode.ClearData();
         KIS_Shared.PartSnapshot(equippedPart).CopyTo(partNode);
         equippedPart.Die();
     }
     evaTransform    = null;
     equippedPart    = null;
     equippedGameObj = null;
     if (actorType == ActorType.Player)
     {
         UISoundPlayer.instance.Play(prefabModule.moveSndPath);
     }
     prefabModule.OnUnEquip(this);
 }
Esempio n. 10
0
        /// <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();
        }
Esempio n. 11
0
        public Dictionary <AttachNode, List <string> > GetMounts()
        {
            Dictionary <AttachNode, List <string> > mounts = new Dictionary <AttachNode, List <string> >();
            ConfigNode node = KIS_Shared.GetBaseConfigNode(this);

            foreach (ConfigNode mountNode in node.GetNodes("MOUNT"))
            {
                if (mountNode.HasValue("attachNode") && mountNode.HasValue("allowedPartName"))
                {
                    string     attachNodeName = mountNode.GetValue("attachNode");
                    AttachNode an             = this.part.findAttachNode(attachNodeName);
                    if (an == null)
                    {
                        KIS_Shared.DebugError("GetMountNodes - Node : " + attachNodeName + " not found !");
                        continue;
                    }

                    List <string> allowedPartNames = new List <string>();
                    foreach (string partName in mountNode.GetValues("allowedPartName"))
                    {
                        allowedPartNames.Add(partName.Replace('_', '.'));
                    }
                    mounts.Add(an, allowedPartNames);
                }
            }
            return(mounts);
        }
Esempio n. 12
0
 /// <summary>Handles keyboard input.</summary>
 private void UpdateKey()
 {
     if (isRunning)
     {
         if (Input.GetKeyDown(KeyCode.Escape) ||
             Input.GetKeyDown(KeyCode.Return))
         {
             Logger.logInfo("Cancel key pressed, stop eva attach mode");
             StopPointer();
             SendPointerClick(PointerTarget.Nothing, Vector3.zero, Quaternion.identity, null, null);
         }
         if (GameSettings.Editor_toggleSymMethod.GetKeyDown()) // "R" by default.
         {
             if (pointerTarget != PointerTarget.PartMount && attachNodes.Count() > 1)
             {
                 attachNodeIndex++;
                 if (attachNodeIndex > (attachNodes.Count - 1))
                 {
                     attachNodeIndex = 0;
                 }
                 Logger.logInfo("Attach node index changed to: {0}", attachNodeIndex);
                 UpdatePointerAttachNode();
                 ResetMouseOver();
                 SendPointerState(pointerTarget, PointerState.OnChangeAttachNode, null, null);
             }
             else
             {
                 KIS_Shared.ShowRightScreenMessage("This part has only one attach node!");
                 audioBipWrong.Play();
             }
         }
     }
 }
Esempio n. 13
0
        private Part CreateAttach(Part tgtPart, Vector3 pos, Quaternion rot, string srcAttachNodeID = null, AttachNode tgtAttachNode = null)
        {
            KIS_Shared.DebugLog("Create part & attach");
            Part newPart;

            draggedItem.StackRemove(1);
            bool useExternalPartAttach = false;

            if (draggedItem.prefabModule)
            {
                if (draggedItem.prefabModule.useExternalPartAttach)
                {
                    useExternalPartAttach = true;
                }
            }
            if (tgtPart && !useExternalPartAttach)
            {
                newPart = KIS_Shared.CreatePart(draggedItem.partNode, pos, rot, draggedItem.inventory.part, tgtPart, srcAttachNodeID, tgtAttachNode, OnPartCoupled);
            }
            else
            {
                newPart = KIS_Shared.CreatePart(draggedItem.partNode, pos, rot, draggedItem.inventory.part);
                KIS_Shared.SendKISMessage(newPart, KIS_Shared.MessageAction.AttachEnd, KISAddonPointer.GetCurrentAttachNode(), tgtPart, tgtAttachNode);
            }
            KISAddonPointer.StopPointer();
            movingPart  = null;
            draggedItem = null;
            draggedPart = null;
            return(newPart);
        }
Esempio n. 14
0
        private void MoveDrop(Part tgtPart, Vector3 pos, Quaternion rot)
        {
            KIS_Shared.DebugLog("Move part");
            ModuleKISPickup modulePickup = GetActivePickupNearest(pos);

            if (modulePickup)
            {
                if (movingPart.parent)
                {
                    bool movingPartMounted   = false;
                    ModuleKISPartMount partM = movingPart.parent.GetComponent <ModuleKISPartMount>();
                    if (partM)
                    {
                        if (partM.PartIsMounted(movingPart))
                        {
                            movingPartMounted = true;
                        }
                    }
                    if (!movingPartMounted)
                    {
                        AudioSource.PlayClipAtPoint(GameDatabase.Instance.GetAudioClip(modulePickup.detachPartSndPath), movingPart.transform.position);
                    }
                }
                AudioSource.PlayClipAtPoint(GameDatabase.Instance.GetAudioClip(modulePickup.dropSndPath), pos);
            }
            KIS_Shared.DecoupleFromAll(movingPart);
            movingPart.transform.position = pos;
            movingPart.transform.rotation = rot;
            KIS_Shared.SendKISMessage(movingPart, KIS_Shared.MessageAction.DropEnd, KISAddonPointer.GetCurrentAttachNode(), tgtPart);
            KISAddonPointer.StopPointer();
            movingPart = null;
        }
Esempio n. 15
0
        /// <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");
        }
Esempio n. 16
0
 public void Drop(Part part, Part fromPart)
 {
     if (!KISAddonPointer.isRunning)
     {
         ModuleKISPickup pickupModule = GetActivePickupNearest(fromPart);
         if (pickupModule)
         {
             KISAddonPointer.allowPart  = KISAddonPointer.allowEva = KISAddonPointer.allowMount = KISAddonPointer.allowStatic = true;
             KISAddonPointer.allowStack = pickupModule.allowPartStack;
             KISAddonPointer.maxDist    = pickupModule.maxDistance;
             if (draggedItem != null)
             {
                 KISAddonPointer.scale = draggedItem.GetScale();
             }
             else
             {
                 KISAddonPointer.scale = 1;
             }
             KISAddonPointer.StartPointer(part, OnPointerAction, OnPointerState, pickupModule.transform);
             pointerMode = PointerMode.Drop;
         }
         else
         {
             KIS_Shared.DebugError("No active pickup nearest !");
         }
     }
     KISAddonCursor.StopPartDetection();
 }
Esempio n. 17
0
        /// <inheritdoc/>
        public override void OnItemUse(KIS_Item item, KIS_Item.UseFrom useFrom)
        {
            pageList.Clear();
            var node = KIS_Shared.GetBaseConfigNode(this);

            foreach (string page in node.GetValues("page"))
            {
                pageList.Add(page);
            }
            if (pageList.Count > 0)
            {
                pageIndex = 0;
                pageTotal = pageList.Count;
                guiObj    = new GameObject("KISManualDialog-" + part.flightID);
                var dlg = guiObj.AddComponent <GuiDialog>();
                dlg.dialogFunction = GuiReader;

                pageTexture = GameDatabase.Instance.GetTexture(pageList[0], false);
                UISoundPlayer.instance.Play(bookOpenSndPath);
            }
            else
            {
                DebugEx.Info("The book has no pages configured");
            }
        }
Esempio n. 18
0
        private void InitConfig(AvailablePart availablePart,
                                ModuleKISInventory inventory, float quantity)
        {
            this.inventory = inventory;
            this.quantity  = quantity;
            prefabModule   = availablePart.partPrefab.GetComponent <ModuleKISItem>();
            volume         = KIS_Shared.GetPartVolume(availablePart);
            cost           = GetCost();

            // Set launchID
            if (partNode.HasValue("launchID"))
            {
                if (int.Parse(this.partNode.GetValue("launchID")) == 0)
                {
                    partNode.SetValue("launchID", this.inventory.part.launchID.ToString(), true);
                }
            }
            else
            {
                partNode.SetValue("launchID", this.inventory.part.launchID.ToString(), true);
            }

            if (prefabModule)
            {
                equipable           = prefabModule.equipable;
                stackable           = prefabModule.stackable;
                equipSlot           = prefabModule.equipSlot;
                usableFromEva       = prefabModule.usableFromEva;
                usableFromContainer = prefabModule.usableFromContainer;
                usableFromPod       = prefabModule.usableFromPod;
                usableFromEditor    = prefabModule.usableFromEditor;
                carriable           = prefabModule.carriable;
            }
            int nonStackableModule = 0;

            foreach (PartModule pModule in availablePart.partPrefab.Modules)
            {
                if (!KISAddonConfig.stackableModules.Contains(pModule.moduleName))
                {
                    nonStackableModule++;
                }
            }
            if (nonStackableModule == 0 && GetResources().Count == 0)
            {
                Logger.logInfo(
                    "No non-stackable module or a resource found on the part, set the item as stackable");
                stackable = true;
            }
            if (KISAddonConfig.stackableList.Contains(availablePart.name) ||
                availablePart.name.IndexOf('.') != -1 &&
                KISAddonConfig.stackableList.Contains(availablePart.name.Replace('.', '_')))
            {
                Logger.logInfo("Part name present in settings.cfg (node StackableItemOverride),"
                               + " force item as stackable");
                stackable = true;
            }
        }
Esempio n. 19
0
        private void InitConfig(AvailablePart availablePart, ModuleKISInventory inventory, float quantity)
        {
            this.inventory    = inventory;
            this.quantity     = quantity;
            this.prefabModule = availablePart.partPrefab.GetComponent <ModuleKISItem>();
            this.volume       = GetVolume();
            this.cost         = GetCost();

            // Set launchID
            if (this.partNode.HasValue("launchID"))
            {
                if (int.Parse(this.partNode.GetValue("launchID")) == 0)
                {
                    this.partNode.SetValue("launchID", this.inventory.part.launchID.ToString(), true);
                }
            }
            else
            {
                this.partNode.SetValue("launchID", this.inventory.part.launchID.ToString(), true);
            }

            if (this.prefabModule)
            {
                if (this.prefabModule.volumeOverride > 0)
                {
                    this.volume = this.prefabModule.volumeOverride;
                }
                this.equipable           = prefabModule.equipable;
                this.stackable           = prefabModule.stackable;
                this.equipSlot           = prefabModule.equipSlot;
                this.usableFromEva       = prefabModule.usableFromEva;
                this.usableFromContainer = prefabModule.usableFromContainer;
                this.usableFromPod       = prefabModule.usableFromPod;
                this.usableFromEditor    = prefabModule.usableFromEditor;
                this.carriable           = prefabModule.carriable;
            }
            int nonStackableModule = 0;

            foreach (PartModule pModule in availablePart.partPrefab.Modules)
            {
                if (!KISAddonConfig.stackableModules.Contains(pModule.moduleName))
                {
                    nonStackableModule++;
                }
            }
            if (nonStackableModule == 0 && GetResources().Count == 0)
            {
                KIS_Shared.DebugLog("No non-stackable module and ressource found on the part, set item as stackable");
                this.stackable = true;
            }
            if (KISAddonConfig.stackableList.Contains(availablePart.name))
            {
                KIS_Shared.DebugLog("Part name present in settings.cfg (node StackableItemOverride), force item as stackable");
                this.stackable = true;
            }
        }
Esempio n. 20
0
        /// <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");
        }
Esempio n. 21
0
        /// <summary>Sets pointer origin to the current attachment node</summary>
        private static void UpdatePointerAttachNode()
        {
            var node = GetCurrentAttachNode();

            pointerNodeTransform.localPosition = node.position;
            // HACK(ihsoft): For some reason Z orientation axis is get mirrored in the parts for the stack
            //   nodes. It results in a weird behavior when aligning parts in "back" or "front" node attach
            //   modes. It may be a KIS code bug but I gave up finding it.
            pointerNodeTransform.localRotation =
                KIS_Shared.GetNodeRotation(node, mirrorZ: node.nodeType != AttachNode.NodeType.Surface);
        }
Esempio n. 22
0
 public override void OnStart(StartState state)
 {
     base.OnStart(state);
     if (state == StartState.Editor || state == StartState.None)
     {
         return;
     }
     Events["Activate"].guiName = activateText;
     KIS_Shared.createFXSound(this.part, fxSndTimeStart, timeStartSndPath, false);
     KIS_Shared.createFXSound(this.part, fxSndTimeLoop, timeLoopSndPath, true);
     KIS_Shared.createFXSound(this.part, fxSndTimeEnd, timeEndSndPath, false);
 }
Esempio n. 23
0
 public static void StopPartDetection()
 {
     partDetectionActive = false;
     if (hoveredPart && delegateOnMouseExitPart != null)
     {
         delegateOnMouseExitPart(hoveredPart);
     }
     if (hoveredPart != null)
     {
         KIS_Shared.SetHierarchySelection(hoveredPart, false /* isSelected */);
     }
     hoveredPart = null;
 }
Esempio n. 24
0
 void Update()
 {
     // Check if grab key is pressed
     if (HighLogic.LoadedSceneIsFlight)
     {
         if (Input.GetKeyDown(grabKey.ToLower()))
         {
             EnableGrabMode();
         }
         if (Input.GetKeyUp(grabKey.ToLower()))
         {
             DisableGrabMode();
         }
     }
     // Check if attach/detach key is pressed
     if (HighLogic.LoadedSceneIsFlight)
     {
         if (Input.GetKeyDown(attachKey.ToLower()))
         {
             EnableAttachMode();
         }
         if (Input.GetKeyUp(attachKey.ToLower()))
         {
             DisableAttachMode();
         }
     }
     // Drag editor parts
     if (HighLogic.LoadedSceneIsEditor)
     {
         if (Input.GetMouseButtonDown(0))
         {
             if (!UIManager.instance.DidPointerHitUI(0) && InputLockManager.IsUnlocked(ControlTypes.EDITOR_PAD_PICK_PLACE))
             {
                 Part part = KIS_Shared.GetPartUnderCursor();
                 if (part)
                 {
                     OnMouseGrabPartClick(part);
                 }
             }
         }
     }
     // On drag released
     if (HighLogic.LoadedSceneIsEditor || HighLogic.LoadedSceneIsFlight)
     {
         if (draggedPart && Input.GetMouseButtonUp(0))
         {
             OnDragReleased();
         }
     }
 }
Esempio n. 25
0
        public void OnEquippedPartCoupled(Part createdPart, Part tgtPart = null,
                                          AttachNode tgtAttachNode       = null)
        {
            if (equipMode == EquipMode.Part)
            {
                //Disable colliders
                foreach (var col in equippedPart.gameObject.GetComponentsInChildren <Collider>())
                {
                    col.isTrigger = true;
                }

                //Destroy joint to avoid buggy eva move
                if (equippedPart.attachJoint)
                {
                    equippedPart.attachJoint.DestroyJoint();
                }

                //Destroy rigidbody
                equippedPart.physicalSignificance = Part.PhysicalSignificance.NONE;
                if (equippedPart.collisionEnhancer)
                {
                    UnityEngine.Object.DestroyImmediate(equippedPart.collisionEnhancer);
                }
                UnityEngine.Object.Destroy(equippedPart.Rigidbody);
            }

            if (equipMode == EquipMode.Physic)
            {
                equippedPart.mass = 0.001f;
                //Disable colliders
                foreach (Collider col in equippedPart.gameObject.GetComponentsInChildren <Collider>())
                {
                    col.isTrigger = true;
                }

                //Destroy joint to avoid buggy eva move
                if (equippedPart.attachJoint)
                {
                    equippedPart.attachJoint.DestroyJoint();
                }

                //Create physic join
                FixedJoint evaJoint = equippedPart.gameObject.AddComponent <FixedJoint>();
                evaJoint.connectedBody = inventory.part.Rigidbody;//evaCollider.attachedRigidbody;
                evaJoint.breakForce    = EqippedPartJointBreakForce;
                evaJoint.breakTorque   = EqippedPartJointBreakForce;
                KIS_Shared.ResetCollisionEnhancer(equippedPart);
            }
        }
Esempio n. 26
0
        void Awake()
        {
            audioBipWrong          = audioGo.AddComponent <AudioSource>();
            audioBipWrong.volume   = GameSettings.UI_VOLUME;
            audioBipWrong.panLevel = 0;  //set as 2D audiosource

            if (GameDatabase.Instance.ExistsAudioClip(KIS_Shared.bipWrongSndPath))
            {
                audioBipWrong.clip = GameDatabase.Instance.GetAudioClip(KIS_Shared.bipWrongSndPath);
            }
            else
            {
                KIS_Shared.DebugError("Awake(AttachPointer) Bip wrong sound not found in the game database !");
            }
        }
Esempio n. 27
0
 public float GetVolume()
 {
     // TweakScale compatibility
     foreach (ConfigNode node in this.partNode.GetNodes("MODULE"))
     {
         if (node.HasValue("name"))
         {
             if (node.GetValue("name") == "TweakScale" && node.HasValue("currentScale") && node.HasValue("defaultScale"))
             {
                 return(KIS_Shared.GetPartVolume(availablePart.partPrefab) * (float)Math.Pow(double.Parse(node.GetValue("currentScale")) / double.Parse(node.GetValue("defaultScale")), 3));
             }
         }
     }
     return(KIS_Shared.GetPartVolume(availablePart.partPrefab));
 }
Esempio n. 28
0
        public void Awake()
        {
            ConfigAccessor.ReadFieldsInType(GetType(), this);
            ConfigAccessor.ReadFieldsInType(typeof(ModuleKISInventory), instance: null);

            // Set inventory module for every eva kerbal
            Debug.Log("Set KIS config...");
            ConfigNode nodeSettings = GameDatabase.Instance.GetConfigNode("KIS/settings/KISConfig");

            if (nodeSettings == null)
            {
                Debug.LogError("KIS settings.cfg not found or invalid !");
                return;
            }

            // Kerbal parts.
            UpdateEvaPrefab(MaleKerbalEva, nodeSettings);
            UpdateEvaPrefab(FemaleKerbalEva, nodeSettings);

            // Set inventory module for every pod with crew capacity.
            Debug.Log("Loading pod inventories...");
            foreach (AvailablePart avPart in PartLoader.LoadedPartsList)
            {
                if (avPart.name == MaleKerbalEva || avPart.name == FemaleKerbalEva ||
                    avPart.name == RdKerbalEva ||
                    !avPart.partPrefab || avPart.partPrefab.CrewCapacity < 1)
                {
                    continue;
                }

                Debug.LogFormat("Found part with CrewCapacity: {0}", avPart.name);
                for (int i = 0; i < avPart.partPrefab.CrewCapacity; i++)
                {
                    try {
                        var moduleInventory =
                            avPart.partPrefab.AddModule(typeof(ModuleKISInventory).Name) as ModuleKISInventory;
                        KIS_Shared.AwakePartModule(moduleInventory);
                        var baseFields = new BaseFieldList(moduleInventory);
                        baseFields.Load(nodeSettings.GetNode("EvaInventory"));
                        moduleInventory.podSeat = i;
                        moduleInventory.invType = ModuleKISInventory.InventoryType.Pod;
                        Debug.LogFormat("Pod inventory module(s) for seat {0} loaded successfully", i);
                    } catch {
                        Debug.LogErrorFormat("Pod inventory module(s) for seat {0} can't be loaded!", i);
                    }
                }
            }
        }
Esempio n. 29
0
        public static void AssignAttachIcon(Part part, AttachNode node, Color iconColor,
                                            string name = null)
        {
            // Create NodeTransform if needed
            if (!node.nodeTransform)
            {
                node.nodeTransform               = new GameObject("KISNodeTransf").transform;
                node.nodeTransform.parent        = part.transform;
                node.nodeTransform.localPosition = node.position;
                node.nodeTransform.localRotation = KIS_Shared.GetNodeRotation(node);
            }

            if (!node.icon)
            {
                node.icon = GameObject.CreatePrimitive(PrimitiveType.Sphere);
                if (node.icon.GetComponent <Collider>())
                {
                    UnityEngine.Object.DestroyImmediate(node.icon.GetComponent <Collider>());
                }
                var iconRenderer = node.icon.GetComponent <Renderer>();

                if (iconRenderer)
                {
                    iconRenderer.material             = new Material(Shader.Find("Transparent/Diffuse"));
                    iconColor.a                       = 0.5f;
                    iconRenderer.material.color       = iconColor;
                    iconRenderer.material.renderQueue = HighlighedPartRenderQueue;
                }
                node.icon.transform.parent = part.transform;
                if (name != null)
                {
                    node.icon.name = name;
                }
                double num;
                if (node.size == 0)
                {
                    num = (double)node.size + 0.5;
                }
                else
                {
                    num = (double)node.size;
                }
                node.icon.transform.localScale    = Vector3.one * node.radius * (float)num;
                node.icon.transform.parent        = node.nodeTransform;
                node.icon.transform.localPosition = Vector3.zero;
                node.icon.transform.localRotation = Quaternion.identity;
            }
        }
Esempio n. 30
0
 public virtual void OnPartUnpack()
 {
     if (allowStaticAttach == 0)
     {
         return;
     }
     if (useExternalStaticAttach)
     {
         return;
     }
     if (staticAttached)
     {
         KIS_Shared.DebugLog("Re-attach static object (OnPartUnpack)");
         GroundAttach();
     }
 }