Ejemplo n.º 1
0
    public static void CreatUI(string l_UIWindowName, UIType l_UIType, UILayerManager l_UILayerManager, bool l_isAutoCreatePrefab)
    {
        GameObject l_uiGo = new GameObject(l_UIWindowName);

        Type         type        = EditorTool.GetType(l_UIWindowName);
        UIWindowBase l_uiBaseTmp = l_uiGo.AddComponent(type) as UIWindowBase;

        l_uiGo.layer = LayerMask.NameToLayer("UI");

        l_uiBaseTmp.m_UIType = l_UIType;

        l_uiGo.AddComponent <Canvas>();
        l_uiGo.AddComponent <GraphicRaycaster>();

        RectTransform l_ui = l_uiGo.GetComponent <RectTransform>();

        l_ui.sizeDelta = Vector2.zero;
        l_ui.anchorMin = Vector2.zero;
        l_ui.anchorMax = Vector2.one;

        GameObject l_BgGo = new GameObject("BG");

        l_BgGo.layer = LayerMask.NameToLayer("UI");
        RectTransform l_Bg = l_BgGo.AddComponent <RectTransform>();

        l_Bg.SetParent(l_ui);
        l_Bg.sizeDelta = Vector2.zero;
        l_Bg.anchorMin = Vector2.zero;
        l_Bg.anchorMax = Vector2.one;

        GameObject l_rootGo = new GameObject("root");

        l_rootGo.layer = LayerMask.NameToLayer("UI");
        RectTransform l_root = l_rootGo.AddComponent <RectTransform>();

        l_root.SetParent(l_ui);
        l_root.sizeDelta = Vector2.zero;
        l_root.anchorMin = Vector2.zero;
        l_root.anchorMax = Vector2.one;

        l_uiBaseTmp.m_bgMask = l_BgGo;
        l_uiBaseTmp.m_uiRoot = l_rootGo;

        if (l_UILayerManager)
        {
            l_UILayerManager.SetLayer(l_uiBaseTmp);
        }

        if (l_isAutoCreatePrefab)
        {
            string Path = "Resources/UI/" + l_UIWindowName + "/" + l_UIWindowName + ".prefab";
            FileTool.CreatFilePath(Application.dataPath + "/" + Path);
            PrefabUtility.CreatePrefab("Assets/" + Path, l_uiGo, ReplacePrefabOptions.ConnectToPrefab);
        }

        ProjectWindowUtil.ShowCreatedAsset(l_uiGo);
    }
Ejemplo n.º 2
0
    public static string[] GetAllEnumType()
    {
        List <string> listTmp = new List <string>();

        Type[] types = Assembly.Load("Assembly-CSharp").GetTypes();

        for (int i = 0; i < types.Length; i++)
        {
            if (types[i].IsSubclassOf(typeof(Enum)))
            {
                if (EditorTool.GetType(types[i].Name) != null)
                {
                    listTmp.Add(types[i].Name);
                }
            }
        }
        return(listTmp.ToArray());
    }
Ejemplo n.º 3
0
    void CreateUIGUI()
    {
        EditorGUI.indentLevel = 0;
        isFoldCreateUI        = EditorGUILayout.Foldout(isFoldCreateUI, "创建UI:");

        if (isFoldCreateUI)
        {
            EditorGUI.indentLevel = 1;
            EditorGUILayout.LabelField("提示: 脚本和 UI 名称会自动添加Window后缀");
            m_uiName = EditorGUILayout.TextField("UI Name:", m_uiName);
            m_UIType = (UIType)EditorGUILayout.EnumPopup("UI Type:", m_UIType);

            isAutoCreatePrefab = EditorGUILayout.Toggle("自动生成 Prefab", isAutoCreatePrefab);

            var l_nameTmp = m_uiName + "Window";
            if (!string.IsNullOrEmpty(m_uiName))
            {
                var l_typeTmp = EditorTool.GetType(l_nameTmp);
                if (l_typeTmp != null)
                {
                    if (l_typeTmp.BaseType.Equals(typeof(UIWindowBase)))
                    {
                        if (GUILayout.Button("创建UI"))
                        {
                            UICreateService.CreatUI(l_nameTmp, m_UIType, m_UILayerManager, isAutoCreatePrefab);
                            m_uiName = "";
                        }
                    }
                    else
                    {
                        EditorGUILayout.LabelField("该类没有继承UIWindowBase");
                    }
                }
                else
                {
                    if (GUILayout.Button("创建UI脚本"))
                    {
                        UICreateService.CreatUIScript(l_nameTmp);
                    }
                }
            }
        }
    }
Ejemplo n.º 4
0
        private void CreateUIScript()
        {
            if (m_UIname == "")
            {
                return;
            }
            string l_nameTmp = m_UIname + "_Window";


            Type l_typeTmp = EditorTool.GetType(m_ui_namespace + l_nameTmp);

            if (l_typeTmp == null)
            {
                CreatUIScript(l_nameTmp);
            }
            if (l_typeTmp != null)
            {
                CreatUI(l_nameTmp, l_typeTmp, m_UIType, m_isAutoCreatePrefab);
            }
        }
Ejemplo n.º 5
0
    public static string[] GetAllEnumType()
    {
        List <string> listTmp = new List <string>();

#if UNITY_WEBGL
        Type[] types = Assembly.Load(Assembly.GetExecutingAssembly().FullName).GetTypes();
#else
        Type[] types = Assembly.Load("Assembly-CSharp").GetTypes();
#endif

        for (int i = 0; i < types.Length; i++)
        {
            if (types[i].IsSubclassOf(typeof(Enum)))
            {
                if (EditorTool.GetType(types[i].Name) != null)
                {
                    listTmp.Add(types[i].Name);
                }
            }
        }
        return(listTmp.ToArray());
    }
Ejemplo n.º 6
0
    public static void CreateGuideWindow()
    {
        string UIWindowName = "GuideWindow";
        UIType UIType       = UIType.TopBar;

        GameObject uiGo = new GameObject(UIWindowName);

        Type            type         = EditorTool.GetType(UIWindowName);
        GuideWindowBase guideBaseTmp = uiGo.AddComponent(type) as GuideWindowBase;

        uiGo.layer = LayerMask.NameToLayer("UI");

        guideBaseTmp.m_UIType = UIType;

        Canvas can = uiGo.AddComponent <Canvas>();

        uiGo.AddComponent <GraphicRaycaster>();

        can.overrideSorting  = true;
        can.sortingLayerName = "Guide";

        RectTransform ui = uiGo.GetComponent <RectTransform>();

        ui.sizeDelta = Vector2.zero;
        ui.anchorMin = Vector2.zero;
        ui.anchorMax = Vector2.one;

        GameObject BgGo = new GameObject("BG");

        BgGo.layer = LayerMask.NameToLayer("UI");
        RectTransform Bg = BgGo.AddComponent <RectTransform>();

        Bg.SetParent(ui);
        Bg.sizeDelta = Vector2.zero;
        Bg.anchorMin = Vector2.zero;
        Bg.anchorMax = Vector2.one;

        GameObject rootGo = new GameObject("root");

        rootGo.layer = LayerMask.NameToLayer("UI");
        RectTransform root = rootGo.AddComponent <RectTransform>();

        root.SetParent(ui);
        root.sizeDelta = Vector2.zero;
        root.anchorMin = Vector2.zero;
        root.anchorMax = Vector2.one;

        GameObject mask = new GameObject("mask");

        mask.layer = LayerMask.NameToLayer("UI");
        RectTransform maskrt = mask.AddComponent <RectTransform>();
        Image         img    = mask.AddComponent <Image>();

        img.color = new Color(0, 0, 0, 0.75f);
        maskrt.SetParent(root);
        maskrt.sizeDelta = Vector2.zero;
        maskrt.anchorMin = Vector2.zero;
        maskrt.anchorMax = Vector2.one;

        GameObject tips = new GameObject("Tips");

        tips.layer = LayerMask.NameToLayer("UI");
        RectTransform tipsrt = tips.AddComponent <RectTransform>();

        tipsrt.SetParent(root);

        guideBaseTmp.m_objectList.Add(tips);

        GameObject Text_tips = new GameObject("Text_tip");

        Text_tips.layer = LayerMask.NameToLayer("UI");
        RectTransform txt_tipsrt = Text_tips.AddComponent <RectTransform>();
        Text          text       = Text_tips.AddComponent <Text>();

        txt_tipsrt.SetParent(tipsrt);

        guideBaseTmp.m_objectList.Add(Text_tips);

        //guideBaseTmp.m_mask = img;
        //guideBaseTmp.m_TipText = text;
        //guideBaseTmp.m_TipTransfrom = txt_tipsrt;

        guideBaseTmp.m_bgMask = BgGo;
        guideBaseTmp.m_uiRoot = rootGo;

        string Path = "Resources/UI/" + UIWindowName + "/" + UIWindowName + ".prefab";

        FileTool.CreatFilePath(Application.dataPath + "/" + Path);
        PrefabUtility.CreatePrefab("Assets/" + Path, uiGo, ReplacePrefabOptions.ConnectToPrefab);

        ProjectWindowUtil.ShowCreatedAsset(uiGo);
    }
Ejemplo n.º 7
0
    public static void CreatUI(string UIWindowName, string UIcameraKey, UIType UIType, UILayerManager UILayerManager, bool isAutoCreatePrefab)
    {
        GameObject uiGo = new GameObject(UIWindowName);

        Type         type      = EditorTool.GetType(UIWindowName);
        UIWindowBase uiBaseTmp = uiGo.AddComponent(type) as UIWindowBase;

        uiGo.layer = LayerMask.NameToLayer("UI");

        uiBaseTmp.m_UIType = UIType;

        Canvas canvas = uiGo.AddComponent <Canvas>();

        if (EditorExpand.isExistShortLayer(UIType.ToString()))
        {
            canvas.overrideSorting  = true;
            canvas.sortingLayerName = UIType.ToString();
        }

        uiGo.AddComponent <GraphicRaycaster>();

        RectTransform ui = uiGo.GetComponent <RectTransform>();

        ui.sizeDelta = Vector2.zero;
        ui.anchorMin = Vector2.zero;
        ui.anchorMax = Vector2.one;

        GameObject BgGo = new GameObject("BG");

        BgGo.layer = LayerMask.NameToLayer("UI");
        RectTransform Bg = BgGo.AddComponent <RectTransform>();

        Bg.SetParent(ui);
        Bg.sizeDelta = Vector2.zero;
        Bg.anchorMin = Vector2.zero;
        Bg.anchorMax = Vector2.one;

        GameObject rootGo = new GameObject("root");

        rootGo.layer = LayerMask.NameToLayer("UI");
        RectTransform root = rootGo.AddComponent <RectTransform>();

        root.SetParent(ui);
        root.sizeDelta = Vector2.zero;
        root.anchorMin = Vector2.zero;
        root.anchorMax = Vector2.one;

        uiBaseTmp.m_bgMask = BgGo;
        uiBaseTmp.m_uiRoot = rootGo;

        if (UILayerManager)
        {
            UILayerManager.SetLayer(uiBaseTmp);
        }

        if (isAutoCreatePrefab)
        {
            string Path = "Resources/UI/" + UIWindowName + "/" + UIWindowName + ".prefab";
            FileTool.CreatFilePath(Application.dataPath + "/" + Path);
            PrefabUtility.CreatePrefab("Assets/" + Path, uiGo, ReplacePrefabOptions.ConnectToPrefab);
        }

        ProjectWindowUtil.ShowCreatedAsset(uiGo);
    }
Ejemplo n.º 8
0
    void CreateUIGUI()
    {
        EditorGUI.indentLevel = 0;
        isFoldCreateUI        = EditorGUILayout.Foldout(isFoldCreateUI, "创建UI:");

        if (isFoldCreateUI)
        {
            cameraKeyList = UIManager.GetCameraNames();

            EditorGUI.indentLevel = 1;
            EditorGUILayout.LabelField("提示: 脚本和 UI 名称会自动添加Window后缀");
            m_UIname = EditorGUILayout.TextField("UI Name:", m_UIname);

            m_UICameraKeyIndex = EditorGUILayout.Popup("Camera", m_UICameraKeyIndex, cameraKeyList);

            m_UIType = (UIType)EditorGUILayout.EnumPopup("UI Type:", m_UIType);

            isUseLua = EditorGUILayout.Toggle("使用 Lua", isUseLua);
            if (isUseLua)
            {
                EditorGUI.indentLevel++;
                isAutoCreateLuaFile = EditorGUILayout.Toggle("自动创建Lua脚本", isAutoCreateLuaFile);
                EditorGUI.indentLevel--;
            }

            isAutoCreatePrefab = EditorGUILayout.Toggle("自动生成 Prefab", isAutoCreatePrefab);

            if (m_UIname != "")
            {
                string l_nameTmp = m_UIname + "Window";

                if (!isUseLua)
                {
                    Type l_typeTmp = EditorTool.GetType(l_nameTmp);
                    if (l_typeTmp != null)
                    {
                        if (l_typeTmp.BaseType.Equals(typeof(UIWindowBase)))
                        {
                            if (GUILayout.Button("创建UI"))
                            {
                                UICreateService.CreatUI(l_nameTmp, cameraKeyList[m_UICameraKeyIndex], m_UIType, m_UILayerManager, isAutoCreatePrefab);
                                m_UIname = "";
                            }
                        }
                        else
                        {
                            EditorGUILayout.LabelField("该类没有继承UIWindowBase");
                        }
                    }
                    else
                    {
                        if (GUILayout.Button("创建UI脚本"))
                        {
                            UICreateService.CreatUIScript(l_nameTmp);
                        }
                    }
                }
                else
                {
                    if (GUILayout.Button("创建UI"))
                    {
                        UICreateService.CreatUIbyLua(l_nameTmp, m_UIType, m_UILayerManager, isAutoCreatePrefab);
                        if (isAutoCreateLuaFile)
                        {
                            UICreateService.CreatUILuaScript(l_nameTmp);
                        }

                        m_UIname = "";
                    }
                }
            }
        }
    }
Ejemplo n.º 9
0
        public override bool Update(GameTime gameTime)
        {
            camera.UpdateBegin();

            if (!gameState.Update(gameTime))
            {
                return(false);
            }

            if (!pauseGame)
            {
                for (int i = 0; i < Entities.Count; i++)
                {
                    Entities[i].Update(gameTime);
                }
            }
#if DEBUG
            else
            {
                player.Update(gameTime);
            }
#endif

#if DEBUG
            #region Editor

            if (Input.e.pressed)
            {
                editorTool++;
                if ((int)editorTool >= Enum.GetNames(editorTool.GetType()).Length)
                {
                    editorTool = 0;
                }
            }
            else if (Input.q.pressed)
            {
                editorTool--;
                if ((int)editorTool < 0)
                {
                    editorTool = (EditorTool)(Enum.GetNames(editorTool.GetType()).Length - 1);
                }
            }

            //if (editorTool != EditorTool.None)
            {
                if (Input.mbLeft.pressed || Input.mbRight.pressed)
                {
                    pressedX  = (int)Math.Floor(camera.mousePos.X / Tile.size);
                    pressedY  = (int)Math.Floor(camera.mousePos.Y / Tile.size);
                    mouseDown = Input.mbLeft.pressed ? Input.mbLeft : Input.mbRight;
                }
                if (mouseDown != null && mouseDown.released)
                {
                    switch (editorTool)
                    {
                        #region Tile
                    case EditorTool.Tile:
                    case EditorTool.Goal:

                        int x = (int)Math.Floor(camera.mousePos.X / Tile.size);
                        int y = (int)Math.Floor(camera.mousePos.Y / Tile.size);

                        int xStart = Math.Min(x, pressedX);
                        int xEnd   = Math.Max(x, pressedX);
                        int yStart = Math.Min(y, pressedY);
                        int yEnd   = Math.Max(y, pressedY);

                        bool setStreet = mouseDown == Input.mbLeft;

                        if (xStart < 0)
                        {
                            xStart = 0;
                        }
                        if (yStart < 0)
                        {
                            yStart = 0;
                        }
                        if (xStart >= width)
                        {
                            xStart = width - 1;
                        }
                        if (yStart >= height)
                        {
                            yStart = height - 1;
                        }

                        if (editorTool == EditorTool.Tile)
                        {
                            for (int y1 = yStart; y1 <= yEnd; y1++)
                            {
                                for (int x1 = xStart; x1 <= xEnd; x1++)
                                {
                                    street[x1, y1] = setStreet;
                                }
                            }
                            UpdateTiles(xStart - 1, xEnd + 1, yStart - 1, yEnd + 1);
                        }
                        else if (editorTool == EditorTool.Goal)
                        {
                            for (int y1 = yStart; y1 <= yEnd; y1++)
                            {
                                for (int x1 = xStart; x1 <= xEnd; x1++)
                                {
                                    AddEntity(new Goal(new Vector2(x1, y1) * Tile.size));
                                }
                            }
                        }
                        break;

                        #endregion
                    case EditorTool.House:
                        if (mouseDown == Input.mbLeft)
                        {
                            House house = new House(GetDragRectangle());
                            AddEntity(house);
                        }
                        break;
                    }

                    mouseDown = null;
                }

                if (mouseDown == Input.mbRight)
                {
                    if (editorTool != EditorTool.Tile)
                    {
                        for (int i = Entities.Count - 1; i >= 0; i--)
                        {
                            if (Entities[i] is E_Mask m && m.Mask.ColVector(camera.mousePos))
                            {
                                RemoveEntity(Entities[i]);
                            }
                        }
                    }
                }
                else
                {
                    switch (editorTool)
                    {
                    case EditorTool.Tile:
                        break;

                    case EditorTool.House:
                        break;

                    case EditorTool.Car:

                        if (Input.mbLeft.pressed)
                        {
                            if (carIndex == 0)
                            {
                                carBuild = new PlayerCar(camera.mousePos, 0f);
                            }
                            else
                            {
                                carBuild = new Car(camera.mousePos, 0f);
                            }
                            AddEntity(carBuild);
                        }

                        if (Input.mbLeft.down)
                        {
                            Vector2 dir = camera.mousePos - carBuild.Pos;
                            carBuild.orientation = (float)Math.Atan2(dir.Y, dir.X);
                        }
                        break;

                    case EditorTool.Bot:

                        if (Input.mbLeft.pressed)
                        {
                            Bot bot = Entities.Find(f => f is Bot b && b.botID == carIndex) as Bot;
                            if (bot == null)
                            {
                                PathTrack path = new PathTrack(new List <Vector2>()
                                {
                                    camera.mousePos
                                });

                                if (carIndex == 0)
                                {
                                    bot = new Friend(path);
                                }
                                else
                                {
                                    bot = new Bot(carIndex, path);
                                }
                                AddEntity(bot);
                            }
                            else
                            {
                                bot.path.nodes.Add(camera.mousePos);
                            }
                        }
                        break;
                    }
                }

                if (Input.plusNum.pressed)
                {
                    carIndex++;
                }
                else if (Input.minusNum.pressed)
                {
                    carIndex--;
                }
            }
            #endregion
#endif

            camera.targetPos = player.Pos;

            camera.UpdateEnd(G.ResX, G.ResY);

#if DEBUG
            if (Input.f.pressed)
            {
                Win();
            }
#endif

            return(true);
        }