/// <summary> /// Replaces the inner text of the content control with a value based on the loaded data from the VariableSource /// </summary> private void Replace(ContentControl control, IVariableSource variableSource) { if (!IsEnabled) { return; } if (control.SdtElement.Parent == null) { return; } //Check if it's the correct type of content control if (control.Type != ContentControlTypeRestriction && ContentControlTypeRestriction != OpenXmlExtensions.ContentControlType.Undefined) { return; } //Check if this is a valid tag and if it matches the defined tag name for this control replacer if (!ValidateAndExtractTag(control.Tag, out var varIdentifier, out var otherParameters)) { return; } //Process the control and get the value that we should use var newValue = ProcessControl(varIdentifier, variableSource, control, otherParameters); SetTextAndRemovePlaceholderFormat(control.SdtElement, newValue); OnReplaced(control); }
protected override string ProcessControl(string variableIdentifier, IVariableSource variableSource, ContentControl contentControl, List <string> otherParameters) { try { var variable = variableSource.GetVariable(variableIdentifier); if (variable == null) { return(null); } //If the variable is not of a complex type or if the content control does not support nested controls, //(ie, is not a RichText control), then just return the string representation of the variable if (contentControl.Type != OpenXmlExtensions.ContentControlType.RichText || !(variable is Dictionary <string, object> innerData)) { return(variable.ToString()); } //If the variable is complex (dictionary) type and the control is rich text, we need to do //recursive replacement. For that we will add it to the queue var innerVariableSource = new VariableSource(innerData); Enqueue(new ControlReplacementExecutionData { Controls = contentControl.DescendingControls, VariableSource = innerVariableSource }); return(null); } catch (VariableNotFoundException) { return(null); } }
private static bool AddVariable(IVariableSource variableSource, string variableName, int variableTypeIndex, bool fromGlobalVariablesWindow) { SharedVariable item = VariableInspector.CreateVariable(variableTypeIndex, variableName, fromGlobalVariablesWindow); List <SharedVariable> list = (variableSource == null) ? null : variableSource.GetAllVariables(); if (list == null) { list = new List <SharedVariable>(); } list.Add(item); GUI.FocusControl("Add"); if (fromGlobalVariablesWindow && variableSource == null) { GlobalVariables globalVariables = ScriptableObject.CreateInstance(typeof(GlobalVariables)) as GlobalVariables; string text = BehaviorDesignerUtility.GetEditorBaseDirectory(null).Substring(6, BehaviorDesignerUtility.GetEditorBaseDirectory(null).Length - 13); string str = text + "/Resources/BehaviorDesignerGlobalVariables.asset"; if (!Directory.Exists(Application.dataPath + text + "/Resources")) { Directory.CreateDirectory(Application.dataPath + text + "/Resources"); } if (!File.Exists(Application.dataPath + str)) { AssetDatabase.CreateAsset(globalVariables, "Assets" + str); EditorUtility.DisplayDialog("Created Global Variables", "Behavior Designer Global Variables asset created:\n\nAssets" + text + "/Resources/BehaviorDesignerGlobalVariables.asset\n\nNote: Copy this file to transfer global variables between projects.", "OK"); } variableSource = globalVariables; } variableSource.SetAllVariables(list); return(true); }
/// <summary> /// Adds a new <see cref="IVariableSource" /> for use in compilation of the pipelines. /// </summary> /// <param name="variableSource">The variable source to add.</param> /// <returns>This compilation builder.</returns> public BlueprintCompilationBuilder AddVariableSource(IVariableSource variableSource) { Guard.NotNull(nameof(variableSource), variableSource); this._blueprintApiBuilder.Options.GenerationRules.VariableSources.Add(variableSource); return(this); }
/// <summary> /// Replaces all matching content controls in the template document with the matched data from the VariableSource /// </summary> /// <param name="doc">The template document</param> /// <param name="variableSource">The data source for variables</param> public void ReplaceAll(TemplateDocument doc, IVariableSource variableSource) { //Enumerate the collections to list in case we add more to the lists while replacing Enqueue(ReplacesOnlyFirstOrderChildren ? new ControlReplacementExecutionData(doc.FirstOrderContentControls.ToList(), variableSource) : new ControlReplacementExecutionData(doc.AllContentControls.ToList(), variableSource)); ExecuteQueue(); }
protected override string ProcessControl(string variableIdentifier, IVariableSource variableSource, ContentControl contentControl, List <string> otherParameters) { var dropdown = contentControl.SdtElement.SdtProperties.GetFirstChild <SdtContentDropDownList>(); return(ProcessDropdownControl(variableIdentifier, variableSource, dropdown, otherParameters)); }
public void ReplaceAll(IEnumerable <ContentControl> contentControls, IVariableSource variableSource) { Enqueue(ReplacesOnlyFirstOrderChildren ? new ControlReplacementExecutionData( contentControls.Where(c => c.IsFirstOrder).ToList(), variableSource) : new ControlReplacementExecutionData(contentControls, variableSource)); ExecuteQueue(); }
public static bool LeftMouseDown(IVariableSource variableSource, BehaviorSource behaviorSource, Vector2 mousePosition, List <float> variablePosition, float variableStartPosition, Vector2 scrollPosition, ref int selectedVariableIndex, ref string selectedVariableName, ref int selectedVariableTypeIndex) { if (variablePosition != null && mousePosition.y > variableStartPosition && variableSource != null) { List <SharedVariable> allVariables; if (!Application.isPlaying && behaviorSource != null && behaviorSource.Owner is Behavior) { Behavior behavior = behaviorSource.Owner as Behavior; if (behavior.ExternalBehavior != null) { BehaviorSource behaviorSource2 = behavior.GetBehaviorSource(); behaviorSource2.CheckForSerialization(true, null); allVariables = behaviorSource2.GetAllVariables(); ExternalBehavior externalBehavior = behavior.ExternalBehavior; externalBehavior.BehaviorSource.Owner = externalBehavior; externalBehavior.BehaviorSource.CheckForSerialization(true, behaviorSource); } else { allVariables = variableSource.GetAllVariables(); } } else { allVariables = variableSource.GetAllVariables(); } if (allVariables == null || allVariables.Count != variablePosition.Count) { return(false); } int i = 0; while (i < variablePosition.Count) { if (mousePosition.y < variablePosition[i] - scrollPosition.y) { if (i == selectedVariableIndex) { return(false); } selectedVariableIndex = i; selectedVariableName = allVariables[i].Name; selectedVariableTypeIndex = VariableInspector.sharedVariableTypesDict[allVariables[i].GetType().Name]; return(true); } else { i++; } } } if (selectedVariableIndex != -1) { selectedVariableIndex = -1; return(true); } return(false); }
// Token: 0x060002BC RID: 700 RVA: 0x0001B100 File Offset: 0x00019300 private static bool AddVariable(IVariableSource variableSource, string variableName, int variableTypeIndex, bool fromGlobalVariablesWindow) { SharedVariable item = VariableInspector.CreateVariable(variableTypeIndex, variableName, fromGlobalVariablesWindow); List <SharedVariable> list = (variableSource == null) ? null : variableSource.GetAllVariables(); if (list == null) { list = new List <SharedVariable>(); } list.Add(item); variableSource.SetAllVariables(list); return(true); }
public StringBuilder Bind(string content, IVariableSource variableSource) { var sb = new StringBuilder(content); foreach (var variable in FindVariablesInContent(content)) { sb.Replace( variable.ReplaceBlock, variableSource.GetVariableValue(variable) ); } return(sb); }
protected override string ProcessControl(string variableIdentifier, IVariableSource variableSource, ContentControl contentControl, List <string> otherParameters) { var value = ConditionalUtils.EvaluateConditionalVariableWithParameters(variableIdentifier, variableSource, otherParameters); if (!value) { contentControl.Remove(); } return(null); }
private static void DeserializeVariables(IVariableSource variableSource, Dictionary <string, object> dict, List <UnityEngine.Object> unityObjects) { object obj; if (dict.TryGetValue("Variables", out obj)) { List <SharedVariable> list = new List <SharedVariable>(); IList list2 = obj as IList; for (int i = 0; i < list2.Count; i++) { SharedVariable item = JSONDeserializationDeprecated.DeserializeSharedVariable(list2[i] as Dictionary <string, object>, variableSource, true, unityObjects); list.Add(item); } variableSource.SetAllVariables(list); } }
/// <summary> /// Initializes a new <see cref="ConfigSectionSessionScopeSettings"/> instance. /// </summary> /// <param name="ownerType">The type, who's name will be used to prefix setting variables with</param> /// <param name="variableSource">The variable source to obtain settings from.</param> public ConfigSectionSessionScopeSettings(Type ownerType, IVariableSource variableSource) : base() { string sessionFactoryObjectNameSettingsKey = UniqueKey.GetTypeScopedString(ownerType, "SessionFactoryObjectName"); string entityInterceptorObjectNameSettingsKey = UniqueKey.GetTypeScopedString(ownerType, "EntityInterceptorObjectName"); string singleSessionSettingsKey = UniqueKey.GetTypeScopedString(ownerType, "SingleSession"); string defaultFlushModeSettingsKey = UniqueKey.GetTypeScopedString(ownerType, "DefaultFlushMode"); VariableAccessor variables = new VariableAccessor(variableSource); this.sessionFactoryObjectName = variables.GetString(sessionFactoryObjectNameSettingsKey, DEFAULT_SESSION_FACTORY_OBJECT_NAME); this.entityInterceptorObjectName = variables.GetString(entityInterceptorObjectNameSettingsKey, null); this.SingleSession = variables.GetBoolean(singleSessionSettingsKey, this.SingleSession); this.DefaultFlushMode = (FlushMode)variables.GetEnum(defaultFlushModeSettingsKey, this.DefaultFlushMode); AssertUtils.ArgumentNotNull(sessionFactoryObjectName, "sessionFactoryObjectName"); // just to be sure }
/// <summary> /// Initializes a new <see cref="ConfigSectionSessionScopeSettings"/> instance. /// </summary> /// <param name="ownerType">The type, who's name will be used to prefix setting variables with</param> /// <param name="variableSource">The variable source to obtain settings from.</param> public ConfigSectionSessionScopeSettings(Type ownerType, IVariableSource variableSource) : base() { string sessionFactoryObjectNameSettingsKey = UniqueKey.GetTypeScopedString(ownerType, "SessionFactoryObjectName"); string entityInterceptorObjectNameSettingsKey = UniqueKey.GetTypeScopedString(ownerType, "EntityInterceptorObjectName"); string singleSessionSettingsKey = UniqueKey.GetTypeScopedString(ownerType, "SingleSession"); string defaultFlushModeSettingsKey = UniqueKey.GetTypeScopedString(ownerType, "DefaultFlushMode"); VariableAccessor variables = new VariableAccessor(variableSource); this.sessionFactoryObjectName = variables.GetString(sessionFactoryObjectNameSettingsKey, DEFAULT_SESSION_FACTORY_OBJECT_NAME); this.entityInterceptorObjectName = variables.GetString(entityInterceptorObjectNameSettingsKey, null); this.SingleSession = variables.GetBoolean(singleSessionSettingsKey, this.SingleSession); this.DefaultFlushMode = (FlushMode)variables.GetEnum(defaultFlushModeSettingsKey, this.DefaultFlushMode); AssertUtils.ArgumentNotNull(sessionFactoryObjectName, "sessionFactoryObjectName"); // just to be sure }
// Token: 0x060002B9 RID: 697 RVA: 0x0001AB2C File Offset: 0x00018D2C public static bool DrawVariables(IVariableSource variableSource, BehaviorSource behaviorSource, ref string variableName, ref bool focusNameField, ref int variableTypeIndex, ref Vector2 scrollPosition, ref List <float> variablePosition, ref float variableStartPosition, ref int selectedVariableIndex, ref string selectedVariableName, ref int selectedVariableTypeIndex) { scrollPosition = GUILayout.BeginScrollView(scrollPosition, new GUILayoutOption[0]); bool flag = false; bool flag2 = false; List <SharedVariable> list = (variableSource == null) ? null : variableSource.GetAllVariables(); if (VariableInspector.DrawHeader(variableSource, behaviorSource == null, ref variableStartPosition, ref variableName, ref focusNameField, ref variableTypeIndex, ref selectedVariableIndex, ref selectedVariableName, ref selectedVariableTypeIndex)) { flag = true; } list = ((variableSource == null) ? null : variableSource.GetAllVariables()); if (list != null && list.Count > 0) { GUI.enabled = !flag2; if (VariableInspector.DrawAllVariables(true, variableSource, ref list, true, ref variablePosition, ref selectedVariableIndex, ref selectedVariableName, ref selectedVariableTypeIndex, true, true)) { flag = true; } } if (flag && variableSource != null) { variableSource.SetAllVariables(list); } GUI.enabled = true; GUILayout.EndScrollView(); if (flag && !EditorApplication.isPlayingOrWillChangePlaymode && behaviorSource != null && behaviorSource.Owner is Behavior) { Behavior behavior = behaviorSource.Owner as Behavior; if (behavior.ExternalBehavior != null) { if (BehaviorDesignerPreferences.GetBool(BDPreferences.BinarySerialization)) { BinarySerialization.Save(behaviorSource); } else { JSONSerialization.Save(behaviorSource); } BehaviorSource behaviorSource2 = behavior.ExternalBehavior.GetBehaviorSource(); behaviorSource2.CheckForSerialization(true, null); VariableInspector.SyncVariables(behaviorSource2, list); } } return(flag); }
protected override string ProcessDropdownControl(string variableIdentifier, IVariableSource data, SdtContentDropDownList dropdown, List <string> otherParameters) { //This is the list that we should check to see if the value should be singular or plural var list = data.GetVariable <IList>(variableIdentifier); var singular = list.Count <= 1; if (dropdown.ChildElements.Count == 0) { return(null); } var dropdownChildElement = singular || dropdown.ChildElements.Count == 1 ? dropdown.ChildElements[0] : dropdown.ChildElements[1]; return(GetListItemValue(dropdownChildElement)); }
/// <summary> /// Replaces all content controls of a template document using all registered and enabled control replacers. /// </summary> /// <param name="doc">The template document</param> /// <param name="variableSource">The data source for variables</param> public void ReplaceAll(TemplateDocument doc, IVariableSource variableSource) { foreach (var enabledControlReplacer in EnabledControlReplacers()) { enabledControlReplacer.ClearQueue(); enabledControlReplacer.Enqueue(new ControlReplacementExecutionData(doc.AllContentControls.ToList(), variableSource)); } foreach (var enabledControlReplacer in EnabledControlReplacers()) { enabledControlReplacer.ExecuteQueue(); } if (KeepContentControlAfterReplacement == false) { doc.RemoveControlsAndKeepContent(); } }
protected override string ProcessControl(string variableIdentifier, IVariableSource variableSource, ContentControl contentControl, List <string> otherParameters) { try { var variable = variableSource.GetVariable(variableIdentifier); if (variable == null) { return(null); } var imagePath = variable.ToString(); var byteArray = File.ReadAllBytes(imagePath); return(Convert.ToBase64String(byteArray)); } catch (VariableNotFoundException) { return(null); } }
internal static bool EvaluateVariable(string varIdentifier, IVariableSource data, out object variableValue) { bool value; try { variableValue = data.GetVariable(varIdentifier); value = EvaluateVariableValue(variableValue); } catch (VariableNotFoundException) { value = false; variableValue = null; } return(value); }
private static bool DrawSharedVariable(IVariableSource variableSource, SharedVariable sharedVariable, bool selected) { if (sharedVariable == null || sharedVariable.GetType().GetProperty("Value") == null) { return(false); } GUILayout.BeginHorizontal(new GUILayoutOption[0]); bool result = false; if (!string.IsNullOrEmpty(sharedVariable.PropertyMapping)) { if (selected) { GUILayout.Label("Property", new GUILayoutOption[0]); } else { GUILayout.Label(sharedVariable.Name, new GUILayoutOption[0]); } string[] array = sharedVariable.PropertyMapping.Split(new char[] { '.' }); GUILayout.Label(array[array.Length - 1].Replace('/', '.'), new GUILayoutOption[0]); } else { EditorGUI.BeginChangeCheck(); FieldInspector.DrawFields(null, sharedVariable, new GUIContent(sharedVariable.Name)); result = EditorGUI.EndChangeCheck(); } if (!sharedVariable.IsGlobal && GUILayout.Button(BehaviorDesignerUtility.VariableMapButtonTexture, BehaviorDesignerUtility.PlainButtonGUIStyle, new GUILayoutOption[] { GUILayout.Width(19f) })) { VariableInspector.ShowPropertyMappingMenu(variableSource as BehaviorSource, sharedVariable); } GUILayout.EndHorizontal(); return(result); }
protected override string ProcessDropdownControl(string variableIdentifier, IVariableSource data, SdtContentDropDownList dropdown, List <string> otherParameters) { if (dropdown.ChildElements.Count == 0) { return(null); } if (dropdown.ChildElements.Count == 1) { return(GetListItemValue(dropdown.ChildElements[0])); } var value = ConditionalUtils.EvaluateConditionalVariableWithParameters(variableIdentifier, data, otherParameters); var dropdownChildElement = value ? dropdown.ChildElements[0] : dropdown.ChildElements[1]; return(GetListItemValue(dropdownChildElement)); }
protected GenerationModel(string className, string inputName, IVariableSource specific, IGenerationConfig config, IList <Frame> frames) { if (!frames.Any()) { throw new ArgumentOutOfRangeException(nameof(frames), "Cannot be an empty list"); } var handlerType = typeof(T).FindInterfaceThatCloses(typeof(IHandler <>)); if (handlerType == null) { throw new ArgumentOutOfRangeException(nameof(T), $"Type {typeof(T).FullName} does not implement IHandler<T>"); } ClassName = className; Config = config; Frames = frames; _specific = specific; var inputType = handlerType.GetGenericArguments().Single(); InputVariable = new Variable(inputType, inputName); var compiled = compileFrames(frames); if (compiled.All(x => !x.IsAsync)) { AsyncMode = AsyncMode.ReturnCompletedTask; } else if (compiled.Count(x => x.IsAsync) == 1 && compiled.Last().IsAsync&& compiled.Last().CanReturnTask()) { AsyncMode = compiled.Any(x => x.Wraps) ? AsyncMode.AsyncTask : AsyncMode.ReturnFromLastNode; } Top = chainFrames(compiled); }
/// <summary> /// Initialize a new instance of an <see cref="VariableAccessor"/> /// </summary> /// <param name="variableSource">The underlying <see cref="IVariableSource"/> to read values from.</param> public VariableAccessor(IVariableSource variableSource) { this.variableSource = variableSource; }
/// <summary> /// Initialize a new instance of an <see cref="VariableAccessor"/> /// </summary> /// <param name="variableSource">The underlying <see cref="IVariableSource"/> to read values from.</param> public VariableAccessor(IVariableSource variableSource) { this.variableSource = variableSource; }
private static SharedVariable BytesToSharedVariable(FieldSerializationData fieldSerializationData, Dictionary <string, int> fieldIndexMap, byte[] bytes, int dataPosition, IVariableSource variableSource, bool fromField, string namePrefix) { SharedVariable sharedVariable = null; string text = (string)LoadField(fieldSerializationData, fieldIndexMap, typeof(string), namePrefix + "Type", null); if (string.IsNullOrEmpty(text)) { return(null); } string name = (string)LoadField(fieldSerializationData, fieldIndexMap, typeof(string), namePrefix + "Name", null); bool flag = Convert.ToBoolean(LoadField(fieldSerializationData, fieldIndexMap, typeof(bool), namePrefix + "IsShared", null, null, null)); bool flag2 = Convert.ToBoolean(LoadField(fieldSerializationData, fieldIndexMap, typeof(bool), namePrefix + "IsGlobal", null, null, null)); if (flag && fromField) { if (!flag2) { sharedVariable = variableSource.GetVariable(name); } else { if (globalVariables == null) { globalVariables = GlobalVariables.Instance; } if (globalVariables != null) { sharedVariable = globalVariables.GetVariable(name); } } } Type typeWithinAssembly = TaskUtility.GetTypeWithinAssembly(text); if (typeWithinAssembly == null) { return(null); } bool flag3 = true; if (sharedVariable == null || !(flag3 = sharedVariable.GetType().Equals(typeWithinAssembly))) { sharedVariable = (TaskUtility.CreateInstance(typeWithinAssembly) as SharedVariable); sharedVariable.Name = name; sharedVariable.IsShared = flag; sharedVariable.IsGlobal = flag2; sharedVariable.NetworkSync = Convert.ToBoolean(LoadField(fieldSerializationData, fieldIndexMap, typeof(bool), namePrefix + "NetworkSync", null)); if (!flag2) { sharedVariable.PropertyMapping = (string)LoadField(fieldSerializationData, fieldIndexMap, typeof(string), namePrefix + "PropertyMapping", null); sharedVariable.PropertyMappingOwner = (GameObject)LoadField(fieldSerializationData, fieldIndexMap, typeof(GameObject), namePrefix + "PropertyMappingOwner", null); sharedVariable.InitializePropertyMapping(variableSource as BehaviorSource); } if (!flag3) { sharedVariable.IsShared = true; } LoadFields(fieldSerializationData, fieldIndexMap, sharedVariable, namePrefix, variableSource); } return(sharedVariable); }
private static object LoadField(FieldSerializationData fieldSerializationData, Dictionary <string, int> fieldIndexMap, Type fieldType, string fieldName, IVariableSource variableSource, object obj = null, FieldInfo fieldInfo = null) { string text = fieldType.Name + fieldName; int num; if (fieldIndexMap.TryGetValue(text, out num)) { object obj2 = null; if (typeof(IList).IsAssignableFrom(fieldType)) { int num2 = BytesToInt(fieldSerializationData.byteDataArray, fieldSerializationData.dataPosition[num]); if (fieldType.IsArray) { Type elementType = fieldType.GetElementType(); if (elementType == null) { return(null); } Array array = Array.CreateInstance(elementType, num2); for (int i = 0; i < num2; i++) { object obj3 = LoadField(fieldSerializationData, fieldIndexMap, elementType, text + i, variableSource, obj, fieldInfo); array.SetValue((!(obj3 is null) && !obj3.Equals(null)) ? obj3 : null, i); } obj2 = array; } else { Type type = fieldType; while (!type.IsGenericType) { type = type.BaseType; } Type type2 = type.GetGenericArguments()[0]; IList list; if (fieldType.IsGenericType) { list = (TaskUtility.CreateInstance(typeof(List <>).MakeGenericType(new Type[] { type2 })) as IList); } else { list = (TaskUtility.CreateInstance(fieldType) as IList); } for (int j = 0; j < num2; j++) { object obj4 = LoadField(fieldSerializationData, fieldIndexMap, type2, text + j, variableSource, obj, fieldInfo); list.Add((!ReferenceEquals(obj4, null) && !obj4.Equals(null)) ? obj4 : null); } obj2 = list; } } else if (typeof(Task).IsAssignableFrom(fieldType)) { if (fieldInfo != null && TaskUtility.HasAttribute(fieldInfo, typeof(InspectTaskAttribute))) { string text2 = BytesToString(fieldSerializationData.byteDataArray, fieldSerializationData.dataPosition[num], GetFieldSize(fieldSerializationData, num)); if (!string.IsNullOrEmpty(text2)) { Type typeWithinAssembly = TaskUtility.GetTypeWithinAssembly(text2); if (typeWithinAssembly != null) { obj2 = TaskUtility.CreateInstance(typeWithinAssembly); LoadFields(fieldSerializationData, fieldIndexMap, obj2, text, variableSource); } } } else { if (taskIDs == null) { taskIDs = new Dictionary <ObjectFieldMap, List <int> >(new ObjectFieldMapComparer()); } int item = BytesToInt(fieldSerializationData.byteDataArray, fieldSerializationData.dataPosition[num]); ObjectFieldMap key = new ObjectFieldMap(obj, fieldInfo); if (taskIDs.ContainsKey(key)) { taskIDs[key].Add(item); } else { List <int> list2 = new List <int>(); list2.Add(item); taskIDs.Add(key, list2); } } } else if (typeof(SharedVariable).IsAssignableFrom(fieldType)) { obj2 = BytesToSharedVariable(fieldSerializationData, fieldIndexMap, fieldSerializationData.byteDataArray, fieldSerializationData.dataPosition[num], variableSource, true, text); } else if (typeof(UnityEngine.Object).IsAssignableFrom(fieldType)) { int index = BytesToInt(fieldSerializationData.byteDataArray, fieldSerializationData.dataPosition[num]); obj2 = IndexToUnityObject(index, fieldSerializationData); } else if (fieldType.Equals(typeof(int)) || fieldType.IsEnum) { obj2 = BytesToInt(fieldSerializationData.byteDataArray, fieldSerializationData.dataPosition[num]); } else if (fieldType.Equals(typeof(uint))) { obj2 = BytesToUInt(fieldSerializationData.byteDataArray, fieldSerializationData.dataPosition[num]); } else if (fieldType.Equals(typeof(float))) { obj2 = BytesToFloat(fieldSerializationData.byteDataArray, fieldSerializationData.dataPosition[num]); } else if (fieldType.Equals(typeof(double))) { obj2 = BytesToDouble(fieldSerializationData.byteDataArray, fieldSerializationData.dataPosition[num]); } else if (fieldType.Equals(typeof(long))) { obj2 = BytesToLong(fieldSerializationData.byteDataArray, fieldSerializationData.dataPosition[num]); } else if (fieldType.Equals(typeof(bool))) { obj2 = BytesToBool(fieldSerializationData.byteDataArray, fieldSerializationData.dataPosition[num]); } else if (fieldType.Equals(typeof(string))) { obj2 = BytesToString(fieldSerializationData.byteDataArray, fieldSerializationData.dataPosition[num], BinaryDeserialization.GetFieldSize(fieldSerializationData, num)); } else if (fieldType.Equals(typeof(byte))) { obj2 = BytesToByte(fieldSerializationData.byteDataArray, fieldSerializationData.dataPosition[num]); } else if (fieldType.Equals(typeof(Vector2))) { obj2 = BytesToVector2(fieldSerializationData.byteDataArray, fieldSerializationData.dataPosition[num]); } else if (fieldType.Equals(typeof(Vector3))) { obj2 = BytesToVector3(fieldSerializationData.byteDataArray, fieldSerializationData.dataPosition[num]); } else if (fieldType.Equals(typeof(Vector4))) { obj2 = BytesToVector4(fieldSerializationData.byteDataArray, fieldSerializationData.dataPosition[num]); } else if (fieldType.Equals(typeof(Quaternion))) { obj2 = BytesToQuaternion(fieldSerializationData.byteDataArray, fieldSerializationData.dataPosition[num]); } else if (fieldType.Equals(typeof(Color))) { obj2 = BytesToColor(fieldSerializationData.byteDataArray, fieldSerializationData.dataPosition[num]); } else if (fieldType.Equals(typeof(Rect))) { obj2 = BytesToRect(fieldSerializationData.byteDataArray, fieldSerializationData.dataPosition[num]); } else if (fieldType.Equals(typeof(Matrix4x4))) { obj2 = BytesToMatrix4x4(fieldSerializationData.byteDataArray, fieldSerializationData.dataPosition[num]); } else if (fieldType.Equals(typeof(AnimationCurve))) { obj2 = BytesToAnimationCurve(fieldSerializationData.byteDataArray, fieldSerializationData.dataPosition[num]); } else if (fieldType.Equals(typeof(LayerMask))) { obj2 = BytesToLayerMask(fieldSerializationData.byteDataArray, fieldSerializationData.dataPosition[num]); } else if (fieldType.IsClass || (fieldType.IsValueType && !fieldType.IsPrimitive)) { obj2 = TaskUtility.CreateInstance(fieldType); LoadFields(fieldSerializationData, fieldIndexMap, obj2, text, variableSource); return(obj2); } return(obj2); } if (typeof(SharedVariable).IsAssignableFrom(fieldType)) { Type type3 = TaskUtility.SharedVariableToConcreteType(fieldType); if (type3 == null) { return(null); } text = type3.Name + fieldName; if (fieldIndexMap.ContainsKey(text)) { SharedVariable sharedVariable = TaskUtility.CreateInstance(fieldType) as SharedVariable; sharedVariable.SetValue(LoadField(fieldSerializationData, fieldIndexMap, type3, fieldName, variableSource, null, null)); return(sharedVariable); } } if (typeof(SharedVariable).IsAssignableFrom(fieldType)) { return(TaskUtility.CreateInstance(fieldType)); } return(null); }
private static void LoadFields(FieldSerializationData fieldSerializationData, Dictionary <string, int> fieldIndexMap, object obj, string namePrefix, IVariableSource variableSource) { FieldInfo[] allFields = TaskUtility.GetAllFields(obj.GetType()); for (int i = 0; i < allFields.Length; i++) { if (!TaskUtility.HasAttribute(allFields[i], typeof(NonSerializedAttribute)) && ((!allFields[i].IsPrivate && !allFields[i].IsFamily) || TaskUtility.HasAttribute(allFields[i], typeof(SerializeField))) && (!(obj is ParentTask) || !allFields[i].Name.Equals("children"))) { object obj2 = LoadField(fieldSerializationData, fieldIndexMap, allFields[i].FieldType, namePrefix + allFields[i].Name, variableSource, obj, allFields[i]); if (obj2 != null && !ReferenceEquals(obj2, null) && !obj2.Equals(null)) { allFields[i].SetValue(obj, obj2); } } } }
private static object ValueToObject(Task task, Type type, object obj, IVariableSource variableSource, List <UnityEngine.Object> unityObjects) { if (type.Equals(typeof(SharedVariable)) || type.IsSubclassOf(typeof(SharedVariable))) { SharedVariable sharedVariable = JSONDeserializationDeprecated.DeserializeSharedVariable(obj as Dictionary <string, object>, variableSource, false, unityObjects); if (sharedVariable == null) { sharedVariable = (TaskUtility.CreateInstance(type) as SharedVariable); } return(sharedVariable); } if (type.Equals(typeof(UnityEngine.Object)) || type.IsSubclassOf(typeof(UnityEngine.Object))) { return(JSONDeserializationDeprecated.IndexToUnityObject(Convert.ToInt32(obj), unityObjects)); } if (!type.IsPrimitive) { if (!type.Equals(typeof(string))) { goto IL_C5; } } try { object result = Convert.ChangeType(obj, type); return(result); } catch (Exception) { object result = null; return(result); } IL_C5: if (type.IsSubclassOf(typeof(Enum))) { try { object result = Enum.Parse(type, (string)obj); return(result); } catch (Exception) { object result = null; return(result); } } if (type.Equals(typeof(Vector2))) { return(JSONDeserializationDeprecated.StringToVector2((string)obj)); } if (type.Equals(typeof(Vector3))) { return(JSONDeserializationDeprecated.StringToVector3((string)obj)); } if (type.Equals(typeof(Vector4))) { return(JSONDeserializationDeprecated.StringToVector4((string)obj)); } if (type.Equals(typeof(Quaternion))) { return(JSONDeserializationDeprecated.StringToQuaternion((string)obj)); } if (type.Equals(typeof(Matrix4x4))) { return(JSONDeserializationDeprecated.StringToMatrix4x4((string)obj)); } if (type.Equals(typeof(Color))) { return(JSONDeserializationDeprecated.StringToColor((string)obj)); } if (type.Equals(typeof(Rect))) { return(JSONDeserializationDeprecated.StringToRect((string)obj)); } if (type.Equals(typeof(LayerMask))) { return(JSONDeserializationDeprecated.ValueToLayerMask(Convert.ToInt32(obj))); } if (type.Equals(typeof(AnimationCurve))) { return(JSONDeserializationDeprecated.ValueToAnimationCurve((Dictionary <string, object>)obj)); } object obj2 = TaskUtility.CreateInstance(type); JSONDeserializationDeprecated.DeserializeObject(task, obj2, obj as Dictionary <string, object>, variableSource, unityObjects); return(obj2); }
private static void DeserializeObject(Task task, object obj, Dictionary <string, object> dict, IVariableSource variableSource, List <UnityEngine.Object> unityObjects) { if (dict == null) { return; } FieldInfo[] allFields = TaskUtility.GetAllFields(obj.GetType()); for (int i = 0; i < allFields.Length; i++) { object obj2; if (dict.TryGetValue(allFields[i].FieldType + "," + allFields[i].Name, out obj2) || dict.TryGetValue(allFields[i].Name, out obj2)) { if (typeof(IList).IsAssignableFrom(allFields[i].FieldType)) { IList list = obj2 as IList; if (list != null) { Type type; if (allFields[i].FieldType.IsArray) { type = allFields[i].FieldType.GetElementType(); } else { Type type2 = allFields[i].FieldType; while (!type2.IsGenericType) { type2 = type2.BaseType; } type = type2.GetGenericArguments()[0]; } bool flag = type.Equals(typeof(Task)) || type.IsSubclassOf(typeof(Task)); if (flag) { if (JSONDeserializationDeprecated.taskIDs != null) { List <int> list2 = new List <int>(); for (int j = 0; j < list.Count; j++) { list2.Add(Convert.ToInt32(list[j])); } JSONDeserializationDeprecated.taskIDs.Add(new JSONDeserializationDeprecated.TaskField(task, allFields[i]), list2); } } else if (allFields[i].FieldType.IsArray) { Array array = Array.CreateInstance(type, list.Count); for (int k = 0; k < list.Count; k++) { array.SetValue(JSONDeserializationDeprecated.ValueToObject(task, type, list[k], variableSource, unityObjects), k); } allFields[i].SetValue(obj, array); } else { IList list3; if (allFields[i].FieldType.IsGenericType) { list3 = (TaskUtility.CreateInstance(typeof(List <>).MakeGenericType(new Type[] { type })) as IList); } else { list3 = (TaskUtility.CreateInstance(allFields[i].FieldType) as IList); } for (int l = 0; l < list.Count; l++) { list3.Add(JSONDeserializationDeprecated.ValueToObject(task, type, list[l], variableSource, unityObjects)); } allFields[i].SetValue(obj, list3); } } } else { Type fieldType = allFields[i].FieldType; if (fieldType.Equals(typeof(Task)) || fieldType.IsSubclassOf(typeof(Task))) { if (TaskUtility.HasAttribute(allFields[i], typeof(InspectTaskAttribute))) { Dictionary <string, object> dictionary = obj2 as Dictionary <string, object>; Type typeWithinAssembly = TaskUtility.GetTypeWithinAssembly(dictionary["ObjectType"] as string); if (typeWithinAssembly != null) { Task task2 = TaskUtility.CreateInstance(typeWithinAssembly) as Task; JSONDeserializationDeprecated.DeserializeObject(task2, task2, dictionary, variableSource, unityObjects); allFields[i].SetValue(task, task2); } } else if (JSONDeserializationDeprecated.taskIDs != null) { List <int> list4 = new List <int>(); list4.Add(Convert.ToInt32(obj2)); JSONDeserializationDeprecated.taskIDs.Add(new JSONDeserializationDeprecated.TaskField(task, allFields[i]), list4); } } else { allFields[i].SetValue(obj, JSONDeserializationDeprecated.ValueToObject(task, fieldType, obj2, variableSource, unityObjects)); } } } else if (typeof(SharedVariable).IsAssignableFrom(allFields[i].FieldType) && !allFields[i].FieldType.IsAbstract) { if (dict.TryGetValue(allFields[i].FieldType + "," + allFields[i].Name, out obj2)) { SharedVariable sharedVariable = TaskUtility.CreateInstance(allFields[i].FieldType) as SharedVariable; sharedVariable.SetValue(JSONDeserializationDeprecated.ValueToObject(task, allFields[i].FieldType, obj2, variableSource, unityObjects)); allFields[i].SetValue(obj, sharedVariable); } else { SharedVariable value = TaskUtility.CreateInstance(allFields[i].FieldType) as SharedVariable; allFields[i].SetValue(obj, value); } } } }
private static SharedVariable DeserializeSharedVariable(Dictionary <string, object> dict, IVariableSource variableSource, bool fromSource, List <UnityEngine.Object> unityObjects) { if (dict == null) { return(null); } SharedVariable sharedVariable = null; object obj; if (!fromSource && variableSource != null && dict.TryGetValue("Name", out obj)) { object value; dict.TryGetValue("IsGlobal", out value); if (!dict.TryGetValue("IsGlobal", out value) || !Convert.ToBoolean(value)) { sharedVariable = variableSource.GetVariable(obj as string); } else { if (JSONDeserializationDeprecated.globalVariables == null) { JSONDeserializationDeprecated.globalVariables = GlobalVariables.Instance; } if (JSONDeserializationDeprecated.globalVariables != null) { sharedVariable = JSONDeserializationDeprecated.globalVariables.GetVariable(obj as string); } } } Type typeWithinAssembly = TaskUtility.GetTypeWithinAssembly(dict["Type"] as string); if (typeWithinAssembly == null) { return(null); } bool flag = true; if (sharedVariable == null || !(flag = sharedVariable.GetType().Equals(typeWithinAssembly))) { sharedVariable = (TaskUtility.CreateInstance(typeWithinAssembly) as SharedVariable); sharedVariable.name = (dict["Name"] as string); object obj2; if (dict.TryGetValue("IsShared", out obj2)) { sharedVariable.isShared = Convert.ToBoolean(obj2); } if (dict.TryGetValue("IsGlobal", out obj2)) { sharedVariable.isGlobal = Convert.ToBoolean(obj2); } if (dict.TryGetValue("NetworkSync", out obj2)) { sharedVariable.networkSync = Convert.ToBoolean(obj2); } if (!sharedVariable.isGlobal && dict.TryGetValue("PropertyMapping", out obj2)) { sharedVariable.propertyMapping = (obj2 as string); if (dict.TryGetValue("PropertyMappingOwner", out obj2)) { sharedVariable.propertyMappingOwner = (JSONDeserializationDeprecated.IndexToUnityObject(Convert.ToInt32(obj2), unityObjects) as GameObject); } sharedVariable.InitializePropertyMapping(variableSource as BehaviorSource); } if (!flag) { sharedVariable.isShared = true; } JSONDeserializationDeprecated.DeserializeObject(null, sharedVariable, dict, variableSource, unityObjects); } return(sharedVariable); }
internal static bool EvaluateConditionalVariableWithParameters(string varIdentifier, IVariableSource variableSource, List <string> otherParameters) { var value = EvaluateVariable(varIdentifier, variableSource, out var variableValue); //If no special parameters are found simply return the found value if (otherParameters.Count <= 0) { return(value); } //Process the extra parameters string lastOperator = null; foreach (var otherParameter in otherParameters) { switch (otherParameter) { case OrTagIdentifier: case AndTagIdentifier: case EqualTagIdentifier: case GreaterTagIdentifier: case LessTagIdentifier: lastOperator = otherParameter; break; case NotTagIdentifier: value = !value; lastOperator = null; break; default: { if (lastOperator != null) { object nextValue; nextValue = variableSource.GetVariable(otherParameter) ?? otherParameter; var nextValueEvaluated = EvaluateVariableValue(nextValue); switch (lastOperator) { case OrTagIdentifier: value = value || nextValueEvaluated; break; case AndTagIdentifier: value = value && nextValueEvaluated; break; case EqualTagIdentifier: value = variableValue?.ToString() == nextValue.ToString(); break; case GreaterTagIdentifier: try { value = float.Parse(variableValue?.ToString()) > float.Parse(nextValue.ToString()); } catch { try { value = int.Parse(variableValue?.ToString()) > int.Parse(nextValue.ToString()); } catch { // ignored } } break; case LessTagIdentifier: try { value = float.Parse(variableValue?.ToString()) < float.Parse(nextValue.ToString()); } catch { try { value = int.Parse(variableValue?.ToString()) < int.Parse(nextValue.ToString()); } catch { // ignored } } break; } lastOperator = null; } break; } } } return(value); }
/// <summary> /// Create a new instance and initialize with the given variable source /// </summary> /// <param name="variableSource"></param> public VariablePlaceholderConfigurer(IVariableSource variableSource) { this.VariableSource = variableSource; }
/// <summary> /// Create a new instance and initialize with the given variable source /// </summary> /// <param name="variableSource"></param> public VariablePlaceholderConfigurer(IVariableSource variableSource) { this.VariableSource = variableSource; }
public TextProcessor(VariablePlaceholderConfigurer owner, IVariableSource variableSource) { this.owner = owner; this.variableSource = variableSource; }