using UnityEngine;
using UnityEditor;
using System.IO;
using System.Collections.Generic;
using System;
using Assets.Plugins.Scripts.Util;
public class CListMaskEditor : MonoBehaviour
{
// [MenuItem("MC/CListMaskHandle(Don't click! Don't click! Don't click!)")]
static void SecondPanelHandle()
{
string uiDirPath = Application.dataPath + "/OriginalResource/UI/";
foreach (string path in Directory.GetDirectories(uiDirPath))
{
string modulePath = path.Substring(path.IndexOf("Assets", StringComparison.Ordinal));
if (path.Contains("/Textures")) //独立贴图
{
}
else// if(path.Contains("MingUI")) //模块
{
Debug.Log(modulePath);
string[] assets = Directory.GetFiles(modulePath + "/Prefabs/");
foreach (string asset in assets)
{
GameObject go = AssetDatabase.LoadAssetAtPath<GameObject>(asset);
if (go != null)
{
GameObject obj = GameObject.Instantiate(go) as GameObject;
//找到需要的obj
CList[] cLists = obj.GetComponentsInChildren<CList>();
if (cLists != null)
{
foreach (CList clist in cLists)
{
//增加一个CSprite
CSprite maskCS = ComponentUtil.CreateCSprite(clist.gameObject, "maskCS", true);
maskCS.Path = "Widget.bg_mask2";
//设置大小和位置
//设置轴点和锚点
maskCS.rectTransform.anchorMax = new Vector2(1, 0);
maskCS.rectTransform.anchorMin = new Vector2(0, 0);
maskCS.rectTransform.pivot = new Vector2(0.5f, 0.5f);
//设置高度
maskCS.rectTransform.sizeDelta = new Vector2(0.0f, 40.0f);
//设置位置
maskCS.rectTransform.anchoredPosition = new Vector2(0, 20);
//替换目标预设
PrefabUtility.ReplacePrefab(obj, go, ReplacePrefabOptions.ReplaceNameBased);
}
//销毁实例化的obj
GameObject.DestroyImmediate(obj);
}
}
}
}
}
//保存修改和刷新
AssetDatabase.SaveAssets();
AssetDatabase.Refresh();
Debug.Log("Done");
}
}
【unity】使用编辑器代码修改预设
最新推荐文章于 2021-03-12 11:52:51 发布