Пример #1
0
 void Awake()
 {
     if (m_Instance == null)
     {
         m_Instance = this;
         DontDestroyOnLoad(gameObject);
     }
     else
     {
         Destroy(gameObject);
     }
 }
Пример #2
0
 private void InstantiateController()
 {
     if (Instance == null)
     {
         Instance = this;
         DontDestroyOnLoad(this);
     }
     else if (this != Instance)
     {
         Destroy(this.gameObject);
     }
 }
Пример #3
0
        public void Start()
        {
            buttonGray    = (Texture)GameDatabase.Instance.GetTexture("001ControlLock/ToolbarButton", false);
            buttonRed     = (Texture)GameDatabase.Instance.GetTexture("001ControlLock/ToolbarButtonRed", false);
            buttonYellow  = (Texture)GameDatabase.Instance.GetTexture("001ControlLock/ToolbarButtonYellow", false);
            buttonCreated = false;
            lockedMods    = new List <string>();
            unboundKeys   = new List <KeyBind>();
            allKeys       = new List <KeyBindString>();
            allKeys       = GetKeyList();
            Debug.Log("ControlLock V1.5 Started");
            DoNotDestroy.DontDestroyOnLoad(this); //never unload this class so we persist across scenes.
            ConfigNode controlLockNode = ConfigNode.Load(KSPUtil.ApplicationRootPath + "GameData/001ControlLock/LockedKeys.cfg");

            if (controlLockNode.nodes.Count > 0)
            {
                for (int i = 1; i <= controlLockNode.nodes.Count; i++)     //under normal contions, this should find no nodes, but if we crashed rebind our keys
                {
                    ConfigNode    key      = controlLockNode.nodes[i - 1]; //nodes is a 0 index list, so first node is zero position
                    string        kbStr    = key.GetValue("KeyBind");
                    KeyBindString kbMaster = allKeys.Find(kb3 => kb3.keyBindString == kbStr);
                    kbMaster.keyBind2.primary   = (KeyCode)Enum.Parse(typeof(KeyCode), key.GetValue("Key1"));
                    kbMaster.keyBind2.secondary = (KeyCode)Enum.Parse(typeof(KeyCode), key.GetValue("Key2"));
                }
                GameSettings.SaveSettings(); //this will only be hit if there are nodes in the file, means we crashed so need to save our settings back
            }
            GameEvents.onGameSceneLoadRequested.Add(SceneSwitch);
            if (ToolbarManager.ToolbarAvailable) //check if toolbar available, load if it is
            {
                //Debug.Log("Make button3");
                CLBtn             = ToolbarManager.Instance.add("CtrlLock", "CLButton");
                CLBtn.TexturePath = "001ControlLock/ToolbarButton";
                CLBtn.ToolTip     = "Control Lock";
                CLBtn.OnClick    += (e) =>
                {
                    if (e.MouseButton == 0)
                    {
                        ToolbarClick();
                    }
                    if (e.MouseButton == 1)
                    {
                        showKeysWindow = !showKeysWindow;
                    }
                };
            }
            else
            {
                StartCoroutine(AddButtons());//GameEvents.onGUIApplicationLauncherReady.Add(AddButtons);
                //GameEvents.onGUIApplicationLauncherUnreadifying.Add(RemoveButtons);
            }
            settings = LoadSettings();
        }
Пример #4
0
    private void Awake()
    {
        if (bCanvas && bCanvas != this)
        {
            Destroy(gameObject);
        }
        else
        {
            bCanvas = this;
        }

        DontDestroyOnLoad(bCanvas);
    }
Пример #5
0
 // Use this for initialization
 void Start()
 {
     //if it exists destroy the duplicate created
     if (instance)
     {
         DestroyImmediate(gameObject);
     }
     else
     {
         //tell it not to be destroyed and set the instance
         DontDestroyOnLoad(gameObject);
         instance = this;
     }
 }
Пример #6
0
    void Awake()
    {
        //If there is no instance of this class....
        if (instance == null)
        {
            //....Then set the instance to this
            instance = this;
        }
        //Otherwise if an instance does not equal to this....
        else if (instance != this)
        {
            //....Then destroy this gameobject
            Destroy(gameObject);
        }

        DontDestroyOnLoad(this.gameObject);
    }
Пример #7
0
 void Awake()
 {
     if (SceneManager.GetActiveScene().name.Equals("level2"))
     {
         if (instance == null)
         {
             instance = this;
             DontDestroyOnLoad(instance);
         }
         else
         {
             Destroy(gameObject);
         }
     }
     else
     {
         Destroy(gameObject);
     }
 }