Ejemplo n.º 1
0
        public static void Save(string guid, ClassMacro target, string code)
        {
            var path      = AssetDatabase.GUIDToAssetPath(guid);
            var finalPath = path.Remove(path.LastIndexOf("/") + 1, path.Length - path.LastIndexOf("/") - 1);

            code.Save().Custom(finalPath, target.title + ".cs").Text();
        }
Ejemplo n.º 2
0
 public void Define(ClassMacro instance, string title)
 {
     foreach (Method method in custom)
     {
         New(instance, method.name, AccessModifier.Public, MethodModifier.None, method.returnType, new ParameterDeclaration[] { });
     }
 }
Ejemplo n.º 3
0
        internal void Set(ClassMacro macro, string name, object value)
        {
            if (variables.ContainsKey(name))
            {
                variables[name] = value;
                return;
            }

            if (macro.variables.Has(name))
            {
                variables.Add(name, value);
            }
        }
Ejemplo n.º 4
0
        internal object Get(ClassMacro macro, string name)
        {
            if (variables.ContainsKey(name))
            {
                return(variables[name]);
            }

            if (macro.variables.Has(name))
            {
                variables.Add(name, macro.variables.Get(name));
                return(variables[name]);
            }

            throw new NullReferenceException("The class '" + macro.title + "' does not contain the a variable named '" + name + "'.");
        }
Ejemplo n.º 5
0
 public override void Initialize()
 {
     Images.Cache();
     _target   = metadata.value as ClassMacro;
     generator = ClassMacroGenerator.GetDecorator(_target);
 }
Ejemplo n.º 6
0
        public Method New(ClassMacro instance, string name, AccessModifier scope, MethodModifier modifier, Type returnType, ParameterDeclaration[] parameters, bool isMagic = false)
        {
            var    asset   = GetRootAsset(instance);
            Method _method = null;

            if (modifier == MethodModifier.Override || modifier == MethodModifier.None && isMagic)
            {
                return(Override());
            }

            return(Custom());

            Method Override()
            {
                asset.Is().NotNull(() =>
                {
                    _method = overrides.Define(previousOverrides, name,
                                               (method) =>
                    {
                        _method      = CreateNest(out addedMethod);
                        _method.name = name;
                        SetNestEntryParameters(_method, parameters);
                        DefineNestMacro(name, _method);
                        Add(_method);
                        AssetDatabase.AddObjectToAsset(_method.macro, asset);
                        addedMethod = true;
                        return(_method);
                    },
                                               (method) =>
                    {
                        EnsureParametersMatch(name, parameters);
                        addedMethod = true;
                        SetOverrideMethod(name);
                        _method = method;
                    });
                });

                if (_method != null)
                {
                    _method.scope               = scope;
                    _method.modifier            = modifier;
                    _method.returnType          = returnType;
                    _method.isSpecial           = isMagic;
                    _method.hasOptionalOverride = true;

                    if (_method.macro.entry.returnType != returnType)
                    {
                        _method.macro.entry.returnType = returnType;
                        _method.macro.entry.DefineReturns();
                    }

                    _method.macro.hideFlags = HideFlags.HideInHierarchy;
                }

                return(_method);
            }

            Method Custom()
            {
                if (_method != null)
                {
                    _method.scope      = scope;
                    _method.modifier   = modifier;
                    _method.returnType = returnType;
                    _method.name       = name;
                    _method.isSpecial  = false;

                    if (_method.macro.entry.returnType != returnType)
                    {
                        _method.macro.entry.returnType = returnType;
                    }

                    _method.macro.hideFlags = HideFlags.HideInHierarchy;

                    _method.macro.entry.Define();
                }

                return(_method);
            }

            Method CreateNest(out bool nestAdded)
            {
                var nest = new Method();

                nest.Initialize();
                nestAdded = true;
                return(nest);
            }
        }
Ejemplo n.º 7
0
 private TypeMacro GetRootAsset(ClassMacro instance)
 {
     return(AssetDatabase.LoadAssetAtPath <TypeMacro>(AssetDatabase.GUIDToAssetPath(HUMAssets.GetGUID(instance))));
 }
Ejemplo n.º 8
0
 public static ClassMacro GetClass(ref ClassMacro macro, string GUID)
 {
     macro = macro ?? AssetDatabase.LoadAssetAtPath <ClassMacro>(AssetDatabase.GUIDToAssetPath(GUID));
     return(macro);
 }
Ejemplo n.º 9
0
 internal T Get <T>(ClassMacro macro, string name)
 {
     return((T)Get(macro, name));
 }