// =================================================================== // CODE GENERATION FUNCTIONS // ------------------------------------------------------------------- /// Generate the code for a function definition. /// /// @param indentSize The indentation of the function. /// @return The generated code for the given function. /// public override string GenerateHeader(int indentSize) { var result = new StringBuilder(1024); result.Append(base.GenerateHeader(indentSize)); // Build components var indent = ToIndent(indentSize + 1); VSObject.ForEachChildPort( p => { if (p.PortIndex < (int)iCS_PortIndex.ParametersEnd) { if (p.IsInProposedDataPort && iCS_Types.IsA <Component>(p.RuntimeType)) { result.Append(indent); result.Append("var "); result.Append(GetLocalVariableName(p)); result.Append("= GetComponent<"); result.Append(ToTypeName(p.RuntimeType)); result.Append(">();\n"); } } } ); return(result.ToString()); }
// ------------------------------------------------------------------- /// Scan the input ports to create special local variables. void CreateLocalVariables() { VSObject.ForEachChildPort( p => { if (p.PortIndex < (int)iCS_PortIndex.ParametersEnd) { if (p.IsInProposedDataPort && iCS_Types.IsA <Component>(p.RuntimeType)) { new LocalVariableDefinition(p, this); } } } ); }
// ------------------------------------------------------------------- /// Build information for parameters. void BuildParameterInformation() { var parameters = GetParameters(VSObject); var pLen = parameters.Length; myParameters = new CodeBase[pLen]; foreach (var p in parameters) { int idx = p.PortIndex; if (idx >= parameters.Length) { VSObject.ForEachChildPort( dp => { Debug.Log("Index: " + dp.PortIndex + " => " + dp.FullName); } ); } if (p.IsInputPort) { var producerPort = GraphInfo.GetProducerPort(p); if (producerPort != null && producerPort != p) { myParameters[idx] = new FunctionCallParameterDefinition(p, this, p.RuntimeType); } else { // Generate class variable for UnityEngine.Objects var portType = p.RuntimeType; if (iCS_Types.IsA <UnityEngine.Object>(portType)) { myParameters[idx] = new FunctionCallParameterDefinition(p, this, p.RuntimeType); var typeDef = GetClassDefinition(); var v = new VariableDefinition(p, typeDef, AccessSpecifier.Public, ScopeSpecifier.NonStatic); typeDef.AddVariable(v); } else { myParameters[idx] = new ConstantDefinition(p, this); } } } else { myParameters[idx] = new FunctionCallOutParameterDefinition(p, this); } } }