示例#1
0
        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);
        }
示例#2
0
        private void RegisterGlobal(Window popupWindow)
        {
            // 新規登録された場合.
            if (globalPopups.All(x => x != popupWindow))
            {
                UnityUtility.SetLayer(gameObject, popupWindow.gameObject, true);
                UnityUtility.SetParent(popupWindow.gameObject, parentGlobal.Parent);

                popupWindow.OnCloseAsObservable()
                .Subscribe(
                    _ =>
                {
                    globalPopups.Remove(popupWindow);
                    UpdateContents();
                })
                .AddTo(this);

                globalPopups.Add(popupWindow);
            }
            else
            {
                // 既に登録済みの場合は最後尾に再登録.
                globalPopups.Remove(popupWindow);
                globalPopups.Add(popupWindow);
            }

            globalPopups = globalPopups.OrderBy(x => x.DisplayPriority).ToList();
        }
示例#3
0
        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);
            }
        }
示例#4
0
        private void RegisterScene(Window popupWindow)
        {
            // 新規登録された場合.
            if (scenePopups.All(x => x != popupWindow))
            {
                UnityUtility.SetLayer(gameObject, popupWindow.gameObject, true);
                UnityUtility.SetParent(popupWindow.gameObject, parentInScene.Parent);

                popupWindow.OnCloseAsObservable()
                .Subscribe(
                    _ =>
                {
                    scenePopups.Remove(popupWindow);
                    UpdateContents();
                })
                .AddTo(this);

                scenePopups.Add(popupWindow);
            }
            else
            {
                // 既に登録済みの場合は最後尾に再登録.
                scenePopups.Remove(popupWindow);
                scenePopups.Add(popupWindow);
            }
        }
示例#5
0
        private void SetupHitBox()
        {
            if (hitBoxEnable)
            {
                var parent = scrollRect.viewport;

                if (hitBox == null)
                {
                    hitBox = UnityUtility.CreateGameObject <GraphicCast>(parent.gameObject, "HitBox");
                }
                else
                {
                    UnityUtility.SetParent(hitBox, parent);
                }

                // HitBoxは全域使用.

                var rt = hitBox.transform as RectTransform;

                rt.FillRect();
            }
            else
            {
                UnityUtility.DeleteGameObject(hitBox);
            }
        }
示例#6
0
        //----- property -----

        //----- method -----

        private void CreateWebViewContent(GameObject prefab)
        {
            if (webViewContent != null)
            {
                return;
            }

            // Awakeを実行させる為一旦ルート階層に生成.
            webViewContent = UnityUtility.Instantiate <WebViewContent>(null, prefab);

            if (webViewContent != null)
            {
                webViewContent.Initialize();

                UnityUtility.SetParent(webViewContent.gameObject, gameObject);
            }
        }
示例#7
0
        public void Release(T target)
        {
            if (target == null || UnityUtility.IsNull(target.gameObject))
            {
                return;
            }

            if (!cachedObjects.Contains(target))
            {
                if (onRelease != null)
                {
                    onRelease.OnNext(target);
                }

                UnityUtility.SetActive(target, false);
                UnityUtility.SetParent(target.gameObject, instance);

                target.transform.Reset();

                cachedObjects.Enqueue(target);
            }
        }
示例#8
0
        public void Clean()
        {
            foreach (var scenePopup in scenePopups)
            {
                UnityUtility.DeleteGameObject(scenePopup);
            }

            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);
            }
        }
示例#9
0
        protected void UpdateContents()
        {
            var        touchBlocIndex = 0;
            GameObject parent         = null;

            CreateTouchBloc();

            if (scenePopups.Any())
            {
                var index = 0;

                parent         = parentInScene.Parent;
                touchBlocIndex = 0;

                var lastPopup = scenePopups.LastOrDefault();

                foreach (var popup in scenePopups)
                {
                    if (popup == lastPopup)
                    {
                        touchBlocIndex = index++;
                    }

                    popup.transform.SetSiblingIndex(index++);
                }
            }

            if (globalPopups.Any())
            {
                var index = 0;

                parent         = parentGlobal.Parent;
                touchBlocIndex = 0;

                var lastPopup = globalPopups.LastOrDefault();

                foreach (var popup in globalPopups)
                {
                    if (popup == lastPopup)
                    {
                        touchBlocIndex = index++;
                    }

                    popup.transform.SetSiblingIndex(index++);
                }
            }

            // ポップアップがなかった場合はグローバルの下に退避.
            if (parent == null)
            {
                parent = parentGlobal.Parent;
            }

            UnityUtility.SetParent(touchBloc.gameObject, parent);

            touchBloc.transform.SetSiblingIndex(touchBlocIndex);

            UnityUtility.SetLayer(parent, touchBloc.gameObject, true);

            // 一つでも登録されたら表示.
            if (!touchBloc.Active && (scenePopups.Any() || globalPopups.Any()))
            {
                if (touchBlocDisposable != null)
                {
                    touchBlocDisposable.Dispose();
                    touchBlocDisposable = null;
                }

                UnityUtility.SetActive(touchBloc, true);

                touchBlocDisposable = touchBloc.FadeIn().Subscribe().AddTo(this);
            }

            // 空になったら非表示.
            if (touchBloc.Active && (scenePopups.IsEmpty() && globalPopups.IsEmpty()))
            {
                if (touchBlocDisposable != null)
                {
                    touchBlocDisposable.Dispose();
                    touchBlocDisposable = null;
                }

                touchBlocDisposable = touchBloc.FadeOut()
                                      .Subscribe(_ => UnityUtility.SetActive(touchBloc, false))
                                      .AddTo(this);
            }
        }
        //----- 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;
                        }
                    }
                }
            }
        }
示例#11
0
        protected void UpdateContents()
        {
            var        touchBlocIndex = 0;
            GameObject parent         = null;

            if (touchBloc == null)
            {
                touchBloc = UnityUtility.Instantiate <TouchBloc>(parentGlobal.Parent, touchBlocPrefab);
                touchBloc.Initialize();
            }

            if (scenePopups.Any())
            {
                var index = 0;

                parent         = parentInScene.Parent;
                touchBlocIndex = 0;

                foreach (var item in scenePopups)
                {
                    if (item == scenePopups.LastOrDefault())
                    {
                        touchBlocIndex = index++;
                    }

                    item.transform.SetSiblingIndex(index++);
                }
            }

            if (globalPopups.Any())
            {
                var index = 0;

                parent         = parentGlobal.Parent;
                touchBlocIndex = 0;

                foreach (var item in globalPopups)
                {
                    if (item == globalPopups.LastOrDefault())
                    {
                        touchBlocIndex = index++;
                    }

                    item.transform.SetSiblingIndex(index++);
                }
            }

            // ポップアップがなかった場合はグローバルの下に退避.
            if (parent == null)
            {
                parent = parentGlobal.Parent;
            }

            UnityUtility.SetParent(touchBloc.gameObject, parent);

            touchBloc.transform.SetSiblingIndex(touchBlocIndex);

            UnityUtility.SetLayer(parent, touchBloc.gameObject, true);

            // 一つでも登録されたら表示.
            if (!touchBloc.Active && (scenePopups.Any() || globalPopups.Any()))
            {
                if (touchBlocDisposable != null)
                {
                    touchBlocDisposable.Dispose();
                    touchBlocDisposable = null;
                }

                touchBlocDisposable = touchBloc.FadeIn().Subscribe().AddTo(this);
            }

            // 空になったら非表示.
            if (touchBloc.Active && (scenePopups.IsEmpty() && globalPopups.IsEmpty()))
            {
                if (touchBlocDisposable != null)
                {
                    touchBlocDisposable.Dispose();
                    touchBlocDisposable = null;
                }

                touchBlocDisposable = touchBloc.FadeOut().Subscribe().AddTo(this);
            }
        }