public Action MakeAction(GameObject ufo, IActionCallback callback)
    {
        var ctl = ufo.GetComponent <UFOController>() as UFOController;

        switch (curActionMode)
        {
        case ActionMode.Kinematics: {
            var action = UFOActionKinematics.GetAction(ctl.speed) as Action;
            action.gameObject = ufo;
            action.transform  = ufo.transform;
            action.callback   = callback;
            return(action);
        }

        case ActionMode.Dynamics: {
            var action = UFOActionDynamics.GetAction(ctl.speed) as Action;
            action.gameObject = ufo;
            action.transform  = ufo.transform;
            action.callback   = callback;
            return(action);
        }

        default:
            break;
        }

        return(null);
    }
Exemple #2
0
    private void runAction(GameObject ufo, IActionCallback callback)
    {
        var action = actionAdapter.MakeAction(ufo, callback);

        startedActions.Add(action);
        actionManager.AddAction(action);
    }
Exemple #3
0
 public void AddAction(GameObject gameObject, Action action, IActionCallback callback)
 {
     action.gameObject = gameObject;
     action.callback   = callback;
     add_list.Add(action);
     action.Start();
 }
Exemple #4
0
 public void RunAction(GameObject gameobject, Action action, IActionCallback manager)
 {
     action.gameobject = gameobject;
     action.transform  = gameobject.transform;
     action.callback   = manager;
     waitingAdd.Add(action);
     action.Start();
 }
 public void RunAction(GameObject gameObject, SSAction action, IActionCallback manager)
 {
     //Debug.Log("run action");
     action.gameObject = gameObject;
     action.transform  = gameObject.transform;
     action.callback   = manager;
     waitingAdd.Add(action);
     action.Start();
 }
        // 创建 SequenceAction 。
        public static SequenceAction GetAction(IActionCallback callback, List <Action> sequence, int repeat = 1, int currentActionIndex = 0)
        {
            SequenceAction action = CreateInstance <SequenceAction>();

            action.callback           = callback;
            action.sequence           = sequence;
            action.repeat             = repeat;
            action.currentActionIndex = currentActionIndex;
            return(action);
        }
Exemple #7
0
        public static TraceAction GetAction(GameObject gameObject, IActionCallback callback, GameObject target, float speed)
        {
            TraceAction action = CreateInstance <TraceAction>();

            action.gameObject = gameObject;
            action.transform  = gameObject.transform;
            action.callback   = callback;
            action.target     = target;
            action.speed      = speed;
            return(action);
        }
        public static MoveToAction GetAction(GameObject gameObject, IActionCallback callback, Vector3 target, float speed, int area)
        {
            MoveToAction action = CreateInstance <MoveToAction>();

            action.gameObject = gameObject;
            action.transform  = gameObject.transform;
            action.callback   = callback;
            action.target     = target;
            action.speed      = speed;
            action.area       = area;
            return(action);
        }
Exemple #9
0
 /// <summary>
 /// Creates a new callback that raises a method that contains one parameter and doesn't return the value.
 /// </summary>
 /// <param name="type"> Type. </param>
 /// <param name="methodInfo"> Method info. </param>
 /// <returns> Callback that raises the method that contains one parameter and doesn't returns the value. </returns>
 private IActionCallback <object, object> CreateReturnlessOneParameterMethodCallback(Type type, MethodInfo methodInfo)
 {
     return(GetDictionaryValue(
                this.oneParameterReturnlessMethodCallbacks,
                type,
                methodInfo,
                () =>
     {
         IActionCallback <object, object> callback = ReflectionUtils.CreateReturnlessOneParameterMethodCallback(type, methodInfo);
         return callback;
     }));
 }
Exemple #10
0
        // 创建 MoveToAction 。
        public static MoveToAction GetAction(GameObject gameObject, IActionCallback callback, Vector3 destination, float speed)
        {
            MoveToAction action = CreateInstance <MoveToAction>();

            // 设置需要进行直线运动的游戏对象。
            action.gameObject = gameObject;
            action.transform  = gameObject.transform;
            action.callback   = callback;
            // 设置直线运动的终点。
            action.destination = destination;
            // 设置直线运动的速度。
            action.speed = speed;
            return(action);
        }
Exemple #11
0
 /// <summary>
 /// Creates a new formattable value.
 /// </summary>
 /// <param name="name"> Name of value. </param>
 /// <param name="optional"> Indicates whether value is optional. </param>
 /// <param name="order"> Determines order in serialization/deserialization. </param>
 /// <param name="type"> Type of the value. </param>
 /// <param name="getValue"> Callback for the get accessor. </param>
 /// <param name="setValue"> Callback for the set accessor. </param>
 public FormattableValue(string name, bool optional, int order, Type type, IFunctionCallback <object, object> getValue, IActionCallback <object, object> setValue)
 {
     this.Name             = name;
     this.Optional         = optional;
     this.Order            = order;
     this.Type             = type;
     this.getValueCallback = getValue.Invoke;
     this.setValueCallback = setValue.Invoke;
 }
        private static void SetPropertyValue(Type type, object obj, string name, object input)
        {
            IActionCallback <object, object> setAccessor = ReflectionUtils.CreateSetAccessor(type, type.GetProperty(name));

            setAccessor.Invoke(obj, input);
        }
        private static void InvokeReturnlessOneParameterMethod(Type type, object obj, string name, object input)
        {
            IActionCallback <object, object> methodActivator = ReflectionUtils.CreateReturnlessOneParameterMethodCallback(type, type.GetMethod(name));

            methodActivator.Invoke(obj, input);
        }
        /// <summary>
        /// Builds a target type that based on declared type that is associated with the current type.
        /// </summary>
        /// <param name="declaredType"> Declared type. </param>
        private void BuildType(Type declaredType)
        {
            Type createdType = null;

            if (!this.createdTypes.TryGetValue(declaredType, out createdType))
            {
                // Creates a new type

                createdType = (this.isGenericTypeDefinition) ? this.hostType.MakeGenericType(declaredType.GetGenericArguments()) : this.hostType;

                // Creates an activator for the created type

                IFunctionCallback <object> factoryMethod = ReflectionUtils.CreateInstance(createdType);

                // Creates the callbacks for the get/set accessors of the fields

                KeyAttribute     keyAttribute;
                FormattableValue value;
                LinkedList <FormattableValue>      loadedValues = new LinkedList <FormattableValue>();
                IFunctionCallback <object, object> getAccessor  = null;
                IActionCallback <object, object>   setAccessor  = null;

                FieldInfo[] fields       = createdType.GetFields(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance | BindingFlags.FlattenHierarchy);
                int         fieldsLength = fields.Length;
                FieldInfo   field        = null;

                for (int i = 0; i < fieldsLength; i++)
                {
                    field        = fields[i];
                    keyAttribute = field.GetAttribute <KeyAttribute>(true);

                    if (keyAttribute != null)
                    {
                        getAccessor = ReflectionUtils.CreateGetAccessor(createdType, field);
                        setAccessor = ReflectionUtils.CreateSetAccessor(createdType, field);

                        value = new FormattableValue(
                            keyAttribute.Name,
                            keyAttribute.Optional,
                            keyAttribute.Order,
                            field.FieldType,
                            getAccessor,
                            setAccessor
                            );

                        loadedValues.AddLast(value);
                    }
                }

                // Action that used for getting the key attribute and property info of the overridden properties

                PropertyInfo property          = null;
                MethodInfo   propertyGetMethod = null;
                Type         baseType          = null;

                Action <Type, string> getPropertyKeyAttributeFromBase = null;
                getPropertyKeyAttributeFromBase = (t, n) =>
                {
                    baseType = t.BaseType;
                    if (baseType == null)
                    {
                        return;
                    }

                    property = baseType.GetProperty(n, BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly);

                    if (property != null)
                    {
                        keyAttribute = property.GetAttribute <KeyAttribute>(true);
                        if (keyAttribute == null)
                        {
                            propertyGetMethod = property.GetGetMethod(true);
                            if (propertyGetMethod == null || propertyGetMethod.GetBaseDefinition() != propertyGetMethod)
                            {
                                // Property is overridden - tests the properties of the base type
                                getPropertyKeyAttributeFromBase(baseType, n);
                            }
                        }
                    }
                    else
                    {
                        // Required property isn't exists in the type - tests the properties of the base type
                        getPropertyKeyAttributeFromBase(baseType, n);
                    }
                };

                // Creates the callbacks for the get/set accessors of the properties

                PropertyInfo[] properties       = createdType.GetProperties(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance | BindingFlags.FlattenHierarchy);
                int            propertiesLength = properties.Length;

                for (int i = 0; i < propertiesLength; i++)
                {
                    property     = properties[i];
                    keyAttribute = property.GetAttribute <KeyAttribute>(true);

                    if (keyAttribute == null)
                    {
                        propertyGetMethod = property.GetGetMethod(true);
                        if (propertyGetMethod == null || propertyGetMethod.GetBaseDefinition() != propertyGetMethod)
                        {
                            // Property is overridden - tests the properties of the base type

                            getPropertyKeyAttributeFromBase(createdType, property.Name);
                        }
                    }

                    if (keyAttribute == null || property.GetIndexParameters().Length != 0)
                    {
                        continue;
                    }

                    getAccessor = ReflectionUtils.CreateGetAccessor(createdType, property);
                    setAccessor = ReflectionUtils.CreateSetAccessor(createdType, property);

                    value = new FormattableValue(
                        keyAttribute.Name,
                        keyAttribute.Optional,
                        keyAttribute.Order,
                        property.PropertyType,
                        getAccessor,
                        setAccessor
                        );

                    loadedValues.AddLast(value);
                }

                // Sorts the values by order

                FormattableValue[] sortedValues = loadedValues.ToArray();
                SortUtils.QuickSort(true, sortedValues);

                // Saves the factory method, sorted values and created type

                this.factoryMethods.Add(declaredType, factoryMethod);
                this.values.Add(declaredType, sortedValues);
                this.createdTypes.Add(declaredType, createdType);
            }
        }
Exemple #15
0
            /// <summary>
            /// Creates a new writer for the <see cref="ICollection"></see>.
            /// </summary>
            /// <param name="formatter"> The formatter. </param>
            /// <param name="enumerable"> The collection. </param>
            public CollectionWriter(AbstractFormatter formatter, IEnumerable enumerable)
            {
                // Gets type and generic type definition of the collection

                Type collectionType = enumerable.GetType();
                Type elementType    = collectionType.GetGenericArguments()[0];
                Type collectionGTD  = collectionType.GetGenericTypeDefinition();

                // Gets the methods of the collection

                MethodInfo methodInfo = null;

                MethodInfo[] methodsInfo = collectionType.GetMethods(BindingFlags.Instance | BindingFlags.Public);

                Func <string, Action <object> > getCallbackReturnMethod = (name) =>
                {
                    // Builds a callback for the public method with specified name
                    // (one parameter, return something)

                    Func <MethodInfo, bool> predicate = (m) =>
                    {
                        if (m.Name != name || m.ReturnType == voidType)
                        {
                            return(false);
                        }

                        ParameterInfo[] parameters = m.GetParameters();
                        return(parameters.Length == 1 && parameters[0].ParameterType.IsBaseTypeOrEquals(elementType));
                    };

                    methodInfo = methodsInfo.FindOrDefault(predicate);
                    IFunctionCallback <object, object, object> callback = formatter.CreateReturnOneParameterMethodCallback(collectionType, methodInfo);
                    return((o) => callback.Invoke(enumerable, o));
                };

                Func <string, Action <object> > getCallbackReturnlessMethod = (name) =>
                {
                    // Builds a callback for the public method with specified name
                    // (one parameter, returnless)

                    Func <MethodInfo, bool> predicate = (m) =>
                    {
                        if (m.Name != name || m.ReturnType != voidType)
                        {
                            return(false);
                        }

                        ParameterInfo[] parameters = m.GetParameters();
                        return(parameters.Length == 1 && parameters[0].ParameterType.IsBaseTypeOrEquals(elementType));
                    };

                    methodInfo = methodsInfo.FindOrDefault(predicate);
                    IActionCallback <object, object> callback = formatter.CreateReturnlessOneParameterMethodCallback(collectionType, methodInfo);
                    return((o) => callback.Invoke(enumerable, o));
                };

                // Finds the specific methods for the adding a new values of the different collections

                if (collectionGTD == linkedListType)
                {
                    // Linked list
                    this.collectionAddAction = getCallbackReturnMethod("AddLast");
                }

                if (collectionGTD == listType)
                {
                    // List
                    IList list = enumerable as IList;
                    this.collectionAddAction = (o) => list.Add(o);
                }

                if (collectionGTD == hashSetType || collectionGTD == sortedSetType)
                {
                    // Hash set, sorted set
                    this.collectionAddAction = getCallbackReturnMethod("Add");
                }

                if (collectionGTD == concurrentBagType)
                {
                    // Concurrent bag
                    this.collectionAddAction = getCallbackReturnlessMethod("Add");
                }

                if (collectionGTD == queueType || collectionGTD == concurrentQueueType)
                {
                    // Queue, concurrent queue
                    this.collectionAddAction = getCallbackReturnlessMethod("Enqueue");
                }

                if (collectionGTD == stackType || collectionGTD == concurrentStackType)
                {
                    // Stack, concurrent stack
                    this.collectionAddAction = getCallbackReturnlessMethod("Push");
                    this.collectionIsStack   = true;
                }

                // Saves the callback for the found method

                if (this.collectionIsStack)
                {
                    this.addAction = (v) => collectedValues.AddFirst(v);
                }
                else
                {
                    this.addAction = this.collectionAddAction;
                }
            }