【unity】使用编辑器代码修改预设





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");
    }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值