Пример #1
0
    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 int AddPropertyName(SharedVariable sharedVariable, GameObject gameObject, ref List <string> propertyNames, ref List <GameObject> propertyGameObjects, bool behaviorGameObject)
        {
            int result = -1;

            if (gameObject != null)
            {
                Component[] components   = gameObject.GetComponents(typeof(Component));
                Type        propertyType = sharedVariable.GetType().GetProperty("Value").PropertyType;
                for (int i = 0; i < components.Length; i++)
                {
                    PropertyInfo[] properties = components[i].GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public);
                    for (int j = 0; j < properties.Length; j++)
                    {
                        if (properties[j].PropertyType.Equals(propertyType) && !properties[j].IsSpecialName)
                        {
                            string text = components[i].GetType().FullName + "/" + properties[j].Name;
                            if (text.Equals(sharedVariable.PropertyMapping) && (object.Equals(sharedVariable.PropertyMappingOwner, gameObject) || (object.Equals(sharedVariable.PropertyMappingOwner, null) && behaviorGameObject)))
                            {
                                result = propertyNames.Count;
                            }
                            propertyNames.Add(text);
                            propertyGameObjects.Add(gameObject);
                        }
                    }
                }
            }
            return(result);
        }
Пример #3
0
        // Token: 0x060001F9 RID: 505 RVA: 0x0001280C File Offset: 0x00010A0C
        private static Dictionary <string, object> SerializeVariable(SharedVariable sharedVariable, ref List <Object> unityObjects)
        {
            if (sharedVariable == null)
            {
                return(null);
            }
            Dictionary <string, object> dictionary = new Dictionary <string, object>();

            dictionary.Add("Type", sharedVariable.GetType());
            dictionary.Add("Name", sharedVariable.Name);
            if (sharedVariable.IsShared)
            {
                dictionary.Add("IsShared", sharedVariable.IsShared);
            }
            if (sharedVariable.IsGlobal)
            {
                dictionary.Add("IsGlobal", sharedVariable.IsGlobal);
            }
            if (sharedVariable.NetworkSync)
            {
                dictionary.Add("NetworkSync", sharedVariable.NetworkSync);
            }
            if (!string.IsNullOrEmpty(sharedVariable.PropertyMapping))
            {
                dictionary.Add("PropertyMapping", sharedVariable.PropertyMapping);
                if (!object.Equals(sharedVariable.PropertyMappingOwner, null))
                {
                    dictionary.Add("PropertyMappingOwner", unityObjects.Count);
                    unityObjects.Add(sharedVariable.PropertyMappingOwner);
                }
            }
            JSONSerialization.SerializeFields(sharedVariable, ref dictionary, ref unityObjects);
            return(dictionary);
        }
Пример #4
0
        public override TaskStatus OnUpdate()
        {
            if (targetGameObject == null || targetGameObject.Value == null)
            {
                Debug.LogWarning("Unable to invoke method");
                return(TaskStatus.Failure);
            }

            var type = TaskUtility.GetTypeWithinAssembly(componentName.Value);

            if (type == null)
            {
                Debug.LogWarning("Unable to invoke - type is null");
                return(TaskStatus.Failure);
            }

            var component = targetGameObject.Value.GetComponent(type);

            if (component == null)
            {
                Debug.LogWarning("Unable to invoke method with component " + componentName.Value);
                return(TaskStatus.Failure);
            }

            var            parameterList     = new List <object>();
            var            parameterTypeList = new List <Type>();
            SharedVariable sharedVariable    = null;

            for (int i = 0; i < 4; ++i)
            {
                var parameterField = GetType().GetField("parameter" + (i + 1));
                if ((sharedVariable = parameterField.GetValue(this) as SharedVariable) != null)
                {
                    parameterList.Add(sharedVariable.GetValue());
                    parameterTypeList.Add(sharedVariable.GetType().GetProperty("Value").PropertyType);
                }
                else
                {
                    break;
                }
            }
            // If you are receiving a compiler error on the Windows Store platform see this topic:
            // http://www.opsive.com/assets/BehaviorDesigner/documentation.php?id=46
            var methodInfo = component.GetType().GetMethod(methodName.Value, parameterTypeList.ToArray());

            if (methodInfo == null)
            {
                Debug.LogWarning("Unable to invoke method " + methodName.Value + " on component " + componentName.Value);
                return(TaskStatus.Failure);
            }

            var result = methodInfo.Invoke(component, parameterList.ToArray());

            if (storeResult != null)
            {
                storeResult.SetValue(result);
            }

            return(TaskStatus.Success);
        }
Пример #5
0
 private static void SaveSharedVariable(SharedVariable sharedVariable, string namePrefix)
 {
     if (sharedVariable == null)
     {
         return;
     }
     BinarySerialization.SaveField(typeof(string), namePrefix + "Type", sharedVariable.GetType().ToString(), null);
     BinarySerialization.SaveField(typeof(string), namePrefix + "Name", sharedVariable.Name, null);
     if (sharedVariable.IsShared)
     {
         BinarySerialization.SaveField(typeof(bool), namePrefix + "IsShared", sharedVariable.IsShared, null);
     }
     if (sharedVariable.IsGlobal)
     {
         BinarySerialization.SaveField(typeof(bool), namePrefix + "IsGlobal", sharedVariable.IsGlobal, null);
     }
     if (sharedVariable.NetworkSync)
     {
         BinarySerialization.SaveField(typeof(bool), namePrefix + "NetworkSync", sharedVariable.NetworkSync, null);
     }
     if (!string.IsNullOrEmpty(sharedVariable.PropertyMapping))
     {
         BinarySerialization.SaveField(typeof(string), namePrefix + "PropertyMapping", sharedVariable.PropertyMapping, null);
         if (!object.Equals(sharedVariable.PropertyMappingOwner, null))
         {
             BinarySerialization.SaveField(typeof(GameObject), namePrefix + "PropertyMappingOwner", sharedVariable.PropertyMappingOwner, null);
         }
     }
     BinarySerialization.SaveFields(sharedVariable, namePrefix);
 }
Пример #6
0
        public override TaskStatus OnUpdate()
        {
            targetGameObject.Value = gameObject;// 临时使用
            if (targetGameObject == null || targetGameObject.Value == null)
            {
                Debug.LogWarning("Unable to invoke method");
                return(TaskStatus.Failure);
            }

            var type = TaskUtility.GetTypeWithinAssembly(componentName.Value);

            if (type == null)
            {
                Debug.LogWarning("Unable to invoke - type is null");
                return(TaskStatus.Failure);
            }

            var component = targetGameObject.Value.GetComponent(type);

            if (component == null)
            {
                Debug.LogWarning("Unable to invoke method with component " + componentName.Value);
                return(TaskStatus.Failure);
            }

            var            parameterList     = new List <object>();
            var            parameterTypeList = new List <Type>();
            SharedVariable sharedVariable    = null;

            for (int i = 0; i < 4; ++i)
            {
                var parameterField = GetType().GetField("parameter" + (i + 1));
                if ((sharedVariable = parameterField.GetValue(this) as SharedVariable) != null)
                {
                    parameterList.Add(sharedVariable.GetValue());
                    parameterTypeList.Add(sharedVariable.GetType().GetProperty("Value").PropertyType);
                }
                else
                {
                    break;
                }
            }
            var methodInfo = component.GetType().GetMethod(methodName.Value, parameterTypeList.ToArray());

            if (methodInfo == null)
            {
                Debug.LogWarning("Unable to invoke method " + methodName.Value + " on component " + componentName.Value);
                return(TaskStatus.Failure);
            }

            var result = methodInfo.Invoke(component, parameterList.ToArray());

            if (storeResult != null)
            {
                storeResult.SetValue(result);
            }

            return(TaskStatus.Success);
        }
        public void SetVariable(SharedVariable sharedVariable)
        {
            if (sharedVariable == null)
            {
                return;
            }
            CheckSerialization();

            if (variables == null)
            {
                variables = new List <SharedVariable>();
            }
            else if (sharedVariableIndex == null)
            {
                UpdateVariablesIndex();
            }
            int index;

            if (sharedVariableIndex != null && sharedVariableIndex.TryGetValue(sharedVariable.GUID, out index))
            {
                SharedVariable sharedVariable2 = variables[index];
                if (!sharedVariable2.GetType().Equals(typeof(SharedVariable)) && !sharedVariable2.GetType().Equals(sharedVariable.GetType()))
                {
                    Debug.LogError(string.Format("Error: Unable to set SharedVariable {0} - the variable type {1} does not match the existing type {2}", sharedVariable.GUID, sharedVariable2.GetType(), sharedVariable.GetType()));
                }
                else
                {
                    sharedVariable2.SetValue(sharedVariable.GetValue());
                }
            }
            else
            {
                variables.Add(sharedVariable);
                UpdateVariablesIndex();
            }
        }
Пример #8
0
 internal static SharedVariable DrawSharedVariableToggleSharedButton(SharedVariable sharedVariable)
 {
     if (sharedVariable == null)
     {
         return(null);
     }
     if (GUILayout.Button((!sharedVariable.IsShared) ? BehaviorDesignerUtility.VariableButtonTexture : BehaviorDesignerUtility.VariableButtonSelectedTexture, BehaviorDesignerUtility.PlainButtonGUIStyle, new GUILayoutOption[]
     {
         GUILayout.Width(15f)
     }))
     {
         bool isShared = !sharedVariable.IsShared;
         if (sharedVariable.GetType().Equals(typeof(SharedVariable)))
         {
             sharedVariable = (Activator.CreateInstance(FieldInspector.FriendlySharedVariableName(sharedVariable.GetType().GetProperty("Value").PropertyType), true) as SharedVariable);
         }
         else
         {
             sharedVariable = (Activator.CreateInstance(sharedVariable.GetType(), true) as SharedVariable);
         }
         sharedVariable.IsShared = isShared;
     }
     return(sharedVariable);
 }
        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);
        }
Пример #10
0
        private static bool DrawSelectedVariable(IVariableSource variableSource, ref List <SharedVariable> variables, SharedVariable sharedVariable, ref int selectedVariableIndex, ref string selectedVariableName, ref int selectedVariableTypeIndex, ref bool deleted)
        {
            bool result = false;

            GUILayout.BeginVertical(BehaviorDesignerUtility.SelectedBackgroundGUIStyle, new GUILayoutOption[0]);
            GUILayout.BeginHorizontal(new GUILayoutOption[0]);
            GUILayout.Label("Name", new GUILayoutOption[]
            {
                GUILayout.Width(70f)
            });
            EditorGUI.BeginChangeCheck();
            selectedVariableName = GUILayout.TextField(selectedVariableName, new GUILayoutOption[]
            {
                GUILayout.Width(140f)
            });
            if (EditorGUI.EndChangeCheck())
            {
                if (VariableInspector.VariableNameValid(variableSource, selectedVariableName))
                {
                    variableSource.UpdateVariableName(sharedVariable, selectedVariableName);
                }
                result = true;
            }
            GUILayout.Space(10f);
            bool enabled = GUI.enabled;

            GUI.enabled = (enabled && selectedVariableIndex < variables.Count - 1);
            if (GUILayout.Button(BehaviorDesignerUtility.DownArrowButtonTexture, BehaviorDesignerUtility.PlainButtonGUIStyle, new GUILayoutOption[]
            {
                GUILayout.Width(19f)
            }))
            {
                SharedVariable value = variables[selectedVariableIndex + 1];
                variables[selectedVariableIndex + 1] = variables[selectedVariableIndex];
                variables[selectedVariableIndex]     = value;
                selectedVariableIndex++;
                result = true;
            }
            GUI.enabled = (enabled && (selectedVariableIndex < variables.Count - 1 || selectedVariableIndex != 0));
            GUILayout.Box(string.Empty, BehaviorDesignerUtility.ArrowSeparatorGUIStyle, new GUILayoutOption[]
            {
                GUILayout.Width(1f),
                GUILayout.Height(18f)
            });
            GUI.enabled = (enabled && selectedVariableIndex != 0);
            if (GUILayout.Button(BehaviorDesignerUtility.UpArrowButtonTexture, BehaviorDesignerUtility.PlainButtonGUIStyle, new GUILayoutOption[]
            {
                GUILayout.Width(20f)
            }))
            {
                SharedVariable value2 = variables[selectedVariableIndex - 1];
                variables[selectedVariableIndex - 1] = variables[selectedVariableIndex];
                variables[selectedVariableIndex]     = value2;
                selectedVariableIndex--;
                result = true;
            }
            GUI.enabled = enabled;
            if (GUILayout.Button(BehaviorDesignerUtility.VariableDeleteButtonTexture, BehaviorDesignerUtility.PlainButtonGUIStyle, new GUILayoutOption[]
            {
                GUILayout.Width(19f)
            }) && EditorUtility.DisplayDialog("Delete Variable", "Are you sure you want to delete this variable?", "Yes", "No"))
            {
                deleted = true;
            }
            GUILayout.EndHorizontal();
            GUILayout.Space(2f);
            GUILayout.BeginHorizontal(new GUILayoutOption[0]);
            GUILayout.Label("Type", new GUILayoutOption[]
            {
                GUILayout.Width(70f)
            });
            EditorGUI.BeginChangeCheck();
            selectedVariableTypeIndex = EditorGUILayout.Popup(selectedVariableTypeIndex, VariableInspector.sharedVariableStrings, EditorStyles.toolbarPopup, new GUILayoutOption[]
            {
                GUILayout.Width(200f)
            });
            if (EditorGUI.EndChangeCheck() && VariableInspector.sharedVariableTypesDict[sharedVariable.GetType().Name] != selectedVariableTypeIndex)
            {
                if (BehaviorDesignerWindow.instance != null)
                {
                    BehaviorDesignerWindow.instance.RemoveSharedVariableReferences(sharedVariable);
                }
                sharedVariable = VariableInspector.CreateVariable(selectedVariableTypeIndex, sharedVariable.Name, sharedVariable.IsGlobal);
                variables[selectedVariableIndex] = sharedVariable;
                result = true;
            }
            GUILayout.EndHorizontal();
            EditorGUI.BeginChangeCheck();
            GUILayout.Space(4f);
            GUILayout.BeginHorizontal(new GUILayoutOption[0]);
            GUI.enabled = VariableInspector.CanNetworkSync(sharedVariable.GetType().GetProperty("Value").PropertyType);
            EditorGUI.BeginChangeCheck();
            sharedVariable.NetworkSync = EditorGUILayout.Toggle(new GUIContent("Network Sync", "Sync this variable over the network. Requires Unity 5.1 or greator. A NetworkIdentity must be attached to the behavior tree GameObject."), sharedVariable.NetworkSync, new GUILayoutOption[0]);
            if (EditorGUI.EndChangeCheck())
            {
                result = true;
            }
            GUILayout.EndHorizontal();
            GUI.enabled = enabled;
            if (VariableInspector.DrawSharedVariable(variableSource, sharedVariable, true))
            {
                result = true;
            }
            BehaviorDesignerUtility.DrawContentSeperator(4, 7);
            GUILayout.EndVertical();
            GUILayout.Space(3f);
            return(result);
        }
Пример #11
0
 public static SharedVariable DrawSharedVariable(Task task, GUIContent guiContent, FieldInfo fieldInfo, Type fieldType, SharedVariable sharedVariable)
 {
     if (!fieldType.Equals(typeof(SharedVariable)) && sharedVariable == null)
     {
         sharedVariable = (Activator.CreateInstance(fieldType, true) as SharedVariable);
         if (TaskUtility.HasAttribute(fieldInfo, typeof(RequiredFieldAttribute)) || TaskUtility.HasAttribute(fieldInfo, typeof(SharedRequiredAttribute)))
         {
             sharedVariable.IsShared = true;
         }
         GUI.changed = true;
     }
     if (sharedVariable == null || sharedVariable.IsShared)
     {
         GUILayout.BeginHorizontal(new GUILayoutOption[0]);
         string[] array           = null;
         int      num             = -1;
         int      num2            = FieldInspector.GetVariablesOfType((sharedVariable == null) ? null : sharedVariable.GetType().GetProperty("Value").PropertyType, sharedVariable != null && sharedVariable.IsGlobal, (sharedVariable == null) ? string.Empty : sharedVariable.Name, FieldInspector.behaviorSource, out array, ref num, fieldType.Equals(typeof(SharedVariable)));
         Color    backgroundColor = GUI.backgroundColor;
         if (num2 == 0 && !TaskUtility.HasAttribute(fieldInfo, typeof(SharedRequiredAttribute)))
         {
             GUI.backgroundColor = Color.red;
         }
         int num3 = num2;
         num2 = EditorGUILayout.Popup(guiContent.text, num2, array, BehaviorDesignerUtility.SharedVariableToolbarPopup, new GUILayoutOption[0]);
         GUI.backgroundColor = backgroundColor;
         if (num2 != num3)
         {
             if (num2 == 0)
             {
                 if (fieldType.Equals(typeof(SharedVariable)))
                 {
                     sharedVariable = null;
                 }
                 else
                 {
                     sharedVariable          = (Activator.CreateInstance(fieldType, true) as SharedVariable);
                     sharedVariable.IsShared = true;
                 }
             }
             else if (num != -1 && num2 >= num)
             {
                 sharedVariable = GlobalVariables.Instance.GetVariable(array[num2].Substring(8, array[num2].Length - 8));
             }
             else
             {
                 sharedVariable = FieldInspector.behaviorSource.GetVariable(array[num2]);
             }
             GUI.changed = true;
         }
         if (!fieldType.Equals(typeof(SharedVariable)) && !TaskUtility.HasAttribute(fieldInfo, typeof(RequiredFieldAttribute)) && !TaskUtility.HasAttribute(fieldInfo, typeof(SharedRequiredAttribute)))
         {
             sharedVariable = FieldInspector.DrawSharedVariableToggleSharedButton(sharedVariable);
             GUILayout.Space(-3f);
         }
         GUILayout.EndHorizontal();
         GUILayout.Space(3f);
     }
     else
     {
         GUILayout.BeginHorizontal(new GUILayoutOption[0]);
         ObjectDrawerAttribute[] array2;
         ObjectDrawer            objectDrawer;
         if (fieldInfo != null && (array2 = (fieldInfo.GetCustomAttributes(typeof(ObjectDrawerAttribute), true) as ObjectDrawerAttribute[])).Length > 0 && (objectDrawer = ObjectDrawerUtility.GetObjectDrawer(task, array2[0])) != null)
         {
             objectDrawer.Value = sharedVariable;
             objectDrawer.OnGUI(guiContent);
         }
         else
         {
             FieldInspector.DrawFields(task, sharedVariable, guiContent);
         }
         if (!TaskUtility.HasAttribute(fieldInfo, typeof(RequiredFieldAttribute)) && !TaskUtility.HasAttribute(fieldInfo, typeof(SharedRequiredAttribute)))
         {
             sharedVariable = FieldInspector.DrawSharedVariableToggleSharedButton(sharedVariable);
         }
         GUILayout.EndHorizontal();
     }
     return(sharedVariable);
 }
Пример #12
0
 private int getVariablesOfType(SharedVariable thisVariable, SkillData _data, out string[] names)
 {
     int result = 0;
         int num = 1;
         List<string> list = new List<string>();
         list.Add("None");
         if (_data.Variables != null)
         {
             foreach (var item in _data.Variables.Values)
             {
                 if (item.GetType().Equals(thisVariable.GetType()))
                 {
                     list.Add(item.name);
                     if (item.name.Equals(thisVariable.name))
                     {
                         result = num;
                     }
                     num++;
                 }
             }
         }
         names = list.ToArray();
         return result;
 }