public void Resize(int count) { if (instance == null) { return; } if (count == cachedObjects.Count) { return; } if (count < cachedObjects.Count) { var deleteCount = cachedObjects.Count - count; for (var i = 0; i < deleteCount; i++) { var item = cachedObjects.Dequeue(); UnityUtility.SafeDelete(item); } } else { var addCount = count - cachedObjects.Count; var items = UnityUtility.Instantiate <T>(instance, prefab, addCount); foreach (var item in items) { Release(item); } } }
public override void OnInspectorGUI() { var instance = target as UIRawImage; var rawImage = instance.RawImage; if (rawImage == null) { return; } GUILayout.Space(4f); DrawDefaultScriptlessInspector(); using (new EditorGUILayout.HorizontalScope()) { EditorGUILayout.PrefixLabel("Dummy Texture"); EditorGUI.BeginChangeCheck(); textureAsset = EditorGUILayout.ObjectField(textureAsset, typeof(Texture), false) as Texture; if (EditorGUI.EndChangeCheck()) { UnityEditorUtility.RegisterUndo("UIRawImageInspector-Undo", instance); var assetGuid = textureAsset != null?UnityEditorUtility.GetAssetGUID(textureAsset) : string.Empty; Reflection.SetPrivateField(instance, "assetGuid", assetGuid); if (textureAsset == null) { if (rawImage.texture != null && rawImage.texture.name == UIRawImage.DummyAssetName) { rawImage.texture = null; } } else { Reflection.InvokePrivateMethod(instance, "ApplyDummyAsset"); } } } if (dummyTexture != null) { if (rawImage.texture != dummyTexture) { UnityUtility.SafeDelete(dummyTexture); dummyTexture = null; } } if (rawImage.texture != null && rawImage.texture.name == UIRawImage.DummyAssetName) { dummyTexture = rawImage.texture; } }
private void EndAction() { switch (endActionType) { case EndActionType.None: currentState = State.Stop; break; case EndActionType.Deactivate: if (Application.isPlaying) { UnityUtility.SetActive(gameObject, false); } currentState = State.Stop; break; case EndActionType.Destroy: if (Application.isPlaying) { UnityUtility.SafeDelete(gameObject); } currentState = State.Stop; break; case EndActionType.Loop: break; } if (onEndAnimation != null) { onEndAnimation.OnNext(this); } }
private void EndAction() { Stop(); switch (endActionType) { case EndActionType.Deactivate: if (Application.isPlaying) { UnityUtility.SetActive(gameObject, false); } break; case EndActionType.Destroy: if (Application.isPlaying) { UnityUtility.SafeDelete(gameObject); } break; case EndActionType.Loop: break; } playObservable = null; if (onEnd != null) { onEnd.OnNext(this); } }
public static void Initialize() { var initializerCreate = false; CriWareInitializer initializer = null; if (!CriWareInitializer.IsInitialized()) { initializer = UnityUtility.FindObjectOfType <CriWareInitializer>(); if (initializer == null) { initializer = UnityUtility.CreateGameObject <CriWareInitializer>(null, "CriWareInitializer"); initializer.hideFlags = HideFlags.DontSaveInBuild | HideFlags.DontSaveInEditor; initializerCreate = true; } initializer.Initialize(); } if (initializer != null && initializerCreate) { UnityUtility.SafeDelete(initializer.gameObject); } }
public void RegisterUniqueComponent(Type type, Behaviour target) { if (UnityUtility.IsNull(target)) { return; } var capturedComponent = capturedComponents.GetValueOrDefault(type); if (capturedComponent == target) { return; } UnityUtility.SafeDelete(capturedComponent); target.OnDestroyAsObservable() .Subscribe(_ => capturedComponents.Remove(type)) .AddTo(Disposable); capturedComponents[type] = target; // 既に回収済みオブジェクトの子階層にある場合は親オブジェクトの変更は行わない. var captured = uniqueComponentsRoot.Descendants().Contains(target.gameObject); if (!captured) { UnityUtility.SetParent(target.gameObject, uniqueComponentsRoot); } }
public RenderTexture CreateRenderTexture(int width, int height, int depth = 16, RenderTextureFormat format = RenderTextureFormat.ARGB32) { if (renderTexture != null && size.x == width && size.y == height) { return(renderTexture); } if (renderCamera == null) { renderCamera = UnityUtility.GetComponent <Camera>(gameObject); } if (renderTexture != null) { UnityUtility.SafeDelete(renderTexture); } this.width = width; this.height = height; this.depth = depth; this.format = format; renderTexture = new RenderTexture(width, height, depth, format); if (renderTexture != null) { renderTexture.hideFlags = HideFlags.DontSaveInBuild | HideFlags.DontSaveInEditor; } renderCamera.targetTexture = renderTexture; return(renderTexture); }
public IObservable <Unit> Close(bool inputProtect = true) { var protect = inputProtect ? new InputProtect() : null; return(OnClose() .Do(_ => { UnityUtility.SetActive(gameObject, false); if (protect != null) { protect.Dispose(); protect = null; } if (onClose != null) { onClose.OnNext(Unit.Default); } if (deleteOnClose) { UnityUtility.SafeDelete(gameObject); } }) .AsUnitObservable()); }
public void ResetParticleMaterial() { UnityUtility.SafeDelete(particleMaterial); particleMaterial = null; originMaterial = null; }
public void Delete(string identifier) { var advObject = advObjects.GetValueOrDefault(identifier); advObjects.Remove(identifier); UnityUtility.SafeDelete(advObject); }
public void DeleteAll() { foreach (var item in advObjects.Values) { UnityUtility.SafeDelete(item); } advObjects.Clear(); }
public void Clear() { if (spriteCache != null) { var cahcedSprites = spriteCache.Values; foreach (var sprite in cahcedSprites) { UnityUtility.SafeDelete(sprite); } } }
private void CloseWebView() { Loading = false; UnityUtility.SafeDelete(EmbeddedBrowser); EmbeddedBrowser = null; if (onClose != null) { onClose.OnNext(Unit.Default); } }
public IEnumerator CaptureScreenShot() { yield return(new WaitForEndOfFrame()); var tex = new Texture2D(Screen.width, Screen.height, TextureFormat.RGB24, false); tex.ReadPixels(new Rect(0, 0, Screen.width, Screen.height), 0, 0); tex.Apply(); screenShotData = tex.EncodeToPNG(); UnityUtility.SafeDelete(tex); }
public void CreateInSceneParent(GameObject sceneRoot) { if (!UnityUtility.IsNull(parentInScene)) { UnityUtility.SafeDelete(parentInScene.gameObject); } var popupParent = CreatePopupParent("Popup (InScene)", sceneRoot, ParentInSceneLayer, sceneCanvasOrder); var ignoreControl = UnityUtility.GetOrAddComponent <IgnoreControl>(popupParent.gameObject); if (ignoreControl != null) { ignoreControl.Type = IgnoreControl.IgnoreType.ActiveControl; } parentInScene = popupParent; }
//----- field ----- //----- property ----- //----- method ----- protected static void ModifyComponent(GameObject rootObject) { var canvasRenderers = rootObject.DescendantsAndSelf().OfComponent <CanvasRenderer>(); foreach (var canvasRenderer in canvasRenderers) { var gameObject = canvasRenderer.gameObject; var graphicComponents = gameObject.GetComponents <Graphic>(); if (graphicComponents.Any()) { continue; } UnityUtility.SafeDelete(canvasRenderer); EditorUtility.SetDirty(gameObject); } }
public void CreateInSceneParent(GameObject sceneRoot) { if (!UnityUtility.IsNull(parentInScene)) { UnityUtility.SafeDelete(parentInScene.gameObject); } var popupParent = UnityUtility.Instantiate <PopupParent>(sceneRoot, parentPrefab); popupParent.transform.name = "Popup (InScene)"; popupParent.Canvas.sortingOrder = sceneCanvasOrder; var ignoreControl = UnityUtility.GetOrAddComponent <IgnoreControl>(popupParent.gameObject); if (ignoreControl != null) { ignoreControl.Type = IgnoreControl.IgnoreType.ActiveControl; } parentInScene = popupParent; }
private void DeleteCreatedAsset() { if (Application.isPlaying) { return; } if (RawImage == null) { return; } var texture = RawImage.texture; if (texture != null && texture.name == DummyAssetName) { RawImage.texture = null; UnityUtility.SafeDelete(texture); } }
private void DeleteCreatedAsset() { if (Application.isPlaying) { return; } if (Image == null) { return; } var sprite = Image.sprite; if (sprite != null && sprite.name == DummyAssetName) { Image.sprite = null; UnityUtility.SafeDelete(sprite); } }
//----- property ----- //----- method ----- public IObservable <Unit> Play(string fileName, bool restart, int?sortingOrder) { var advEngine = AdvEngine.Instance; if (particlePlayer != null) { UnityUtility.SafeDelete(particlePlayer.gameObject); } var resourcePath = advEngine.Resource.GetResourcePath <AdvParticle>(fileName); var prefab = advEngine.Resource.Get <GameObject>(resourcePath); particlePlayer = UnityUtility.Instantiate <ParticlePlayer>(gameObject, prefab); if (sortingOrder.HasValue) { particlePlayer.SortingOrder = sortingOrder.Value; } return(particlePlayer.Play(restart).AsUnitObservable()); }
private void CloseAllRecordWindow() { var recordWindows = Resources.FindObjectsOfTypeAll <RecordWindow>(); foreach (var recordWindow in recordWindows) { if (recordWindow == null) { continue; } try { recordWindow.Close(); UnityUtility.SafeDelete(recordWindow); } catch { // ignored } } }
private void Release(TextEffectBase target) { var material = target.Text.material; if (!reference.ContainsKey(material)) { return; } reference[material].Remove(target); if (reference[material].IsEmpty()) { var item = materials.FirstOrDefault(x => x.Value == material); reference.Remove(material); materials.Remove(item.Key); target.Text.material = null; UnityUtility.SafeDelete(material); } }
public async UniTask Close(bool blockInput = true) { var inputBlock = blockInput ? new BlockInput() : null; await OnClose(); UnityUtility.SetActive(gameObject, false); if (inputBlock != null) { inputBlock.Dispose(); inputBlock = null; } if (onClose != null) { onClose.OnNext(Unit.Default); } if (deleteOnClose) { UnityUtility.SafeDelete(gameObject); } }
protected void Release() { Initialize(); var material = target.material; target.material = null; if (reference.ContainsKey(material)) { reference[material].Remove(this); if (reference[material].IsEmpty()) { var item = cache.FirstOrDefault(x => x.Value == material); reference.Remove(material); cache.Remove(item.Key); UnityUtility.SafeDelete(material); } } }
public void Clean() { foreach (var scenePopup in scenePopups) { UnityUtility.SafeDelete(scenePopup.gameObject); } scenePopups.Clear(); UnityUtility.SetParent(touchBloc.gameObject, parentGlobal.Parent); UnityUtility.SetLayer(parentGlobal.Parent, touchBloc.gameObject, true); if (globalPopups.IsEmpty()) { if (touchBlocDisposable != null) { touchBlocDisposable.Dispose(); touchBlocDisposable = null; } touchBloc.Hide(); touchBloc.transform.SetSiblingIndex(0); } }
void OnDestroy() { UnityUtility.SafeDelete(eventTrigger); }
protected override void OnDestroy() { base.OnDestroy(); UnityUtility.SafeDelete(particleMaterial); }
//----- method ----- private void CollectUniqueComponents(GameObject[] rootObjects) { if (uniqueComponentsRoot == null) { uniqueComponentsRoot = new GameObject("UniqueComponents"); UnityEngine.Object.DontDestroyOnLoad(uniqueComponentsRoot); } foreach (var uniqueComponent in UniqueComponents) { var key = uniqueComponent.Key; foreach (var rootObject in rootObjects) { var allObjects = rootObject.DescendantsAndSelf().ToArray(); var components = allObjects .SelectMany(x => x.GetComponents(key)) .OfType <Behaviour>() .ToArray(); // 対象のコンポーネントがなければなにもしない. if (components.IsEmpty()) { continue; } // 管理中のコンポーネントがなければとりあえず1つ管理する. if (!capturedComponents.ContainsKey(key)) { var component = components.First(); capturedComponents[key] = component; // 既に回収済みオブジェクトの子階層にある場合は親オブジェクトの変更は行わない. var captured = uniqueComponentsRoot.Descendants().Contains(component.gameObject); if (!captured) { UnityUtility.SetParent(component.gameObject, uniqueComponentsRoot); } } // 管理中のコンポーネントしかない場合終了. if (components.Length == 1 && components.First() == capturedComponents[key]) { continue; } // 管理外のコンポーネント foreach (var component in components.Where(x => x != capturedComponents[key]).Where(x => x.enabled)) { switch (uniqueComponent.Value.DuplicateAction) { case DuplicatedAction.DisableComponent: component.enabled = false; break; case DuplicatedAction.DisableGameObject: UnityUtility.SetActive(component.gameObject, false); break; case DuplicatedAction.DestroyGameObject: UnityUtility.SafeDelete(component.gameObject); break; } } } } }