zoukankan      html  css  js  c++  java
  • 批量处理Prefab

     
    using UnityEngine;
    using UnityEditor;
    using System;
    using System.Collections;
    using System.Collections.Generic;
    
    using Object = UnityEngine.Object;
    using System.IO;
    
    public class AddItemEffect {
    
        [ExecuteInEditMode]
        [MenuItem("Tools/AddItemEffect")]
        private static void RecordPointAddFlame() {
            GameObject itemPrefab = AssetDatabase.LoadAssetAtPath("Assets/Configs/Resources/NewUI/@Plugin/item_base_new.prefab", typeof(GameObject)) as GameObject;
            GameObject itembase = PrefabUtility.InstantiatePrefab(itemPrefab) as GameObject;
            itembase.SetActive(true);
            Transform effect = itembase.transform.FindChild("Icon1@Quality/IconEffect@");
    
            string[] ids = AssetDatabase.FindAssets("t:Prefab", new string[] { "Assets/Configs/Resources/NewUI" });
            for (int i = 0; i < ids.Length; i++) {
                string path = AssetDatabase.GUIDToAssetPath(ids[i]);
                Debug.Log(path);
                if (path.Contains("item_base_new.prefab")) {
                    continue;
                }
                GameObject originPrefab = AssetDatabase.LoadAssetAtPath(path, typeof(GameObject)) as GameObject;
                GameObject prefabClone = PrefabUtility.InstantiatePrefab(originPrefab) as GameObject;
    
                Transform[] allChild = prefabClone.GetComponentsInChildren<Transform>(true);
                bool isChange = false;
                foreach (Transform item in allChild) {
                    if (item.name.Contains("Icon1@")) {
                        if (item.FindChild("IconEffect@") == null) {
                            isChange = true;
                            GameObject go = GameObject.Instantiate(effect.gameObject) as GameObject;
                            go.transform.parent = item;
                            go.transform.localPosition = Vector3.zero;
                            go.transform.localScale = Vector3.one;
                            go.transform.localRotation = Quaternion.identity;
                            go.name = "IconEffect@";
                            UISprite spriteChild = go.GetComponent<UISprite>();
                            UISprite spriteParent = item.GetComponent<UISprite>();
                            spriteChild.width = spriteParent.width * 120 / 92;
                            spriteChild.height = spriteParent.height * 120 / 92;
                            spriteChild.depth = spriteParent.depth + 3;
                        }
                    }
                }
                if (isChange) {
                    PrefabUtility.ReplacePrefab(prefabClone, originPrefab, ReplacePrefabOptions.Default);
                }
                MonoBehaviour.DestroyImmediate(prefabClone);
            }
    
            AssetDatabase.SaveAssets();
            EditorUtility.DisplayDialog("成功", "AddItemEffect完成!", "确定");
            Debug.Log("Done");
        }
        [ExecuteInEditMode]
        [MenuItem("Tools/RemoveItemEffect")]
        private static void RemoveItemEffect() {
    
            string[] ids = AssetDatabase.FindAssets("t:Prefab", new string[] { "Assets/Configs/Resources/NewUI" });
            for (int i = 0; i < ids.Length; i++) {
                string path = AssetDatabase.GUIDToAssetPath(ids[i]);
                Debug.Log(path);
                if (path.Contains("item_base_new.prefab")) {
                    continue;
                }
                GameObject originPrefab = AssetDatabase.LoadAssetAtPath(path, typeof(GameObject)) as GameObject;
                GameObject prefabClone = PrefabUtility.InstantiatePrefab(originPrefab) as GameObject;
    
                Transform[] allChild = prefabClone.GetComponentsInChildren<Transform>(true);
                bool isChange = false;
                for (int m = allChild.Length-1;m>-1;m--) {
                    if (allChild[m].name.Contains("Icon1@")) {
                        Transform ts = allChild[m].FindChild("IconEffect@");
                        if (ts != null) {
                            isChange = true;
                            MonoBehaviour.DestroyImmediate(ts.gameObject);
                        }
                    }
                }
                if (isChange) {
                    PrefabUtility.ReplacePrefab(prefabClone, originPrefab, ReplacePrefabOptions.Default);
                }
                MonoBehaviour.DestroyImmediate(prefabClone);
            }
    
            AssetDatabase.SaveAssets();
            EditorUtility.DisplayDialog("成功", "RemoveItemEffect完成!", "确定");
            Debug.Log("Done");
        }
    }
    
    
    
    
    

    查找指定文件下,所有prefab,在所有的名字中含有Icon1&&字符串的子物体下,添加一张图片

    参考自:http://www.cnblogs.com/klkucan/p/4934518.html

  • 相关阅读:
    什么是一阶矩和二阶矩?
    [Pytorch]基于混和精度的模型加速
    Pytorch: 命名实体识别: BertForTokenClassification/pytorch-crf
    ipykernel_launcher.py: error: unrecognized arguments: -f /Users/apple/Library/Jupyter/runtime/kernel
    pytorch中查看gpu信息
    NLP突破性成果 BERT 模型详细解读 bert参数微调
    os.environ["CUDA_DEVICE_ORDER"] = "PCI_BUS_ID" os.environ["CUDA_VISIBLE_DEVICES"] = "0"
    禁用gpu首选
    Tensorflow中tf.ConfigProto()详解
    python命令之m参数 局域网传输
  • 原文地址:https://www.cnblogs.com/kuluodisi/p/7857228.html
Copyright © 2011-2022 走看看