/// <summary> /// Create a block from block definitions /// </summary> /// <param name="workspace">The Block's workspace</param> /// <param name="type">block unique type</param> /// <param name="uid">block uid</param> /// <returns></returns> public Block CreateBlock(Workspace workspace, string type, string uid = null) { Block block = new Block(workspace, type, uid); BlockDefinition definition; if (!mDefinitions.TryGetValue(type, out definition)) { //Debug.LogWarning("There is no block definition for type: " + type + ". Please ensure to load it first"); Debug.Log("Create an empty block: " + type); } else { List <Input> inputs = definition.CreateInputList(); Connection output = definition.CreateOutputConnection(); Connection prev = definition.CreatePreviousStatementConnection(); Connection next = definition.CreateNextStatementConnection(); Mutator mutator = definition.CreateMutator(); bool inputsInline = definition.GetInputsInlineDefault(); block.Reshape(inputs, output, prev, next); if (mutator != null) { block.SetMutator(mutator); } if (inputsInline) { block.SetInputsInline(true); } } return(block); }
/// <summary> /// Sets the mutator for this block. Called from BlockFractory, and can only be called once (for now). /// </summary> public void SetMutator(Mutator mutator) { if (this.Mutator != null) { throw new Exception("Cannot change mutators on a block."); } this.Mutator = mutator; mutator.AttachToBlock(this); }
/// <summary> /// mutator factory method /// </summary> public static Mutator Create(string mutatorId) { if (mMutatorDict == null) { mMutatorDict = new Dictionary <string, Type>(); Assembly assem = Assembly.GetAssembly(typeof(Field)); foreach (Type type in assem.GetTypes()) { if (type.IsSubclassOf(typeof(Mutator))) { var attrs = type.GetCustomAttributes(typeof(MutatorClassAttribute), false); if (attrs.Length > 0) { string mutatorIdStr = ((MutatorClassAttribute)attrs[0]).MutatorId; string[] strs = mutatorIdStr.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries); for (int i = 0; i < strs.Length; i++) { mMutatorDict[strs[i]] = type; } } } } } Type mutatorType; if (!mMutatorDict.TryGetValue(mutatorId, out mutatorType)) { throw new Exception(string.Format( "There is no class implementation defined for mutator id: \"{0}\", or you might forget to add a \"MutatorClassAttribute\" to the class.", mutatorId)); } Mutator mutator = Activator.CreateInstance(mutatorType) as Mutator; mutator.MutatorId = mutatorId; return(mutator); }
public MemorySafeMutatorObserver(Mutator mutatorRef) { mMutatorRef = mutatorRef; }