string desc(RTSPluginAttribute cmd) { string sc; if (!string.IsNullOrEmpty(cmd.Define)) { sc = cmd.Define; } else { sc = cmd.Name + '('; if (cmd.ArgCount >= 0) { for (int i = 0; i < cmd.ArgCount; i++) { if (i > 0) { sc += ','; } sc += ' '; sc += (char)('a' + i); } } else { sc += " a..."; } sc += " )"; } if (!string.IsNullOrEmpty(cmd.Doc)) { sc += "\n\t" + cmd.Doc; } return(sc); }
public void LoadFunction(object target) { #if UNITY_EDITOR if (target == null) { return; } System.Type tp = target.GetType(); HashSet <RTSPluginAttribute> sets = new HashSet <RTSPluginAttribute>(); mFunctions[tp] = sets; MethodInfo[] methods = tp.GetMethods(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static); //bool first = true; for (int i = 0; i < methods.Length; i++) { try { object[] cmds = methods[i].GetCustomAttributes(typeof(RTSPluginAttribute), true); if (cmds.Length > 0) { RTSPluginAttribute cmd = cmds[0] as RTSPluginAttribute; if (!RTSUtil.isGoodName(cmd.Name)) { continue; } RTSPluginDelegate func = (RTSPluginDelegate)System.Delegate.CreateDelegate(typeof(RTSPluginDelegate), target, methods[i].Name); RTSPluginFunc f = new RTSPluginFunc(null, func, cmd.ArgCount); if (cmd.IsCmd) { AddCommand(cmd.Name, f); } else { AddFunction(cmd.Name, f); } //Debug.LogFormat("Load Function: {0}" , desc(cmd)); if (!string.IsNullOrEmpty(cmd.Doc)) { sets.Add(cmd); } } } catch (System.Exception e) { PutLog(Level.error, e.ToString()); Debug.LogException(e); } } #endif }
object mk_doc(object[] args) { RTSPluginAttribute att = new RTSPluginAttribute(); if (args[0] != null) { att.Name = args[0].ToString(); } if (args[1] != null) { att.Define = args[1].ToString(); } if (args[2] != null) { att.Doc = args[2].ToString(); } if (!string.IsNullOrEmpty(att.Name) && !string.IsNullOrEmpty(att.Doc)) { mCustomDocs[att.Name] = att; } return(RTSVoid.VOID); }