SSTUTools.SolarData.enable C# (CSharp) Method

enable() public method

public enable ( Transform root, float yOffset ) : void
root UnityEngine.Transform
yOffset float
return void
        public void enable(Transform root, float yOffset)
        {
            SSTUUtils.destroyChildren(root);
            int len = positions.Length;
            rootTransforms = new Transform[len];
            models = new SingleModelData[len];
            Vector3 pos;
            for (int i = 0; i < len; i++)
            {
                rootTransforms[i] = new GameObject(root.name + "-" + i).transform;
                pos = positions[i].position.CopyVector();
                pos.y += yOffset;
                rootTransforms[i].parent = root;
                rootTransforms[i].position = root.position;
                rootTransforms[i].rotation = root.rotation;
                rootTransforms[i].localPosition = pos;
                rootTransforms[i].Rotate(positions[i].rotation, Space.Self);
                models[i] = new SingleModelData(modelName);
                models[i].setupModel(rootTransforms[i], ModelOrientation.TOP);
                rootTransforms[i].localScale = positions[i].scale;
            }
        }

Usage Example

        /// <summary>
        /// Restore the currently selected modules' models, and restore their current texture-set selection
        /// Removes any existing models from special-named root transforms with no attempt at re-use
        /// </summary>
        private void restoreModels()
        {
            topDockModule.setupModel(getTopDockRoot(true), ModelOrientation.TOP);
            topModule.setupModel(getTopRoot(true), ModelOrientation.TOP);
            coreModule.setupModel(getCoreRoot(false), ModelOrientation.CENTRAL, true);//setup model on prefab part and don't touch it after that
            bottomModule.setupModel(getBottomRoot(true), ModelOrientation.BOTTOM);
            bottomDockModule.setupModel(getBottomDockRoot(true), ModelOrientation.BOTTOM);
            solarModule.enable(getSolarRoot(true), 0);

            topModule.enableTextureSet(currentTopTexture);
            coreModule.enableTextureSet(currentCoreTexture);
            bottomModule.enableTextureSet(currentBottomTexture);

            //control transforms need to exist during part initialization
            //else things will explode if one of those transforms is the reference transform when a vessel is reloaded
            //so create them on prefab and restore on other instances
            if (!HighLogic.LoadedSceneIsEditor && !HighLogic.LoadedSceneIsFlight)
            {
                Transform modelRoot = part.transform.FindRecursive("model");

                topDockTransform = new GameObject(topDockName).transform;
                topDockTransform.NestToParent(modelRoot);
                topDockTransform.Rotate(-90, 0, 0, Space.Self);
                topControlTransform = new GameObject(topDockName + "Control").transform;
                topControlTransform.NestToParent(modelRoot);

                bottomDockTransform = new GameObject(bottomDockName).transform;
                bottomDockTransform.NestToParent(modelRoot);
                bottomDockTransform.Rotate(90, 0, 0, Space.Self);
                bottomControlTransform = new GameObject(bottomDockName + "Control").transform;
                bottomControlTransform.NestToParent(modelRoot);
                bottomControlTransform.Rotate(180, 0, 0, Space.Self);
            }
            else
            {
                topDockTransform       = part.transform.FindRecursive(topDockName);
                topControlTransform    = part.transform.FindRecursive(topDockName + "Control");
                bottomDockTransform    = part.transform.FindRecursive(bottomDockName);
                bottomControlTransform = part.transform.FindRecursive(bottomDockName + "Control");
            }
            SSTUStockInterop.updatePartHighlighting(part);
        }
All Usage Examples Of SSTUTools.SolarData::enable