private bool GetIsProperBlockDefinitionType(Type parameterType, BlockDefinitionAttribute.BlockDefinitionType blockDefinitionType) { switch (blockDefinitionType) { case BlockDefinitionAttribute.BlockDefinitionType.BooleanBlockInput: if (typeof(BooleanBlock) == parameterType || parameterType.IsSubclassOf(typeof(BooleanBlock))) { return(true); } break; case BlockDefinitionAttribute.BlockDefinitionType.GlobalVariableSelector: if (typeof(ReporterBlock) == parameterType || parameterType.IsSubclassOf(typeof(BooleanBlock))) { return(true); } break; case BlockDefinitionAttribute.BlockDefinitionType.ReporterBlockInput: if (typeof(ReporterBlock) == parameterType || parameterType.IsSubclassOf(typeof(ReporterBlock))) { return(true); } break; } return(false); }
//private ElementContent[] ElementContentInBlockElements; private void InitElementsOfBlockUnit() { this.ClearDefinitionOfBlockEditorUnit(); Type[] parameterTypes = this.TargetBlock.ParametersTypes; BlockDefinitionAttribute blockDefinition = this.TargetBlock.GetType().GetCustomAttribute <BlockDefinitionAttribute>(); if (blockDefinition != null) {//If Block class have BlockDefinitionAttribute object[] blockDefinitions = blockDefinition._BlockDefinitions; for (int i = 0; i < blockDefinitions.Length; i++) { if (blockDefinitions[i] != null) { if (blockDefinitions[i] is string) { this.AddDefinitionOfBlockEditorUnit(new TextDefinitionContentOfBlock((string)blockDefinitions[i])); } else if (blockDefinitions[i] is BlockDefinitionAttribute.BlockDefinitionType) { #if UNITY_EDITOR if (parameterTypes == null || this.parameterIndex >= parameterTypes.Length) { Debug.LogError("Can't add BlockInputDefinitionContent Please Change BlockDefinitionAttribute of Block ( " + this.TargetBlock.GetType().Name + " ) "); continue; } BlockDefinitionAttribute.BlockDefinitionType blockDefinitionType = (BlockDefinitionAttribute.BlockDefinitionType)blockDefinitions[i]; if (this.GetIsProperBlockDefinitionType(parameterTypes[this.parameterIndex], blockDefinitionType) == false) { Debug.LogError("Improper BlockDefinitionAttribute of Block ( " + this.TargetBlock.GetType().Name + " ) , " + parameterTypes[this.parameterIndex].Name + " : " + blockDefinitionType.ToString()); continue; } #endif switch (blockDefinitionType) { case BlockDefinitionAttribute.BlockDefinitionType.BooleanBlockInput: this.AddDefinitionOfBlockEditorUnit(new BooleanBlockInputDefinitionContentOfBlock()); break; case BlockDefinitionAttribute.BlockDefinitionType.GlobalVariableSelector: this.AddDefinitionOfBlockEditorUnit(new GlobalVariableSelectorDefinitionContentOfBlock()); break; case BlockDefinitionAttribute.BlockDefinitionType.ReporterBlockInput: this.AddDefinitionOfBlockEditorUnit(new ReporterBlockInputDefinitionContentOfBlock()); break; } } } } } else { //If Block class don't have BlockDefinitionAttribute AddDefinitionOfBlockEditorUnit(new TextDefinitionContentOfBlock(this.TargetBlock.GetType().Name)); //First Add Text Element with class name //Automatically add ElementOfBlockUnit if (parameterTypes != null) { for (int i = 0; i < parameterTypes.Length; i++) { if (parameterTypes[i] != null) { if (parameterTypes[i] == typeof(BooleanBlock) || parameterTypes[i].IsSubclassOf(typeof(BooleanBlock))) { this.AddDefinitionOfBlockEditorUnit(new BooleanBlockInputDefinitionContentOfBlock()); } else if (parameterTypes[i] == typeof(ReporterBlock) || parameterTypes[i].IsSubclassOf(typeof(ReporterBlock))) { this.AddDefinitionOfBlockEditorUnit(new ReporterBlockInputDefinitionContentOfBlock()); } else { Debug.LogError("Cant Find Proper Parameter Element. " + parameterTypes[i].Name); } } } } } }