Пример #1
0
 public static void IsNull(object obj, CFAction nullCallBack)
 {
     if (obj == null)
     {
         nullCallBack?.Invoke();
     }
 }
Пример #2
0
 /// <summary>
 /// Assert断言仅用于测试环境调试
 /// 条件委托是否为true
 /// </summary>
 /// <param name="handler">条件委托</param>
 /// <param name="trueCallBack">true时候的回调</param>
 public static void Predicate(CFPredicateAction handler, CFAction trueCallBack)
 {
     if (handler.Invoke())
     {
         trueCallBack?.Invoke();
     }
 }
Пример #3
0
 /// <summary>
 /// Assert断言仅用于测试环境调试
 /// 是否为继承
 /// </summary>
 /// <typeparam name="T1">super</typeparam>
 /// <typeparam name="T2">sub</typeparam>
 /// <param name="callBack">若不为继承,则启用回调</param>
 public static void IsAssignable <T1, T2>(CFAction callBack)
 {
     if (!typeof(T1).IsAssignableFrom(typeof(T2)))
     {
         callBack?.Invoke();
     }
 }
Пример #4
0
        protected IEnumerator EnumCollect(float delay, CFAction <object> action, object arg)
        {
            int tempFlag = Utility.Int(arg);

            yield return(new WaitForSeconds(delay));

            action?.Invoke(tempFlag);
        }
Пример #5
0
        protected IEnumerator EnumCollect(float delay, CFAction action = null)
        {
            Utility.DebugLog("BeforeEnumCollectYield");
            yield return(new WaitForSeconds(delay));

            action?.Invoke();
            Utility.DebugLog("AfterEnumCollectYield");
        }
Пример #6
0
 /// <summary>
 /// 载入面板,若字典中已存在,则使用回调,并返回。若不存在,则异步加载且使用回调。
 /// 基于Resources
 /// </summary>
 /// <typeparam name="T"> UILogicBase</typeparam>
 /// <param name="panelName">相对完整路径</param>
 /// <param name="callBack">仅在载入时回调</param>
 public void ShowPanel <T>(string panelName, CFAction <T> callBack = null)
     where T : UILogicBase
 {
     if (HasPanel(panelName))
     {
         callBack?.Invoke(uiPanelMap[panelName] as T);
         return;
     }
     Facade.Instance.LoadResAysnc <GameObject>(panelName, go =>
     {
         GameObject result = go;
         result.transform.SetParent(MainUICanvas.transform);
         (result.transform as RectTransform).ResetLocalTransform();
         T panel = result.GetComponent <T>();
         callBack?.Invoke(panel);
         uiPanelMap.Add(panelName, panel);
     });
 }
        IEnumerator EnumLoadResAssetAsync <T>(string path, CFAction <T> callBack = null)
            where T : UnityEngine.Object
        {
            ResourceRequest req = Resources.LoadAsync <T>(path);

            yield return(req);

            callBack?.Invoke(req.asset as T);
        }
Пример #8
0
        //数据处理
        //DataProcess dataProcess = new DataProcess();
        public void ParseDataFromResource <T>(string relativePath, string fileName, ref T dataSet, CFAction <T> callBack = null)
            where T : class, new()
        {
            string    relativeFullPath = Utility.CombineRelativeFilePath(fileName, relativePath);
            TextAsset ta = Facade.Instance.LoadResAsset <TextAsset>(relativeFullPath);

            JsonUtility.FromJsonOverwrite(ta.text, dataSet);
            callBack?.Invoke(dataSet);
        }
Пример #9
0
        IEnumerator EnumAction(object arg, CFAction handler)
        {
            yield return(new WaitForSeconds(Utility.Float(arg)));

            handler?.Invoke();
            if (loop)
            {
                tempRoutine = Facade.Instance.StartCoroutine(EnumAction(Interval, () => action.Invoke()));
            }
        }
Пример #10
0
        IEnumerator EnumLoadSceneAsync(string sceneName, CFAction <float> callBack = null)
        {
            AsyncOperation ao = UnityEngine.SceneManagement.SceneManager.LoadSceneAsync(sceneName);

            while (!ao.isDone)
            {
                callBack?.Invoke(ao.progress);
                yield return(ao.progress);
            }
            yield return(null);
        }
Пример #11
0
 /// <summary>
 /// Assert断言仅用于测试环境调试
 /// 判断不为空
 /// </summary>
 /// <param name="obj"></param>
 /// <param name="notNullCallBack">不为空的回调</param>
 /// <param name="nullCallBack">为空时候的回调</param>
 public static void NotNull(object obj, CFAction notNullCallBack, CFAction nullCallBack)
 {
     if (obj == null)
     {
         nullCallBack?.Invoke();
     }
     else
     {
         notNullCallBack?.Invoke();
     }
 }
Пример #12
0
 /// <summary>
 /// Assert断言仅用于测试环境调试
 /// 判断不为空
 /// 若不为空,则执行回调
 /// </summary>
 /// <typeparam name="T">泛型类型</typeparam>
 /// <param name="arg">泛型对象</param>
 /// <param name="callBack">若不为空,则执行回调</param>
 public static void NotNull(object obj, CFAction notNullCallBack)
 {
     if (obj == null)
     {
         throw new ArgumentNullException("object" + obj.ToString() + "is null !");
     }
     else
     {
         notNullCallBack?.Invoke();
     }
 }
Пример #13
0
 /// <summary>
 /// Assert断言仅用于测试环境调试
 /// 普通异常处理捕捉者
 /// </summary>
 /// <param name="handler">处理者函数</param>
 /// <param name="exceptionHandler">异常处理函数</param>
 public static void ExceptionCatcher(CFAction handler, CFAction exceptionHandler)
 {
     try
     {
         handler?.Invoke();
     }
     catch
     {
         exceptionHandler?.Invoke();
     }
 }
Пример #14
0
 /// <summary>
 /// Assert断言仅用于测试环境调试
 /// 条件委托,
 /// 若handler返回true,则run callBack
 /// </summary>
 /// <typeparam name="T">泛型对象</typeparam>
 /// <param name="arg">对象</param>
 /// <param name="handler">处理者</param>
 /// <param name="callBack">回调</param>
 public static void Predicate <T>(T arg, Predicate <T> handler, CFAction <T> callBack)
 {
     if (handler == null)
     {
         return;
     }
     if (handler.Invoke(arg))
     {
         callBack?.Invoke(arg);
     }
 }
        IEnumerator EnumLoadResAsync <T>(string path, CFAction <T> callBack = null)
            where T : UnityEngine.Object
        {
            ResourceRequest req = Resources.LoadAsync <T>(path);

            yield return(req);

            if (req.asset is GameObject)
            {
                callBack?.Invoke(GameObject.Instantiate(req.asset) as T);
            }
        }
Пример #16
0
        IEnumerator EnumLoadSceneAsync(int sceneIndex, CFAction <AsyncOperation> callBack = null)
        {
            AsyncOperation ao = UnityEngine.SceneManagement.SceneManager.LoadSceneAsync(sceneIndex);

            while (!ao.isDone)
            {
                callBack?.Invoke(ao);
                yield return(null);
                //yield return ao.progress;
            }
            //yield return null;
        }
Пример #17
0
        /// <summary>
        /// 异步加载迭代器 index
        /// </summary>
        /// <param name="sceneIndex"></param>
        /// <param name="callBack"></param>
        /// <returns></returns>
        IEnumerator EnumLoadSceneAsync(int sceneIndex, CFAction callBack = null)
        {
            AsyncOperation ao = UnityEngine.SceneManagement.SceneManager.LoadSceneAsync(sceneIndex);

            while (!ao.isDone)
            {
                yield return(ao.progress);
            }
            yield return(ao.progress);

            callBack?.Invoke();
        }
Пример #18
0
            /// <summary>
            /// Assert断言仅用于测试环境调试
            /// if assaignable ,run callBack method
            /// </summary>
            /// <typeparam name="T1">superType</typeparam>
            /// <typeparam name="T2">subType</typeparam>
            /// <param name="sub">subType arg</param>
            /// <param name="callBack">若可执行,则回调,传入参数为sub对象</param>
            public static void IsAssignable <T1, T2>(T2 sub, CFAction <T2> callBack)
            {
                Type superType = typeof(T1);
                Type subType   = typeof(T2);

                if (superType.IsAssignableFrom(superType))
                {
                    callBack?.Invoke(sub);
                }
                else
                {
                    throw new InvalidCastException("SuperType : " + subType.FullName + "unssignable from subType : " + subType.FullName);
                }
            }
        /// <summary>
        /// 更改控制状态
        /// </summary>
        /// <param name="mode"></param>
        /// <param name="callBack">回调函数,与具体mode无关</param>
        public void SetControlMode(ControlMode mode, CFAction callBack = null)
        {
            switch (mode)
            {
            case ControlMode.FirstPerson:
                break;

            case ControlMode.FreeControl:
                break;

            case ControlMode.ThirdPerson:
                break;
            }
            currentControlMode = mode;
            callBack?.Invoke();
        }
 public void Despawn(GameObject go)
 {
     if (ObjectCount >= ObjectPoolManager._ObjectPoolCapacity)
     {
         GameManager.KillObject(go);//超出部分被销毁
     }
     else
     {
         onDespawn?.Invoke(go);
         if (go == null)
         {
             return;
         }
         go.SetActive(false);
         objectList.Add(go);//只有回收的时候会被加入列表
     }
 }
        IEnumerator EnumLoadABAssetAsync <T>(ResourceUnit resUnit, CFAction <float> loadingCallBack, CFAction <T> loadDoneCallBack)
            where T : UnityEngine.Object
        {
            //先加载依赖资源
            yield return(Facade.Instance.StartCoroutine(EnumLoadDependenciesABAsyn(resUnit.AssetBundleName)));

            var ab = QueryAssetBundle(resUnit.AssetBundleName);

            if (ab != null)
            {
                loadingCallBack?.Invoke(1);
                yield return(null);

                UnityEngine.Object asset = ab.LoadAsset <T>(resUnit.AssetPath);
                loadDoneCallBack?.Invoke(asset as T);
            }
        }
Пример #22
0
        public void LoadJsonDataFromLocal <T>(string fullRelativeFilePath, ref T dataSet, CFAction <T> callBack = null)
        {
            string absoluteFullpath = Utility.CombinePersistentPath(fullRelativeFilePath);

            if (!File.Exists(absoluteFullpath))
            {
                return;
            }
            using (FileStream stream = File.Open(Utility.CombinePersistentPath(absoluteFullpath), FileMode.Open))
            {
                Utility.DebugLog("Load local path:\n" + Utility.CombineRelativeFilePath(absoluteFullpath), MessageColor.green);
                BinaryFormatter bf   = new BinaryFormatter();
                string          json = (string)bf.Deserialize(stream);
                JsonUtility.FromJsonOverwrite(json, dataSet);
                callBack?.Invoke(dataSet);
                stream.Close();
            }
        }
Пример #23
0
        /// <summary>
        /// 保存Json数据到本地的绝对路径
        /// </summary>
        /// <param name="relativePath">相对路径</param>
        /// <param name="fileName">文件名称</param>
        /// <param name="dataSet">装箱后的数据</param>
        /// <param name="callBack">回调函数,当写入成功后调用</param>
        public void SaveJsonDataToLocal <T>(string relativePath, string fileName, T dataSet, CFAction callBack = null)
        {
            string absoluteFullpath = Utility.CombinePersistentPath(relativePath);

            if (!Directory.Exists(absoluteFullpath))
            {
                Directory.CreateDirectory(absoluteFullpath);
            }
            using (FileStream stream = File.Create(Utility.CombineRelativeFilePath(fileName, absoluteFullpath)))
            {
                Utility.DebugLog("Save local path:\n" + Utility.CombineRelativeFilePath(fileName, absoluteFullpath), MessageColor.green);
                BinaryFormatter bf   = new BinaryFormatter();
                var             json = JsonUtility.ToJson(dataSet);
                bf.Serialize(stream, json);
                callBack?.Invoke();
                stream.Close();
            }
        }
        public GameObject Spawn()
        {
            GameObject go;

            if (objectList.Count > 0)
            {
                go = FindUseable();
                if (go != null)
                {
                    objectList.Remove(go);//从数组中移除
                }
            }
            else
            {
                go = GameObject.Instantiate(spawnItem) as GameObject;//实例化产生
            }
            go.SetActive(true);
            onSpawn?.Invoke(go);//表示一个可空类型,空内容依旧可以执行
            return(go);
        }
Пример #25
0
        protected IEnumerator EnumCollect(float delay, CFAction action = null)
        {
            yield return(new WaitForSeconds(delay));

            action?.Invoke();
        }
Пример #26
0
        IEnumerator EnumCoroutine(Coroutine routine, CFAction callBack)
        {
            yield return(routine);

            callBack?.Invoke();
        }
Пример #27
0
        IEnumerator EnumDelay(float delay, CFAction callBack)
        {
            yield return(new WaitForSeconds(delay));

            callBack?.Invoke();
        }
Пример #28
0
 /// <summary>
 /// 同步加载 name
 /// </summary>
 /// <param name="sceneName"></param>
 /// <param name="callBack"></param>
 public void LoadScene(string sceneName, CFAction callBack = null)
 {
     UnityEngine.SceneManagement.SceneManager.LoadScene(sceneName);
     callBack?.Invoke();
 }
Пример #29
0
 /// <summary>
 /// 同步加载 index
 /// </summary>
 /// <param name="sceneIndex"></param>
 /// <param name="callBack"></param>
 public void LoadScene(int sceneIndex, CFAction callBack = null)
 {
     UnityEngine.SceneManagement.SceneManager.LoadScene(sceneIndex);
     callBack?.Invoke();
 }