public void CanResizeArrayToSmaller() { SerializedPropertyX property = new SerializedPropertyX("name", typeof(string[]), new string[] { "1", "2" }); property.ArraySize--; Assert.AreEqual(property.GetValue <string[]>().Length, 1); Assert.AreEqual(property.GetValue <string[]>()[0], "1"); }
public void CanResizListToSmaller() { SerializedPropertyX property = new SerializedPropertyX("name", typeof(List <string>), new List <string> { "1", "2" }); property.ArraySize--; Assert.AreEqual(property.GetValue <List <string> >().Count, 1); Assert.AreEqual(property.GetValue <List <string> >()[0], "1"); }
public void CanHandleArrayType() { SerializedPropertyX property = new SerializedPropertyX("name", typeof(string[])); property.Value = new string[] { "hello", "there" }; Assert.IsInstanceOf <string[]>(property.Value); Assert.AreEqual(property.GetValue <string[]>()[0], "hello"); Assert.AreEqual(property.GetValue <string[]>()[1], "there"); Assert.AreEqual(property.ArraySize, 2); Assert.IsTrue(property.IsArrayLike); }
public override void OnGUI(SerializedPropertyX property, GUIContent label) { IntRange attr = property.GetValue <IntRange>(); label.text = property.displayName + " (" + attr.Value + ")"; property.isExpanded = EditorGUILayout.Foldout(property.isExpanded, label); if (property.isExpanded) { property["baseValue"].Value = EditorGUILayout.IntField(new GUIContent("Base Value"), property["baseValue"].GetValue <int>()); if (Mathf.Approximately(attr.BaseValue, 0)) { attr.BaseValue = 0; } attr.BaseValue = property["baseValue"].GetValue <int>(); property["currentValue"].Value = attr.Value; EditorGUI.indentLevel++; IntModifier[] modifiers = attr.GetReadOnlyModiferList(); for (int i = 0; i < modifiers.Length; i++) { IntModifier modifier = modifiers[i]; string valueStr = "Flat: " + modifier.flatBonus + " Percent: " + modifier.percentBonus; GUI.enabled = false; EditorGUILayout.TextField(new GUIContent(modifier.id), valueStr); GUI.enabled = true; } EditorGUILayoutX.PropertyField(property["min"]); EditorGUILayoutX.PropertyField(property["max"]); EditorGUI.indentLevel--; } }
protected override void RenderBody(SerializedPropertyX considerationProperty, RenderData _data, int index) { ConsiderationRenderData data = _data as ConsiderationRenderData; Consideration consideration = considerationProperty.GetValue <Consideration>(); //manually render description and curve to make sure they come first DrawerUtil.PushLabelWidth(125); DrawerUtil.PushIndentLevel(1); consideration.description = EditorGUILayout.TextField(new GUIContent("Description"), consideration.description); GUIContent content = new GUIContent(); content.text = Util.SplitAndTitlize(consideration.GetType().Name); EditorGUILayout.BeginHorizontal(); data.isInputDisplayed = EditorGUILayout.Foldout(data.isInputDisplayed, content); EditorGUILayout.EndHorizontal(); if (data.isInputDisplayed) { EditorGUI.indentLevel++; for (int i = 0; i < considerationProperty.ChildCount; i++) { SerializedPropertyX child = considerationProperty.GetChildAt(i); if (skipRenderingFields.IndexOf(child.name) != -1) { continue; } EditorGUILayoutX.PropertyField(child, child.label, child.isExpanded); } EditorGUI.indentLevel--; } RenderCurve(considerationProperty.FindProperty("curve"), data); DrawerUtil.PopLabelWidth(); DrawerUtil.PopIndentLevel(); }
public override void Render() { if (targetItem == null) { return; } SerializedPropertyX property = rootProperty.FindProperty("contextType"); Type contextType = property.GetValue <Type>(); if (contextType == null) { contextType = typeof(Context); } //shown = EditorGUILayout.Foldout(shown, "Context"); //action : context factory int idx = contextTypeList.IndexOf(contextType); if (idx == -1) { idx = 0; } int newIdx = EditorGUILayout.Popup("Context Type", idx, contextTypeNames); if (newIdx != idx) { //todo pop up revalidate dialog //todo remove components / requirements where T does not match context type selected property.Value = contextTypeList[newIdx]; } }
public void CanResizeArrayToLarger() { SerializedPropertyX property = new SerializedPropertyX("name", typeof(string[]), new string[] { "1", "2" }); property.ArraySize++; Assert.AreEqual(property.GetValue <string[]>().Length, 3); Assert.AreEqual(property.ChildCount, 3); }
public void CanSwapArrayElements() { SerializedPropertyX property = new SerializedPropertyX("name", typeof(string[])); property.Value = new string[] { "hello", "there" }; var child1 = property.GetChildAt(0); var child2 = property.GetChildAt(1); property.SwapArrayElements(0, 1); Assert.AreEqual(property.GetValue <string[]>()[1], "hello"); Assert.AreEqual(property.GetValue <string[]>()[0], "there"); Assert.AreEqual(property.GetChildAt(1), child1); Assert.AreEqual(property.GetChildAt(0), child2); Assert.AreEqual(property.ChildCount, 2); }
public void CanResizeListToLarger() { SerializedPropertyX property = new SerializedPropertyX("name", typeof(List <string>), new List <string> { "1", "2" }); property.ArraySize++; Assert.AreEqual(property.GetValue <List <string> >().Count, 3); Assert.AreEqual(property.ChildCount, 3); }
public override void Render() { if (targetItem == null) { return; } SerializedPropertyX contextTypeProp = rootProperty["contextType"]; Type selectedType; if (typePopUp.DrawPopup("Context Type", contextTypeProp.GetValue <Type>(), out selectedType)) { SerializedPropertyX componentsProp = rootProperty["components"]; SerializedPropertyX requirementsProp = rootProperty["requirements"]; List <SerializedPropertyX> nukeList = new List <SerializedPropertyX>(); for (int i = 0; i < componentsProp.ChildCount; i++) { AbilityComponent component = componentsProp.GetChildAt(i).Value as AbilityComponent; if (!selectedType.IsAssignableFrom(component.GetContextType())) { nukeList.Add(componentsProp.GetChildAt(i)); } } for (int i = 0; i < requirementsProp.ChildCount; i++) { Requirement requirement = requirementsProp.GetChildAt(i).Value as Requirement; if (!selectedType.IsAssignableFrom(requirement.GetContextType())) { nukeList.Add(requirementsProp.GetChildAt(i)); } } if (nukeList.Count > 0) { if (ShouldNuke(nukeList, selectedType)) { for (int i = 0; i < nukeList.Count; i++) { SerializedPropertyX toNuke = nukeList[i]; int reqChildIndex = requirementsProp.GetChildIndex(toNuke); int comChildIndex = componentsProp.GetChildIndex(toNuke); requirementsProp.DeleteArrayElementAt(reqChildIndex); componentsProp.DeleteArrayElementAt(comChildIndex); } contextTypeProp.Value = selectedType; } } else { contextTypeProp.Value = selectedType; } } }
public override float GetPropertyHeight(SerializedPropertyX property, GUIContent label) { IntValue attr = property.GetValue <IntValue>(); if (shown) { return(EditorGUIUtility.singleLineHeight * (attr.GetReadOnlyModiferList().Length + 2)); } else { return(EditorGUIUtility.singleLineHeight); } }
public override void OnGUI(SerializedPropertyX property, GUIContent label) { FloatValue attr = property.GetValue <FloatValue>(); string labelText = property.displayName + " (" + attr.Value + ")"; if (Mathf.Approximately(attr.Value, float.MaxValue) || Mathf.Approximately(attr.Value, float.MinValue)) { labelText = property.displayName + " (--)"; } label.text = labelText; shown = EditorGUILayout.Foldout(shown, label); if (shown) { EditorGUI.indentLevel++; attr.BaseValue = (float)System.Math.Round(EditorGUILayout.FloatField(new GUIContent("Base Value"), attr.BaseValue), 3); if (Mathf.Approximately(attr.BaseValue, 0)) { attr.BaseValue = 0; } property["baseValue"].Value = attr.BaseValue; FloatRange.FloatRangeBoundry rangeBoundry = attr as FloatRange.FloatRangeBoundry; if (rangeBoundry != null) { //this code makes sure the parent's value is clamped now that we've updated a range boundry rangeBoundry.BaseValue = property["baseValue"].GetValue <float>(); float parentValue = rangeBoundry.parent.Value; property["parent"]["currentValue"].Value = parentValue; } FloatModifier[] modifiers = attr.GetReadOnlyModiferList(); for (int i = 0; i < modifiers.Length; i++) { FloatModifier modifier = modifiers[i]; string valueStr = ""; if (modifier.flatBonus != 0) { valueStr += modifier.flatBonus; } else if (modifier.percentBonus != 0) { valueStr += modifier.percentBonus + " %"; } EditorGUILayout.LabelField(modifier.id); EditorGUILayout.LabelField(valueStr); } EditorGUI.indentLevel--; } }
private void CalculateButton(SerializedPropertyX property) { property.ApplyModifiedProperties(); property.Update(); GUILayout.Space(5); EditorGUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); if (GUILayout.Button("Calculate Formula", GUILayout.Width(150))) { DamageFormula d = property.GetValue <DamageFormula>(); d.OnUse(); } GUILayout.FlexibleSpace(); EditorGUILayout.EndHorizontal(); }
public override void Render() { if (rootProperty == null) { return; } SerializedPropertyX isExpirable = rootProperty.FindProperty("IsExpirable"); SerializedPropertyX isDispellable = rootProperty.FindProperty("IsDispellable"); SerializedPropertyX isRefreshable = rootProperty.FindProperty("IsRefreshable"); SerializedPropertyX isUnique = rootProperty.FindProperty("IsUnique"); SerializedPropertyX duration = rootProperty.FindProperty("duration").FindProperty("baseValue"); SerializedPropertyX tickRate = rootProperty.FindProperty("tickRate").FindProperty("baseValue"); SerializedPropertyX ticks = rootProperty.FindProperty("ticks").FindProperty("baseValue"); GUILayout.BeginHorizontal(); isExpirable.Value = EditorGUILayout.ToggleLeft(new GUIContent("Is Expirable"), (bool)isExpirable.Value); isDispellable.Value = EditorGUILayout.ToggleLeft(new GUIContent("Is Dispellable"), (bool)isDispellable.Value); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); isRefreshable.Value = EditorGUILayout.ToggleLeft(new GUIContent("Is Refreshable"), (bool)isRefreshable.Value); isUnique.Value = EditorGUILayout.ToggleLeft(new GUIContent("Is Unique"), (bool)isUnique.Value); GUILayout.EndHorizontal(); GUILayout.Space(10f); using (var h = new EditorGUILayout.HorizontalScope()) { duration.Value = EditorGUILayout.FloatField("Duration", duration.GetValue <float>()); } using (var h = new EditorGUILayout.HorizontalScope()) { ticks.Value = EditorGUILayout.FloatField("Ticks", ticks.GetValue <float>()); } using (var h = new EditorGUILayout.HorizontalScope()) { tickRate.Value = EditorGUILayout.FloatField("Tick Rate", tickRate.GetValue <float>()); } }
public override void Render() { if (rootProperty == null) { return; } SerializedPropertyX contextTypeProp = rootProperty["contextType"]; Type currentType = contextTypeProp.GetValue <Type>(); if (currentType == null) { currentType = typeof(Context); } int idx = 0; for (int i = 1; i < contextTypes.Length; i++) { if (currentType == contextTypes[i]) { idx = i; break; } } int newIdx = EditorGUILayout.Popup("Context Type", idx, contextTypeNames, GUILayout.Width(EditorGUIUtility.labelWidth + 300)); if (idx != newIdx || currentType == null) { Type newType = contextTypes[newIdx]; SerializedPropertyX considerationsProp = rootProperty["considerations"]; SerializedPropertyX requirementsProp = rootProperty["requirements"]; List <SerializedPropertyX> nukeList = new List <SerializedPropertyX>(); for (int i = 0; i < considerationsProp.ChildCount; i++) { Consideration consideration = considerationsProp.GetChildAt(i).Value as Consideration; if (!newType.IsAssignableFrom(consideration.GetContextType())) { nukeList.Add(considerationsProp.GetChildAt(i)); } } for (int i = 0; i < requirementsProp.ChildCount; i++) { Requirement requirement = requirementsProp.GetChildAt(i).Value as Requirement; if (!newType.IsAssignableFrom(requirement.GetContextType())) { nukeList.Add(requirementsProp.GetChildAt(i)); } } if (nukeList.Count > 0) { if (ShouldNuke(nukeList, newType)) { for (int i = 0; i < nukeList.Count; i++) { SerializedPropertyX toNuke = nukeList[i]; int reqChildIndex = requirementsProp.GetChildIndex(toNuke); int conChildIndex = considerationsProp.GetChildIndex(toNuke); requirementsProp.DeleteArrayElementAt(reqChildIndex); considerationsProp.DeleteArrayElementAt(conChildIndex); } contextTypeProp.Value = newType; } } else { contextTypeProp.Value = newType; } } }
protected override void RenderBody(SerializedPropertyX property, RenderData renderData, int index) { DecisionRenderData data = renderData as DecisionRenderData; EditorGUI.indentLevel++; EditorGUILayoutX.PropertyField(property["name"]); EditorGUILayoutX.PropertyField(property["description"]); EditorGUILayoutX.PropertyField(property["weight"]); SerializedPropertyX action = property["action"]; SerializedPropertyX collector = property["contextCollector"]; CharacterAction charAction = action.GetValue <CharacterAction>(); string contextString = "<" + charAction.ContextType.Name + ">"; string actionString = "Action (" + action.Type.Name + contextString + ")"; if (action.ChildCount > 0) { data.isActionShown = EditorGUILayout.Foldout(data.isActionShown, actionString); } else { GUIContent content = new GUIContent(actionString); content.image = EditorGUIUtility.FindTexture("cs Script Icon"); EditorGUILayout.LabelField(content); data.isActionShown = false; } if (data.isActionShown) { EditorGUI.indentLevel++; EditorGUILayoutX.DrawProperties(action); EditorGUI.indentLevel--; } data.GetContextCollectorData(charAction, collector.GetValue <ContextCollector>()); string[] options = data.contextCollectorNames; int currentIndex = data.contextCollectorIndex; int idx = EditorGUILayout.Popup("Collector", currentIndex, options, GUILayout.Width(EditorGUIUtility.labelWidth + 300f)); if (idx != data.contextCollectorIndex) { if (idx == 0) { collector.Value = null; //todo return an empty collector type? } else { Type newCollectorType = data.contextCollectorTypes[idx]; collector.Value = Activator.CreateInstance(newCollectorType) as ContextCollector; } } if (collector.Value != null) { EditorGUI.indentLevel++; EditorGUILayoutX.DrawProperties(collector); EditorGUI.indentLevel--; } data.isEvaluatorShown = EditorGUILayout.Foldout(data.isEvaluatorShown, "Evaluator"); if (data.isEvaluatorShown) { EditorGUI.indentLevel++; SerializedPropertyX evaluator = property["evaluator"]; SerializedPropertyX considerations = evaluator["considerations"]; SerializedPropertyX requirements = evaluator["requirements"]; if (considerations.ChildCount == 0 && requirements.ChildCount == 0) { data.GetEvaluatorTemplateData(charAction.ContextType); int newIdx = EditorGUILayout.Popup("Set From Template", 0, data.evaluatorOptions, GUILayout.Width(EditorGUIUtility.labelWidth + 300f)); if (newIdx != 0) { evaluator.Value = data.evaluatorCreators[newIdx].Create(); data.requirementSection.SetTargetProperty(evaluator); data.considerationSection.SetTargetProperty(evaluator); } } data.requirementSection.Render(); data.considerationSection.Render(); EditorGUI.indentLevel--; } EditorGUI.indentLevel--; }
private void RenderCurve(SerializedPropertyX curveProperty, ConsiderationRenderData data) { ResponseCurve curve = curveProperty.GetValue <ResponseCurve>(); bool updateTexture = false; Texture2D graphTexture = data.graphTexture; if (graphTexture == null) { data.graphTexture = new Texture2D(1, 1, TextureFormat.RGBA32, true); } EditorGUILayout.BeginHorizontal(); data.isCurveShown = EditorGUILayout.Foldout(data.isCurveShown, "Curve(" + curve.curveType.ToString() + ")"); if (!data.isCurveShown) { if (graphTexture.width != 64) { graphTexture.Resize(64, 32); Rect rect = new Rect() { x = 0, y = 0, width = graphTexture.width, height = graphTexture.height }; GraphHelper.DrawGraphLines(rect, graphTexture, (float input) => { return(curve.Evaluate(input)); }); graphTexture.FlipVertically(); graphTexture.Apply(true); } GUILayout.FlexibleSpace(); GUIContent content = new GUIContent(); content.text = curve.DisplayString; content.image = graphTexture; GUIStyle style = new GUIStyle(GUI.skin.box); style.alignment = TextAnchor.MiddleLeft; GUILayout.Box(content, style); } EditorGUILayout.EndHorizontal(); if (!data.isCurveShown) { return; } DrawerUtil.PushIndentLevel(1); EditorGUILayout.BeginHorizontal(); { EditorGUI.BeginChangeCheck(); GUILayout.BeginVertical(GUILayout.MaxWidth(400f)); curve.curveType = (ResponseCurveType)EditorGUILayout.EnumPopup("Curve Type", curve.curveType); curve.slope = EditorGUILayout.FloatField("Slope", curve.slope); curve.exp = EditorGUILayout.FloatField("Exp", curve.exp); curve.vShift = EditorGUILayout.FloatField("Vertical Shift", curve.vShift); curve.hShift = EditorGUILayout.FloatField("Horizontal Shift", curve.hShift); curve.threshold = EditorGUILayout.FloatField("Threshold", curve.threshold); curve.invert = EditorGUILayout.Toggle(new GUIContent("Inverted"), curve.invert); GUILayout.BeginHorizontal(); GUILayout.Space(EditorGUIUtility.labelWidth); if (GUILayout.Button("Reset")) { curve.Reset(); } GUILayout.EndHorizontal(); GUILayout.EndVertical(); updateTexture = EditorGUI.EndChangeCheck(); } //draw the graph { if (updateTexture || graphTexture.width != 512) { curveProperty.Update(); graphTexture.Resize(512, (int)(8.75f * EditorGUIUtility.singleLineHeight)); Rect rect = new Rect() { x = 0, y = 0, width = graphTexture.width, height = graphTexture.height }; GraphHelper.DrawGraphLines(rect, graphTexture, (float input) => { return(curve.Evaluate(input)); }); graphTexture.FlipVertically(); graphTexture.Apply(true); } DrawerUtil.DrawLayoutTexture(graphTexture); } EditorGUILayout.EndHorizontal(); DrawerUtil.PopIndentLevel(); }