protected override AlloyFieldDrawer GenerateDrawer(AlloyInspectorBase editor) { AlloyFieldDrawer ret = null; for (int i = 0; i < Arguments.Length; i++) { var argument = Arguments[i]; var valProp = argument.ArgumentToken as AlloyValueToken; switch (argument.ArgumentName) { case "Vector": if (valProp != null) { ret = SetupVectorDrawer(editor, valProp, ret); } break; } } if (ret == null) { ret = new AlloyVectorDrawer(editor, MaterialProperty); ((AlloyVectorDrawer)ret).Mode = AlloyVectorDrawer.VectorMode.Vector4; } return(ret); }
AlloyFieldDrawer SetupVectorDrawer(AlloyInspectorBase editor, AlloyValueToken valProp, AlloyFieldDrawer ret) { if (valProp.ValueType == AlloyValueToken.ValueTypeEnum.String) { switch (valProp.StringValue) { case "Euler": ret = new AlloyVectorDrawer(editor, MaterialProperty); ((AlloyVectorDrawer)ret).Mode = AlloyVectorDrawer.VectorMode.Euler; break; case "TexCoord": ret = new AlloyTexCoordDrawer(editor, MaterialProperty); break; case "Channels": ret = new AlloyMaskDrawer(editor, MaterialProperty); break; default: Debug.LogError("Non supported vector property!"); break; } } else if (valProp.ValueType == AlloyValueToken.ValueTypeEnum.Float) { switch ((int)valProp.FloatValue) { case 2: ret = new AlloyVectorDrawer(editor, MaterialProperty); ((AlloyVectorDrawer)ret).Mode = AlloyVectorDrawer.VectorMode.Vector2; break; case 3: ret = new AlloyVectorDrawer(editor, MaterialProperty); ((AlloyVectorDrawer)ret).Mode = AlloyVectorDrawer.VectorMode.Vector3; break; case 4: ret = new AlloyVectorDrawer(editor, MaterialProperty); ((AlloyVectorDrawer)ret).Mode = AlloyVectorDrawer.VectorMode.Vector4; break; default: Debug.LogError("Non supported vector property!"); break; } } return(ret); }
private static void SetMinOption(AlloyFieldDrawer retDrawer, AlloyToken argToken) { var floatDrawer = retDrawer as AlloyFloatDrawer; var minValToken = argToken as AlloyValueToken; if (floatDrawer != null) { floatDrawer.HasMin = true; if (minValToken != null) { floatDrawer.MinValue = minValToken.FloatValue; } } }
private AlloyFieldDrawer SetupVectorDrawer(AlloyInspectorBase editor, AlloyValueToken valProp, AlloyFieldDrawer ret) { if (valProp.ValueType == AlloyValueToken.ValueTypeEnum.String) { switch (valProp.StringValue) { case "Euler": ret = new AlloyVectorDrawer(editor, MaterialProperty); ((AlloyVectorDrawer) ret).Mode = AlloyVectorDrawer.VectorMode.Euler; break; case "TexCoord": ret = new AlloyTexCoordDrawer(editor, MaterialProperty); break; case "Mask": ret = new AlloyMaskDrawer(editor, MaterialProperty); break; default: Debug.LogError("Non supported vector property!"); break; } } else if (valProp.ValueType == AlloyValueToken.ValueTypeEnum.Float) { switch ((int) valProp.FloatValue) { case 2: ret = new AlloyVectorDrawer(editor, MaterialProperty); ((AlloyVectorDrawer) ret).Mode = AlloyVectorDrawer.VectorMode.Vector2; break; case 3: ret = new AlloyVectorDrawer(editor, MaterialProperty); ((AlloyVectorDrawer) ret).Mode = AlloyVectorDrawer.VectorMode.Vector3; break; case 4: ret = new AlloyVectorDrawer(editor, MaterialProperty); ((AlloyVectorDrawer) ret).Mode = AlloyVectorDrawer.VectorMode.Vector4; break; default: Debug.LogError("Non supported vector property!"); break; } } return ret; }
private static void SetDropdownOption(AlloyFieldDrawer retDrawer, AlloyToken argToken) { var drawer = retDrawer as AlloyDropdownDrawer; if (drawer == null) { return; } var options = argToken as AlloyCollectionToken; if (options == null) { return; } var dropOptions = new List <AlloyDropdownOption>(); for (int i = 0; i < options.SubTokens.Count; i++) { AlloyArgumentToken arg = (AlloyArgumentToken)options.SubTokens[i]; var collection = arg.ArgumentToken as AlloyCollectionToken; if (collection == null) { continue; } // Split PascalCase name into words separated by spaces while skipping acronyms. var dropOption = new AlloyDropdownOption { Name = Regex.Replace(arg.ArgumentName, @"(?<=[A-Za-z])(?=[A-Z][a-z])|(?<=[a-z0-9])(?=[0-9]?[A-Z])", " "), HideFields = collection.SubTokens.Select(alloyToken => alloyToken.Token).ToArray() }; dropOptions.Add(dropOption); } drawer.DropOptions = dropOptions.ToArray(); }
private static void SetToggleOption(AlloyFieldDrawer retDrawer, AlloyToken argToken) { var drawer = retDrawer as AlloyToggleDrawer; if (drawer == null) { return; } var collectionToken = argToken as AlloyCollectionToken; if (collectionToken == null) { return; } foreach (var token in collectionToken.SubTokens) { var arg = token as AlloyArgumentToken; if (arg != null && arg.ArgumentName == "On") { var onToken = arg.ArgumentToken as AlloyCollectionToken; if (onToken != null) { drawer.OnHideFields = onToken.SubTokens.Select(colToken => colToken.Token).ToArray(); } } else if (arg != null && arg.ArgumentName == "Off") { var offToken = arg.ArgumentToken as AlloyCollectionToken; if (offToken != null) { drawer.OffHideFields = offToken.SubTokens.Select(colToken => colToken.Token).ToArray(); } } } }
private static void SetDropdownOption(AlloyFieldDrawer retDrawer, AlloyToken argToken) { var drawer = retDrawer as AlloyDropdownDrawer; if (drawer == null) { return; } var options = argToken as AlloyCollectionToken; if (options == null) { return; } var dropOptions = new List <AlloyDropdownOption>(); for (int i = 0; i < options.SubTokens.Count; i++) { AlloyArgumentToken arg = (AlloyArgumentToken)options.SubTokens[i]; var collection = arg.ArgumentToken as AlloyCollectionToken; if (collection == null) { continue; } // Split name at capital letters, then insert spaces between words. var dropOption = new AlloyDropdownOption { Name = string.Join(" ", Regex.Split(arg.ArgumentName, @"(?<!^)(?=[A-Z])")), HideFields = collection.SubTokens.Select(alloyToken => alloyToken.Token).ToArray() }; dropOptions.Add(dropOption); } drawer.DropOptions = dropOptions.ToArray(); }
void SetSectionOption(AlloyFieldDrawer retDrawer, AlloyToken argToken) { var sectionDrawer = retDrawer as AlloyTabDrawer; if (sectionDrawer != null) { var collectionToken = argToken as AlloyCollectionToken; if (collectionToken == null) { sectionDrawer.Color = c_defaultSectionColor; } else { foreach (var token in collectionToken.SubTokens) { var arg = token as AlloyArgumentToken; if (arg != null && arg.ArgumentName == "Color") { var value = arg.ArgumentToken as AlloyValueToken; // Calculate color from section index and HSV scale factor. if (value != null) { var hueIndex = value.FloatValue; if (hueIndex > -0.1f) { sectionDrawer.Color = Color.HSVToRGB((hueIndex / AlloyUtils.SectionColorMax) * 0.6f, 0.75f, 0.5f); } } else { // Manually specify color. var colCollection = arg.ArgumentToken as AlloyCollectionToken; if (colCollection != null) { var r = colCollection.SubTokens[0] as AlloyValueToken; var g = colCollection.SubTokens[1] as AlloyValueToken; var b = colCollection.SubTokens[2] as AlloyValueToken; if (r != null && g != null && b != null) { sectionDrawer.Color = new Color32((byte)r.FloatValue, (byte)g.FloatValue, (byte)b.FloatValue, 255); } } } } else if (arg != null && arg.ArgumentName == "Hide") { var featureDrawer = sectionDrawer as AlloyFeatureDrawer; var offToken = arg.ArgumentToken as AlloyCollectionToken; if (offToken != null) { featureDrawer.HideFields = offToken.SubTokens.Select(colToken => colToken.Token).ToArray(); } } } } } }
protected override AlloyFieldDrawer GenerateDrawer(AlloyInspectorBase editor) { AlloyFieldDrawer retDrawer = null; foreach (var token in Arguments) { var argName = token.ArgumentName; var argToken = token.ArgumentToken; switch (argName) { case "Min": AlloyFloatDrawer minDrawer = null; var minValToken = argToken as AlloyValueToken; if (retDrawer != null) { minDrawer = retDrawer as AlloyFloatDrawer; } if (minDrawer == null) { minDrawer = new AlloyFloatDrawer(editor, MaterialProperty); } minDrawer.HasMin = true; minDrawer.MinValue = minValToken.FloatValue; retDrawer = minDrawer; break; case "Max": AlloyFloatDrawer maxDrawer = null; var maxValToken = argToken as AlloyValueToken; if (retDrawer != null) { maxDrawer = retDrawer as AlloyFloatDrawer; } if (maxDrawer == null) { maxDrawer = new AlloyFloatDrawer(editor, MaterialProperty); } maxDrawer.HasMax = true; maxDrawer.MaxValue = maxValToken.FloatValue; retDrawer = maxDrawer; break; case "Section": retDrawer = new AlloySectionDrawer(editor, MaterialProperty); SetSectionOption(retDrawer, argToken); break; case "Feature": retDrawer = new AlloyFeatureDrawer(editor, MaterialProperty); SetSectionOption(retDrawer, argToken); break; case "Toggle": retDrawer = new AlloyToggleDrawer(editor, MaterialProperty); SetToggleOption(retDrawer, argToken); break; case "SpeedTreeGeometryType": retDrawer = new AlloySpeedTreeGeometryTypeDrawer(editor, MaterialProperty); SetDropdownOption(retDrawer, argToken); break; case "RenderingMode": retDrawer = new AlloyRenderingModeDrawer(editor, MaterialProperty); SetDropdownOption(retDrawer, argToken); break; case "Dropdown": retDrawer = new AlloyDropdownDrawer(editor, MaterialProperty); SetDropdownOption(retDrawer, argToken); break; case "LightmapEmissionProperty": retDrawer = new AlloyLightmapEmissionDrawer(editor, MaterialProperty); break; case "RenderQueue": retDrawer = new AlloyRenderQueueDrawer(editor, MaterialProperty); break; case "EnableInstancing": retDrawer = new AlloyEnableInstancingDrawer(editor, MaterialProperty); break; case "DoubleSidedGI": retDrawer = new AlloyDoubleSidedGiDrawer(editor, MaterialProperty); break; } } if (retDrawer == null) { retDrawer = new AlloyFloatDrawer(editor, MaterialProperty); } return(retDrawer); }
private static void SetDropdownOption(AlloyFieldDrawer retDrawer, AlloyToken argToken) { var drawer = retDrawer as AlloyDropdownDrawer; if (drawer == null) { return; } var options = argToken as AlloyCollectionToken; if (options == null) { return; } var dropOptions = new List<AlloyDropdownOption>(); for (int i = 0; i < options.SubTokens.Count; i++) { AlloyArgumentToken arg = (AlloyArgumentToken)options.SubTokens[i]; var collection = arg.ArgumentToken as AlloyCollectionToken; if (collection == null) { continue; } var dropOption = new AlloyDropdownOption { Name = arg.ArgumentName, HideFields = collection.SubTokens.Select(alloyToken => alloyToken.Token).ToArray() }; dropOptions.Add(dropOption); } drawer.DropOptions = dropOptions.ToArray(); }