예제 #1
0
 static void MovePrefabToUIViewTest()
 {
     HelpFunEditor.LoadGameRoot();
     GameObject[] obj = Selection.gameObjects;
     if (obj != null)
     {
         for (int i = 0; i < obj.Length; i++)
         {
             GameObject instantiatePrefab = HelpFunEditor.InstantiatePrefab(GameObject.Find("GameRoot/Game/UIRoot/UIWindowParent/Canvas/TestWindow").gameObject, obj[i]);
             Selection.activeGameObject                = instantiatePrefab;
             instantiatePrefab.transform.localScale    = Vector3.one;
             instantiatePrefab.transform.localPosition = Vector3.zero;
             RectTransform rect = instantiatePrefab.transform.GetComponent <RectTransform>();
             //rect.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Left,0f,0f );
             //rect.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Right, 0f, 0f);
             //rect.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Bottom, 0f, 0f);
             //rect.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Top, 0f, 0f);
             rect.anchorMin = Vector2.zero;
             rect.anchorMax = Vector2.one;
             rect.pivot     = new Vector2(0.5f, 0.5f);
             rect.offsetMax = Vector2.zero;
             rect.offsetMin = Vector2.zero;
         }
     }
 }
예제 #2
0
        void DealPrefab(string prefabName)
        {
            string prefabPath = UICreatorPathTools.mCreatorResPath + "PackageName_Null.prefab";

            switch (uiTypeIndex)
            {
            case 1:
                prefabPath = UICreatorPathTools.mCreatorResPath + "PackageName_WindowBase.prefab";
                break;

            case 2:
                prefabPath = UICreatorPathTools.mCreatorResPath + "PackageName_WindowDialog.prefab";
                break;

            case 3:
                prefabPath = UICreatorPathTools.mCreatorResPath + "PackageName_WindowFullScreen.prefab";
                break;
            }

            Debug.Log(prefabPath);

            GameObject go = HelpFunEditor.InstantiateGameObject(GameObject.Find(UICreatorPathTools.mTestViewPath).gameObject,
                                                                AssetDatabase.LoadAssetAtPath <GameObject>(prefabPath)
                                                                );

            var eventCollector = go.GetComponent <UGUIExtend.GameEventCollector>();

            eventCollector.packageName = packageNames[packageIndex].ToLower();
            eventCollector.moduleName  = mUIName.ToLower();

            SetGameObject(go);

            EditorUtility.DisplayProgressBar("请稍候", "正在生成预制件", 0.7f);

            string outResDir = UICreatorPathTools.GetResDir(packageNames[packageIndex], mUIName);

            if (!Directory.Exists(outResDir))
            {
                Directory.CreateDirectory(outResDir);
            }
            string createPrefab = string.Format("{0}" + outResDir.Replace(Application.dataPath, "") + prefabName + ".prefab", "Assets");           //(outResDir+ prefabName + ".prefab").Replace(Application.dataPath.Replace("Assets/",""),"");

            Debug.Log("createPrefab = " + createPrefab);
            Object tempPrefab = PrefabUtility.CreateEmptyPrefab(createPrefab);

            PrefabUtility.ReplacePrefab(go, tempPrefab);

            GameObject.DestroyImmediate(go);

            EditorUtility.DisplayProgressBar("请稍候", "正在生成预制件", 0.8f);

            go = HelpFunEditor.InstantiatePrefab(GameObject.Find(UICreatorPathTools.mTestViewPath).gameObject,
                                                 AssetDatabase.LoadAssetAtPath <GameObject>(createPrefab)
                                                 );

            SetGameObject(go);
            EditorUtility.DisplayProgressBar("请稍候", "正在生成预制件", 0.9f);
        }
예제 #3
0
    /// <summary>
    /// project视图引用
    /// </summary>
    static void DrawProject(int index)
    {
        EditorGUILayout.BeginVertical("TextArea");
        EditorGUILayout.BeginHorizontal();
        EditorGUILayout.ObjectField("预制件:", mUsed[index], typeof(GameObject), false);
        EditorGUILayout.EndHorizontal();

        if (mProDic.ContainsKey(mUsed[index]))
        {
            for (int j = 0; j < mProDic[mUsed[index]].Count; j++)
            {
                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.LabelField("物体" + (j + 1).ToString() + ":", GUILayout.Width(145));
                if (GUILayout.Button(mProDic[mUsed[index]][j], GUILayout.Width(250)))
                {
                    GameObject go = FindByName(mUsed[index].name);
                    if (go == null)
                    {
                        go = HelpFunEditor.InstantiatePrefab(GameObject.Find("GameRoot/Game/UIRoot/UIWindowParent/Canvas/TestWindow").gameObject, mUsed[index] as GameObject);
                        go.transform.localScale    = Vector3.one;
                        go.transform.localPosition = Vector3.zero;
                        RectTransform rect = go.transform.GetComponent <RectTransform>();
                        //rect.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Left,0f,0f );
                        //rect.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Right, 0f, 0f);
                        //rect.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Bottom, 0f, 0f);
                        //rect.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Top, 0f, 0f);
                        rect.anchorMin = Vector2.zero;
                        rect.anchorMax = Vector2.one;
                        rect.pivot     = new Vector2(0.5f, 0.5f);
                        rect.offsetMax = Vector2.zero;
                        rect.offsetMin = Vector2.zero;
                    }
                    if (go == null)
                    {
                        Debug.LogError("无法定位该预制件!无法加载到Hierarchy!");
                        continue;
                    }
                    if (!mGo.ContainsKey(go))
                    {
                        mGo[go] = new List <GameObject>();
                    }
                }
                EditorGUILayout.EndHorizontal();
            }
        }
        EditorGUILayout.EndVertical();
        EditorGUILayout.Space();
    }
예제 #4
0
    static void MovePrefabToSceneMonsterParant()
    {
        HelpFunEditor.LoadGameRoot();
        GameObject[] obj = Selection.gameObjects;
        if (obj != null)
        {
            for (int i = 0; i < obj.Length; i++)
            {
                GameObject instantiatePrefab = HelpFunEditor.InstantiatePrefab(GameObject.Find("GameRoot/SceneRoot/Group/TableTest").gameObject, obj[i]);
                var        rectTrans         = instantiatePrefab.transform as RectTransform;
                if (rectTrans != null)
                {
                    rectTrans.anchoredPosition = Vector2.zero;
                    rectTrans.sizeDelta        = Vector2.zero;
                }
                else
                {
                    instantiatePrefab.transform.localPosition = new UnityEngine.Vector3(0, 0, 0);
                }

                Selection.activeGameObject = instantiatePrefab;
            }
        }
    }
예제 #5
0
        private static void DrawItem(ProvinceData config, int index)
        {
            EditorGUILayout.BeginVertical("TextArea", GUILayout.Width(500), GUILayout.Height(25));
            GUILayout.Space(10);
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("省份名:", GUILayout.Width(60));
            config.name = EditorGUILayout.TextField(config.name, GUILayout.Width(100));
            EditorGUILayout.LabelField("缩写名:", GUILayout.Width(50));
            config.shortName = EditorGUILayout.TextField(config.shortName, GUILayout.Width(100));
            EditorGUILayout.LabelField("游戏内名:", GUILayout.Width(50));
            config.gameName = EditorGUILayout.TextField(config.gameName, GUILayout.Width(100));
            EditorGUILayout.EndHorizontal();

            GUILayout.Space(10);
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("标签:", GUILayout.Width(60));
            config.popTag = (PopTagEnum)EditorGUILayout.EnumPopup(config.popTag, GUILayout.Width(100));
            EditorGUILayout.LabelField("是否开启:", GUILayout.Width(60));
            config.isOpen = EditorGUILayout.Toggle(config.isOpen);
            EditorGUILayout.LabelField("是否上线:", GUILayout.Width(50));
            config.isOnline = EditorGUILayout.Toggle(config.isOnline, GUILayout.Width(50));
            EditorGUILayout.EndHorizontal();

            GUILayout.Space(10);
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("AppName:", GUILayout.Width(60));
            config.appName = EditorGUILayout.TextField(config.appName, GUILayout.Width(100));

            EditorGUILayout.EndHorizontal();

            GUILayout.Space(10);
//				EditorGUILayout.BeginHorizontal();
//					EditorGUILayout.LabelField("附加字段:", GUILayout.Width(60));
//					config.tips = EditorGUILayout.TextField(config.tips,GUILayout.Width(100));
//					config.isOpenUrl = EditorGUILayout.Toggle(config.isOpenUrl,GUILayout.Width(20));
//					if(config.isOpenUrl)
//					{
//						config.openUrl = EditorGUILayout.TextField(config.openUrl,GUILayout.Width(234));
//					}
//				EditorGUILayout.EndHorizontal();

            Texture popObj  = null;
            Texture iconObj = null;

            GUILayout.Space(10);
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("按钮icon:", GUILayout.Width(60));
            EditorGUI.BeginDisabledGroup(true);
            config.btnIcon = EditorGUILayout.TextField(config.btnIcon, GUILayout.Width(300));
            EditorGUI.EndDisabledGroup();
            iconObj = AssetDatabase.LoadAssetAtPath <Texture>(config.btnIcon);
            iconObj = (Texture)EditorGUILayout.ObjectField(iconObj, typeof(Texture), true, GUILayout.Width(120));
            if (iconObj != null)
            {
                config.btnIcon = AssetDatabase.GetAssetPath(iconObj);
            }
            EditorGUILayout.EndHorizontal();

            GUILayout.Space(10);
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("气泡Icon:", GUILayout.Width(60));
            EditorGUI.BeginDisabledGroup(true);
            config.popIcon = EditorGUILayout.TextField(config.popIcon, GUILayout.Width(300));
            EditorGUI.EndDisabledGroup();
            popObj = AssetDatabase.LoadAssetAtPath <Texture>(config.popIcon);
            popObj = (Texture)EditorGUILayout.ObjectField(popObj, typeof(Texture), true, GUILayout.Width(120));
            if (popObj != null)
            {
                config.popIcon = AssetDatabase.GetAssetPath(popObj);
            }
            EditorGUILayout.EndHorizontal();

            GUILayout.Space(10);
            EditorGUILayout.BeginHorizontal();
            if (GUILayout.Button("编辑省内玩法"))
            {
                //popObj == null || iconObj == null ||
                if (config.name == "新增的省份" || config.shortName == "新省" || config.gameName == "NewProvince")
                {
                    EditorUtility.DisplayDialog("错误", "需要完成按钮图片、省份名、缩略名,游戏名设置!", "确定");
                }
                else
                {
                    PlayModeTools.curProvince = index;
                }
            }

            if (popObj != null && iconObj != null)
            {
                if (GUILayout.Button("编辑省份按钮"))
                {
                    GameObject go = GameObject.Find("Public_WindowSetProvince");
                    if (go == null)
                    {
                        go = HelpFunEditor.InstantiatePrefab(GameObject.Find("GameRoot/Game/UIRoot/UIWindowParent/Canvas/TestWindow").gameObject,
                                                             AssetDatabase.LoadAssetAtPath <GameObject>("Assets/Game/PackagingResources/Public/Module/SetProvincePublic_WindowSetProvince.prefab")
                                                             );

                        go.transform.localScale    = Vector3.one;
                        go.transform.localPosition = Vector3.zero;
                        RectTransform rect = go.transform.GetComponent <RectTransform>();
                        rect.anchorMin = Vector2.zero;
                        rect.anchorMax = Vector2.one;
                        rect.pivot     = new Vector2(0.5f, 0.5f);
                        rect.offsetMax = Vector2.zero;
                        rect.offsetMin = Vector2.zero;
                    }

                    GameObject btnPrefab     = go.transform.Find("Center/Scroll View/Viewport/Content/Item/btnPrefab").gameObject;
                    string     editorBtnName = "btn" + config.gameName;
                    Transform  clone         = btnPrefab.transform.parent.Find(editorBtnName);
                    Transform  createBtn     = null;
                    if (clone == null)
                    {
                        clone               = GameObject.Instantiate(btnPrefab).transform;
                        clone.parent        = btnPrefab.transform.parent;
                        clone.localScale    = btnPrefab.transform.localScale;
                        clone.localPosition = btnPrefab.transform.localPosition;
                        clone.SetSiblingIndex(config.key);
                        clone.name     = editorBtnName;
                        createBtn      = clone.Find("btnPrefab").transform;
                        createBtn.name = clone.name;
                    }
                    createBtn = clone.Find(clone.name);


                    Image btnImg = createBtn.GetComponent <Image>();
                    btnImg.sprite = AssetDatabase.LoadAssetAtPath <Sprite>(config.btnIcon);
                    btnImg.SetNativeSize();

                    Image popImg = clone.Find("Pop").GetComponent <Image>();
                    popImg.sprite = AssetDatabase.LoadAssetAtPath <Sprite>(config.popIcon);
                    popImg.SetNativeSize();

                    Text    nameTxt = clone.Find("Pop/Text").GetComponent <Text>();
                    Outline outLine = nameTxt.transform.GetComponent <Outline>();
                    nameTxt.text        = config.shortName;
                    outLine.effectColor = popObj.name.Contains("蓝") ? outLineColors[0]: popObj.name.Contains("橘") ? outLineColors[1] :popObj.name.Contains("兰") ? outLineColors[3]:outLineColors[2];

                    clone.gameObject.SetActive(true);

                    Selection.activeGameObject = clone.gameObject;
                }
            }
            EditorGUILayout.EndHorizontal();



            EditorGUILayout.EndVertical();
        }