Example #1
0
    public static void GenAtlas()
    {
        LoadConfig();
        string[] dirs = config.GetChangedDir();
        PathUtil.EnsuerFolder(PathUtil.GetFullPath("Atlas"));

        // 召唤一个工人 ㄟ( ▔ , ▔ )ㄏ
        UGUIAtlasWorker worker = new UGUIAtlasWorker();
        Shader          shader = AssetDatabase.LoadAssetAtPath <Shader>("Assets/Shader/UI-Default.shader");

        // work work  (╯‵□′)╯︵┻━┻(摔!)
        if (dirs.Length > 0)
        {
            Process(GenAtlasProcessor, dirs, worker, FormatArg());
            Process(SplitAlphaProcessor, dirs, worker);    // mark readable
            Process(UpdateBorderProcessor, dirs, worker);
            Process(UpdateSettingProcessor, dirs, worker); // isReadable = false
            Process(GenMaterialProcessor, dirs, worker, shader);
            TTLoger.Log("哦!太感动了,居然成功了!");
        }
        else
        {
            TTLoger.Log("无美术资源变化,不需生成!");
        }

        dirs = config.GetRemovedList();
        Process(RemoveUnUsedProcessor, dirs, worker);

        // 验收记录 Y( ̄o ̄)Y
        config.UpdateAndGetChangedAtlas();
        EditorUtility.SetDirty(config);
        shader = null;
        Resources.UnloadUnusedAssets();
        AssetDatabase.Refresh();
    }
Example #2
0
    public static void CopyGOPath()
    {
        GameObject obj = Selection.gameObjects[0];

        List <string> strList = new List <string>();

        strList.Add(obj.name);
        Transform trans = obj.transform;

        while (trans.parent != null)
        {
            strList.Add(trans.parent.name);
            trans = trans.parent;
        }

        strList.Reverse();
        StringBuilder sb = new StringBuilder();

        for (int i = 1; i < strList.Count; i++)
        {
            sb.Append(strList[i]);
            if (i != strList.Count - 1)
            {
                sb.Append(".");
            }
        }
        TTLoger.LogError(sb.ToString());
    }
    public void Init(int dataCount)
    {
        if (scrollRect == null || content == null || goItemPrefab == null)
        {
            TTLoger.LogError("异常:请检测<" + gameObject.name + ">对象上UIWarpContent对应ScrollRect、Content、GoItemPrefab 是否存在值...." + scrollRect + " _" + content + "_" + goItemPrefab);
            return;
        }
        if (dataCount < 0)
        {
            return;
        }
        setDataCount(dataCount);


        if (arrangement == Arrangement.Page)
        {
            scrollRect.inertia = false;
        }

        //移除
        for (int i = listItem.Count - 1; i >= 0; i--)
        {
            UIWarpContentItem item = listItem[i];
            item.Index = -1;
            unUseItem.Enqueue(item);
        }
        listItem.Clear();

        setUpdateRectItem(getCurScrollPerLineIndex());
    }
Example #4
0
 // 资源清单检查
 bool CheckRes(GameResType type, string name, out GameBundleInfo data)
 {
     data = GameTable.GetGameBundleRes(type, name);
     if (data == null)
     {
         TTLoger.LogError("资源清单未找到资源 : " + name + ",请检查resBundle");
         return(false);
     }
     return(true);
 }
Example #5
0
    static void LogError(StreamReader streamReader)
    {
        string s = streamReader.ReadToEnd();

        if (string.IsNullOrEmpty(s))
        {
            return;
        }
        TTLoger.LogError(s);
    }
    public void OnUpdateDownloadStart(WWW www)
    {
        TTLoger.LogError("开始下载:" + www.url);

        this.startTime = TimeKit.GetMillisTime();

        if (OnStartDownload != null)
        {
            OnStartDownload(www);
        }
    }
    public void OnUpdateDownloadEnd(WWW www)
    {
        TTLoger.LogError("完成下载:" + www.url);

        ++currentDownloaded;

        if (OnEndDownload != null)
        {
            OnEndDownload(www);
        }
    }
Example #8
0
 static float GetBatteryLevelAndroid()
 {
     try
     {
         string capacityString = System.IO.File.ReadAllText("/sys/class/power_supply/battery/capacity");
         return((float.Parse(capacityString)) / 100);
     }
     catch (Exception e) {
         TTLoger.LogWarning("Failed to read battery power : " + e.Message);
     }
     return(-1f);
 }
    public void OnUpdateDownloading(WWW www)
    {
        TTLoger.LogError(string.Format("下载中({0}):{1}", www.bytesDownloaded, www.url));
        long nowTime = TimeKit.GetMillisTime();

        downloadSpeed = 1000.0f / 1024 / 1024 * www.bytesDownloaded / (nowTime - startTime);

        if (OnDownloading != null)
        {
            OnDownloading(www);
        }
    }
    /**
     * @des:实例化预设对象 、添加实例化对象到指定的子对象下
     */
    private GameObject addChild(GameObject goPrefab, Transform parent)
    {
        if (goPrefab == null || parent == null)
        {
            TTLoger.LogError("异常。UIWarpContent.cs addChild(goPrefab = null  || parent = null)");
            return(null);
        }
        GameObject goChild = GameObject.Instantiate(goPrefab) as GameObject;

        goChild.layer = parent.gameObject.layer;
        goChild.transform.SetParent(parent, false);
        goChild.SetActive(true);

        return(goChild);
    }
 protected override void Start()
 {
     if (text == null)
     {
         text       = GetComponent <Text>();
         oldText    = text.text;
         rect       = GetComponent <RectTransform>();
         oldSize    = rect.sizeDelta;
         oldSpacing = m_spacing;
     }
     if (text == null)
     {
         TTLoger.LogWarning("LetterSpacing: Missing Text component");
         return;
     }
 }
Example #12
0
    static void OpenFile()
    {
        string logFolder = Application.dataPath.Substring(0, Application.dataPath.LastIndexOf('/') + 1) + "Log";

        if (!Directory.Exists(logFolder))
        {
            TTLoger.LogError("当前没有任何日志!");
            return;
        }

        var path = EditorUtility.OpenFilePanel(
            "选择一个日志",
            logFolder,
            "log");

        if (!string.IsNullOrEmpty(path))
        {
            OpenWindow(path);
        }
    }
Example #13
0
    public LuaTable InitLuaController(object param = null)
    {
        // 先执行lua脚本得到管理器
#if UNITY_EDITOR
        if (string.IsNullOrEmpty(this.scriptName))
        {
            TTLoger.LogError("未指定界面管理器函数 : " + this.gameObject.name);
            return(null);
        }
#endif
        LuaFunction func = Lua.GetFunction(scriptName);
#if UNITY_EDITOR
        if (func == null)
        {
            TTLoger.LogError("未找到界面管理器函数 :" + scriptName);
            return(null);
        }
#endif
        func.BeginPCall();
        func.Push(param);
        func.Push(this.gameObject);
        func.PCall();
        luaController = func.CheckLuaTable();
        func.EndPCall();


#if UNITY_EDITOR
        if (luaController == null)
        {
            TTLoger.LogError("无效的界面管理器函数 : " + scriptName + "(" + this.gameObject.name + ")");
            return(null);
        }
#endif


        IntPtr L = Lua.state.L;

        // 赋个gameObject
        luaController["gameObject"] = this.gameObject;
        luaController["transform"]  = this.transform;

        // 先导出子导出器
        InitSubController(L);

        // 如果没有导出控件就完事了
        if (exportNames == null || exportNames.Count == 0)
        {
            return(luaController);
        }

        // 准备导出控件
        int oldTop = LuaDLL.lua_gettop(L);
        Lua.state.Push(luaController);

        // 出现多个同名导出控件,转成table形式
        HashSet <string> tabled = new HashSet <string>();   // 转table标记

        for (int i = 0; i < exportNames.Count; ++i)
        {
            // 说明已经导出过了
            if (tabled.Contains(exportNames[i]))
            {
                continue;
            }
            // push 控件名
            LuaDLL.lua_pushstring(L, exportNames[i]);

            // 检查如果后面有同名的就一起以table形式导出
            int n = 1;
            for (int j = i + 1; j < exportNames.Count; ++j)
            {
                if (exportNames[i].Equals(exportNames[j]))
                {
                    if (!tabled.Contains(exportNames[i]))
                    {
                        LuaDLL.lua_newtable(L);
                        tabled.Add(exportNames[i]);
                        Lua.state.Push(exportWrappers[i]);
                        LuaDLL.lua_rawseti(L, -2, n++);
                    }

                    Lua.state.Push(exportWrappers[j]);
                    LuaDLL.lua_rawseti(L, -2, n++);
                }
            }
            if (!tabled.Contains(exportNames[i]))
            {
                Lua.state.Push(exportWrappers[i]);
            }
            LuaDLL.lua_settable(L, -3);
        }

        LuaDLL.lua_settop(L, oldTop);
        return(luaController);
    }
Example #14
0
 public void OnUpdateDownloadError(WWW www)
 {
     TTLoger.LogError("下载失败:" + www.url);
 }
        void OnGUI()
        {
            bool hasNotValid = false;
            bool hasValid    = false;

            if (config == null)
            {
                config = LoadConfig();
                if (config == null)
                {
                    config = new AssetBundleBuildConfig();
                }
            }

            UpdateStyles();

            GUILayout.BeginHorizontal(Styles.toolbar);
            {
                for (int i = 0; i < config.filters.Count; ++i)
                {
                    if (!config.filters[i].valid)
                    {
                        hasNotValid = true;
                    }
                    else
                    {
                        hasValid = true;
                    }
                }

                if (GUILayout.Button(hasNotValid ? "SelectAll" : "UnselectAll", Styles.toolbarButton))
                {
                    for (int i = 0; i < config.filters.Count; ++i)
                    {
                        config.filters[i].valid = hasNotValid;
                    }
                }

                if (GUILayout.Button("Add", Styles.toolbarButton))
                {
                    config.filters.Add(new AssetBundleFilterMain());
                }

                if (GUILayout.Button("Gen", Styles.toolbarButton))
                {
                    AssetBundleBuilder.Build(config, true);
                }

                if (GUILayout.Button("Clear", Styles.toolbarButton))
                {
                    EditorApplication.delayCall += () =>
                    {
                        PathUtil.DeleteFileOrFolder(Application.streamingAssetsPath);
                        AssetDatabase.Refresh();
                        TTLoger.Log("清理完成!");
                    };
                }

                GUILayout.FlexibleSpace();
            }
            GUILayout.EndHorizontal();

            UnityEngine.Event e = UnityEngine.Event.current;
            if (e.type == EventType.scrollWheel)
            {
                scrollPos = new Vector2(0f, scrollPos.y + (-10) * e.delta.y);
            }
            scrollPos = GUILayout.BeginScrollView(scrollPos, false, false);

            GUILayout.BeginVertical();
            for (int i = 0; i < config.filters.Count; i++)
            {
                AssetBundleFilterMain filter = config.filters[i];
                i -= DrawMainFilter(filter);
            }

            if (!hasValid)
            {
                GUI.enabled = false;
            }

            GUILayout.FlexibleSpace();
            if (GUILayout.Button("Build"))
            {
                EditorApplication.delayCall += Build;
            }
            if (!hasValid)
            {
                GUI.enabled = true;
            }
            GUILayout.EndVertical();
            GUILayout.EndScrollView();

            //set dirty
            if (GUI.changed)
            {
                Save();
            }

            UpdateEvent();
            Repaint();
        }
        public override void ModifyMesh(VertexHelper helper)//List<UIVertex> verts
        {
            if (!IsActive())
            {
                return;
            }

            List <UIVertex> verts = new List <UIVertex>();

            helper.GetUIVertexStream(verts);

            Text text = GetComponent <Text>();

            if (text == null)
            {
                TTLoger.LogWarning("LetterSpacing: Missing Text component");
                return;
            }

            string s = text.text;

            string[] lines = s.Split('\n');
            Vector3  pos;
            float    letterOffset    = spacing * (float)text.fontSize / 100f;
            float    alignmentFactor = 0;
            int      glyphIdx        = 0;

            switch (text.alignment)
            {
            case TextAnchor.LowerLeft:
            case TextAnchor.MiddleLeft:
            case TextAnchor.UpperLeft:
                alignmentFactor = 0f;
                break;

            case TextAnchor.LowerCenter:
            case TextAnchor.MiddleCenter:
            case TextAnchor.UpperCenter:
                alignmentFactor = 0.5f;
                break;

            case TextAnchor.LowerRight:
            case TextAnchor.MiddleRight:
            case TextAnchor.UpperRight:
                alignmentFactor = 1f;
                break;
            }

            for (int lineIdx = 0; lineIdx < lines.Length; lineIdx++)
            {
                string line       = lines[lineIdx];
                float  lineOffset = (line.Length - 1) * letterOffset * alignmentFactor;

                for (int charIdx = 0; charIdx < line.Length; charIdx++)
                {
                    int idx1 = glyphIdx * 6 + 0;
                    int idx2 = glyphIdx * 6 + 1;
                    int idx3 = glyphIdx * 6 + 2;
                    int idx4 = glyphIdx * 6 + 3;
                    int idx5 = glyphIdx * 6 + 4;
                    int idx6 = glyphIdx * 6 + 5;
                    // Check for truncated text (doesn't generate verts for all characters)
                    //if (IsRichText(glyphIdx))
                    //    continue;
                    if (idx6 > verts.Count - 1)
                    {
                        return;
                    }

                    UIVertex vert1 = verts[idx1];
                    UIVertex vert2 = verts[idx2];
                    UIVertex vert3 = verts[idx3];
                    UIVertex vert4 = verts[idx4];
                    UIVertex vert5 = verts[idx5];
                    UIVertex vert6 = verts[idx6];

                    pos = Vector3.right * (letterOffset * charIdx - lineOffset);


                    vert1.position += pos;
                    vert2.position += pos;
                    vert3.position += pos;
                    vert4.position += pos;
                    vert5.position += pos;
                    vert6.position += pos;

                    verts[idx1] = vert1;
                    verts[idx2] = vert2;
                    verts[idx3] = vert3;
                    verts[idx4] = vert4;
                    verts[idx5] = vert5;
                    verts[idx6] = vert6;

                    glyphIdx++;
                }

                // Offset for carriage return character that still generates verts
                glyphIdx++;
            }

            helper.Clear();
            helper.AddUIVertexTriangleStream(verts);
        }
        public override void ModifyMesh(VertexHelper helper)//List<UIVertex> verts
        {
            if (!IsActive())
            {
                return;
            }

            List <UIVertex> verts = new List <UIVertex>();

            helper.GetUIVertexStream(verts);

            Text text = GetComponent <Text>();

            if (text == null)
            {
                TTLoger.LogWarning("LetterSpacing: Missing Text component");
                return;
            }

            string s = text.text;

            rt.ParseRichText(s);

            string[] lines = s.Split('\n');
            Vector3  pos;
            float    letterOffset    = spacing * (float)text.fontSize / ScaleFactor;
            float    alignmentFactor = 0;

            switch (text.alignment)
            {
            case TextAnchor.LowerLeft:
            case TextAnchor.MiddleLeft:
            case TextAnchor.UpperLeft:
                alignmentFactor = 0f;
                break;

            case TextAnchor.LowerCenter:
            case TextAnchor.MiddleCenter:
            case TextAnchor.UpperCenter:
                alignmentFactor = 0.5f;
                break;

            case TextAnchor.LowerRight:
            case TextAnchor.MiddleRight:
            case TextAnchor.UpperRight:
                alignmentFactor = 1f;
                break;
            }

            // 遍历所有行
            for (int lineIdx = 0; lineIdx < lines.Length; lineIdx++)
            {
                // 获取行
                string line = lines[lineIdx];
                // 计算行偏移
                float lineOffset = (line.Length - 1) * letterOffset * alignmentFactor;
                // 遍历行对象
                for (int i = 0; i < rt.root.childCount; ++i)
                {
                    // 获取行对象
                    RichTextSegment lineSeg = rt.root.GetChild(i) as RichTextSegment;

                    int startShowGlyphIndexInLine = 0;

                    // 遍历行内对象
                    for (int k = 0; k < lineSeg.childCount; ++k)
                    {
                        // 获取行内对象
                        RichTextSegment child = lineSeg.GetChild(k);

                        //
                        for (int showGlyphIdx = 0; showGlyphIdx < child.showGlyphCount; ++showGlyphIdx)
                        {
                            int glyphIndex = child.startIndex + showGlyphIdx;

                            int idx1 = glyphIndex * 6 + 0;
                            int idx2 = glyphIndex * 6 + 1;
                            int idx3 = glyphIndex * 6 + 2;
                            int idx4 = glyphIndex * 6 + 3;
                            int idx5 = glyphIndex * 6 + 4;
                            int idx6 = glyphIndex * 6 + 5;

                            if (idx6 > verts.Count - 1)
                            {
                                return;
                            }

                            UIVertex vert1 = verts[idx1];
                            UIVertex vert2 = verts[idx2];
                            UIVertex vert3 = verts[idx3];
                            UIVertex vert4 = verts[idx4];
                            UIVertex vert5 = verts[idx5];
                            UIVertex vert6 = verts[idx6];

                            float f = (letterOffset * (startShowGlyphIndexInLine + showGlyphIdx) - lineOffset);
                            pos = Vector3.right * f;

                            vert1.position += pos;
                            vert2.position += pos;
                            vert3.position += pos;
                            vert4.position += pos;
                            vert5.position += pos;
                            vert6.position += pos;

                            verts[idx1] = vert1;
                            verts[idx2] = vert2;
                            verts[idx3] = vert3;
                            verts[idx4] = vert4;
                            verts[idx5] = vert5;
                            verts[idx6] = vert6;
                        }

                        startShowGlyphIndexInLine += child.showGlyphCount;
                    }
                }
            }

            helper.Clear();
            helper.AddUIVertexTriangleStream(verts);
        }