//private bool showMenu = false;
        //private Rect windowRect = new Rect(500f, 250f, 250f, 50f);
        //private FSGUIPopup popup;

        public override void OnStart(PartModule.StartState state)
        {
            debug.debugMode = debugMode;
            engine          = new FSengineWrapper(part);
            if (engine.type != FSengineWrapper.EngineType.NONE)
            {
                //Debug.Log("FSswitchEngineThrustTransform: Engine module found");
                thrustTransform         = part.FindModelTransform(defaultTTName);
                defaultTT               = new GameObject().transform;
                defaultTT.localPosition = thrustTransform.localPosition;
                defaultTT.localRotation = thrustTransform.localRotation;
                //defaultTT = part.FindModelTransform(defaultTTName);
                if (useNamedAlternate == 1)
                {
                    debug.debugMessage("Finding alternate TT");
                    alternateTT = part.FindModelTransform(alternateTTName);
                    if (alternateTT == null)
                    {
                        debug.debugMessage("Did not find alternate TT " + alternateTTName);
                    }
                }
                else
                {
                    debug.debugMessage("Using flipped default TT as reverse");
                    alternateTT = new GameObject().transform;
                    alternateTT.localPosition = defaultTT.localPosition;
                    alternateTT.localRotation = defaultTT.localRotation;
                    alternateTT.Rotate(alternateTT.right, 180f);
                }
                if (defaultTT == null || alternateTT == null)
                {
                    valid = false;
                }

                if (isReversed)
                {
                    setTTReverseState(true);
                }
                else
                {
                    setTTReverseState(false);
                }
            }
            else
            {
                valid = false;
                Debug.Log("FSswitchEngineThrustTransform: no engine module found");
            }

            animateThrottle = part.Modules.OfType <FSanimateThrottle>().FirstOrDefault();
            if (animateThrottle != null)
            {
                animateThrottle.modeList.Add(new mode(animateThrottleRange.x, animateThrottleRange.y));
                animateThrottleMode = animateThrottle.modeList.Count - 1;
            }
        }
Esempio n. 2
0
 public void useTexture(Material targetMat)
 {
     if (targetMat != null && texList.Count > 0)
     {
         if (GameDatabase.Instance.ExistsTexture(texList[selectedTexture]))
         {
             debug.debugMessage("assigning texture: " + texList[selectedTexture]);
             targetMat.mainTexture = GameDatabase.Instance.GetTexture(texList[selectedTexture], false);
             selectedTextureURL    = texList[selectedTexture];
             if (mapList.Count > selectedTexture)
             {
                 targetMat.SetTexture(additionalMapType, GameDatabase.Instance.GetTexture(mapList[selectedTexture], mapIsNormal));
                 selectedMapURL = mapList[selectedTexture];
             }
         }
         else
         {
             debug.debugMessage("no such texture: " + texList[selectedTexture]);
         }
     }
     else
     {
         debug.debugMessage("FStextureSwitch: No target material in object.");
     }
 }
        // runs the kind of commands that would normally be in OnStart, if they have not already been run. In case a method is called upon externally, but values have not been set up yet
        private void initializeData()
        {
            if (!initialized)
            {
                debug = new FSdebugMessages(debugMode, "FStextureSwitch2");
                // you can't have fuel switching without symmetry, it breaks the editor GUI.
                if (useFuelSwitchModule)
                {
                    updateSymmetry = true;
                }

                objectList         = Tools.parseNames(objectNames, true);
                texList            = Tools.parseNames(textureNames, true, true, textureRootFolder);
                mapList            = Tools.parseNames(mapNames, true, true, textureRootFolder);
                textureDisplayList = Tools.parseNames(textureDisplayNames);
                fuelTankSetupList  = Tools.parseIntegers(fuelTankSetups);

                debug.debugMessage("found " + texList.Count + " textures, using number " + selectedTexture + ", found " + objectList.Count + " objects, " + mapList.Count + " maps");

                foreach (String targetObjectName in objectList)
                {
                    Transform[]     targetObjectTransformArray = part.FindModelTransforms(targetObjectName);
                    List <Material> matList = new List <Material>();
                    foreach (Transform t in targetObjectTransformArray)
                    {
                        if (t != null && t.gameObject.GetComponent <Renderer>() != null) // check for if the object even has a mesh. otherwise part list loading crashes
                        {
                            Material targetMat = t.gameObject.GetComponent <Renderer>().material;
                            if (targetMat != null)
                            {
                                if (!matList.Contains(targetMat))
                                {
                                    matList.Add(targetMat);
                                }
                            }
                        }
                    }
                    targetMats.Add(matList);
                }

                if (useFuelSwitchModule)
                {
                    fuelSwitch = part.GetComponent <FSfuelSwitch>(); // only looking for first, not supporting multiple fuel switchers
                    if (fuelSwitch == null)
                    {
                        useFuelSwitchModule = false;
                        debug.debugMessage("no FSfuelSwitch module found, despite useFuelSwitchModule being true");
                    }
                }
                initialized = true;
            }
        }
Esempio n. 4
0
    public void placeMeshEvent(string modelName)
    {
        structure = GameDatabase.Instance.GetModel(meshName);
        structure.transform.position = part.transform.position + new Vector3(0f, 0f, 2f);
        Rigidbody newRigidBody = structure.AddComponent <Rigidbody>();

        newRigidBody.mass = 1.0f;
        newRigidBody.drag = 0.05f;
        newRigidBody.collisionDetectionMode = CollisionDetectionMode.Continuous;
        FSstaticMeshCollisionHandler colliderHandler = structure.AddComponent <FSstaticMeshCollisionHandler>();

        colliderHandler.thisCollider = structure.collider;
        structure.AddComponent <physicalObject>();

        structure.SetActive(true);
        db.debugMessage("FS: mesh pos == " + structure.transform.position);
        db.debugMessage("FS: part pos == " + part.transform.position);
    }
 private void applyTexToPart(bool calledByPlayer)
 {
     initializeData();
     foreach (List <Material> matList in targetMats)
     {
         foreach (Material mat in matList)
         {
             useTextureOrMap(mat);
         }
     }
     if (useFuelSwitchModule)
     {
         debug.debugMessage("calling on FSfuelSwitch tank setup " + selectedTexture);
         if (selectedTexture < fuelTankSetupList.Count)
         {
             fuelSwitch.selectTankSetup(fuelTankSetupList[selectedTexture], calledByPlayer);
         }
         else
         {
             debug.debugMessage("no such fuel tank setup");
         }
         if (calledByPlayer && HighLogic.LoadedSceneIsFlight)
         {
             //Do a screeen message of what we just swapped to!
             var msg = string.Format("Converted Tank to {0}", textureDisplayList[selectedTexture]);
             ScreenMessages.PostScreenMessage(msg, 5f, ScreenMessageStyle.UPPER_CENTER);
         }
     }
 }
Esempio n. 6
0
 private void applyTexToPart(bool calledByPlayer)
 {
     initializeData();
     foreach (List <Material> matList in targetMats)
     {
         foreach (Material mat in matList)
         {
             useTextureOrMap(mat);
         }
     }
     if (useFuelSwitchModule)
     {
         debug.debugMessage("calling on FSfuelSwitch tank setup " + selectedTexture);
         if (selectedTexture < fuelTankSetupList.Count)
         {
             fuelSwitch.selectTankSetup(fuelTankSetupList[selectedTexture], calledByPlayer);
         }
         else
         {
             debug.debugMessage("no such fuel tank setup");
         }
     }
 }
Esempio n. 7
0
        public void useTextureOrMap(Material targetMat)
        {
            if (targetMat != null)
            {
                useTexture(targetMat);

                useMap(targetMat);
            }
            else
            {
                debug.debugMessage("No target material in object.");
            }
        }
Esempio n. 8
0
    private void findTransforms(bool verboseErrors)
    {
        #region find transforms

        flap = part.FindModelTransform(flapName);
        if (flap != null)
        {
            useFlap    = true;
            flapDefRot = flap.localRotation.eulerAngles;
        }
        else if (verboseErrors)
        {
            debug.debugMessage("FSwing: did not find flap " + flapName);
        }

        leadingEdgeTop = part.FindModelTransform(leadingEdgeTopName);
        if (leadingEdgeTop == null && verboseErrors)
        {
            debug.debugMessage("FSwing: did not find leadingEdgeTop " + leadingEdgeTopName);
        }
        leadingEdgeBottom = part.FindModelTransform(leadingEdgeBottomName);
        if (leadingEdgeBottom == null && verboseErrors)
        {
            debug.debugMessage("FSwing: did not find leadingEdgeBottom " + leadingEdgeBottomName);
        }
        if (leadingEdgeTop != null)
        {
            useLeadingEdge = true;
        }

        //flapRetracted = part.FindModelTransform(flapRetractedName);
        //if (flapRetracted == null && verboseErrors) debug.debugMessage("FSwing: did not find flapRetracted " + flapRetractedName);
        //flapExtended = part.FindModelTransform(flapExtendedName);
        //if (flapExtended == null && verboseErrors) debug.debugMessage("FSwing: did not find flapExtended " + flapExtendedName);

        leadingEdgeTopExtended = part.FindModelTransform(leadingEdgeTopExtendedName);
        if (leadingEdgeTopExtended == null && verboseErrors)
        {
            debug.debugMessage("FSwing: did not find leadingEdgeTopExtended " + leadingEdgeTopExtendedName);
        }
        leadingEdgeTopRetracted = part.FindModelTransform(leadingEdgeTopRetractedName);
        if (leadingEdgeTopRetracted == null && verboseErrors)
        {
            debug.debugMessage("FSwing: did not find leadingEdgeTopRetracted " + leadingEdgeTopRetractedName);
        }

        leadingEdgeBottomExtended = part.FindModelTransform(leadingEdgeBottomExtendedName);
        if (leadingEdgeBottomExtended == null && verboseErrors)
        {
            debug.debugMessage("FSwing: did not find leadingEdgeBottomExtended " + leadingEdgeBottomExtendedName);
        }
        leadingEdgeBottomRetracted = part.FindModelTransform(leadingEdgeBottomRetractedName);
        if (leadingEdgeBottomRetracted == null && verboseErrors)
        {
            debug.debugMessage("FSwing: did not find leadingEdgeBottomRetracted " + leadingEdgeBottomRetractedName);
        }

        controlSurface = part.FindModelTransform(controlSurfaceName);
        if (controlSurface == null)
        {
            if (verboseErrors)
            {
                debug.debugMessage("FSwing: did not find controlSurface " + controlSurfaceName);
            }
        }
        else
        {
            useCtrlSrf     = true;
            ctrllSrfDefRot = controlSurface.localRotation.eulerAngles;
        }

        #endregion
    }