Exemplo n.º 1
0
    void TestFind()
    {
        var btn_1 = gameObject.FindChild <Button>("btn_1");

        if (btn_1)
        {
            btn_1.onClick.RemoveAllListeners();
            btn_1.onClick.AddListener(() => { });
        }

        Log.Info("find btn_1:{0}", btn_1);

        var btn_xxx = gameObject.FindChild <Button>("btn_xxx");

        Log.Info("find btn_xxx:{0}", btn_xxx);

        var text = gameObject.FindChild <Text>("Text");

        Log.Info("find Text:{0} ,Text.text={1}", text, text?.text);

        KProfiler.BeginWatch("Find-Queue");
        var text_name = gameObject.FindChild <Text>("text_name", false, false);

        Log.Info("find text_name:{0} ,Text.text={1}", text_name, text_name?.text);
        KProfiler.EndWatch("Find-Queue");
        var text_test = gameObject.FindChild <Button>("text_name");
    }
 public void Run()
 {
     KProfiler.BeginThreadProfiling("KJobManager", thread.Name);
     while (true)
     {
         semaphore.WaitOne();
         if (jobManager.isShuttingDown)
         {
             break;
         }
         try
         {
             bool flag = true;
             while (flag)
             {
                 flag = jobManager.DoNextWorkItem();
             }
         }
         catch (Exception item)
         {
             exceptions.Add(item);
             errorOccured = true;
             Debugger.Break();
         }
         jobManager.DecrementActiveWorkerThreadCount();
     }
     KProfiler.EndThreadProfiling();
 }
Exemplo n.º 3
0
    private void AddVisibleTexture(Texture texture, Material ownerMat, GameObject ownerObj)
    {
        if (texture != null)
        {
            if (!_visibleTextures.ContainsKey(texture))
            {
                _visibleTextures.Add(texture, new HashSet <Material>());
            }
            _visibleTextures[texture].Add(ownerMat);

            if (!_visibleGameObjects.ContainsKey(texture))
            {
                _visibleGameObjects.Add(texture, new List <GameObject>());
            }
            _visibleGameObjects[texture].Add(ownerObj);

            // refresh the size
            if (!_textureSizeLut.ContainsKey(texture))
            {
                //_textureSizeLut[texture] = UsTextureUtil.CalculateTextureSizeBytes(texture);
                _textureSizeLut[texture] =
#if JX3M
                    KProfiler.GetRuntimeMemorySize(texture);
#else
                    (int)Profiler.GetRuntimeMemorySizeLong(texture);
#endif
            }

            // refresh the category
            if (!_textureCatLut.ContainsKey(texture))
            {
                _textureCatLut[texture] = TextureCategorizing.GetTextureCategory(ownerObj);
            }
        }
    }
Exemplo n.º 4
0
        private void OnOpen(UILoadState uiState, params object[] args)
        {
            if (uiState.IsLoading)
            {
                uiState.OpenWhenFinish = true;
                uiState.OpenArgs       = args;
                return;
            }

            UIController uiBase = uiState.UIWindow;

            if (uiBase.Canvas != null && uiBase.Canvas.enabled)
            {
                //已经打开无需再次打开
                return;
            }

            uiBase.BeforeOpen(args);
            //TODO 播放界面出现动画
            uiBase.gameObject.SetActiveX(true);
            if (uiBase.Canvas)
            {
                uiBase.Canvas.enabled = true;
                if (sortOrder >= int.MaxValue)
                {
                    sortOrder = 0;
                }

                uiBase.Canvas.sortingOrder = sortOrder++;
            }

            if (AppConfig.IsLogFuncCost || AppConfig.IsSaveCostToFile)
            {
                KProfiler.BeginWatch("UI.OnOpen");
            }
            uiBase.OnOpen(args);
            KWatchResult profilerData = null;

            if (AppConfig.IsLogFuncCost)
            {
                profilerData = KProfiler.EndWatch("UI.OnOpen", string.Concat(uiBase.UIName, ".OnOpen"));
            }
            if (AppConfig.IsSaveCostToFile)
            {
                if (profilerData == null)
                {
                    profilerData = KProfiler.EndWatch("UI.OnOpen", string.Concat(uiBase.UIName, ".OnOpen"));
                }
                LogFileRecorder.WriteUILog(uiBase.UIName, LogFileRecorder.UIState.OnOpen, profilerData.costTime);
            }

            if (OnOpenEvent != null)
            {
                OnOpenEvent(uiBase);
            }
        }
Exemplo n.º 5
0
        private void InitWindow(UILoadState uiState, UIController uiBase, bool open, params object[] args)
        {
            if (AppConfig.IsLogFuncCost || AppConfig.IsSaveCostToFile)
            {
                KProfiler.BeginWatch("UI.Init");
            }
            uiBase.OnInit();
            KWatchResult profilerData = null;

            if (AppConfig.IsLogFuncCost)
            {
                profilerData = KProfiler.EndWatch("UI.Init", string.Concat(uiState.InstanceName, ".OnInit"));
            }
            if (AppConfig.IsSaveCostToFile)
            {
                if (profilerData == null)
                {
                    profilerData = KProfiler.EndWatch("UI.Init", string.Concat(uiState.InstanceName, ".OnInit"));
                }
                LogFileRecorder.WriteUILog(uiState.InstanceName, LogFileRecorder.UIState.OnInit, profilerData.costTime);
            }
            if (OnInitEvent != null)
            {
                OnInitEvent(uiBase);
            }
            if (open)
            {
                OnOpen(uiState, args);
            }

            if (!open)
            {
                if (!uiState.IsStaticUI)
                {
                    CloseWindow(uiBase.UIName); // Destroy
                    return;
                }
                else
                {
                    if (uiBase.Canvas != null)
                    {
                        uiBase.Canvas.enabled = false;
                    }
                    else
                    {
                        uiBase.gameObject.SetActiveX(false);
                    }
                }
            }

            uiState.OnUIWindowLoadedCallbacks(uiState, uiBase);
        }
        public bool AdjustLoad(float currentFrameTime, float frameTimeDelta)
        {
            bool flag = frameTimeDelta > 0f;
            int  num  = 0;
            int  num2 = Math.Max(probeCount, Math.Min(brains.Count, CPUBudget.coreCount));

            num       += num2 - probeCount;
            probeCount = num2;
            float num3 = Math.Min(1f, (float)probeCount / (float)CPUBudget.coreCount);
            float num4 = num3 * (float)this.probeSize;
            float num5 = num3 * (float)this.probeSize;
            float num6 = currentFrameTime / num5;
            float num7 = frameTimeDelta / num6;

            if (num == 0)
            {
                float num8 = num4 + num7 / (float)CPUBudget.coreCount;
                int   num9 = MathUtil.Clamp(MinProbeSize(), IdealProbeSize(), (int)(num8 / num3));
                num           += num9 - this.probeSize;
                this.probeSize = num9;
            }
            if (num == 0)
            {
                int num10     = Math.Max(1, (int)num3 + (flag ? 1 : (-1)));
                int probeSize = MathUtil.Clamp(MinProbeSize(), IdealProbeSize(), (int)((num5 + num7) / (float)num10));
                int num11     = Math.Min(brains.Count, num10 * CPUBudget.coreCount);
                num           += num11 - probeCount;
                probeCount     = num11;
                this.probeSize = probeSize;
            }
            if (num == 0 && flag)
            {
                int num12 = this.probeSize + ProbeSizeStep();
                num           += num12 - this.probeSize;
                this.probeSize = num12;
            }
            if (num < 0)
            {
                KProfiler.AddEvent(decreaseLoadLabel);
            }
            else if (num > 0)
            {
                KProfiler.AddEvent(increaseLoadLabel);
            }
            else
            {
                Debug.LogWarning("AdjustLoad() failed");
            }
            return(num != 0);
        }
Exemplo n.º 7
0
        private void OnOpen(UILoadState uiState, params object[] args)
        {
            if (uiState.IsLoading)
            {
                uiState.OpenWhenFinish = true;
                uiState.OpenArgs       = args;
                return;
            }

            UIController uiBase = uiState.UIWindow;

            if (uiBase.Canvas != null && uiBase.Canvas.enabled)
            {
                //已经打开无需再次打开
                return;
            }

            uiBase.BeforeOpen(args);
            //TODO 播放界面出现动画
            uiBase.gameObject.SetActiveX(true);
            SetUIOrder(uiBase);
            string watchKey = null;

            if (AppConfig.IsLogFuncCost || AppConfig.IsSaveCostToFile)
            {
                watchKey = string.Concat(uiBase.UIName, ".OnOpen");
                KProfiler.BeginWatch(watchKey);
            }
            uiBase.OnOpen(args);
            KWatchResult profilerData = null;

            if (AppConfig.IsLogFuncCost)
            {
                profilerData = KProfiler.EndWatch(watchKey);
            }
            if (AppConfig.IsSaveCostToFile)
            {
                if (profilerData == null)
                {
                    profilerData = KProfiler.EndWatch(watchKey, null, false);
                }
                LogFileManager.WriteUILog(uiBase.UIName, LogState.OnOpen, profilerData.costTime);
            }

            if (OnOpenEvent != null)
            {
                OnOpenEvent(uiBase);
            }
        }
Exemplo n.º 8
0
    void DrawDebugUI()
    {
        GUILayout.BeginHorizontal("HelpBox");
        EditorGUILayout.LabelField("== Debug Module ==");
        GUILayout.EndHorizontal();

        GUILayout.BeginHorizontal();
        if (GUILayout.Button("Dump", GUILayout.ExpandWidth(true), GUILayout.MaxHeight(20)))
        {
            KProfiler.Dump();
        }
        if (GUILayout.Button("打开AB加载耗时记录", GUILayout.ExpandWidth(true), GUILayout.MaxHeight(20)))
        {
            OpenFolder(Application.persistentDataPath, true);
        }
        GUILayout.EndHorizontal();
    }
 public void EndUpdate(bool isComplete)
 {
     isUpdating = false;
     if (groupProber != null)
     {
         groupProber.Occupy(this, serialNo, freshlyOccupiedCells);
     }
     if (isComplete)
     {
         if (groupProber != null)
         {
             groupProber.SetValidSerialNos(this, serialNo, serialNo);
         }
         previousSerialNo = serialNo;
         KProfiler.AddEvent("PathGrid.EndUpdate");
     }
 }
Exemplo n.º 10
0
        public static void BuildAllAssetBundles()
        {
            if (EditorApplication.isPlaying)
            {
                Log.Error("Cannot build in playing mode! Please stop!");
                return;
            }
            MakeAssetBundleNames();
            var outputPath = GetExportPath(EditorUserBuildSettings.activeBuildTarget);

            KProfiler.BeginWatch("BuildAB");
            Log.Info("AsseBundle start build to: {0}", outputPath);
            //压缩算法不建议用Lzma,要用LZ4 . Lzma读全部的buffer Lz4一个一个block读取,只读取4字节
            var opt = BuildAssetBundleOptions.DeterministicAssetBundle | BuildAssetBundleOptions.ChunkBasedCompression;//BuildAssetBundleOptions.AppendHashToAssetBundleName;

            BuildPipeline.BuildAssetBundles(outputPath, opt, EditorUserBuildSettings.activeBuildTarget);
            KProfiler.EndWatch("BuildAB", "AsseBundle build Finish");
        }
 public void BeginUpdate(int root_cell, bool isContinuation)
 {
     isUpdating = true;
     freshlyOccupiedCells.Clear();
     if (!isContinuation)
     {
         KProfiler.AddEvent("PathGrid.BeginUpdate");
         if (applyOffset)
         {
             Grid.CellToXY(root_cell, out rootX, out rootY);
             rootX -= widthInCells / 2;
             rootY -= heightInCells / 2;
         }
         serialNo++;
         if (groupProber != null)
         {
             groupProber.SetValidSerialNos(this, previousSerialNo, serialNo);
         }
     }
 }
    public void UpdateProbe(NavGrid nav_grid, int cell, NavType nav_type, PathFinderAbilities abilities, PathFinder.PotentialPath.Flags flags)
    {
        if (scratchPad == null)
        {
            scratchPad = new PathFinder.PotentialScratchPad(nav_grid.maxLinksPerCell);
        }
        bool flag  = updateCount == -1;
        bool flag2 = Potentials.Count == 0 || flag;

        PathGrid.BeginUpdate(cell, !flag2);
        bool is_cell_in_range;

        if (flag2)
        {
            updateCount = 0;
            PathFinder.Cell          cell_data      = PathGrid.GetCell(cell, nav_type, out is_cell_in_range);
            PathFinder.PotentialPath potential_path = new PathFinder.PotentialPath(cell, nav_type, flags);
            PathFinder.AddPotential(potential_path, Grid.InvalidCell, NavType.NumNavTypes, 0, 0, -1, Potentials, PathGrid, ref cell_data);
        }
        int num = (potentialCellsPerUpdate > 0 && !flag) ? potentialCellsPerUpdate : 2147483647;

        updateCount++;
        while (Potentials.Count > 0 && num > 0)
        {
            KeyValuePair <int, PathFinder.PotentialPath> keyValuePair = Potentials.Next();
            num--;
            PathFinder.Cell cell2 = PathGrid.GetCell(keyValuePair.Value, out is_cell_in_range);
            if (cell2.cost == keyValuePair.Key)
            {
                PathFinder.AddPotentials(scratchPad, keyValuePair.Value, cell2.cost, cell2.underwaterCost, ref abilities, null, nav_grid.maxLinksPerCell, nav_grid.Links, Potentials, PathGrid, cell2.parent, cell2.parentNavType);
            }
        }
        bool flag3 = Potentials.Count == 0;

        PathGrid.EndUpdate(flag3);
        if (flag3 && updateCount > 25)
        {
            KProfiler.AddEvent("PathProberUpdateCountExceeded");
        }
    }
    public static void AddPotentials(PotentialScratchPad potential_scratch_pad, PotentialPath potential, int cost, int underwater_cost, ref PathFinderAbilities abilities, PathFinderQuery query, int max_links_per_cell, NavGrid.Link[] links, PotentialList potentials, PathGrid path_grid, int parent_cell, NavType parent_nav_type)
    {
        int num = 0;

        NavGrid.Link[] linksWithCorrectNavType = potential_scratch_pad.linksWithCorrectNavType;
        int            num2 = potential.cell * max_links_per_cell;

        NavGrid.Link link = links[num2];
        for (int link2 = link.link; link2 != InvalidHandle; link2 = link.link)
        {
            if (link.startNavType == potential.navType && (parent_cell != link2 || parent_nav_type != link.startNavType))
            {
                linksWithCorrectNavType[num++] = link;
            }
            num2++;
            link = links[num2];
        }
        int num4 = 0;

        PotentialScratchPad.PathGridCellData[] linksInCellRange = potential_scratch_pad.linksInCellRange;
        for (int i = 0; i < num; i++)
        {
            NavGrid.Link link3            = linksWithCorrectNavType[i];
            int          link4            = link3.link;
            bool         is_cell_in_range = false;
            Cell         cell             = path_grid.GetCell(link4, link3.endNavType, out is_cell_in_range);
            if (is_cell_in_range)
            {
                int  num5  = cost + link3.cost;
                bool flag  = cell.cost == -1;
                bool flag2 = num5 < cell.cost;
                if (flag || flag2)
                {
                    linksInCellRange[num4++] = new PotentialScratchPad.PathGridCellData
                    {
                        pathGridCell = cell,
                        link         = link3
                    };
                }
            }
        }
        for (int j = 0; j < num4; j++)
        {
            PotentialScratchPad.PathGridCellData pathGridCellData = linksInCellRange[j];
            NavGrid.Link link5 = pathGridCellData.link;
            int          link6 = link5.link;
            pathGridCellData.isSubmerged = IsSubmerged(link6);
            linksInCellRange[j]          = pathGridCellData;
        }
        for (int k = 0; k < num4; k++)
        {
            PotentialScratchPad.PathGridCellData pathGridCellData2 = linksInCellRange[k];
            NavGrid.Link  link7     = pathGridCellData2.link;
            int           link8     = link7.link;
            Cell          cell_data = pathGridCellData2.pathGridCell;
            int           num7      = cost + link7.cost;
            PotentialPath path      = potential;
            path.cell    = link8;
            path.navType = link7.endNavType;
            int underwater_cost2;
            if (pathGridCellData2.isSubmerged)
            {
                underwater_cost2 = underwater_cost + 1;
                int submergedPathCostPenalty = abilities.GetSubmergedPathCostPenalty(path, link7);
                num7 += submergedPathCostPenalty;
            }
            else
            {
                underwater_cost2 = 0;
            }
            PotentialPath.Flags flags = path.flags;
            bool flag3 = abilities.TraversePath(ref path, potential.cell, potential.navType, num7, link7.transitionId, underwater_cost2);
            if (path.flags != flags)
            {
                KProfiler.AddEvent("NavChange");
            }
            if (flag3)
            {
                AddPotential(path, potential.cell, potential.navType, num7, underwater_cost2, link7.transitionId, potentials, path_grid, ref cell_data);
            }
        }
    }