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); } }
private Material GetMaterial() { var softMaskable = IsSoftMaskable(); var key = GetCacheKey(softMaskable); var material = cache.GetValueOrDefault(key); if (UnityUtility.IsNull(material)) { cache.Remove(key); } else { return(material); } var shader = GetShader(softMaskable); if (shader == null) { return(null); } material = new Material(shader); SetShaderParams(material); material.hideFlags = HideFlags.DontSaveInBuild | HideFlags.DontSaveInEditor; cache[key] = material; return(material); }
public T Get(GameObject parent) { var target = cachedObjects.Any() ? cachedObjects.Dequeue() : null; if (target != null && UnityUtility.IsNull(target.gameObject)) { target = null; } if (target == null) { target = UnityUtility.Instantiate <T>(instance, prefab); if (onCreate != null) { onCreate.OnNext(target); } } if (parent != null) { UnityUtility.SetParent(target.gameObject, parent); } if (onGet != null) { onGet.OnNext(target); } return(target); }
public void Stop() { if (!isInitialized) { return; } if (State == State.Stop) { return; } if (UnityUtility.IsNull(animatorInfo.Animator)) { return; } // Animator停止. foreach (var clip in animatorInfo.Clips) { clip.SampleAnimation(animatorInfo.Animator.gameObject, clip.length); } Refresh(); }
// 指定アニメーションへ遷移待ち. private IEnumerator WaitTransitionState() { while (true) { if (UnityUtility.IsNull(this)) { yield break; } if (UnityUtility.IsNull(gameObject)) { yield break; } if (!UnityUtility.IsActiveInHierarchy(gameObject)) { break; } var stateInfo = animatorInfo.Animator.GetCurrentAnimatorStateInfo(0); if (stateInfo.IsName(animationName)) { break; } yield return(null); } }
// 指定アニメーションへ遷移待ち. private void WaitTransitionStateImmediate() { while (true) { if (UnityUtility.IsNull(this)) { return; } if (UnityUtility.IsNull(gameObject)) { return; } if (!UnityUtility.IsActiveInHierarchy(gameObject)) { break; } if (IsCurrentState(CurrentAnimationName, GetCurrentLayerIndex())) { break; } Animator.Update(0); } }
// 指定アニメーションへ遷移待ち. private IEnumerator WaitTransitionState() { // ステートの遷移待ち. while (true) { if (UnityUtility.IsNull(this)) { yield break; } if (UnityUtility.IsNull(gameObject)) { yield break; } if (!UnityUtility.IsActiveInHierarchy(gameObject)) { break; } if (IsCurrentState(CurrentAnimationName, GetCurrentLayerIndex())) { break; } yield return(null); } }
private Material GetMaterial(string cacheKey, TextEffectBase[] components, bool softMaskable) { var material = materials.GetValueOrDefault(cacheKey); if (UnityUtility.IsNull(material)) { materials.Remove(cacheKey); } else { return(material); } var shader = GetShader(components, softMaskable); if (shader == null) { return(null); } material = new Material(shader); material.hideFlags = HideFlags.DontSaveInBuild | HideFlags.DontSaveInEditor; components.ForEach(x => x.SetShaderParams(material)); materials[cacheKey] = material; return(material); }
public IObservable <Unit> UpdateContents(bool keepScrollPosition = false) { // 既に実行中の場合は実行中の物を返す. if (updateQueueing != null) { return(updateQueueing); } if (initialize == Status.None) { Initialize(); } if (updateItemDisposables.Any()) { foreach (var item in updateItemDisposables) { if (UnityUtility.IsNull(item.Key)) { continue; } item.Value.Dispose(); } updateItemDisposables.Clear(); } updateQueueing = Observable.FromMicroCoroutine(() => UpdateContentsInternal(keepScrollPosition)) .Do(_ => initialize = Status.Done) .Do(_ => updateQueueing = null) .Share(); return(updateQueueing); }
private IEnumerator PlayInternal() { UnityUtility.SetActive(gameObject, true); ApplySortingOrder(sortingOrder); while (true) { if (!UnityUtility.IsActiveInHierarchy(gameObject)) { break; } // 状態リセット. ResetContents(); // 開始. SetState(State.Play); for (var i = 0; i < particleInfos.Length; i++) { var particleInfo = particleInfos[i]; // 止まってたら開始. if (!particleInfo.ParticleSystem.isPlaying) { particleInfo.ParticleSystem.Play(); } particleInfo.LifeCycle = LifecycleType.None; } // 再生速度. ApplySpeedRate(); // 終了待ち. var updateYield = Observable.FromMicroCoroutine(() => FrameUpdate()).ToYieldInstruction(); while (!updateYield.IsDone) { yield return(null); } if (endActionType != EndActionType.Loop) { break; } if (State == State.Stop) { break; } } if (!UnityUtility.IsNull(this)) { EndAction(); } }
public void Update() { if (UnityUtility.IsNull(movieController)) { return; } var prevStatus = Status; Status = Player.status; PlayTime = GetPlayTime(); TotalTime = GetTotalTime(); if (prevStatus != Status && Status == Player.Status.PlayEnd) { UnityUtility.SetActive(movieController.gameObject, false); UnityUtility.DeleteComponent(movieController); if (onFinish != null) { onFinish.OnNext(Unit.Default); } } }
private static void HierarchyChanged() { // 実行中は負荷が高いので実行しない. if (Application.isPlaying) { return; } if (onHierarchyChangedAsObservable != null) { onHierarchyChangedAsObservable.OnNext(Unit.Default); } var createObserver = onCreateAsObservable != null && onCreateAsObservable.HasObservers; var deleteObserver = onDeleteAsObservable != null && onDeleteAsObservable.HasObservers; if (createObserver || deleteObserver) { var nowScene = SceneManager.GetActiveScene(); if (hierarchyObjects != null) { hierarchyObjects = hierarchyObjects.Where(x => !UnityUtility.IsNull(x)).ToArray(); } if (hierarchyObjects == null || hierarchyObjects.IsEmpty() || currentScene != nowScene) { CollectHierarchyObjects(); } else { // Hierarchy上のGameObjectを検索して取得. var objects = UnityEditorUtility.FindAllObjectsInHierarchy(); // キャッシュ済みGameObjectとの差分で新規作成されたGameObjectを発見. var newObjects = objects.Where(x => hierarchyObjects.All(y => x != y)).ToArray(); // 新規作成通知. if (0 < newObjects.Length) { if (onCreateAsObservable != null) { onCreateAsObservable.OnNext(newObjects.ToArray()); } } if (objects.Length < hierarchyObjects.Length) { if (onDeleteAsObservable != null) { onDeleteAsObservable.OnNext(Unit.Default); } } hierarchyObjects = objects; } } }
//----- property ----- //----- method ----- void Update() { if (UnityUtility.IsNull(target)) { return; } UpdateScale(); }
private void RepaintParticleSystem() { var particleInfos = Reflection.GetPrivateField <ParticlePlayer, ParticlePlayer.ParticleInfo[]>(instance, "particleInfos"); var requestRepaint = false; var requestCanvasUpdate = false; var rectTransform = instance.transform as RectTransform; foreach (var particleInfo in particleInfos) { var particleSystem = particleInfo.ParticleSystem; if (UnityUtility.IsNull(particleSystem)) { continue; } if (particleSystem.particleCount != 0) { requestRepaint = true; } if (rectTransform != null) { var uiParticleSystem = UnityUtility.GetComponent <UIParticleSystem>(particleSystem); if (uiParticleSystem != null) { uiParticleSystem.SetAllDirty(); requestCanvasUpdate = true; } } } if (requestCanvasUpdate) { // 実行中でない時はRectTransformの更新が正しく実行されないので一瞬座標を書き換える事で強制的に更新を行う. var localScale = rectTransform.localScale; localScale.z++; rectTransform.localScale = localScale; localScale.z--; rectTransform.localScale = localScale; } if (requestRepaint) { InternalEditorUtility.RepaintAllViews(); } }
public bool Enable() { if (!scene.HasValue) { return(false); } if (enable) { return(true); } if (activeRoots == null) { return(true); } if (!scene.Value.isLoaded || !scene.Value.IsValid()) { return(false); } var rootObjects = scene.Value.GetRootGameObjects(); foreach (var rootObject in activeRoots) { if (UnityUtility.IsNull(rootObject)) { continue; } if (!rootObjects.Contains(rootObject)) { continue; } var ignoreControl = UnityUtility.GetComponent <IgnoreControl>(rootObject); if (ignoreControl != null) { if (ignoreControl.Type.HasFlag(IgnoreControl.IgnoreType.ActiveControl)) { continue; } } UnityUtility.SetActive(rootObject, true); } enable = true; return(true); }
private void UpdateObjectsPriority() { var items = advObjects.Values .Where(x => !UnityUtility.IsNull(x)) .OrderBy(x => x.Priority) .ToArray(); for (var i = 0; i < items.Length; i++) { items[i].transform.SetSiblingIndex(i); } }
public void Stop(bool immediate = false, bool clear = true) { if (!isInitialized) { return; } if (particleSystems != null) { foreach (var ps in particleSystems) { if (UnityUtility.IsNull(ps.ParticleSystem)) { continue; } var stopBehavior = immediate ? ParticleSystemStopBehavior.StopEmittingAndClear : ParticleSystemStopBehavior.StopEmitting; ps.ParticleSystem.Stop(true, stopBehavior); } } Action onStopComplete = () => { if (playDisposable != null) { playDisposable.Dispose(); playDisposable = null; } currentTime = 0f; playObservable = null; SetState(State.Stop); if (clear) { Clear(); } }; if (immediate) { onStopComplete(); } else { OnEndAsObservable().Subscribe(_ => onStopComplete()).AddTo(disposable.Disposable); } }
private void ApplyColorForChildren(Color applyColor) { foreach (var graphic in childGraphics) { if (!UnityUtility.IsNull(graphic)) { graphic.canvasRenderer.SetColor(applyColor); graphic.SetAllDirty(); } } prevColor = applyColor; }
private void RestoreSortOrder() { foreach (var item in managedObjects) { if (UnityUtility.IsNull(item.Target)) { continue; } item.Target.Layer.Canvas.sortingOrder = item.SortOrder; } managedObjects.Clear(); }
private void UpdateCurrentTime(float time) { if (State != State.Play) { return; } UpdateState(); prevTime = currentTime; currentTime += time; // Particle更新. for (var i = 0; i < particleInfos.Length; i++) { var particleInfo = particleInfos[i]; var particleSystem = particleInfo.ParticleSystem; if (UnityUtility.IsNull(particleSystem)) { continue; } // フレーム更新. particleSystem.Simulate(time, false, false); // 状態更新. var playback = particleSystem.IsPlayback(particleInfo.IsSubemitter); switch (particleInfo.LifeCycle) { case LifecycleType.None: particleInfo.LifeCycle = playback ? LifecycleType.Birth : LifecycleType.None; break; case LifecycleType.Birth: particleInfo.LifeCycle = playback ? LifecycleType.Alive : LifecycleType.Death; break; case LifecycleType.Alive: particleInfo.LifeCycle = playback ? LifecycleType.Alive : LifecycleType.Death; break; case LifecycleType.Death: particleInfo.LifeCycle = LifecycleType.None; break; } } }
// アニメーションの終了待ち. private IEnumerator WaitForEndOfAnimation() { if (!isInitialized) { yield break; } while (true) { if (State == State.Stop) { yield break; } if (State == State.Play) { if (Application.isPlaying) { var time = ignoreTimeScale ? Time.unscaledDeltaTime : Time.deltaTime; // 時間更新. FrameUpdate(time); // ParticleSysmteのSimulate. foreach (var ps in particleSystems) { if (UnityUtility.IsNull(ps.ParticleSystem)) { continue; } if (!ps.ParticleSystem.gameObject.activeInHierarchy) { continue; } ps.ParticleSystem.Simulate(time, false, false); } // 終了監視. if (!IsAlive()) { break; } } } yield return(null); } }
//----- method ----- public SceneInstance(Scenes?identifier, ISceneBase instance, Scene?scene) { this.scene = scene; Identifier = identifier; Instance = instance; var rootObjects = scene.Value.GetRootGameObjects(); activeRoots = rootObjects .Where(x => !UnityUtility.IsNull(x)) .Where(x => UnityUtility.IsActive(x)) .ToArray(); }
private void Clear() { if (particleSystems != null) { foreach (var ps in particleSystems) { if (UnityUtility.IsNull(ps.ParticleSystem)) { continue; } ps.ParticleSystem.Clear(); } } }
private void SetParticleSystemsDirty() { var particleSystemInfos = Reflection.GetPrivateField <ParticlePlayer, ParticlePlayer.ParticleSystemInfo[]>(instance, "particleSystems"); foreach (var info in particleSystemInfos) { if (UnityUtility.IsNull(info.ParticleSystem)) { continue; } EditorUtility.SetDirty(info.ParticleSystem.gameObject); } InternalEditorUtility.RepaintAllViews(); }
private IEnumerator WaitInternal() { while (true) { if (UnityUtility.IsNull(this)) { break; } if (!UnityUtility.IsActive(gameObject)) { break; } yield return(null); } }
//----- method ----- public IObservable <Unit> UpdateContents(bool keepScrollPosition = false) { // 既に実行中の場合は実行中の物を返す. if (updateQueueing != null) { return(updateQueueing); } if (initialize == Status.None) { updateItemDisposables = new Dictionary <VirtualScrollItem <T>, IDisposable>(); scrollRectTransform = UnityUtility.GetComponent <RectTransform>(scrollRect.gameObject); scrollRect.horizontal = direction == Direction.Horizontal; scrollRect.vertical = direction == Direction.Vertical; itemList = new List <VirtualScrollItem <T> >(); ScrollPosition = 0f; initialize = Status.Initialize; } if (updateItemDisposables.Any()) { foreach (var item in updateItemDisposables) { if (UnityUtility.IsNull(item.Key)) { continue; } item.Value.Dispose(); } updateItemDisposables.Clear(); } updateQueueing = Observable.FromMicroCoroutine(() => UpdateContentsInternal(keepScrollPosition)) .Do(_ => initialize = Status.Done) .Do(_ => updateQueueing = null) .Share(); return(updateQueueing); }
public async UniTask Wait() { while (true) { if (UnityUtility.IsNull(this)) { break; } if (!UnityUtility.IsActive(gameObject)) { break; } await UniTask.NextFrame(); } }
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; }
public void Update() { var prevStatus = Status; Status = UnityUtility.IsNull(movieController) ? Player.Status.PlayEnd : Player.status; PlayTime = GetPlayTime(); TotalTime = GetTotalTime(); if (prevStatus != Status && Status == Player.Status.PlayEnd) { if (onFinish != null) { onFinish.OnNext(Unit.Default); } } }
// Canvasにカメラを適用. protected virtual void ModifyCanvasCamera() { var canvas = Canvas; if (!modifyCanvasCamera) { return; } var layer = 1 << canvas.gameObject.layer; // 最初に一致したカメラを適用. foreach (var camera in Cameras) { if (UnityUtility.IsNull(camera)) { continue; } if ((layer & camera.cullingMask) != 0) { canvasCamera = camera; break; } } if (canvasCamera != null) { canvas.worldCamera = canvasCamera; canvas.renderMode = RenderMode.ScreenSpaceCamera; } // この関数でカメラを設定した際にNearClipとFarClipの範囲外の場合は警告を出す. if (canvas.worldCamera != null) { var planeDistance = canvas.planeDistance; if (planeDistance < canvas.worldCamera.nearClipPlane || canvas.worldCamera.farClipPlane < planeDistance) { Debug.LogWarning("Out of Range Canvas PanelDistance."); } } }