Exemplo n.º 1
0
        private void GetBindingInfo()
        {
            GScriptInfo so;

            if (FileHelper.IsExists(GConfigure.InfoPath))
            {
                so = AssetDatabase.LoadAssetAtPath <GScriptInfo>(GConfigure.InfoPath);
            }
            else
            {
                so = ScriptableObject.CreateInstance <GScriptInfo>();
            }

            if (so == null)
            {
                return;
            }

            List <GScriptInfo.FieldInfo> fieldInfos = new List <GScriptInfo.FieldInfo>();

            foreach (var key in dic.Keys)
            {
                var target = dic[key];
                if (target.state.isVariable)
                {
                    GScriptInfo.FieldInfo info = new GScriptInfo.FieldInfo();
                    info.path = GGlobalFun.GetGameObjectPath(key, GConfigure.selectTransform);
                    info.mainAttrInfo.name    = target.state.attributeName;
                    info.mainAttrInfo.type    = target.type.ToString();
                    info.mainAttrInfo.isAttr  = target.state.isAttribute;
                    info.mainAttrInfo.isEvent = target.state.isEvent;

                    var subStates = target.state.LstSubState;
                    info.subField = new List <GScriptInfo.FieldAttrInfo>();
                    for (int i = 0; i < subStates.Count; i++)
                    {
                        GScriptInfo.FieldAttrInfo subInfo = new GScriptInfo.FieldAttrInfo();
                        subInfo.name    = subStates[i].attributeName;
                        subInfo.type    = subStates[i].Model.type.ToString();
                        subInfo.isAttr  = subStates[i].isAttribute;
                        subInfo.isEvent = subStates[i].isEvent;
                        info.subField.Add(subInfo);
                    }
                    fieldInfos.Add(info);
                }
            }

            var infos = fieldInfos.ToArray();

            so.SetClassInfo(GConfigure.MainFileName, GConfigure.Version, infos);

            if (FileHelper.IsExists(GConfigure.InfoPath))
            {
                AssetDatabase.SaveAssets();
            }
            else
            {
                if (FileHelper.IsDirctoryName(GConfigure.InfoPath, true))
                {
                    AssetDatabase.CreateAsset(so, GConfigure.InfoPath);
                }
            }

            EditorUtility.SetDirty(so);
        }
Exemplo n.º 2
0
 private void BindAttributeByInfo(System.Type type, Transform root, Component target, GScriptInfo.FieldInfo fieldInfo, GScriptInfo.FieldAttrInfo attrInfo)
 {
     if (attrInfo.type == "GameObject")
     {
         type.InvokeMember("m_" + attrInfo.name,
                           BindingFlags.SetField |
                           BindingFlags.Instance |
                           BindingFlags.NonPublic,
                           null, target, new object[] { root.Find(fieldInfo.path).gameObject }, null, null, null);
     }
     else
     {
         type.InvokeMember("m_" + attrInfo.name,
                           BindingFlags.SetField |
                           BindingFlags.Instance |
                           BindingFlags.NonPublic,
                           null, target, new object[] { root.Find(fieldInfo.path).GetComponent(attrInfo.type) }, null, null, null);
     }
 }