Пример #1
0
 public void Destroy(UnityEngine.Object o)
 {
     if (Application.isPlaying)
     {
         MonoBehaviour.Destroy(o);
     }
     else
     {
         string p = AssetDatabase.GetAssetPath(o);
         if (p != null && p.Equals(""))                 // don't try to destroy assets
         {
             MonoBehaviour.DestroyImmediate(o, false);
         }
     }
 }
Пример #2
0
            private void PlatformOnlyObjects()
            {
                var objectsWithTag = new List <GameObject>();

                #if !UNITY_STANDALONE
                objectsWithTag = objectsWithTag.FindGameObjectsWithTag(PCOnly);
                #endif
                #if !UNITY_ANDROID
                objectsWithTag = objectsWithTag.FindGameObjectsWithTag(AndroidOnly);
                #endif
                foreach (var gameObject in objectsWithTag)
                {
                    MonoBehaviour.DestroyImmediate(gameObject);
                }
            }
Пример #3
0
    void Update()
    {
        transform.Translate(SPEED * TimeHelper.deltaTime, 0, 0);

        if (transform.position.x > _endPosition.x)
        {
            _isOver = true;
            MonoBehaviour.DestroyImmediate(this.gameObject);
            return;
        }
        if (transform.position.x > _worldPosition.x)
        {
            _flyOver = true;
        }
    }
Пример #4
0
    public static void DestroyChildren(this  Transform t, bool destroyImmediately = false)
    {
        foreach (Transform child in t)
        {
            if (destroyImmediately)
            {
                MonoBehaviour.DestroyImmediate(child.gameObject);
            }

            else
            {
                MonoBehaviour.Destroy(child.gameObject);
            }
        }
    }
Пример #5
0
        public override void Build(ModuleMaker maker, GameObject root, GameObject head)
        {
            if (this.trackableHead)
            {
                head.AddComponent <KinectTrackableHead>();
            }

            if (this.trackableHands)
            {
                GameObject leftHand = GameObject.CreatePrimitive(PrimitiveType.Sphere);
                leftHand.name             = "Left Hand";
                leftHand.transform.parent = root.transform;
                leftHand.transform.SetSiblingIndex(1);
                leftHand.transform.localPosition = new Vector3(-0.3f, 1f, 0f);
                leftHand.GetComponent <SphereCollider>().radius        = 0.1f;
                leftHand.AddComponent <KinectTrackableHand>().HandType = HandType.Left;
                MonoBehaviour.DestroyImmediate(leftHand.GetComponent <MeshRenderer>());

                GameObject rightHand = GameObject.CreatePrimitive(PrimitiveType.Sphere);
                rightHand.name             = "Right Hand";
                rightHand.transform.parent = root.transform;
                rightHand.transform.SetSiblingIndex(2);
                rightHand.transform.localPosition = new Vector3(0.3f, 1f, 0f);
                rightHand.GetComponent <SphereCollider>().radius        = 0.1f;
                rightHand.AddComponent <KinectTrackableHand>().HandType = HandType.Right;
                MonoBehaviour.DestroyImmediate(rightHand.GetComponent <MeshRenderer>());
            }

            GameObject kinect = new GameObject("Kinect Play Area");

            kinect.transform.parent        = root.transform;
            kinect.transform.localPosition = Vector3.zero;

            KinectPlayArea playArea = kinect.AddComponent <KinectPlayArea>();

            string         assetPath = ModuleMaker.AssetPath + "/Kinect Settings.asset";
            KinectSettings asset     = AssetDatabase.LoadAssetAtPath <KinectSettings>(assetPath);

            if (asset == null)
            {
                asset = ScriptableObject.CreateInstance <KinectSettings>();
                asset.SensorLocation = this.sensorLocation;
                asset.TrackingArea   = new Rect(0f, 0f, this.trackingAreaWidth, this.trackingAreaLength);
                AssetDatabase.CreateAsset(asset, assetPath);
            }

            playArea.Settings = asset;
        }
        public static void Set(T newT, bool overwrite = false, System.Action <T> ifOverwriteDoThisOnOriginal = null, System.Action <T> ifNotOverwriteDoThisOnNewT = null)
        {
            lock (m_Lock)
            {
                if (newT == null)
                {
                    if (instance != null)
                    {
                        MonoBehaviour.Destroy(instance);
                    }
                    instance = null;
                    return;
                }

                Debug.Log($"Trying to set Singleton of type {newT.GetType().Name}...instance: " + newT);
                if (SingletonBehaviourLocator <T> .instance == null)
                {
                    SingletonBehaviourLocator <T> .instance = newT;
                }
                if (SingletonBehaviourLocator <T> .instance != newT)
                {
                    if (!overwrite)
                    {
                        ifNotOverwriteDoThisOnNewT?.Invoke(newT);
                        MonoBehaviour.DestroyImmediate(newT);
                    }
                    else
                    {
                        ifOverwriteDoThisOnOriginal?.Invoke(Instance);
                        MonoBehaviour.DestroyImmediate(Instance);
                        SingletonBehaviourLocator <T> .instance = newT;
                    }
                }

                try
                {
                    #if DDOL_EXT
                    DDOLRegistry.DontDestroyOnLoad(newT.gameObject);
                    #else
                    MonoBehaviour.DontDestroyOnLoad(newT);
                    #endif
                }
                catch (System.Exception e)
                {
                    Debug.Log("SBL:: Setting singleton of " + newT.GetType().Name + ", Exception: " + e);
                }
            }
        }
Пример #7
0
        /// <summary>
        /// This method replaces standard Unity Text elements with TextMeshPro elements
        /// </summary>
        /// <param name="handler">The text element marker</param>
        private void TMProFromText(TextHandler handler)
        {
            if (handler == null)
            {
                return;
            }

            //The TextHandler element should be attached only to objects with a Unity Text element
            //Note that the "[RequireComponent(typeof(Text))]" attribute cannot be attached to TextHandler since Unity will not allow the Text element to be removed
            Text text = handler.GetComponent <Text>();

            if (text == null)
            {
                return;
            }

            //Cached all of the relevent information from the Text element
            string               t       = text.text;
            Color                c       = text.color;
            int                  i       = text.fontSize;
            bool                 r       = text.raycastTarget;
            FontStyles           sty     = getStyle(text.fontStyle);
            TextAlignmentOptions align   = getAnchor(text.alignment);
            float                spacing = text.lineSpacing;
            GameObject           obj     = text.gameObject;

            //The existing Text element must by destroyed since Unity will not allow two UI elements to be placed on the same GameObject
            MonoBehaviour.DestroyImmediate(text);

            BasicOrbitTextMeshProHolder tmp = obj.AddComponent <BasicOrbitTextMeshProHolder>();

            //Populate the TextMeshPro fields with the cached data from the old Text element
            tmp.text          = t;
            tmp.color         = c;
            tmp.fontSize      = i;
            tmp.raycastTarget = r;
            tmp.alignment     = align;
            tmp.fontStyle     = sty;
            tmp.lineSpacing   = spacing;

            //Load the TMP Font from disk
            tmp.font = Resources.Load("Fonts/Calibri SDF", typeof(TMP_FontAsset)) as TMP_FontAsset;
            tmp.fontSharedMaterial = Resources.Load("Fonts/Materials/Calibri Dropshadow", typeof(Material)) as Material;

            tmp.enableWordWrapping = true;
            tmp.isOverlay          = false;
            tmp.richText           = true;
        }
Пример #8
0
    // Start is called before the first frame update
    void Start()
    {
        //create a quad a circle for gazeing in VR or mouse cursor in non VR
        oGazeQuad = GameObject.CreatePrimitive(PrimitiveType.Quad);
        oGazeQuad.transform.parent = transform;
        MonoBehaviour.DestroyImmediate(oGazeQuad.GetComponent <Collider>());
        oCursorMaterial = Resources.Load("Cursor", typeof(Material)) as Material;
        oGazeQuad.GetComponent <MeshRenderer>().material = oCursorMaterial;
        oGazeQuad.transform.localScale = new Vector3(.38f, .38f, 1);
        oGazeQuad.SetActive(false);

        poseActionR = SteamVR_Input.GetAction <SteamVR_Action_Pose>("Pose_right_tip");
        poseActionL = SteamVR_Input.GetAction <SteamVR_Action_Pose>("Pose_left_tip");

        iRightHanded = 0;
    }
Пример #9
0
 /// <summary>
 /// 清除T
 /// </summary>
 /// <param name="url"></param>
 public void ClearT(string url)
 {
     if (saveConDic.ContainsKey(url))
     {
         if (typeof(T) == typeof(Texture2D) || typeof(T) == typeof(Sprite) || typeof(T) == typeof(NetVideoClip) ||
             typeof(T) == typeof(TextAsset) || typeof(T) == typeof(AudioClip))
         {
             MonoBehaviour.DestroyImmediate(saveConDic[url]);
         }
         if (typeof(T) == typeof(AssetBundle))
         {
             (saveConDic[url] as AssetBundle).Unload(false);
         }
         saveConDic.Remove(url);
     }
 }
Пример #10
0
        /// <summary>
        /// Destroy all the 'TYPE' object in the scene.
        /// </summary>
        public static void DestroyImmediateAllTypeObjectInScene <T>()
            where T : MonoBehaviour
        {
            // Destroy all the live object in the scene.
            T[] rrEnemy = Resources.FindObjectsOfTypeAll <T>();

            foreach (T e in rrEnemy)
            {
                // NOTE(JenChieh): kill the object that are clone!
                // or else it will effect the prefab object...
                if (e.gameObject.name.Contains("(Clone)"))
                {
                    MonoBehaviour.DestroyImmediate(e.gameObject);
                }
            }
        }
Пример #11
0
 /// <summary>
 /// 清除缓存的所有资源
 /// </summary>
 public void ClearAllT()
 {
     foreach (var item in saveConDic)
     {
         if (typeof(T) == typeof(Texture2D) || typeof(T) == typeof(Sprite) || typeof(T) == typeof(NetVideoClip) ||
             typeof(T) == typeof(TextAsset) || typeof(T) == typeof(AudioClip))
         {
             MonoBehaviour.DestroyImmediate(item.Value);
         }
         if (typeof(T) == typeof(AssetBundle))
         {
             (item.Value as AssetBundle).Unload(false);
         }
     }
     saveConDic.Clear();
 }
Пример #12
0
        public static void RemoveChildren(this Transform transform, int childIndex = 0)
        {
            int k = 0;

            for (int i = transform.childCount - 1; i >= childIndex; i--)
            {
                GameObject go = transform.GetChild(i).gameObject;
#if UNITY_EDITOR
                MonoBehaviour.DestroyImmediate(go);
#else
                MonoBehaviour.Destroy(go);
#endif
                k++;
            }
            //        Debug.Log("destroyed " + k + " children of " + transform.name, transform.gameObject);
        }
Пример #13
0
            public IEnumerator shot_should_create_a_bullet()
            {
                Weapon weapon_instance = weapon.GetComponent <Weapon>();

                yield return(new WaitForSeconds(0.1f));

                GameObject bullet_clone = weapon_instance.shot();

                yield return(new WaitForSeconds(0.1f));

                GameObject bullet_finded_in_scenary = GameObject.Find(
                    bullet_clone.name);

                Assert.IsNotNull(bullet_finded_in_scenary);
                MonoBehaviour.DestroyImmediate(bullet_clone);
            }
Пример #14
0
        public T AddToggleSetting <T>(string name) where T : SwitchSettingsController
        {
            var        volumeSettings    = Resources.FindObjectsOfTypeAll <WindowModeSettingsController>().FirstOrDefault();
            GameObject newSettingsObject = MonoBehaviour.Instantiate(volumeSettings.gameObject, transform);

            newSettingsObject.name = name;

            WindowModeSettingsController volume = newSettingsObject.GetComponent <WindowModeSettingsController>();
            T newToggleSettingsController       = (T)ReflectionUtil.CopyComponent(volume, typeof(SwitchSettingsController), typeof(T), newSettingsObject);

            MonoBehaviour.DestroyImmediate(volume);

            newSettingsObject.GetComponentInChildren <TMP_Text>().text = name;

            return(newToggleSettingsController);
        }
Пример #15
0
    public static void Save(GameObject Obj, string assetName)
    {
        if (!AssetDatabase.IsValidFolder("Assets/SMDExport/Meshes"))// create directory if not exist
        {
            System.IO.Directory.CreateDirectory("Assets/SMDExport/Meshes");
            AssetDatabase.Refresh();
        }

        if (AssetDatabase.IsValidFolder("Assets/SMDExport/Meshes"))
        {
            var url = "Assets/SMDExport/Meshes/" + assetName + ".asset";
            // create mesh asset
            if (!AssetDatabase.LoadAssetAtPath(url, typeof(Mesh)))
            {
                AssetDatabase.CreateAsset(Obj.GetComponent <MeshFilter>().sharedMesh, url);
                AssetDatabase.SaveAssets();

                //load mesh
                var mesh = (Mesh)AssetDatabase.LoadAssetAtPath(url, typeof(Mesh));


                // pass mesh  to clone game object mesh filter
                var instance = new GameObject();

                var cloneMesh = instance.AddComponent <MeshFilter>();
                instance.AddComponent <MeshRenderer>().materials = Obj.GetComponent <MeshRenderer>().sharedMaterials;
                cloneMesh.sharedMesh = mesh;

                // create clone prefab
                PrefabUtility.CreatePrefab("Assets/SMDExport/" + assetName + ".prefab", instance);
                // destroy instance game object
                MonoBehaviour.DestroyImmediate(instance);

                EditorUtility.DisplayDialog(
                    "Success",
                    "Asset exported successfully , it can be found here 'Assets/SMDExport/' ",
                    "Ok");
            }
            else
            {
                EditorUtility.DisplayDialog(
                    "error",
                    "Asset already exist, please change asset name!",
                    "Ok");
            }
        }
    }
Пример #16
0
    public static void SavePrefab(GameObject Obj, string assetName)
    {
        bool success = false;

        //Get the saving path
        var path = EditorUtility.SaveFilePanelInProject("Save", assetName, "asset", "Save Mesh!");

        if (path == "")
        {
            return;
        }


        //Make a copy of the mesh provided and save it to disk
        var copiedMesh = CopyMesh(Obj.GetComponent <MeshFilter>().sharedMesh, path);

        AssetDatabase.SaveAssets();

        //Create a prefab instance
        var instance = new GameObject();

        instance.AddComponent <MeshFilter>().sharedMesh        = copiedMesh;
        instance.AddComponent <MeshRenderer>().sharedMaterials = Obj.GetComponent <MeshRenderer>().sharedMaterials;

        //Correct the path to save the prefab
        var prefabPath = Regex.Split(path, ".asset")[0] + ".prefab";

        //Save the prefab
        PrefabUtility.SaveAsPrefabAsset(instance, prefabPath, out success);

        if (success)
        {
            // destroy instance game object
            MonoBehaviour.DestroyImmediate(instance);
            EditorUtility.DisplayDialog(
                "Success",
                "Asset exported successfully !! ",
                "Ok");
        }
        else
        {
            EditorUtility.DisplayDialog(
                "Error",
                "Oops, Something went wrong !!!",
                "Ok");
        }
    }
Пример #17
0
        // Create configuration for token with blank configuration
        public static int CreateConfiguration(string serverToken)
        {
            // Generate blank asset
            WitConfiguration configurationAsset = ScriptableObject.CreateInstance <WitConfiguration>();

            configurationAsset.name = WitTexts.Texts.ConfigurationFileNameLabel;
            configurationAsset.clientAccessToken = string.Empty;
            // Create
            int index = SaveConfiguration(serverToken, configurationAsset);

            if (index == -1)
            {
                MonoBehaviour.DestroyImmediate(configurationAsset);
            }
            // Return new index
            return(index);
        }
        static void InstantiateAndCleanupPersistentGameObject()
        {
            const string persistentName            = "Persistent";
            const string persistentCloneName       = "Persistent(Clone)";
            GameObject   persistentGameObject      = GameObject.Find(persistentName);
            GameObject   persistentCloneGameObject = GameObject.Find(persistentCloneName);

            if (EditorApplication.isPlayingOrWillChangePlaymode && persistentGameObject == null && persistentCloneGameObject == null)
            {
                GameObject prefab   = (GameObject)Resources.Load(persistentName);
                GameObject instance = GameObject.Instantiate(prefab);
            }
            else if (!EditorApplication.isPlayingOrWillChangePlaymode && persistentCloneGameObject != null)
            {
                MonoBehaviour.DestroyImmediate(persistentCloneGameObject);
            }
        }
Пример #19
0
        protected virtual void Awake()
        {
            if (s_Instance == null)
            {
                s_Instance = this as T;
            }
            else if (s_Instance != this)
            {
                MonoBehaviour.DestroyImmediate(this);
                return;
            }

            if (s_Instance.GetComponent <DontDestroyGameObject>() == null)
            {
                s_Instance.gameObject.AddComponent <DontDestroyGameObject>();
            }
        }
Пример #20
0
        public static void RemoveCameras(GameObject currentAvatar, bool localPlayer, bool friend)
        {
            if (!localPlayer)
            {
                foreach (Camera camera in currentAvatar.GetComponentsInChildren <Camera>(true))
                {
                    Debug.LogWarning("Removing camera from " + camera.gameObject.name);

                    if (friend && camera.targetTexture != null)
                    {
                        camera.enabled = false;
                    }
                    else
                    {
                        Component[] components = camera.gameObject.GetComponents <Component>();
                        foreach (var c in components)
                        {
                            bool     deleteMe = false;
                            object[] requires = c.GetType().GetCustomAttributes(typeof(RequireComponent), true);
                            foreach (var r in requires)
                            {
                                RequireComponent rc = r as RequireComponent;
                                if (rc.m_Type0 == typeof(Camera) ||
                                    rc.m_Type1 == typeof(Camera) ||
                                    rc.m_Type2 == typeof(Camera))
                                {
                                    deleteMe = true;
                                }
                            }

                            if (deleteMe)
                            {
                                MonoBehaviour.DestroyImmediate(c);
                            }
                        }

                        camera.enabled = false;
                        if (camera.targetTexture != null)
                        {
                            camera.targetTexture = new RenderTexture(16, 16, 24);
                        }
                        MonoBehaviour.DestroyImmediate(camera);
                    }
                }
            }
        }
Пример #21
0
    /// <summary>
    /// 查看英雄装备的奥义
    /// </summary>
    /// <param name="item"></param>
    /// <param name="isPressed"></param>
    void SeeHeroArcaneInfo(UIGridItem item, bool isPressed)
    {
        RaycastHit hit;
        Ray        ray;
        UIGridItem hitItem;

        if (item.mScripts[2] == null)
        {
            return;
        }
        if (isPressed)
        {
            Facade.SendNotification(NotificationID.ArcaneInfoOpen, item);
            startPos = item;
            item.GetComponent <UIGridItem>().mScripts[2].GetComponent <CardRole>().ShowHighlighter();
            ResourceManager.Instance.LoadPrefab("linerender", LoadLineRenderComplete, LoadFail, item.gameObject);
        }
        else
        {
            panel.startPos.gameObject.SetActive(false);
            item.GetComponent <UIGridItem>().mScripts[2].GetComponent <CardRole>().HideHighlighter();
            if (ArcaneInfoMediator.arcaneInfoMediator != null)
            {
                Facade.SendNotification(NotificationID.ArcaneInfoClose);
            }
            if (Main.Ins.lineRender != null)
            {
                MonoBehaviour.DestroyImmediate(Main.Ins.lineRender.gameObject);
                Main.Ins.lineRender = null;
            }
            Main.Ins.Camera3D.gameObject.SetActive(false);
            ray = UICamera.currentCamera.ScreenPointToRay(Input.mousePosition);
            if (Physics.Raycast(ray, out hit, Mathf.Infinity))
            {
                if (hit.collider.transform.name.Contains("hero") && hit.collider.GetComponent <UIGridItem>() != null)
                {
                    hitItem = hit.collider.GetComponent <UIGridItem>();
                    if (hitItem.mScripts[2] != null)
                    {
                        hitItem.mScripts[2].GetComponent <CardRole>().HideHighlighter();
                    }
                    SwitchTwoHeroPosition(startPos, hit.collider.GetComponent <UIGridItem>());
                }
            }
        }
    }
        public static void RemoveTerrainsFromWorld(OpenWorldSettings openWorldSettings)
        {
            if (!EditorUtility.DisplayDialog("Remove Terrains", "Are you sure you want to remove terrain objects from all world scenes?", "Yes", "No"))
            {
                return;
            }

            string directory = OpenWorldSettingsEditor.GetDirectory(openWorldSettings);

            GameSettingsList.disableRefresh = true;

            for (int i = 0; i < openWorldSettings.worldSceneNames_1.Length; i++)
            {
                string scenePath = directory + openWorldSettings.worldSceneNames_1[i] + ".unity";

                Scene scene = EditorSceneManager.GetSceneByName(openWorldSettings.worldSceneNames_1[i]);

                bool wasOpen = scene.IsValid();
                if (!wasOpen)
                {
                    scene = EditorSceneManager.OpenScene(scenePath, OpenSceneMode.Additive);
                }

                GameObject[] rootObjects = scene.GetRootGameObjects();
                for (int x = 0; x < rootObjects.Length; x++)
                {
                    TerrainChunk terrain = rootObjects[x].GetComponentInChildren <TerrainChunk>(true);
                    if (terrain != null)
                    {
                        MonoBehaviour.DestroyImmediate(terrain.gameObject);
                        break;
                    }
                }

                EditorSceneManager.SaveScene(scene, scenePath);
                if (!wasOpen)
                {
                    EditorSceneManager.CloseScene(scene, true);
                }
            }

            GameSettingsList.disableRefresh = false;

            AssetDatabase.SaveAssets();
        }
Пример #23
0
    protected void Reset()
    {
        if (myStarfieldPS != null)
        {
            MonoBehaviour.DestroyImmediate(myStarfieldPS);
        }

        myStarfieldPS       = gameObject.AddComponent <ParticleSystem>();
        myStarfieldRenderer = GetComponent <ParticleSystemRenderer>();

        // Setup the particle system component the first time it's added
        SetParticleSystemPropertiesInEditor();

        if (Application.isEditor && !Application.isPlaying)
        {
            myStarfieldPS.hideFlags = HideFlags.NotEditable; // Restore with HideFlags.None;
        }
    }
Пример #24
0
 public void SetBar(GameObject mod, float buttomToScreen, float RightToScreen)
 {
     this.buttomToScreen = buttomToScreen;
     this.RightToScreen  = RightToScreen;
     if (toolBar != null)
     {
         MonoBehaviour.DestroyImmediate(toolBar);
     }
     toolBar = create
               (
         mod,
         Program.camera_main_2d.ScreenToWorldPoint(new Vector3(Screen.width - RightToScreen, -100, 0)),
         new Vector3(0, 0, 0),
         false,
         Program.ui_main_2d
               );
     fixScreenProblem();
 }
Пример #25
0
    public static void deleteGO(string info) //Function used to delete a gameobject
    {
        string gOId = deserializeString(ref info);

        int hashLoc = genHashCode(gOId);

        int xLoc = hashLoc % 10;
        int yLoc = hashLoc % 100;

        MarkerFlag thisFlag = null;

        thisFlag = findInList(gOId, xLoc, yLoc);

        if (thisFlag != null)
        {
            MonoBehaviour.DestroyImmediate(thisFlag.gameObject);
        }
    }
Пример #26
0
        private void TMProFromText(TextHandler handler)
        {
            if (handler == null)
            {
                return;
            }

            Text text = handler.GetComponent <Text>();

            if (text == null)
            {
                return;
            }

            string               t       = text.text;
            Color                c       = text.color;
            int                  i       = text.fontSize;
            bool                 r       = text.raycastTarget;
            FontStyles           sty     = TMPProUtil.FontStyle(text.fontStyle);
            TextAlignmentOptions align   = TMPProUtil.TextAlignment(text.alignment);
            float                spacing = text.lineSpacing;
            GameObject           obj     = text.gameObject;

            MonoBehaviour.DestroyImmediate(text);

            CWTextMeshPro tmp = obj.AddComponent <CWTextMeshPro>();

            tmp.text          = t;
            tmp.color         = c;
            tmp.fontSize      = i;
            tmp.raycastTarget = r;
            tmp.alignment     = align;
            tmp.fontStyle     = sty;
            tmp.lineSpacing   = spacing;

            tmp.font = UISkinManager.TMPFont;
            tmp.fontSharedMaterial = Resources.Load("Fonts/Materials/Calibri Dropshadow", typeof(Material)) as Material;

            tmp.enableWordWrapping = true;
            tmp.isOverlay          = false;
            tmp.richText           = true;

            tmp.Setup(handler);
        }
Пример #27
0
        public void OnUnregister(IInjectionContainer container)
        {
            container.afterAddBinding   -= this.OnAfterAddBinding;
            container.bindingResolution -= this.OnBindingResolution;

            if (behaviour != null && behaviour.gameObject != null)
            {
                MonoBehaviour.DestroyImmediate(behaviour.gameObject);
            }
            behaviour = null;

            disposable.Clear();
            updateable.Clear();
            lateUpdateable.Clear();
            fixedUpdateable.Clear();
            focusable.Clear();
            pausable.Clear();
            quitable.Clear();
        }
Пример #28
0
        public T AddIntSetting <T>(string name, string hintText) where T : IntSettingsController
        {
            var        volumeSettings    = Resources.FindObjectsOfTypeAll <WindowModeSettingsController>().FirstOrDefault();
            GameObject newSettingsObject = MonoBehaviour.Instantiate(volumeSettings.gameObject, transform);

            newSettingsObject.name = name;

            WindowModeSettingsController volume = newSettingsObject.GetComponent <WindowModeSettingsController>();
            T newToggleSettingsController       = (T)ReflectionUtil.CopyComponent(volume, typeof(IncDecSettingsController), typeof(T), newSettingsObject);

            MonoBehaviour.DestroyImmediate(volume);

            var tmpText = newSettingsObject.GetComponentInChildren <TMP_Text>();

            tmpText.text = name;
            BeatSaberUI.AddHintText(tmpText.rectTransform, hintText);

            return(newToggleSettingsController);
        }
Пример #29
0
        public void FinishBarrelRollAnimation()
        {
            performingAnimation = false;

            TheShip.ApplyRotationHelpers();
            TheShip.ResetRotationHelpers();
            TheShip.SetAngles(TemporaryShipBase.transform.eulerAngles);

            MonoBehaviour.DestroyImmediate(TemporaryShipBase);

            GameManagerScript Game = GameObject.Find("GameManager").GetComponent <GameManagerScript>();

            Game.Movement.CollidedWith = null;

            MovementTemplates.HideLastMovementRuler();

            TheShip.ToggleShipStandAndPeg(true);
            TheShip.FinishPosition(FinishBarrelRollAnimationPart2);
        }
Пример #30
0
        public static GameObject DisplayBlankPanel <T>(MainMenuUI mainMenu, string name, string title, Action onClose = null) where T : BaseUI
        {
            var h = GameObject.Instantiate(mainMenu.optionsUI);

            h.name = name;
            Component.DestroyImmediate(h.GetComponent <OptionsUI>());

            for (int i = 0; i < h.transform.GetChild(0).childCount; i++)
            {
                var v = h.transform.GetChild(0).GetChild(i).gameObject;
                if (v.name == "CloseButton")
                {
                    v.GetComponent <Button>().onClick = new Button.ButtonClickedEvent();
                    v.GetComponent <Button>().onClick.AddListener(() =>
                    {
                        GameObject.Destroy(h);
                        onClose?.Invoke();
                    });
                }
                else if (v.name == "Title" && title != null)
                {
                    MonoBehaviour.DestroyImmediate(v.GetComponent <XlateText>());
                    v.GetComponent <TMP_Text>().text = title;
                }
                else
                {
                    GameObject.Destroy(v);
                }
            }


            mainMenu.gameObject.SetActive(false);
            var baseUI = h.AddComponent <T>();

            baseUI.onDestroy += () =>
            {
                if (mainMenu)
                {
                    mainMenu.gameObject.SetActive(true);
                }
            };
            return(h);
        }