コード例 #1
0
        internal GameObject CreatePart(GameObject parent, int skin)
        {
            var partObj = UnityEngine.Object.Instantiate(Craft.PartBase) as GameObject;

            if (null != descriptor)
            {
                // Give the part object a useful name in the Unity GUI
                partObj.name = descriptor.PartType.ToString() + " part";
            }

            var lods = new List <LOD>();

            foreach (var lod in _lods)
            {
                lods.Add(lod.MakeLOD(partObj, skin));
            }

            var lodGroup = partObj.AddComponent <LODGroup>();

            lodGroup.SetLODs(lods.ToArray());
            // Some low LOD meshes comletely replace meshes from other parts.
            // So ensure that all parts cutover at the same distance to avoid flickering.
            lodGroup.localReferencePoint = new Vector3(0, 0, 0);
            lodGroup.size = Craft.Size;

            // Generate hardpoints
            foreach (var hardpoint in ShipPart.OfType <Hardpoint <Vector3> >())
            {
                hardpointFactory.MakeHardpoint(partObj, hardpoint, descriptor);
            }

            if (null != targetPoint)
            {
                Helpers.AttachTransform(partObj, targetPoint.CreateTargetPoint(), descriptor.HitboxCenterPoint);
            }

            Helpers.AttachTransform(parent, partObj);

            Craft.ProcessPart?.Invoke(partObj, descriptor, rotationInfo);

            return(partObj);
        }