Esempio n. 1
0
        /// <summary>
        /// override this method in a dervied class to add custom clearing for any chart type. default implementation deletes all chartItem components from this transform
        /// </summary>
        protected virtual void ClearChart()
        {
            mHovered.Clear();

            if (TextController != null) // destroy all child text object
            {
                TextController.DestroyAll();
                TextController.transform.SetParent(transform, false); // the text controller my not be a direct child of this gameobject , make it so that it is.
            }


            // destroy all child ChartItem objects
            ChartItem[] children = GetComponentsInChildren <ChartItem>();
            for (int i = 0; i < children.Length; ++i)
            {
                if (children[i] != null)
                {
                    RectMask2D mask = children[i].GetComponent <RectMask2D>();
                    if (mask != null)
                    {
                        Debug.Log(mask.gameObject);
                    }
                    if (TextController != null && children[i].gameObject == TextController.gameObject)
                    {
                        continue;
                    }
                    if (children[i].gameObject.GetComponent <ChartItemNoDelete>() != null)
                    {
                        continue;
                    }
                    if (children[i].gameObject != gameObject)
                    {
                        ChartCommon.SafeDestroy(children[i].gameObject);
                    }
                }
            }
            // ensure the text controller has been created ( it is generated only when the graph chart is first created)
            EnsureTextController();


            //destroy all axis components in this chart
            for (int i = 0; i < mAxis.Count; i++)
            {
                if (mAxis[i] != null && mAxis[i].This() != null)
                {
                    ChartCommon.SafeDestroy(mAxis[i].GetGameObject());
                }
            }
            mAxis.Clear();
        }
Esempio n. 2
0
        protected virtual void ClearChart()
        {
            mHovered.Clear();
            if (TextController != null)
            {
                TextController.DestroyAll();
                TextController.transform.SetParent(transform, false);
            }

            ChartItem[] children = GetComponentsInChildren <ChartItem>();
            for (int i = 0; i < children.Length; ++i)
            {
                if (children[i] != null)
                {
                    RectMask2D mask = children[i].GetComponent <RectMask2D>();
                    if (mask != null)
                    {
                        Debug.Log(mask.gameObject);
                    }
                    if (TextController != null && children[i].gameObject == TextController.gameObject)
                    {
                        continue;
                    }
                    if (children[i].gameObject != gameObject)
                    {
                        ChartCommon.SafeDestroy(children[i].gameObject);
                    }
                }
            }
            EnsureTextController();

            for (int i = 0; i < mAxis.Count; i++)
            {
                if (mAxis[i] != null && mAxis[i].This() != null)
                {
                    ChartCommon.SafeDestroy(mAxis[i].GetGameObject());
                }
            }
            mAxis.Clear();
        }
        /// <summary>
        /// override this method in a dervied class to add custom clearing for any chart type. default implementation deletes all chartItem components from this transform
        /// </summary>
        protected virtual void ClearChart()
        {
//#if UNITY_2018_3_OR_NEWER
//#if UNITY_EDITOR

//            //  if (Application.isEditor == true && Application.isPlaying == false)
//            //  {
//            var path = UnityEditor.PrefabUtility.GetPrefabAssetPathOfNearestInstanceRoot(gameObject);
//            if (!(path == null || path.Trim().Length == 0))
//            {
//                // Load the contents of the Prefab Asset.
//                GameObject contentsRoot = UnityEditor.PrefabUtility.LoadPrefabContents(path);

//                bool save = false;
//                // Modify Prefab contents.
//                foreach (var item in contentsRoot.GetComponentsInChildren<ChartItem>())
//                {
//                    if (item == null)
//                        continue;
//                    if (item.gameObject != null)
//                    {
//                        save = true;
//                        DestroyImmediate(item.gameObject);
//                    }
//                }
//                if (save)
//                {
//                    //  try
//                    //  {
//                    UnityEditor.PrefabUtility.SaveAsPrefabAsset(contentsRoot, path);
//                    //  }
//                    //  catch (Exception e)
//                    //  {
//                    //  }

//                }

//                UnityEditor.PrefabUtility.UnloadPrefabContents(contentsRoot);
//            }
//            // }
//#endif
//#endif
            mHovered.Clear();

            if (TextController != null) // destroy all child text object
            {
                TextController.DestroyAll();
                TextController.transform.SetParent(transform, false); // the text controller my not be a direct child of this gameobject , make it so that it is.
            }

            // destroy all child ChartItem objects
            ChartItem[] children = GetComponentsInChildren <ChartItem>();
            for (int i = 0; i < children.Length; ++i)
            {
                if (children[i] != null)
                {
                    RectMask2D mask = children[i].GetComponent <RectMask2D>();
                    if (mask != null)
                    {
                        //   Debug.Log(mask.gameObject);
                    }
                    if (TextController != null && children[i].gameObject == TextController.gameObject)
                    {
                        continue;
                    }
                    if (children[i].gameObject.GetComponent <ChartItemNoDelete>() != null)
                    {
                        continue;
                    }
                    if (children[i].gameObject.GetComponentInParent <AnyChart>() != this)
                    {
                        continue;
                    }
                    if (children[i].gameObject != gameObject)
                    {
                        ChartCommon.SafeDestroy(children[i].gameObject);
                    }
                }
            }
            // ensure the text controller has been created ( it is generated only when the graph chart is first created)
            EnsureTextController();


            //destroy all axis components in this chart
            for (int i = 0; i < mAxis.Count; i++)
            {
                if (mAxis[i] != null && mAxis[i].This() != null)
                {
                    ChartCommon.SafeDestroy(mAxis[i].GetGameObject());
                }
            }
            mAxis.Clear();
        }