Example #1
0
 /// <summary>
 /// 直接读取一个脚本
 /// </summary>
 private void TryLoadSingleScript(MonoScript script, List <MonoScript> scriptList)
 {
     if (RefineUtility.IsMonoBehaiverOrScriptObjectRuntime(script))
     {
         scriptList.Add(script);
     }
 }
Example #2
0
        /// <summary>
        /// 将scriptObject用到的脚本读取到列表中
        /// </summary>
        private void TryLoadFromScriptObject(ScriptableObject scriptObj, List <MonoScript> scriptList)
        {
            var mono = MonoScript.FromScriptableObject(scriptObj);

            if (RefineUtility.IsMonoBehaiverOrScriptObjectRuntime(mono))
            {
                scriptList.Add(mono);
            }
        }
Example #3
0
        /// <summary>
        /// 生成worp脚本
        /// </summary>
        private void ExportWorpScripts()
        {
            var oldPath = PlayerPrefs.GetString(preferPath);
            var folder  = EditorUtility.SaveFolderPanel("选择导出路径", oldPath, "");

            if (!string.IsNullOrEmpty(folder))
            {
                PlayerPrefs.SetString(preferPath, folder);
                RefineUtility.ExportScripts(folder, refineObj.refineList);
            }
        }
Example #4
0
        internal void Update(Type type)
        {
            this.name     = type.Name;
            this.type     = type.ToString();
            this.assemble = type.Assembly.ToString();
            if (type.BaseType != null)
            {
                this.baseType = type.BaseType.ToString();
            }
            arguments = new List <Argument>();
            RefineUtility.AnalysisArguments(type, arguments);
            attributes = new List <AttributeInfo>();
            var atts = type.GetCustomAttributes(false);

            RefineUtility.AnalysisAttributes(atts, attributes);
        }
Example #5
0
 private void DrawMatchField()
 {
     EditorGUI.BeginChangeCheck();
     match = EditorGUILayout.TextField(match, EditorStyles.textField);
     if (EditorGUI.EndChangeCheck() && !string.IsNullOrEmpty(match))
     {
         refineListProp_w.ClearArray();
         for (int i = 0; i < refineListProp.arraySize; i++)
         {
             var prop = refineListProp.GetArrayElementAtIndex(i);
             if (prop.FindPropertyRelative("type").stringValue.ToLower().Contains(match.ToLower()))
             {
                 refineListProp_w.InsertArrayElementAtIndex(0);
                 RefineUtility.CopyPropertyValue(refineListProp_w.GetArrayElementAtIndex(0), prop);
             }
         }
     }
 }
Example #6
0
        /// <summary>
        /// 从预制体身上加载脚本
        /// </summary>
        /// <param name="trans"></param>
        /// <param name="types"></param>
        private void TryLoadScriptsFromPrefab(GameObject go, List <MonoScript> behaivers)
        {
            if (go == null)
            {
                return;
            }
            var trans    = go.transform;
            var behaiver = trans.GetComponents <MonoBehaviour>();

            if (behaiver != null)
            {
                //var monos = new MonoScript[behaiver.Length];
                var monos = new List <MonoScript>();
                for (int i = 0; i < behaiver.Length; i++)
                {
                    if (behaiver[i] == null)
                    {
                        Debug.Log(trans.name + ":scriptMissing", go);
                    }
                    else
                    {
                        var mono = MonoScript.FromMonoBehaviour(behaiver[i]);
                        if (RefineUtility.IsMonoBehaiverOrScriptObjectRuntime(mono))
                        {
                            monos.Add(mono);
                        }
                    }
                }
                behaivers.AddRange(monos);
            }
            if (trans.childCount == 0)
            {
                return;
            }
            else
            {
                for (int i = 0; i < trans.childCount; i++)
                {
                    var childTrans = trans.GetChild(i);
                    TryLoadScriptsFromPrefab(childTrans.gameObject, behaivers);
                }
            }
        }
        internal static void ExportScripts(string path, List <RefineItem> refineList)
        {
            for (int i = 0; i < refineList.Count; i++)
            {
                var item = refineList[i];
                if (item.type.Contains("+"))
                {
                    continue;
                }
                string typeName = item.type;
                if (item.type.Contains("`"))
                {
                    var count = int.Parse(typeName.Substring(typeName.IndexOf('`') + 1, 1));
                    typeName = typeName.Remove(typeName.IndexOf('`')) + count.ToString();
                }
                var scriptPath = path + "\\" + typeName.Replace(".", "\\") + ".cs";
                var dir        = System.IO.Path.GetDirectoryName(scriptPath);
                if (!Directory.Exists(dir))
                {
                    Directory.CreateDirectory(dir);
                }
                var metaPath = scriptPath + ".meta";
                var type     = Assembly.Load(item.assemble).GetType(item.type);
                if (type == null)
                {
                    type = Type.GetType(item.type);
                }
                if (type == null)
                {
                    Debug.Log(item.type + ":empty");
                    continue;
                }

                var newScript = RefineUtility.GenerateNewScirpt(type, item.attributes, item.arguments, refineList);
                System.IO.File.WriteAllText(scriptPath, newScript);
                if (!string.IsNullOrEmpty(item.metaFilePath))
                {
                    var metaFile = System.IO.File.ReadAllText(item.metaFilePath);
                    System.IO.File.WriteAllText(metaPath, metaFile);
                }
            }
        }
Example #8
0
        private void LoopInsertItem(RefineItem item, List <RefineItem> refineList)
        {
            //遍历参数
            foreach (var arg in item.arguments)
            {
                if (!string.IsNullOrEmpty(arg.subType))
                {
                    var type = Assembly.Load(arg.subAssemble).GetType(arg.subType);

                    if (type == null)
                    {
                        continue;
                    }

                    if (type.IsGenericType)
                    {
                        type = type.GetGenericArguments()[0];
                    }
                    else if (type.IsArray)
                    {
                        type = type.GetElementType();
                    }

                    if (RefineUtility.IsInternalScript(type))
                    {
                        continue;
                    }
                    if (IsIgnored(type))
                    {
                        continue;
                    }

                    var old = refineObj.refineList.Find(x => x.type == type.ToString());
                    if (old == null)
                    {
                        var refineItem = new RefineItem(type);
                        refineObj.refineList.Add(refineItem);
                        LoopInsertItem(refineItem, refineList);
                    }
                    else
                    {
                        old.Update(type);
                    }
                }
            }

            var currentType = Assembly.Load(item.assemble).GetType(item.type);

            if (currentType == null)
            {
                currentType = Type.GetType(item.type);
            }
            if (currentType == null)
            {
                Debug.Log(item.type + ": load empty");
                return;
            }

            //遍历泛型类
            if (currentType.IsGenericType)
            {
                var gtypes = currentType.GetGenericArguments();
                foreach (var gtype in gtypes)
                {
                    if (RefineUtility.IsInternalScript(gtype))
                    {
                        continue;
                    }
                    if (IsIgnored(gtype))
                    {
                        continue;
                    }

                    var old = refineObj.refineList.Find(x => x.type == gtype.ToString());
                    if (old == null)
                    {
                        var refineItem = new RefineItem(gtype);
                        refineObj.refineList.Add(refineItem);
                        LoopInsertItem(refineItem, refineObj.refineList);
                    }
                    else
                    {
                        old.Update(gtype);
                    }
                }
            }

            //遍历类父级
            while (currentType != null && currentType.BaseType != null)
            {
                currentType = currentType.BaseType;

                if (RefineUtility.IsInternalScript(currentType))
                {
                    continue;
                }
                if (IsIgnored(currentType))
                {
                    continue;
                }

                var old = refineObj.refineList.Find(x => x.type == currentType.ToString());
                if (old == null)
                {
                    var refineItem = new RefineItem(currentType);
                    refineObj.refineList.Add(refineItem);
                    LoopInsertItem(refineItem, refineObj.refineList);
                }
                else
                {
                    old.Update(currentType);
                }
            }
        }