Exemplo n.º 1
0
        //Modifies the size of a part
        private void UpdateScale(Part part, RealChuteModule module)
        {
            if (sizes.Count <= 1 || !moduleNodes.Keys.Contains(this.part.partInfo.name))
            {
                return;
            }
            SizeNode size = sizes[this.size], lastSize = sizes[this.lastSize];

            part.transform.GetChild(0).localScale = Vector3.Scale(originalSize, size.size);
            module.caseMass = size.caseMass;
            if ((HighLogic.LoadedSceneIsEditor && part == EditorLogic.SortedShipList[0]) || (HighLogic.LoadedSceneIsFlight && this.vessel.rootPart == part))
            {
                if (part.findAttachNode("top") != null)
                {
                    AttachNode topNode = part.findAttachNode("top");
                    topNode.position = size.topNode;
                    topNode.size     = size.topNodeSize;
                    if (topNode.attachedPart != null)
                    {
                        float topDifference = size.topNode.y - lastSize.topNode.y;
                        topNode.attachedPart.transform.Translate(0, topDifference, 0, part.transform);
                        if (part.findAttachNode("top").attachedPart.GetAllChildren().Count > 0)
                        {
                            topNode.attachedPart.GetAllChildren().ForEach(p => p.transform.Translate(0, topDifference, 0, part.transform));
                        }
                    }
                }
                if (part.findAttachNode("bottom") != null)
                {
                    AttachNode bottomNode = part.findAttachNode("bottom");
                    bottomNode.position = size.bottomNode;
                    bottomNode.size     = size.bottomNodeSize;
                    if (bottomNode.attachedPart != null)
                    {
                        float bottomDifference = size.bottomNode.y - lastSize.bottomNode.y;
                        bottomNode.attachedPart.transform.Translate(0, bottomDifference, 0, part.transform);
                        if (part.findAttachNode("bottom").attachedPart.GetAllChildren().Count > 0)
                        {
                            bottomNode.attachedPart.GetAllChildren().ForEach(p => p.transform.Translate(0, bottomDifference, 0, part.transform));
                        }
                    }
                }
            }
            else if (part.findAttachNode("bottom") != null && part.findAttachNode("bottom").attachedPart != null && part.parent != null && part.findAttachNode("bottom").attachedPart == part.parent)
            {
                AttachNode bottomNode = part.findAttachNode("bottom");
                bottomNode.position = size.bottomNode;
                bottomNode.size     = size.bottomNodeSize;
                float bottomDifference = size.bottomNode.y - lastSize.bottomNode.y;
                part.transform.Translate(0, -bottomDifference, 0, part.transform);
                if (part.findAttachNode("top") != null)
                {
                    AttachNode topNode = part.findAttachNode("top");
                    topNode.position = size.topNode;
                    topNode.size     = size.topNodeSize;
                    float topDifference = size.topNode.y - lastSize.topNode.y;
                    if (part.GetAllChildren().Count > 0)
                    {
                        part.GetAllChildren().ForEach(p => p.transform.Translate(0, -(bottomDifference - topDifference), 0, part.transform));
                    }
                }
            }
            else if (part.findAttachNode("top") != null && part.findAttachNode("top").attachedPart != null && part.parent != null && part.findAttachNode("top").attachedPart == part.parent)
            {
                AttachNode topNode = part.findAttachNode("top");
                topNode.position = size.topNode;
                topNode.size     = size.topNodeSize;
                float topDifference = size.topNode.y - lastSize.topNode.y;
                part.transform.Translate(0, -topDifference, 0, part.transform);
                if (part.findAttachNode("bottom") != null)
                {
                    AttachNode bottomNode = part.findAttachNode("bottom");
                    bottomNode.position = size.bottomNode;
                    bottomNode.size     = size.bottomNodeSize;
                    float bottomDifference = size.bottomNode.y - lastSize.bottomNode.y;
                    if (part.GetAllChildren().Count > 0)
                    {
                        part.GetAllChildren().ForEach(p => p.transform.Translate(0, -(topDifference - bottomDifference), 0, part.transform));
                    }
                }
            }

            float   scaleX = part.transform.GetChild(0).localScale.x / Vector3.Scale(originalSize, lastSize.size).x;
            float   scaleZ = part.transform.GetChild(0).localScale.z / Vector3.Scale(originalSize, lastSize.size).z;
            Vector3 chute  = main.chute.forcePosition - part.transform.position;

            main.chute.parachute.transform.Translate(chute.x * (scaleX - 1), 0, chute.z * (scaleZ - 1), part.transform);
            if (secondaryChute)
            {
                Vector3 secChute = secondary.chute.forcePosition - part.transform.position;
                secondary.chute.parachute.transform.Translate(secChute.x * (scaleX - 1), 0, secChute.z * (scaleZ - 1), part.transform);
            }

            if (part.children.Count(p => p.attachMode == AttachModes.SRF_ATTACH) > 0)
            {
                List <Part> surfaceAttached = new List <Part>(part.children.Where(p => p.attachMode == AttachModes.SRF_ATTACH));
                surfaceAttached.Where(p => p.GetAllChildren().Count > 0).ToList().ForEach(p => surfaceAttached.AddRange(p.GetAllChildren()));
                foreach (Part p in surfaceAttached)
                {
                    Vector3 v = p.transform.position - part.transform.position;
                    p.transform.Translate(v.x * (scaleX - 1), 0, v.z * (scaleZ - 1), part.transform);
                }
            }
            this.lastSize = this.size;
        }
Exemplo n.º 2
0
        //Modifies the size of a part
        private void UpdateScale(Part part, RealChuteModule module)
        {
            //Thanks to Brodicus for the optimization here
            if (this.sizes.Count <= 1)
            {
                return;
            }
            SizeNode  size = this.sizes[this.size], lastSize = this.sizes[this.lastSize];
            Transform root = this.part.transform.GetChild(0);

            root.localScale = Vector3.Scale(this.originalSize, size.Size);
            module.caseMass = size.CaseMass;
            module.UpdateMass();
            AttachNode  topNode, bottomNode;
            bool        hasTopNode = part.TryGetAttachNodeById("top", out topNode);
            bool        hasBottomNode = part.TryGetAttachNodeById("bottom", out bottomNode);
            List <Part> allTopChildParts, allBottomChildParts;

            // If this is the root part, move things for the top and the bottom.
            if (HighLogic.LoadedSceneIsEditor && this.part == EditorLogic.SortedShipList[0] || HighLogic.LoadedSceneIsFlight && this.vessel.rootPart == this.part)
            {
                if (hasTopNode)
                {
                    topNode.position = size.TopNode;
                    topNode.size     = size.TopNodeSize;
                    if (topNode.attachedPart != null)
                    {
                        float topDifference = size.TopNode.y - lastSize.TopNode.y;
                        topNode.attachedPart.transform.Translate(0, topDifference, 0, this.part.transform);
                        allTopChildParts = topNode.attachedPart.GetAllChildren();
                        allTopChildParts.ForEach(c => c.transform.Translate(0, topDifference, 0, this.part.transform));
                    }
                }

                if (hasBottomNode)
                {
                    bottomNode.position = size.BottomNode;
                    bottomNode.size     = size.BottomNodeSize;
                    if (bottomNode.attachedPart != null)
                    {
                        float bottomDifference = size.BottomNode.y - lastSize.BottomNode.y;
                        bottomNode.attachedPart.transform.Translate(0, bottomDifference, 0, this.part.transform);
                        allBottomChildParts = bottomNode.attachedPart.GetAllChildren();
                        allBottomChildParts.ForEach(c => c.transform.Translate(0, bottomDifference, 0, this.part.transform));
                    }
                }
            }

            // If not root and parent is attached to the bottom
            else if (hasBottomNode && CheckParentNode(bottomNode))
            {
                bottomNode.position = size.BottomNode;
                bottomNode.size     = size.BottomNodeSize;
                float bottomDifference = size.BottomNode.y - lastSize.BottomNode.y;
                this.part.transform.Translate(0, -bottomDifference, 0, this.part.transform);
                if (hasTopNode)
                {
                    topNode.position = size.TopNode;
                    topNode.size     = size.TopNodeSize;
                    if (topNode.attachedPart != null)
                    {
                        float diff = size.TopNode.y - lastSize.TopNode.y - bottomDifference;
                        topNode.attachedPart.transform.Translate(0, diff, 0, this.part.transform);
                        allTopChildParts = topNode.attachedPart.GetAllChildren();
                        allTopChildParts.ForEach(c => c.transform.Translate(0, diff, 0, this.part.transform));
                    }
                }
            }
            // If not root and parent is attached to the top
            else if (hasTopNode && CheckParentNode(topNode))
            {
                topNode.position = size.TopNode;
                topNode.size     = size.TopNodeSize;
                float topDifference = size.TopNode.y - lastSize.TopNode.y;
                this.part.transform.Translate(0, -topDifference, 0, this.part.transform);
                if (hasBottomNode)
                {
                    bottomNode.position = size.BottomNode;
                    bottomNode.size     = size.BottomNodeSize;
                    if (bottomNode.attachedPart != null)
                    {
                        float diff = size.BottomNode.y - lastSize.BottomNode.y - topDifference;
                        bottomNode.attachedPart.transform.Translate(0, diff, 0, part.transform);
                        allBottomChildParts = bottomNode.attachedPart.GetAllChildren();
                        allBottomChildParts.ForEach(c => c.transform.Translate(0, diff, 0, part.transform));
                    }
                }
            }

            //Parachute transforms
            Vector3 scale  = Vector3.Scale(this.originalSize, lastSize.Size);
            float   scaleX = root.localScale.x / scale.x;
            float   scaleY = root.localScale.y / scale.y;
            float   scaleZ = root.localScale.z / scale.z;

            foreach (Parachute chute in this.rcModule.parachutes)
            {
                Vector3 pos = chute.ForcePosition - this.part.transform.position;
                chute.parachute.transform.Translate(pos.x * (scaleX - 1), pos.y * (scaleY - 1), pos.z * (scaleZ - 1), this.part.transform);
            }

            //Surface attached parts
            if (this.part.children.Exists(c => c.attachMode == AttachModes.SRF_ATTACH))
            {
                foreach (Part child in this.part.children)
                {
                    if (child.attachMode == AttachModes.SRF_ATTACH)
                    {
                        Vector3 vX = (child.transform.localPosition + (child.transform.localRotation * child.srfAttachNode.position)) - this.part.transform.position;
                        Vector3 vY = child.transform.position - this.part.transform.position;
                        child.transform.Translate(vX.x * (scaleX - 1), vY.y * (scaleY - 1), vX.z * (scaleZ - 1), this.part.transform);
                        child.GetAllChildren().ForEach(c => c.transform.Translate(vX.x * (scaleX - 1), vY.y * (scaleY - 1), vX.z * (scaleZ - 1), this.part.transform));
                    }
                }
            }
            this.lastSize = this.size;
            this.part.SendMessage("RC_Rescale", new Vector3(scaleX, scaleY, scaleZ));
            if (HighLogic.LoadedSceneIsEditor)
            {
                GameEvents.onEditorShipModified.Fire(EditorLogic.fetch.ship);
            }
        }
Exemplo n.º 3
0
        //Modifies the size of a part
        private void UpdateScale(Part part, RealChuteModule module)
        {
            //Thanks to Brodicus for the help here
            if (sizes.Count <= 1)
            {
                return;
            }
            SizeNode  size = sizes[this.size], lastSize = sizes[this.lastSize];
            Transform root = part.transform.GetChild(0);

            root.localScale = Vector3.Scale(originalSize, size.size);
            module.caseMass = size.caseMass;
            AttachNode  topNode = null, bottomNode = null;
            bool        hasTopNode = part.TryGetAttachNodeById("top", out topNode);
            bool        hasBottomNode = part.TryGetAttachNodeById("bottom", out bottomNode);
            List <Part> allTopChildParts = null, allBottomChildParts = null;

            // If this is the root part, move things for the top and the bottom.
            if ((HighLogic.LoadedSceneIsEditor && part == EditorLogic.SortedShipList[0]) || (HighLogic.LoadedSceneIsFlight && this.vessel.rootPart == part))
            {
                if (hasTopNode)
                {
                    topNode.position = size.topNode;
                    topNode.size     = size.topNodeSize;
                    if (topNode.attachedPart != null)
                    {
                        float topDifference = size.topNode.y - lastSize.topNode.y;
                        topNode.attachedPart.transform.Translate(0, topDifference, 0, part.transform);
                        if (allTopChildParts == null)
                        {
                            allTopChildParts = topNode.attachedPart.GetAllChildren();
                        }
                        allTopChildParts.ForEach(c => c.transform.Translate(0, topDifference, 0, part.transform));
                    }
                }

                if (hasBottomNode)
                {
                    bottomNode.position = size.bottomNode;
                    bottomNode.size     = size.bottomNodeSize;
                    if (bottomNode.attachedPart != null)
                    {
                        float bottomDifference = size.bottomNode.y - lastSize.bottomNode.y;
                        bottomNode.attachedPart.transform.Translate(0, bottomDifference, 0, part.transform);
                        if (allBottomChildParts == null)
                        {
                            allBottomChildParts = bottomNode.attachedPart.GetAllChildren();
                        }
                        allBottomChildParts.ForEach(c => c.transform.Translate(0, bottomDifference, 0, part.transform));
                    }
                }
            }

            // If not root and parent is attached to the bottom
            else if (hasBottomNode && CheckParentNode(bottomNode))
            {
                bottomNode.position = size.bottomNode;
                bottomNode.size     = size.bottomNodeSize;
                float bottomDifference = size.bottomNode.y - lastSize.bottomNode.y;
                part.transform.Translate(0, -bottomDifference, 0, part.transform);
                if (hasTopNode)
                {
                    topNode.position = size.topNode;
                    topNode.size     = size.topNodeSize;
                    if (topNode.attachedPart != null)
                    {
                        float topDifference = size.topNode.y - lastSize.topNode.y;
                        topNode.attachedPart.transform.Translate(0, topDifference - bottomDifference, 0, part.transform);
                        if (allTopChildParts == null)
                        {
                            allTopChildParts = topNode.attachedPart.GetAllChildren();
                        }
                        allTopChildParts.ForEach(c => c.transform.Translate(0, topDifference - bottomDifference, 0, part.transform));
                    }
                }
            }
            // If not root and parent is attached to the top
            else if (hasTopNode && CheckParentNode(topNode))
            {
                topNode.position = size.topNode;
                topNode.size     = size.topNodeSize;
                float topDifference = size.topNode.y - lastSize.topNode.y;
                part.transform.Translate(0, -topDifference, 0, part.transform);
                if (hasBottomNode)
                {
                    bottomNode.position = size.bottomNode;
                    bottomNode.size     = size.bottomNodeSize;
                    if (bottomNode.attachedPart != null)
                    {
                        float bottomDifference = size.bottomNode.y - lastSize.bottomNode.y;
                        bottomNode.attachedPart.transform.Translate(0, bottomDifference - topDifference, 0, part.transform);
                        if (allBottomChildParts == null)
                        {
                            allBottomChildParts = bottomNode.attachedPart.GetAllChildren();
                        }
                        allBottomChildParts.ForEach(c => c.transform.Translate(0, bottomDifference - topDifference, 0, part.transform));
                    }
                }
            }

            //Parachute transforms
            float scaleX = root.localScale.x / Vector3.Scale(originalSize, lastSize.size).x;
            float scaleY = root.localScale.y / Vector3.Scale(originalSize, lastSize.size).y;
            float scaleZ = root.localScale.z / Vector3.Scale(originalSize, lastSize.size).z;

            foreach (Parachute chute in rcModule.parachutes)
            {
                Vector3 pos = chute.forcePosition - part.transform.position;
                chute.parachute.transform.Translate(pos.x * (scaleX - 1), pos.y * (scaleY - 1), pos.z * (scaleZ - 1), part.transform);
            }

            //Surface attached parts
            if (part.children.Any(c => c.attachMode == AttachModes.SRF_ATTACH))
            {
                foreach (Part child in part.children)
                {
                    if (child.attachMode == AttachModes.SRF_ATTACH)
                    {
                        Vector3 vX = new Vector3(), vY = new Vector3();
                        vX = (child.transform.localPosition + child.transform.localRotation * child.srfAttachNode.position) - part.transform.position;
                        vY = child.transform.position - part.transform.position;
                        child.transform.Translate(vX.x * (scaleX - 1), vY.y * (scaleY - 1), vX.z * (scaleZ - 1), part.transform);
                        child.GetAllChildren().ForEach(c => c.transform.Translate(vX.x * (scaleX - 1), vY.y * (scaleY - 1), vX.z * (scaleZ - 1), part.transform));
                    }
                }
            }
            this.lastSize = this.size;
        }