Ejemplo n.º 1
0
 public void Recovery(ViewElement ve, bool ignoreTransition = true)
 {
     viewElementQueue.Remove(ve);
     ve.ChangePage(false, null, null, ignoreTransition: ignoreTransition);
     recoveryAction?.Invoke(ve);
     //runtimePool.RecoveryQueuedViewElement(true);
 }
Ejemplo n.º 2
0
        public void SetupChild()
        {
            viewElement = GetComponent <ViewElement>();

            var childViewElementGroups = GetComponentsInChildren <ViewElementGroup>()
                                         .Where(m => m != this);

            foreach (var item in childViewElementGroups)
            {
                item.SetupChild();
            }

            childViewElements = GetComponentsInChildren <ViewElement>()
                                .Where(m => m != viewElement)
                                .ToList();

            //Remove the item which is a child of Other ViewElementGroup
            var viewElementsInChildGroup = childViewElementGroups.Select(m => m.childViewElements);

            foreach (var item in viewElementsInChildGroup)
            {
                foreach (var ve in item)
                {
                    childViewElements.RemoveAll(m => m == ve);
                }
            }
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Get the cached pool
 /// </summary>
 /// <param name="template">The source ViewElement</param>
 /// <returns>the pool</returns>
 public static ViewElementRequestedPool GetPool(ViewElement template)
 {
     if (!requestPoolCache.TryGetValue(template.GetInstanceID(), out ViewElementRequestedPool result))
     {
         result = new ViewElementRequestedPool(template);
         requestPoolCache.Add(template.GetInstanceID(), result);
     }
     return(result);
 }
Ejemplo n.º 4
0
 void OnEnable()
 {
     viewElement            = (ViewElement)target;
     viewElementGroup       = viewElement.GetComponent <ViewElementGroup>();
     parentViewElement      = viewElement?.GetComponentsInParent <ViewElement>().Where(m => m != viewElement).FirstOrDefault();
     parentViewElementGroup = parentViewElement?.GetComponent <ViewElementGroup>();
     onShowHandle           = serializedObject.FindProperty("OnShowHandle");
     onLeaveHandle          = serializedObject.FindProperty("OnLeaveHandle");
     showV2Setting.valueChanged.AddListener(Repaint);
 }
 public ComponentTreeView(GameObject go, ViewElement viewElement, TreeViewState treeViewState, bool isPrefabRoot, System.Func <SerializedProperty, string, bool> IsModify, System.Action OnDelete)
     : base(treeViewState)
 {
     this.go          = go;
     this.viewElement = viewElement;
     rowHeight        = 24;
     showBorder       = true;
     showAlternatingRowBackgrounds = true;
     this.IsModify = IsModify;
     this.OnDelete = OnDelete;
     CacheComponent(go, 0, isPrefabRoot);
     Reload();
 }
Ejemplo n.º 6
0
        public void QueueViewElementToRecovery(ViewElement toRecovery)
        {
            toRecovery.rectTransform.SetParent(_hierachyPool.transformCache, true);

            if (toRecovery.IsUnique)
            {
                // unique ViewElement just needs to disable gameObject
                RecoveryViewElement(toRecovery);
            }
            else
            {
                if (!recycleQueue.Contains(toRecovery))
                {
                    recycleQueue.Enqueue(toRecovery);
                }
            }
        }
Ejemplo n.º 7
0
        void Rebuild(ViewElement viewElement)
        {
            viewElement.gameObject.SetActive(false);
            viewElement.gameObject.SetActive(true);
            // foreach (var rectTransform in viewElement.GetComponents<RectTransform>())
            // {
            //     rectTransform.ForceUpdateRectTransforms();
            // }
            // foreach (var graphic in viewElement.GetComponents<UnityEngine.UI.Graphic>())
            // {
            //     graphic.SetAllDirty();
            //     graphic.SetVerticesDirty();
            //     UnityEngine.UI.CanvasUpdateRegistry.RegisterCanvasElementForGraphicRebuild(graphic);
            // }
            // Canvas.ForceUpdateCanvases();

            // UnityEditorInternal.InternalEditorUtility.RepaintAllViews();
            // UnityEngine.UI.LayoutRebuilder.ForceRebuildLayoutImmediate(viewElement.rectTransform);
        }
Ejemplo n.º 8
0
        public ViewElement RequestViewElement(ViewElement source)
        {
            ViewElement result;

            if (source.IsUnique)
            {
                if (!uniqueVeDicts.TryGetValue(source.GetInstanceID(), out result))
                {
                    result = UnityEngine.Object.Instantiate(source, _hierachyPool.rectTransform);
                    result.gameObject.SetActive(false);
                    result.name = source.name;
                    uniqueVeDicts.Add(source.GetInstanceID(), result);
                }
            }
            else
            {
                Queue <ViewElement> veQueue;
                if (!veDicts.TryGetValue(source.GetInstanceID(), out veQueue))
                {
                    veQueue = new Queue <ViewElement>();
                    veDicts.Add(source.GetInstanceID(), veQueue);
#if UNITY_EDITOR
                    veNameDicts.Add(source.GetInstanceID(), source.name);
#endif
                }
                if (veQueue.Count > 0)
                {
                    result = veQueue.Dequeue();
                    // Debug.Log($"Request {source.name} from dequeue :  { Time.frameCount}");
                }
                else
                {
                    var a = UnityEngine.Object.Instantiate(source, _hierachyPool.rectTransform);
                    a.gameObject.SetActive(false);
                    a.name = source.name;
                    result = a;
                    // Debug.Log($"Request {source.name} from generate new one : { Time.frameCount}");
                }
            }
            result.PoolKey = source.GetInstanceID();
            return(result);
        }
Ejemplo n.º 9
0
 public void RecoveryViewElement(ViewElement toRecovery)
 {
     // Debug.Log($"Recovery {toRecovery.name}");
     if (toRecovery.IsUnique)
     {
         // unique ViewElement just needs to disable gameObject
         toRecovery.gameObject.SetActive(false);
     }
     else
     {
         if (!veDicts.TryGetValue(toRecovery.PoolKey, out Queue <ViewElement> veQueue))
         {
             ViewSystemLog.LogWarning("Cannot find pool of ViewElement " + toRecovery.name + ", Destroy directly.", toRecovery);
             UnityEngine.Object.Destroy(toRecovery);
             return;
         }
         toRecovery.gameObject.SetActive(false);
         veQueue.Enqueue(toRecovery);
     }
 }
Ejemplo n.º 10
0
        public ViewElement PrewarmUniqueViewElement(ViewElement source)
        {
            if (!source.IsUnique)
            {
                ViewSystemLog.LogWarning("The ViewElement trying to Prewarm is not an unique ViewElement");
                return(null);
            }

            if (!uniqueVeDicts.ContainsKey(source.GetInstanceID()))
            {
                var temp = UnityEngine.Object.Instantiate(source, _hierachyPool.rectTransform);
                temp.name = source.name;
                uniqueVeDicts.Add(source.GetInstanceID(), temp);
                temp.gameObject.SetActive(false);
                return(temp);
            }
            else
            {
                ViewSystemLog.LogWarning("ViewElement " + source.name + " has been prewarmed");
                return(uniqueVeDicts[source.GetInstanceID()]);
            }
        }
Ejemplo n.º 11
0
 /// <summary>
 /// Create new ViewElementRequestedPool, it is strongly recommend to use <See cref="ViewElementRequestedPool.GetPool(ViewElement)"> to get the global cached instance instead of create a new one.
 /// </summary>
 /// <param name="template">The source ViewElement</param>
 /// <param name="recoveryAction">The callback will invoke every time while the ViewElement is recovery which managed by ViewElementRequestedPool</param>
 public ViewElementRequestedPool(ViewElement template, Action <ViewElement> recoveryAction)
 {
     this.template       = template;
     this.recoveryAction = recoveryAction;
 }
Ejemplo n.º 12
0
 /// <summary>
 /// Create new ViewElementRequestedPool, it is strongly recommend to use <See cref="ViewElementRequestedPool.GetPool(ViewElement)"> to get the global cached instance instead of create a new one.
 /// </summary>
 /// <param name="template">The source ViewElement</param>
 public ViewElementRequestedPool(ViewElement template)
 {
     this.template = template;
 }
Ejemplo n.º 13
0
 public ViewPageItem(ViewElement ve)
 {
     viewElement = ve;
     GenerateId();
 }
Ejemplo n.º 14
0
 public OverridePopup(ViewElementPropertyOverrideData data, ViewElement target)
 {
     this.data   = data;
     this.target = target;
     CacheHierarchy();
 }
Ejemplo n.º 15
0
        public override void OnGUI(Rect oriRect, SerializedProperty property, GUIContent label)
        {
            GUILayout.Label(property.displayName, EditorStyles.boldLabel);
            using (var vertical = new EditorGUILayout.VerticalScope("box"))
            {
                try
                {
                    viewElement = (property.serializedObject.targetObject as Component).GetComponentInParent <ViewElement>();
                    original    = PrefabUtility.GetCorrespondingObjectFromSource(viewElement);
                }
                catch { }
                Event e = Event.current;
                if (e.type == EventType.ValidateCommand)
                {
                    RebuildList(property);
                    Debug.Log("Rebuid due to paste");
                }

                if (reorderableList == null)
                {
                    RebuildList(property);
                }

                if (viewElement == null || original == null)
                {
                    Color c = GUI.color;
                    GUI.color = Color.red;
                    GUILayout.Label(new GUIContent("No ViewElement Prefab found, or you are under Prefab Mode.", Drawer.miniErrorIcon, "Due to the limitation of PrefabUtility API these feature cannot work under Prefab Mode"));
                    GUI.color = c;
                }
                using (var horizon = new GUILayout.HorizontalScope())
                {
                    using (var disable = new EditorGUI.DisabledGroupScope(viewElement == null || original == null))
                    {
                        if (GUILayout.Button("Preview"))
                        {
                            DoPreview();
                        }
                        if (GUILayout.Button("Pick"))
                        {
                            PickCurrent();
                        }
                    }
                    if (GUILayout.Button(new GUIContent(EditorGUIUtility.FindTexture("d_SaveAs@2x"), "Save"), Drawer.removeButtonStyle, GUILayout.Width(EditorGUIUtility.singleLineHeight)))
                    {
                        SaveAsset((List <ViewElementPropertyOverrideData>)reorderableList.list);
                    }
                    if (GUILayout.Button(new GUIContent(EditorGUIUtility.FindTexture("d_Profiler.Open@2x"), "Load"), Drawer.removeButtonStyle, GUILayout.Width(EditorGUIUtility.singleLineHeight)))
                    {
                        LoadAsset();
                    }
                }
                this.propertySource = property;
                GUIStyle myStyle = new GUIStyle("Foldout");
                myStyle.margin = new RectOffset(10, 0, 0, 0);
                using (var horizon = new EditorGUILayout.HorizontalScope())
                {
                    fold = EditorGUILayout.Foldout(fold, "Override datas", myStyle);
                    EditorGUILayout.Space();
                    if (GUILayout.Button(EditorGUIUtility.FindTexture("d_Refresh")))
                    {
                        RebuildList(property);
                    }
                }

                if (fold)
                {
                    reorderableList.DoLayoutList();
                }
            }
        }