예제 #1
0
        public IMediator getMediator(string mediatorName)
        {
            IMediator mediator = view.getMediator(mediatorName) as IMediator;

            if (mediator == null)
            {
                Type cls = Singleton.getClass(mediatorName);
                if (cls != null)
                {
                    mediator = (IMediator)Activator.CreateInstance(cls);
                    mvcInjectMediatorLock[mediatorName] = mediator;

                    inject(mediator);
                    registerMediator(mediator);

                    mvcInjectMediatorLock.Remove(mediatorName);
                }
                else
                {
                    if (UnityEngine.Application.platform == UnityEngine.RuntimePlatform.WindowsEditor)
                    {
                        UnityEngine.Debug.Log(mediatorName + "未注册");
                    }

                    DebugX.Log(mediatorName + "未注册");
                }
            }
            return(mediator);
        }
예제 #2
0
        private static void setValue(FieldInfo toInfo, string name, object obj, object value)
        {
            try
            {
                toInfo.SetValue(obj, value);
            }
            catch (Exception)
            {
                try
                {
                    if (toInfo.FieldType == typeof(BigInteger))
                    {
                        if (value is string && string.IsNullOrEmpty((string)value))
                        {
                            value = 0;
                        }

                        value = BigIntegerHelper.FromScientific(value.ToString());
                    }


                    value = Convert.ChangeType(value, toInfo.FieldType);
                    toInfo.SetValue(obj, value);
                }
                catch (Exception e)
                {
                    DebugX.Log(obj.ToString() + ":" + name + " 类型转换失败,需要为:" + toInfo.FieldType + " value:" + value + "\n" +
                               e.Message);
                }
            }
        }
예제 #3
0
        public static string Hash(byte[] buffer, bool isUpper = false)
        {
            string strResult   = "";
            string strHashData = "";

            byte[] arrbytHashValue;
            MD5CryptoServiceProvider oMD5Hasher =
                new MD5CryptoServiceProvider();

            try
            {
                arrbytHashValue = oMD5Hasher.ComputeHash(buffer);//计算指定Stream 对象的哈希值
                //由以连字符分隔的十六进制对构成的String,其中每一对表示value 中对应的元素;例如“F-2C-4A”
                strHashData = BitConverter.ToString(arrbytHashValue);
                //替换-
                strHashData = strHashData.Replace("-", "");
                if (isUpper == false)
                {
                    strResult = strHashData.ToLower();
                }
            }
            catch (Exception ex)
            {
                DebugX.Log("md5Error:" + ex.Message);
            }
            return(strResult);
        }
예제 #4
0
 private static void Log(string v, params object[] parms)
 {
     if (DEBUG)
     {
         string message = StringUtil.substitute(v, parms);
         DebugX.Log(message);
     }
 }
예제 #5
0
        public static DirectoryInfo[] FinDirectory(string dirPath)
        {
            DirectoryInfo dirInfo = new DirectoryInfo(dirPath);

            if (dirInfo.Exists == false)
            {
                DebugX.Log(dirPath + ":不存在");
                return(new DirectoryInfo[0]);
            }
            return(dirInfo.GetDirectories());
        }
예제 #6
0
        public static void execute(string type, object o = null, params object[] args)
        {
            IParser parser = null;

            if (parserMapping.TryGetValue(type, out parser) == false)
            {
                DebugX.Log("Executer type:{0} 解析不存在", type);
                return;
            }

            parser.parse(o, args);
        }
예제 #7
0
 public static void SaveBytes(byte[] bytes, string itemPath)
 {
     AutoCreateDirectory(itemPath);
     try
     {
         File.WriteAllBytes(itemPath, bytes);
     }
     catch (Exception ex)
     {
         DebugX.Log("saveBytesError:" + ex.Message);
     }
 }
예제 #8
0
        protected override IEnumerator doLoad()
        {
            www = new WWW(formatedURL(url));

            if (checkProgress)
            {
                TickManager.add(progress);
            }
            yield return(www);

            if (checkProgress)
            {
                TickManager.remove(progress);
            }

            if (www == null)
            {
                _state = AssetState.FAILD;
                _data  = null;
                string message = string.Format("加载文件失败:{0} 已被dispose", url);
                DebugX.Log(message);
                this.dispatchEvent(new EventX(EventX.FAILED, message));
            }
            else
            {
                if (string.IsNullOrEmpty(www.error))
                {
//                    if (www.isDone)
//                    {
                    _state = AssetState.READY;
                    _data  = www.bytes;
                    this.simpleDispatch(EventX.COMPLETE, _data);
                    //                   }
//                    else
//                    {
//                        _state = AssetState.FAILD;
//                        _data = null;
//                        string message = string.Format("加载文件失败:{0} 没有完成", url);
//                        DebugX.Log(message);
//                        this.dispatchEvent(new EventX(EventX.FAILED, message));
//                    }
                }
                else
                {
                    _state = AssetState.FAILD;
                    _data  = null;
                    string message = string.Format("加载文件失败:{0} error:{1}", url, www.error);
                    DebugX.LogWarning(message);
                    this.simpleDispatch(EventX.FAILED, message);
                }
            }
        }
예제 #9
0
        public XmlDocument getXML()
        {
            XmlDocument  doc    = new XmlDocument();
            MemoryStream stream = new MemoryStream((byte[])_data);

            try
            {
                doc.Load(stream);
            }
            catch (Exception e)
            {
                DebugX.Log("parserXML error:" + e);
            }

            return(doc);
        }
예제 #10
0
        protected bool _remove(SignalNode t, Action <EventX> value)
        {
            if (t == null)
            {
                DebugX.Log("d");
            }

            SignalNode pre  = t.pre;
            SignalNode next = t.next;

            if (pre != null)
            {
                pre.next = next;
            }
            else
            {
                firstNode = next;
            }



            if (next != null)
            {
                next.pre = pre;
            }
            else
            {
                lastNode = pre;
            }
            t.active = 0;

            maping.Remove(value);

            if (nodePool.Count < MAX)
            {
                t.data = null;
                nodePool.Push(t);
            }
            len--;

            return(true);
        }
예제 #11
0
        protected void update(float progress)
        {
            if (startTime == 0)
            {
                startTime = lastDebugTime = Time.realtimeSinceStartup;
            }
            sinceTime = Time.realtimeSinceStartup - startTime;
            if (progress != preProgress && progress > 0)
            {
                preTime     = Time.realtimeSinceStartup;
                preProgress = progress;
                this.simpleDispatch(EventX.PROGRESS, preProgress);
            }

            if ((Time.realtimeSinceStartup - lastDebugTime) > DEBUG_TIMEOUT)
            {
                lastDebugTime = Time.realtimeSinceStartup;
                DebugX.Log(_url + " time:" + sinceTime + " pro:" + progress);
            }
        }
예제 #12
0
        public virtual void load(uint retryCount = 0, bool progress = false, int priority = 0)
        {
            if (_status == AssetState.LOADING)
            {
                //DebugX.Log("assetLoading:" + _url);
                return;
            }

            if (isLoaded)
            {
                if (_status == AssetState.FAILD)
                {
                    if (WebRequestLoader.mapping404[_url] == true)
                    {
                        this.dispatchEvent(new EventX(EventX.FAILED, "404"));
                        return;
                    }

                    //重新加载;
                    _status = AssetState.LOADING;
                    _loadImp(priority, progress, retryCount);       // 开始加载
                    return;
                }
                //Debug.Log(DateUtils.getSimple(DateTime.Now) + ":" + url + "");
                this.dispatchEvent(new EventX(EventX.COMPLETE, _data));
                return;
            }

            if (string.IsNullOrEmpty(url))
            {
                _status = AssetState.FAILD;
                DebugX.Log("assetLoading:" + _url);
                this.dispatchEvent(new EventX(EventX.FAILED, "url is empty"));
                return;
            }

            _status = AssetState.LOADING;
            _loadImp(priority, progress, retryCount);       // 开始加载
        }
        public RFLoader getLoader(string url, string uri)
        {
            if (PRE_HASH_LEN > 5)
            {
                int index = url.IndexOf(PRE_HASH);
                if (index != -1)
                {
                    string localPath = url.Substring(index + PRE_HASH_LEN);

                    string formatedPath = AssetLoader.formatedURL(localPath);
                    if (isInPackage(formatedPath))
                    {
                        url = getLocal(localPath);
                    }
                    else if (!Application.isEditor)
                    {
                        DebugX.Log("本地无,从远程加载文件:{0}", url);
                    }
                }
            }
            return(new AssetLoader(url, uri));
        }
예제 #14
0
        protected virtual object parserData(object data)
        {
            switch (parserType)
            {
            case LoaderXDataType.AMF:

                ByteArray bytes = new ByteArray((byte[])data);
                if (bytes.BytesAvailable > 0)
                {
                    try
                    {
                        data = bytes.ReadObject();
                    }
                    catch (Exception ex)
                    {
                        data = null;
                        try
                        {
                            bytes.Inflate();
                            data = bytes.ReadObject();
                        }
                        catch (Exception)
                        {
                            bytes.Position = 0;
                            DebugX.Log("amfError:" + _url + " \tmsg:" + ex);
                        }
                    }
                }
                else
                {
                    data = null;
                }
                break;

            case LoaderXDataType.MANIFEST:
                AssetBundle         assetBundle = (AssetBundle)data;
                AssetBundleManifest manifest    = assetBundle.LoadAsset <AssetBundleManifest>("AssetBundleManifest");
                data = manifest;
                assetBundleManifestDef.manifest = manifest;

//                    string[] allAssetBundles = manifest.GetAllAssetBundles();
//                    foreach (string item in allAssetBundles)
//                    {
//                        Hash128 hash128 = manifest.GetAssetBundleHash(item);
//                        Hash128Link oldLink;
//                        if (allManifesMaping.TryGetValue(hash128, out oldLink))
//                        {
//                            UnityEngine.Debug.Log(item + " routerPath:" + oldLink.manifestDef + " new:" +
//                                                  assetBundleManifestDef);
//                        }
//                        else
//                        {
//                            Hash128Link link = new Hash128Link();
//                            link.hash128 = hash128;
//                            link.key = item;
//                            link.manifestDef = assetBundleManifestDef;
//                            allManifesMaping.Add(hash128, link);
//                        }
//                    }
                break;
            }
            return(data);
        }
        public virtual void sleep()
        {
            DebugX.Log("sleep:" + type);

            this.simpleDispatch(EventX.EXIT);
        }
        /// <summary>
        /// 进入当前状态;
        /// </summary>

        public virtual void awaken()
        {
            DebugX.Log("awaken:" + type);
        }
예제 #17
0
        public static RuntimeAnimatorController GetEditorAnimatorController(AnimatorClipRef animatorClipRef, string prefix, string altName = "")
        {
#if UNITY_EDITOR
            Dictionary <string, AnimationClip> dic = new Dictionary <string, AnimationClip>();
            AnimationClip defaultAnimationClip     = null;
            string        name;
            foreach (AnimationClip animationClip in animatorClipRef.animationClips)
            {
                if (animationClip)
                {
                    name      = animationClip.name;
                    dic[name] = animationClip;
                    if (defaultAnimationClip == null || name.ToLower().IndexOf(IDLE_NAME) == 0)
                    {
                        defaultAnimationClip = animationClip;
                    }
                }
            }
            foreach (AnimationClip animationClip in animatorClipRef.placeholderClips)
            {
                if (animationClip && dic.ContainsKey(animationClip.name) == false)
                {
                    dic[animationClip.name] = animationClip;
                }
            }

            RuntimeAnimatorController t = animatorClipRef.controller;
            if (t != null)
            {
                altName = t.name;
            }

            if (string.IsNullOrEmpty(altName))
            {
                return(null);
            }
            string fullName = prefix + altName + ".controller";
            UnityEditor.Animations.AnimatorController animatorController;
            if (EditorAnimatorControllerMap.TryGetValue(fullName, out animatorController))
            {
                return(animatorController);
            }
            if (File.Exists(fullName) == false)
            {
                return(null);
            }
            animatorController = AssetDatabase.LoadAssetAtPath <UnityEditor.Animations.AnimatorController>(fullName);
            if (animatorController == null)
            {
                return(null);
            }
            DebugX.Log("AnimatorControllerAutoCreate name:" + altName);
            animatorController           = Instantiate(animatorController);
            animatorController.hideFlags = HideFlags.DontSave;
            EditorAnimatorControllerMap.Add(fullName, animatorController);

            UnityEditor.Animations.AnimatorControllerLayer layer = animatorController.layers[0];
            DoAnimatorStateMachine(layer.stateMachine, defaultAnimationClip, dic);
            return(animatorController);
#else
            return(null);
#endif
        }
예제 #18
0
        private void manifesHandle(EventX e)
        {
            currentProgress = 0.1f;
            simpleDispatch(EventX.PROGRESS, currentProgress);
            if (dependenciesResource.Count > 0)
            {
                foreach (AssetResource assetResource in dependenciesResource)
                {
                    assetResource.removeEventListener(EventX.DEPEND_READY, dependsHandle);
                    AssetsManager.bindEventHandle(assetResource, dependsHandle, false);
                    assetResource.release();
                }
                dependenciesResource.Clear();
            }

            AssetResource resource = e.target as AssetResource;

            AssetsManager.bindEventHandle(resource, manifesHandle, false);
            if (e.type != EventX.COMPLETE)
            {
                _data = null;
                resourceComplete(EventX.FAILED);
                return;
            }
            assetBundleManifest = resource.data as AssetBundleManifest;

            string[]      dependencies = assetBundleManifest.GetDirectDependencies(dependKey);
            AssetResource tempResource;
            int           len = _needLoadedDependCount = dependencies.Length;

            //增加自身
            _needLoadedDependCount += 1;

            if (len > 0)
            {
                //DebugX.Log(dependKey + ":::::::::::::::::::::::::::::::::::::" + len);
                for (int i = 0; i < len; i++)
                {
                    string dependency = dependencies[i];
                    if (dependency == dependKey)
                    {
                        _needLoadedDependCount--;
                        continue;
                    }
                    string url = manifesPrefix + dependency;
                    //DebugX.Log(url);
                    tempResource = AssetsManager.getResource(url, LoaderXDataType.ASSETBUNDLE);
                    if (dependenciesResource.Contains(tempResource))
                    {
                        DebugX.Log("hasDuplicate:" + url);
                        _needLoadedDependCount--;
                        continue;
                    }
                    tempResource.retain();
                    dependenciesResource.Add(tempResource);

                    AssetBundle old;
                    string      key = url.ToLower();
                    RFLoader.assetBundleMapping.TryGetValue(key, out old);
                    if (old != null || tempResource.isLoaded)
                    {
                        //DebugX.LogWarning("has:"+url);
                        _needLoadedDependCount--;
                        continue;
                    }

                    tempResource.addEventListener(EventX.DEPEND_READY, dependsHandle);
                    AssetsManager.bindEventHandle(tempResource, dependsHandle);

                    tempResource.load();
                }
            }

            _totalDependCount = _needLoadedDependCount;

            base._loadImp(0, isProgress);
        }
예제 #19
0
        public static Dictionary <InjectEventType, Dictionary <string, Action <EventX> > > CollectionEventInterests(
            IEventInterester instance,
            Dictionary <InjectEventType, Dictionary <string, Action <EventX> > > _eventInterests = null)
        {
            Type type = instance.GetType();

            if (_eventInterests == null)
            {
                _eventInterests = new Dictionary <InjectEventType, Dictionary <string, Action <EventX> > >();
            }
            Dictionary <string, Action <EventX> > dic = null;

            MethodInfo[] methods =
                type.GetMethods(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
            MVCEventAttribute attr;
            Type attributeType = typeof(MVCEventAttribute);
            int  len           = methods.Length;

            for (int i = 0; i < len; i++)
            {
                MethodInfo info  = methods[i];
                object[]   attrs = info.GetCustomAttributes(attributeType, true);
                int        alen  = attrs.Length;
                for (int j = 0; j < alen; j++)
                {
                    attr = attrs[j] as MVCEventAttribute;

                    if (_eventInterests.TryGetValue(attr.injectEventType, out dic) == false)
                    {
                        dic = new Dictionary <string, Action <EventX> >();
                        _eventInterests.Add(attr.injectEventType, dic);
                    }
                    foreach (string eventType in attr.eventList)
                    {
                        if (dic.ContainsKey(eventType) == false)
                        {
                            dic.Add(eventType, (EventX e) =>
                            {
                                try
                                {
                                    info.Invoke(instance, new[] { e });
                                }
                                catch (Exception exception)
                                {
                                    if (exception.InnerException != null)
                                    {
                                        DebugX.LogError(exception.InnerException.ToString());
                                    }
                                    //DebugX.LogError("class:"+ type.Name+ "MethodInfo:"+ info.Name);
                                }
                            });
                        }
                        else
                        {
                            DebugX.Log("MVCEventAttribute inject:{0} type:{1} not exist event:{2}", type.FullName,
                                       attr.injectEventType, eventType);
                        }
                    }
                }
            }
            return(_eventInterests);
        }