Ejemplo n.º 1
0
    IEnumerator spawnPickup_blue(Vector3 m)
    {
        InstanceObj = Instantiate(obj, m, Quaternion.identity);
        count_blue  = count_blue - 1;
        InstanceObj.SetActive(true);
        print("entered the activate numerator");
        for (float f = reactivate; f > 0; f -= 0.1f)
        {
            yield return(null);
        }
        InstanceObj.AddComponent <BoxCollider>();
        yield return(new WaitForSeconds(1f));

        InstanceObj.GetComponent <BoxCollider>().isTrigger = true;
        print("collider enabled");
    }
Ejemplo n.º 2
0
        Type LoadImplementTypeByAssemblies(Type interfaceType, AutoCall autoCall)
        {
            if (null == assemblies)
            {
                return(null);
            }
            if (0 == assemblies.Count)
            {
                return(null);
            }

            Type   impl_type     = null;
            string implName      = "";
            Regex  regex         = null;
            bool   isIgnoreCase1 = false;

            AutoCallMatch(autoCall, ref implName, ref regex, ref isIgnoreCase1);

            InstanceObj impl1 = null;
            Type        type1 = null;

            foreach (KeyValuePair <string, InstanceObj> item in interfaceImplements)
            {
                impl1 = item.Value;
                if (null == impl1)
                {
                    continue;
                }

                type1 = impl1.newInstance.GetType();
                if (false == type1.IsImplementInterface(interfaceType))
                {
                    continue;
                }

                if (!MatchImpl(regex, type1, implName, isIgnoreCase1))
                {
                    continue;
                }

                impl_type = impl1.newInstance.GetType();
                break;
            }

            if (null != impl_type)
            {
                return(impl_type);
            }

            Type[] types = null;
            foreach (Assembly item in assemblies)
            {
                try
                {
                    types     = item.GetTypes();
                    impl_type = GetImplTypeByTypes(types, interfaceType, autoCall, regex, implName, isIgnoreCase1);
                }
                catch { }

                if (null != impl_type)
                {
                    break;
                }
            }

            return(impl_type);
        }
Ejemplo n.º 3
0
        void Adapter()
        {
            if (string.IsNullOrEmpty(rootPath))
            {
                return;
            }

            object[] arr = null;

            string    resetKeyName  = "";
            Type      interfaceType = null;
            Type      implType      = null;
            CKeyValue kv            = null;
            MatchRule mr            = null;
            object    impl          = null;
            object    implNew       = null;
            object    impl_1        = null;

            bool        isShowCode         = false;
            bool        isSingleCall       = false;
            bool        isSingleInstance   = false;
            bool        isUnSingleInstance = false;
            InstanceObj instanceObj        = null;

            string unSingleInstanceStr = typeof(IUnSingleInstance).FullName;

            TempImpl temp = new TempImpl();

            temp.codeCompiler = codeCompiler;

            bool enableCompiler = false;

            if (null != codeCompiler && null != dataServerProvider && null != DbHelper)
            {
                enableCompiler = true;
            }

            Action <object, Action> action = (obj, action1) =>
            {
                if (null != obj)
                {
                    if (null != (obj as IUnSingleInstance))
                    {
                        isUnSingleInstance = true;
                        isSingleCall       = false;
                        isSingleInstance   = false;
                    }

                    if ((null != (obj as ISingleInstance) || isSingleCall) && false == isUnSingleInstance)
                    {
                        isSingleCall     = true;
                        isSingleInstance = true;
                        action1?.Invoke();
                    }
                }
            };

            Regex  rg           = null;
            string implName     = "";
            bool   isIgnoreCase = false;

            AutoCall autoCall = null;

            FieldInfo[] fArr = null; // currentObj.GetType().GetFields(BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static);

            List <Type> objList  = new List <Type>();
            Type        _objType = currentObj.GetType();
            int         n        = 0;

            while (20 > n && typeof(object) != _objType && typeof(ImplementAdapter) != _objType)
            {
                objList.Add(_objType);
                _objType = _objType.BaseType;
                n++;
            }

            if (0 == objList.Count && null != currentObj)
            {
                objList.Add(currentObj.GetType());
            }

            foreach (Type typeItem in objList)
            {
                fArr = typeItem.GetFields(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static);
                foreach (FieldInfo p in fArr)
                {
                    arr = p.GetCustomAttributes(typeof(AutoCall), true);
                    if (0 == arr.Length)
                    {
                        continue;
                    }

                    autoCall = null;
                    foreach (var item in arr)
                    {
                        if (null != (item as AutoCall))
                        {
                            autoCall = (AutoCall)item;
                            break;
                        }
                    }

                    interfaceType = p.FieldType;

                    if (!autoCall.LoadBeforeFilter(interfaceType))
                    {
                        continue;
                    }
                    autoCall.errorLevels1 = errorLevels1;

                    impl               = null;
                    impl_1             = null;
                    implType           = null;
                    resetKeyName       = null;
                    isSingleInstance   = false;
                    isUnSingleInstance = false;
                    instanceObj        = null;

                    arr          = p.GetCustomAttributes(typeof(SingleCall), true);
                    isSingleCall = 0 < arr.Length;

                    resetKeyName = GetInterfaceName(interfaceType, autoCall);
                    interfaceImplements.TryGetValue(resetKeyName, out instanceObj);
                    if (null != instanceObj)
                    {
                        impl = instanceObj.newInstance;
                    }
                    if (null != instanceObj)
                    {
                        implName     = "";
                        rg           = null;
                        isIgnoreCase = false;
                        AutoCallMatch(autoCall, ref implName, ref rg, ref isIgnoreCase);
                        if (null != rg)
                        {
                            if (!MatchImpl(rg, instanceObj.oldInstanceType, implName, isIgnoreCase))
                            {
                                impl = null;
                            }
                        }
                    }
                    impl_1 = impl;

                    action(impl, () =>
                    {
                        impl = null;
                    });

                    if (null == impl)
                    {
                        kv         = GetKvByInterfaceType(interfaceType);
                        mr         = null == kv ? null : ((MatchRule)kv.Value);
                        isShowCode = false;
                        if (interfaceType.IsInterface)
                        {
                            if (null != mr)
                            {
                                isShowCode = mr.IsShowCode;
                                implType   = LoadImplementTypeByMatchRule(mr, interfaceType, autoCall);
                            }
                            else
                            {
                                implType = LoadImplementTypeByInterface(interfaceType, autoCall);
                            }

                            if (null == implType)
                            {
                                implType = LoadImplementTypeByAssemblies(interfaceType, autoCall);
                            }

                            if (enableCompiler && null == (autoCall as ExistCall))
                            {
                                implNew = temp.NewImplement(interfaceType, implType, autoCall, isShowCode);
                                if (null != implNew)
                                {
                                    impl = implNew;
                                }
                            }

                            if (null != implType && null == impl)
                            {
                                try
                                {
                                    impl = Activator.CreateInstance(implType);
                                }
                                catch (Exception ex)
                                {
                                    string err = "[" + implType.FullName + "] 实例可能缺少一个无参构造函数(或该类访问权限不够)\r\n" + ex.ToString();
                                    autoCall.ExecuteExcption(interfaceType, null, null, null, new Exception(err));
                                    //throw;
                                }
                            }
                        }
                        else
                        {
                            if (enableCompiler)
                            {
                                implType      = interfaceType;
                                interfaceType = typeof(IEmplyInterface);
                                implNew       = temp.NewImplement(interfaceType, implType, autoCall, isShowCode);
                                if (null != implNew)
                                {
                                    impl = implNew;
                                }
                            }

                            if (null == impl && null != implType)
                            {
                                try
                                {
                                    impl = Activator.CreateInstance(implType);
                                }
                                catch (Exception ex)
                                {
                                    string err = "[" + implType.FullName + "] 实例可能缺少一个无参构造函数(或该类访问权限不够)\r\n" + ex.ToString();
                                    autoCall.ExecuteExcption(interfaceType, null, null, null, new Exception(err));
                                    //throw;
                                }
                            }
                        }

                        if (false == isUnSingleInstance)
                        {
                            action(impl, null);
                        }

                        if (null != impl && null == impl_1 && false == isSingleCall)
                        {
                            lock (_adapterOfImplement)
                            {
                                interfaceImplements.TryGetValue(resetKeyName, out instanceObj);
                                if (null == instanceObj)
                                {
                                    interfaceImplements.Add(resetKeyName, new InstanceObj()
                                    {
                                        newInstance     = impl,
                                        oldInstanceType = implType
                                    });
                                }
                                else
                                {
                                    impl = instanceObj.newInstance;
                                }
                            }
                        }
                    }

                    if (null == impl)
                    {
                        continue;
                    }

                    isSingleInstance = false;
                    if (null != (impl as ISingleInstance))
                    {
                        isSingleInstance = true;
                    }

                    if (isSingleInstance)
                    {
                        if (null == ((ISingleInstance)impl).Instance)
                        {
                            ((ISingleInstance)impl).Instance = impl;
                        }
                    }

                    if (!autoCall.LoadAfterFilter(impl))
                    {
                        continue;
                    }

                    p.SetValue(currentObj, impl);
                }
            }
        }