Пример #1
0
        public static GameObject InstantiateInactive(GameObject original)
        {
            var state = original.activeSelf;

            original.SetActive(false);
            bool          originalRuntimeValue = false;
            RuntimePrefab comp = original.GetComponent <RuntimePrefab>();

            if (comp)
            {
                originalRuntimeValue           = comp.ShouldEnableOnInstantiate;
                comp.ShouldEnableOnInstantiate = false;
            }
            var newObj = GameObject.Instantiate(original);

            if (comp)
            {
                comp.ShouldEnableOnInstantiate = originalRuntimeValue;
                newObj.GetComponent <RuntimePrefab>().ShouldEnableOnInstantiate = originalRuntimeValue;
            }
            original.SetActive(state);
            return(newObj);
        }
Пример #2
0
        public static GameObject InstantiateInactive(GameObject original, Vector3 position, Quaternion rotation, Transform parent)
        {
            var state = original.activeSelf;

            original.SetActive(false);
            bool          originalRuntimeValue = false;
            RuntimePrefab comp = original.GetComponent <RuntimePrefab>();

            if (comp)
            {
                originalRuntimeValue           = comp.ShouldEnableOnInstantiate;
                comp.ShouldEnableOnInstantiate = false;
            }
            var newObj = GameObject.Instantiate(original, position, rotation, parent);

            if (comp)
            {
                comp.ShouldEnableOnInstantiate = originalRuntimeValue;
                newObj.GetComponent <RuntimePrefab>().ShouldEnableOnInstantiate = originalRuntimeValue;
            }
            original.SetActive(state);
            return(newObj);
        }