Example #1
0
        public Transform GetSkeleton(string name)
        {
            if (_skeletonCache.ContainsKey(name))
            {
                return(_skeletonCache[name]);
            }

            if (CacheTransform == null)
            {
                return(null);
            }

            var trans = CacheTransform.GetComponentsInChildren <Transform>(true);

            for (int i = 0; i < trans.Length; i++)
            {
                var node = trans[i];
                if (node.name == name)
                {
                    _skeletonCache.Add(name, node);
                    return(node);
                }
            }
            _skeletonCache.Add(name, null);
            return(null);
        }
Example #2
0
 public void CacheAll()
 {
     properties.Clear();
     Transform[] children = CacheTransform.GetComponentsInChildren <Transform>(true);
     for (int i = 0; i < children.Length; i++)
     {
         var childTransform = children[i];
         if (childTransform != null)
         {
             var childName = childTransform.name;
             if (childName.StartsWith("Q_"))
             {
                 var property = new Property();
                 property.Name       = childName;
                 property.GameObject = childTransform.gameObject;
                 var components = new List <Component>();
                 for (int j = 0; j < serializeComponents.Count; j++)
                 {
                     var component = childTransform.GetComponent(serializeComponents[j]);
                     if (component != null)
                     {
                         components.Add(component);
                     }
                 }
                 property.Components = components;
                 properties.Add(property);
             }
         }
     }
 }
Example #3
0
        public void GenerateCodeEditor()
        {
            transformGroup.Clear();
            Transform[] children = CacheTransform.GetComponentsInChildren <Transform>(true);
            for (int i = 0; i < children.Length; i++)
            {
                Transform child    = children[i];
                string    fullName = child.name;
                string[]  tmpName  = fullName.Split('_');
                if (tmpName.Length > 1)
                {
                    Type type;
                    if (name_type.TryGetValue(tmpName[0], out type))
                    {
                        transformGroup.Add(child, type);
                    }
                }
            }

            //读取
            StreamReader streamReader = new StreamReader(UI_TEMPLATE_PATH, Encoding.UTF8);
            string       ClassText    = streamReader.ReadToEnd();

            streamReader.Close();

            //生成
            UIBase       uIBase       = GetComponent <UIBase>();
            string       uiBasePath   = StringUtility.Format(Application.dataPath + "/Lemon/Scripts/UI/{0}/{1}_Generate.cs", uIBase.name, uIBase.name);
            StreamWriter streamWriter = new StreamWriter(uiBasePath, false, Encoding.UTF8);

            //添加自动化的变量
            StringBuilder stringBuilder = StringUtility.GetStringBuilder();

            stringBuilder.Append("\n");
            Dictionary <Transform, Type> .Enumerator enumerator = transformGroup.GetEnumerator();
            while (enumerator.MoveNext())
            {
                string name = enumerator.Current.Key.name;
                Type   type = enumerator.Current.Value;
                stringBuilder.Append("        public " + type.Name + " " + name + "; ");
                stringBuilder.Append("\n");
            }

            ClassText = ClassText.Replace("UITemplate", uIBase.name);
            ClassText = ClassText.Replace(KEY_VARIABLE, KEY_VARIABLE + stringBuilder.ToString());

            //添加自动化的变量路径
            stringBuilder = StringUtility.GetStringBuilder();
            stringBuilder.Append("\n");
            enumerator = transformGroup.GetEnumerator();
            while (enumerator.MoveNext())
            {
                Transform childTransform = enumerator.Current.Key;
                Type      type           = enumerator.Current.Value;
                stringBuilder.Append("            " + childTransform.name + " = " + "CacheTransform.Find(\"" + UtilityEditor.GetPath(childTransform, CacheTransform) + "\").GetComponent<" + type.Name + ">();\n");
            }

            ClassText = ClassText.Replace(KEY_PATH, KEY_PATH + stringBuilder.ToString());

            streamWriter.Write(ClassText);
            streamWriter.Close();

            UnityEditor.AssetDatabase.Refresh();
        }