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


C# Transform.FindOrCreate方法代码示例

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


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

示例1: generatePanels

        public GameObject[] generatePanels(Transform parent, Vector3 pivot)
        {
            //each panelEdgeGroup should now contain the vertical edge loops for each vertical panel grouping
            //from here, need to generate meshes for panels depending upon splitPanels setting
            int len = panelGroups.Length;
            GameObject[] gos = generatePanels(parent);
            float newX, newZ;
            for (int i = 0; i < len; i++)
            {
                float yRot = panelGroups[i].getPivotRotation();
                float dist = Mathf.Sqrt(pivot.x * pivot.x + pivot.z * pivot.z);

                newX = Mathf.Cos(yRot * Mathf.Deg2Rad)*dist;
                newZ = Mathf.Sin(yRot * Mathf.Deg2Rad)*dist;
                Vector3 newPivot = new Vector3(newX, pivot.y, newZ);

                GameObject pivotObject = parent.FindOrCreate("FairingPanelPivot-"+i).gameObject;
                pivotObject.transform.parent = parent;
                pivotObject.transform.rotation = parent.transform.rotation;
                pivotObject.transform.localPosition = newPivot + offset;
                pivotObject.transform.Rotate(new Vector3(0, 1, 0), -yRot + 90f, Space.Self);

                gos[i].transform.parent = pivotObject.transform;
                gos[i] = pivotObject;
            }
            return gos;
        }
开发者ID:shadowmage45,项目名称:SSTULabs,代码行数:27,代码来源:MeshGenerators.cs

示例2: generatePanels

        public GameObject[] generatePanels(Transform parent)
        {
            //each panelEdgeGroup should now contain the vertical edge loops for each vertical panel grouping
            //from here, need to generate meshes for panels depending upon splitPanels setting
            int len = panelGroups.Length;
            GameObject[] gos = new GameObject[panels];
            for (int i = 0; i < len; i++)
            {
                gos[i] = parent.FindOrCreate("FairingPanel-"+i).gameObject;
                MeshFilter mf = gos[i].GetComponent<MeshFilter>();
                if (mf == null) { mf = gos[i].AddComponent<MeshFilter>(); }
                mf.mesh = panelGroups[i].generatePanels(offset, outsideUV, insideUV, edgesUV);

                MeshRenderer mr = gos[i].GetComponent<MeshRenderer>();
                if (mr == null) { mr = gos[i].AddComponent<MeshRenderer>(); }
                gos[i].transform.parent = parent;
                gos[i].transform.localPosition = Vector3.zero;
                gos[i].transform.rotation = parent.rotation;
            }
            return gos;
        }
开发者ID:Joshg213,项目名称:SSTULabs,代码行数:21,代码来源:MeshGenerators.cs

示例3: setupModel

        public void setupModel(Part part, Transform baseTransform, Transform targetRotator)
        {
            this.partTransform = part.transform;

            String suffix = (main ? "-main-" : "-drogue-") + index;

            retractedTarget = targetRotator.FindOrCreate("ParachuteRetractedTarget" + suffix).gameObject;
            retractedTarget.transform.NestToParent(targetRotator);
            retractedTarget.transform.localPosition = new Vector3(-retractedUpVector.x, -retractedUpVector.z, retractedUpVector.y);

            semiDeployedTarget = targetRotator.FindOrCreate("ParachuteSemiDeployTarget" + suffix).gameObject;
            semiDeployedTarget.transform.NestToParent(targetRotator);
            semiDeployedTarget.transform.localPosition = new Vector3(-semiDeployedUpVector.x, -semiDeployedUpVector.z, semiDeployedUpVector.y);

            fullDeployedTarget = targetRotator.FindOrCreate("ParachuteFullDeployTarget" + suffix).gameObject;
            fullDeployedTarget.transform.NestToParent(targetRotator);
            fullDeployedTarget.transform.localPosition = new Vector3(-fullDeployedUpVector.x, -fullDeployedUpVector.z, fullDeployedUpVector.y);

            parachutePivot = baseTransform.FindOrCreate("ParachuteSpacingPivot" + suffix).gameObject;
            parachutePivot.transform.NestToParent(baseTransform);
            parachutePivot.transform.localPosition = new Vector3(localPosition.x, localPosition.y, -localPosition.z);//TODO -- why does this need to be inverted?

            Transform modelTransform = parachutePivot.transform.FindRecursive(modelName);
            if (modelTransform == null)
            {
                baseModel = SSTUUtils.cloneModel(modelName);
            }
            else
            {
                baseModel = modelTransform.gameObject;
            }
            baseModel.transform.NestToParent(parachutePivot.transform);
            if (!String.IsNullOrEmpty(texture))
            {
                SSTUUtils.setMainTextureRecursive(baseModel.transform, GameDatabase.Instance.GetTexture(texture, false));
            }

            Transform tr = baseModel.transform.FindRecursive(definition.capName);
            if (tr == null) { MonoBehaviour.print("ERROR: Could not locate transform for cap name: " + definition.capName); }
            capModel = tr.gameObject;
            tr = baseModel.transform.FindRecursive(definition.lineName);
            if (tr == null) { MonoBehaviour.print("ERROR: Could not locate transform for line name: " + definition.lineName); }
            lineModel = tr.gameObject;

            Vector3 lookDir = (-(parachutePivot.transform.position - semiDeployedTarget.transform.position));
            lookDir.Normalize();
            parachutePivot.transform.rotation = Quaternion.LookRotation(lookDir, part.transform.forward);
            prevWind = parachutePivot.transform.rotation;
            baseModel.transform.localRotation = Quaternion.AngleAxis(-90, Vector3.left);
        }
开发者ID:shadowmage45,项目名称:SSTULabs,代码行数:50,代码来源:SSTUModularParachute.cs


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