예제 #1
0
        private void ReceivedEvent(object arg1)
        {
            ReceivedEvent();

            if (storedValue1 != null && !storedValue1.IsNone)
            {
                storedValue1.SetValue(arg1);
            }
        }
예제 #2
0
        public override TaskStatus OnUpdate()
        {
            if (propertyValue == null)
            {
                Debug.LogWarning("Unable to get property - property value is null");
                return(TaskStatus.Failure);
            }

            if (targetGameObject == null || targetGameObject.Value == null)
            {
                Debug.LogWarning("Unable to get property - target GameObject is null");
                return(TaskStatus.Failure);
            }

            var component = targetGameObject.Value.GetComponent(TaskUtility.GetTypeWithinAssembly(componentName.Value));

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

            var property = component.GetType().GetProperty(propertyName.Value);

            propertyValue.SetValue(property.GetValue(component, null));

            return(TaskStatus.Success);
        }
예제 #3
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);
        }
예제 #4
0
        public override TaskStatus OnUpdate()
        {
            if (propertyValue == null)
            {
                Debug.LogWarning("Unable to get property - property value is null");
                return(TaskStatus.Failure);
            }

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

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

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

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

            // 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 property = component.GetType().GetProperty(propertyName.Value);

            propertyValue.SetValue(property.GetValue(component, null));

            return(TaskStatus.Success);
        }
예제 #5
0
        public override TaskStatus OnUpdate()
        {
            if (fieldValue == null)
            {
                Debug.LogWarning("Unable to get field - field value is null");
                return(TaskStatus.Failure);
            }

            if (targetGameObject == null || targetGameObject.Value == null)
            {
                Debug.LogWarning("Unable to get field - target GameObject is null");
                return(TaskStatus.Failure);
            }

            var component = targetGameObject.Value.GetComponent(TaskUtility.GetTypeWithinAssembly(componentName.Value));

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

            var field = component.GetType().GetField(fieldName.Value);

            fieldValue.SetValue(field.GetValue(component));

            return(TaskStatus.Success);
        }
        public override TaskStatus OnUpdate()
        {
            if (fieldValue == null)
            {
                Debug.LogWarning("Unable to get field - field value is null");
                return(TaskStatus.Failure);
            }

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

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

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

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

            // If you are receiving a compiler error on the Windows Store platform see this topic:
            // https://www.opsive.com/support/documentation/behavior-designer/installation/
            var field = component.GetType().GetField(fieldName.Value);

            fieldValue.SetValue(field.GetValue(component));

            return(TaskStatus.Success);
        }
예제 #7
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 override TaskStatus OnUpdate()
        {
            if (variable == null)
            {
                return(TaskStatus.Failure);
            }

            variable.SetValue(ValueHelper.GetValue(value));

            return(TaskStatus.Success);
        }
예제 #9
0
        public void SetVariable(string name, object value)
        {
            if (_behavior_tree == null)
            {
                return;
            }
            SharedVariable sharedvar = _behavior_tree.GetVariable(name);

            if (sharedvar != null)
            {
                sharedvar.SetValue(value);
            }
        }
예제 #10
0
        private void DoSync()
        {
            FsmVariable    variable       = this.Root.GetVariable(variableName.Value);
            SharedVariable sharedVariable = behaviorTree.GetVariable(variableName.Value);

            if (direction == Direction.FromBehaviourTree)
            {
                variable.SetValue(sharedVariable.GetValue());
            }
            else
            {
                sharedVariable.SetValue(variable.GetValue());
            }
        }
        // Token: 0x060002BA RID: 698 RVA: 0x0001AC70 File Offset: 0x00018E70
        public static bool SyncVariables(BehaviorSource localBehaviorSource, List <SharedVariable> variables)
        {
            List <SharedVariable> list = localBehaviorSource.GetAllVariables();

            if (variables != null)
            {
                bool result = false;
                if (list == null)
                {
                    list = new List <SharedVariable>();
                    localBehaviorSource.SetAllVariables(list);
                    result = true;
                }
                for (int i = 0; i < variables.Count; i++)
                {
                    if (list.Count - 1 < i)
                    {
                        SharedVariable sharedVariable = Activator.CreateInstance(variables[i].GetType()) as SharedVariable;
                        sharedVariable.Name     = variables[i].Name;
                        sharedVariable.IsShared = true;
                        sharedVariable.SetValue(variables[i].GetValue());
                        list.Add(sharedVariable);
                        result = true;
                    }
                    else if (list[i].Name != variables[i].Name || list[i].GetType() != variables[i].GetType())
                    {
                        SharedVariable sharedVariable2 = Activator.CreateInstance(variables[i].GetType()) as SharedVariable;
                        sharedVariable2.Name     = variables[i].Name;
                        sharedVariable2.IsShared = true;
                        sharedVariable2.SetValue(variables[i].GetValue());
                        list[i] = sharedVariable2;
                        result  = true;
                    }
                }
                for (int j = list.Count - 1; j > variables.Count - 1; j--)
                {
                    list.RemoveAt(j);
                    result = true;
                }
                return(result);
            }
            if (list != null && list.Count > 0)
            {
                list.Clear();
                return(true);
            }
            return(false);
        }
예제 #12
0
        private void ReceivedEvent(object arg1, object arg2, object arg3)
        {
            ReceivedEvent();

            if (storedValue1 != null && !storedValue1.IsNone)
            {
                storedValue1.SetValue(arg1);
            }

            if (storedValue2 != null && !storedValue2.IsNone)
            {
                storedValue2.SetValue(arg2);
            }

            if (storedValue3 != null && !storedValue3.IsNone)
            {
                storedValue3.SetValue(arg3);
            }
        }
        public override void OnGUI(GUIContent label)
        {
            SharedVariable variable      = Value as SharedVariable;
            IVariableOwner variableOwner = variable.VariableOwner;

            if (variableOwner == null)
            {
                EditorGUILayout.HelpBox("没有VariableOwner", MessageType.Error); return;
            }
            //EditorGUILayout.HelpBox("ReferenceType:" + variable.GUID, MessageType.Info);
            //if (variableOwner.GetVariable(variable.GUID) == null)
            //    variableOwner.SetVariable(variable.Clone() as SharedVariable);
            EditorGUI.BeginChangeCheck();
            object value = EditorGUILayoutExtension.DrawField(label, variable.GetValueType(), variable.GetValue());

            if (EditorGUI.EndChangeCheck())
            {
                variable.SetValue(value);
                EditorUtility.SetDirty(variableOwner.Self());
            }
        }
예제 #14
0
    public virtual void KnockbackEnemy(Vector3 knockBackDirection, float knockBackTime = .2f, float KnockBackSpeed = 50f)
    {
        SharedVariable KnockBackDirVar = behaviorTree.GetVariable("KnockBackDirection");

        if (KnockBackDirVar != null)
        {
            KnockBackDirVar.SetValue(knockBackDirection);
        }
        SharedVariable KnockbackTime = behaviorTree.GetVariable("KnockbackTime");

        if (KnockbackTime != null)
        {
            KnockbackTime.SetValue(knockBackTime);
        }
        SharedVariable KnockbackSpeed = behaviorTree.GetVariable("KnockbackSpeed");

        if (KnockbackSpeed != null)
        {
            KnockbackSpeed.SetValue(KnockBackSpeed);
        }
        behaviorTree.SendEvent("TookDamage");
    }
        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();
            }
        }
예제 #16
0
    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);
    }
예제 #17
0
 public static void DrawSharedVariableValue(SharedVariable sharedVariable, int width)
 {
     if (sharedVariable == null)
     {
         return;
     }
     try
     {
         switch (sharedVariable.ValueType)
         {
             case SharedVariableTypes.Int:
                 sharedVariable.SetValue(EditorGUILayout.IntField((int)sharedVariable.GetValue(), new GUILayoutOption[]
                 {
                     GUILayout.Width((float)width)
                 }));
                 break;
             case SharedVariableTypes.Float:
                 sharedVariable.SetValue(EditorGUILayout.FloatField((float)sharedVariable.GetValue(), new GUILayoutOption[]
                 {
                     GUILayout.Width((float)width)
                 }));
                 break;
             case SharedVariableTypes.Bool:
                 sharedVariable.SetValue(EditorGUILayout.Toggle((bool)sharedVariable.GetValue(), EditorStyles.toggle, new GUILayoutOption[]
                 {
                     GUILayout.Width((float)width)
                 }));
                 break;
             case SharedVariableTypes.String:
                 sharedVariable.SetValue(EditorGUILayout.TextField((string)sharedVariable.GetValue(), new GUILayoutOption[]
                 {
                     GUILayout.Width((float)width)
                 }));
                 break;
             case SharedVariableTypes.Vector2:
                 sharedVariable.SetValue(VariableInspector.Vector2Field((Vector2)sharedVariable.GetValue()));
                 break;
             case SharedVariableTypes.Vector3:
                 sharedVariable.SetValue(VariableInspector.Vector3Field((Vector3)sharedVariable.GetValue()));
                 break;
             case SharedVariableTypes.Vector4:
                 sharedVariable.SetValue(VariableInspector.Vector4Field((Vector4)sharedVariable.GetValue()));
                 break;
             case SharedVariableTypes.Quaternion:
                 {
                     Vector4 vector = VariableInspector.QuaternionToVector4((Quaternion)sharedVariable.GetValue());
                     Vector4 vector2 = VariableInspector.Vector4Field(vector);
                     if (vector != vector2)
                     {
                         sharedVariable.SetValue(new Quaternion(vector2.x, vector2.y, vector2.z, vector2.w));
                     }
                     break;
                 }
             case SharedVariableTypes.Color:
                 sharedVariable.SetValue(EditorGUILayout.ColorField((Color)sharedVariable.GetValue(), new GUILayoutOption[]
                 {
                     GUILayout.Width((float)width)
                 }));
                 break;
             case SharedVariableTypes.Rect:
                 sharedVariable.SetValue(EditorGUILayout.RectField((Rect)sharedVariable.GetValue(), new GUILayoutOption[0]));
                 break;
             case SharedVariableTypes.GameObject:
                 sharedVariable.SetValue(EditorGUILayout.ObjectField((GameObject)sharedVariable.GetValue(), typeof(GameObject), true, new GUILayoutOption[]
                 {
                     GUILayout.Width((float)width)
                 }));
                 break;
             case SharedVariableTypes.Transform:
                 sharedVariable.SetValue(EditorGUILayout.ObjectField((Transform)sharedVariable.GetValue(), typeof(Transform), true, new GUILayoutOption[]
                 {
                     GUILayout.Width((float)width)
                 }));
                 break;
             case SharedVariableTypes.Object:
                 sharedVariable.SetValue(EditorGUILayout.ObjectField((UnityEngine.Object)sharedVariable.GetValue(), typeof(UnityEngine.Object), true, new GUILayoutOption[]
                 {
                     GUILayout.Width((float)width)
                 }));
                 break;
         }
     }
     catch (Exception)
     {
     }
 }