当前位置: 首页>>代码示例>>C#>>正文


C# Part.addChild方法代码示例

本文整理汇总了C#中Part.addChild方法的典型用法代码示例。如果您正苦于以下问题:C# Part.addChild方法的具体用法?C# Part.addChild怎么用?C# Part.addChild使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Part的用法示例。


在下文中一共展示了Part.addChild方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: rebuildTreeRecursive

        private void rebuildTreeRecursive(Part ThisPart, Part PrevPart)
        {
            if (ThisPart == this.vessel.rootPart) {
                PrevPart.removeChild (ThisPart);
                foreach (Part child in ThisPart.children) {
                    ThisPart.removeChild (child);
                }
                ThisPart.addChild (this);
            } else {

                //print ("thispart : "+ ThisPart.name);
                if (ThisPart.potentialParent != null)
                    print ("potential parent : " + ThisPart.potentialParent.name);

                ThisPart.children.Remove (PrevPart);
                if (ThisPart.parent != null) {
                    //print ("parent : "+ThisPart.parent.name);
                    ThisPart.addChild (ThisPart.parent);
                    rebuildTreeRecursive (ThisPart.parent, ThisPart);
                }
                ThisPart.parent = PrevPart;
                if (ThisPart.parent == null) {
                    //print (ThisPart.name + " parent should =  " + PrevPart);
                    //print (ThisPart.name + " parent = " + ThisPart.parent);
                }
            }
        }
开发者ID:Veterok,项目名称:EscapePod,代码行数:27,代码来源:Parts.cs

示例2: AttachFuelLine


//.........这里部分代码省略.........
            // Make a new FuelLine object
            // Don't make the object until we're sure we can place it!
            //AvailablePart ap = PartLoader.getPartInfoByName ("fuelLine");
            UnityEngine.Object obj = UnityEngine.Object.Instantiate (ap.partPrefab);
            CompoundPart f = (CompoundPart)obj;
            f.gameObject.SetActive (true);
            //f.gameObject.name = "fuelLine";
            f.gameObject.name = ap.name;
            f.partInfo = ap;
            //f.highlightRecurse = true;
            f.attachMode = AttachModes.SRF_ATTACH;

            ASPConsoleStuff.AAprint ("    set position in space");
            // set position in space, relative to source tank
            f.transform.localScale = sourceTank.transform.localScale;
            f.transform.parent = sourceTank.transform; // must be BEFORE localposition!
            //f.transform.parent = null;
            //f.transform.parent = findRootPart(sourceTank).transform;

            f.transform.position = startPosition;
            //f.transform.parent = startTransform.parent;
            //f.transform.position = startTransform.position;
            //f.transform.rotation = startTransform.rotation;

            // Aim the fuel node starting position at the destination position so we can calculate the direction later
            //f.transform.LookAt (destTransform);
            //f.transform.LookAt (destPosition);
            f.transform.up = sourceTank.transform.up;
            f.transform.forward = sourceTank.transform.forward;
            f.transform.LookAt (destTank.transform);
            f.transform.Rotate (0, 90, 0);  // need to correct results from LookAt... dunno why.

            ASPConsoleStuff.AAprint ("    attach to source tank");
            // attach to source tank
            AttachNode an = new AttachNode ();
            an.id = "srfAttach";
            an.attachedPart = sourceTank;
            an.attachMethod = AttachNodeMethod.HINGE_JOINT;
            an.nodeType = AttachNode.NodeType.Surface;
            an.size = 1;  // found from inspecting fuel lines
            an.orientation = new Vector3 (0.12500000f, 0.0f, 0.0f); // seems to be a magic number
            f.srfAttachNode = an;

            ASPConsoleStuff.printPart ("    attach to destination", destTank);
            // attach to destination tank
            f.target = destTank;

            ASPConsoleStuff.AAprint ("    targetposition");
            f.targetPosition = destPosition;

            ASPConsoleStuff.AAprint ("    direction");
            //f.direction=(f.transform.position - destTank.transform.position).normalized;
            //f.direction = f.transform.localRotation * f.transform.localPosition;  // only works if destTank is parent
            //f.direction = (f.transform.InverseTransformPoint(destTank.transform.position) - f.transform.localPosition).normalized;  // works but crooked
            //f.direction = (f.transform.InverseTransformPoint(destPosition) - f.transform.localPosition).normalized; // doesn't connect
            //f.direction = (f.transform.InverseTransformPoint(destPosition) - f.transform.localPosition); // doesn't connect
            f.direction = f.transform.InverseTransformPoint (destTank.transform.position).normalized;  // correct!

            /*if (isParent(sourceTank,destTank)){
                f.direction = f.transform.localRotation * f.transform.localPosition;
            } else {
                f.direction = (f.transform.InverseTransformPoint(destTank.transform.position) - f.transform.localPosition).normalized;
            }*/

            /*
            r = new Ray ();
            r.origin = startPosition;
            r.direction = f.direction;
            hit = new RaycastHit();
            if (destTank.collider.Raycast (r, out hit, 1000)){
                ASPConsoleStuff.printVector3 ("f.direction hits at", hit.point);
                ASPConsoleStuff.printVector3 ("destPosition at", destPosition);
                print("    dist: "+(Vector3.Distance(hit.point,midway)).ToString("F2"));
            } else {
                print (" !!! f.direction ray failed!!!");
            }*/

            if (texturePath != null) {
                foreach (PartModule pm in f.Modules) {
                    if (pm.moduleName == "FStextureSwitch2") {
                        pm.GetType ().GetField ("selectedTexture").SetValue (pm, textureNum);
                        pm.GetType ().GetField ("selectedTextureURL").SetValue (pm, texturePath);
                    }
                }
            }

            // add to ship
            ASPConsoleStuff.AAprint ("    adding to ship");
            sourceTank.addChild (f);

            EditorLogic.fetch.ship.Add (f);

            FuelSet fs = new FuelSet ();
            fs.fromPart = sourceTank;
            fs.toPart = destTank;
            fs.fl = f;
            fuelSetsToConnect.Add (fs);
            ASPConsoleStuff.AAprint ("    added to fuelSetsToConnect, total: " + fuelSetsToConnect.Count.ToString ());
            return true;
        }
开发者ID:henrybauer,项目名称:AutoAsparagus,代码行数:101,代码来源:ASPFuelLine.cs

示例3: rebuildTree

 //            private void OrganizeTree (Part root)
 //        {
 //            Vessel ship = root.vessel;
 //            List<Part> NewTree = new List<Part> ();
 //
 //            OrganizeTreeRecursive (NewTree, root);
 //            ship.parts.Clear ();
 //            foreach (Part part in NewTree) {
 //                print ("ADDED : "+part.name);
 //                this.vessel.parts.Add (part);
 //            }
 //            print ("Tree Restructured");
 //            }
 //
 //        private void OrganizeTreeRecursive (List<Part> Tree, Part ThisPart)
 //        {
 //            Tree.Add (ThisPart);
 //            foreach (Part child in ThisPart.children) {
 //                OrganizeTreeRecursive (Tree, child);
 //            }
 //
 //        }
 private void rebuildTree(Part Root)
 {
     //vesselTransform(Root);
     print ("*Tree Rebuid*");
     if (Root.parent != null) {
         Root.addChild (Root.parent);
         rebuildTreeRecursive(Root.parent,Root);
             //Root.parent = null;
     }
     print ("*Tree Rebuilt*");
 }
开发者ID:Veterok,项目名称:EscapePod,代码行数:33,代码来源:Parts.cs


注:本文中的Part.addChild方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。