コード例 #1
0
        /// <summary>
        /// res config配置文件 和 资源文件不在同一目录下时使用该方法
        /// </summary>
        /// <param name="remoteConfigFilePath"></param>
        /// <param name="localConfigFilePath"></param>
        /// <param name="remoteResPath"></param>
        /// <param name="localResPath"></param>
        /// <param name="callback"></param>
        /// <param name="checkVersion">是否判断res config的版本号,false:忽略版本号检测</param>
        /// <param name="checkItemExist">文件如果存在就不下载,不存在的时候再下载</param>
        public void StartResUpdate(string remoteConfigFilePath, string localConfigFilePath, string remoteResPath, string localResPath,
                                   Action <ResUpdateData> callback, bool checkVersion = true, bool checkItemExist = false)
        {
            mCheckVersion = checkVersion;

            mCheckItemExist = checkItemExist;

            onUpdateResCallback = callback;

            mRemoteResPath = remoteResPath;

            mLocalConfigFilePath = localConfigFilePath;

            mLocalResPath = localResPath;

            mResUpdateData = new ResUpdateData();

            mUpdateItems = new Queue <ResItem>();

            mLocalTempDir = Application.persistentDataPath + "/" + TempModuleResDir;

            ServicePointManager.ServerCertificateValidationCallback += (sender, certificate, chain, sslPolicyErrors) => true;

            PTDebug.LogWarning("获取远程配置文件:" + remoteConfigFilePath);
            StartCoroutine(PTModuleUpdateUtil.GetTextFromServer(remoteConfigFilePath, 3, OnGetServerConfigCallback));
        }
コード例 #2
0
        public static void SetResVersion(string text)
        {
            var resdata = JsonUtility.FromJson <ResRemoteData>(text);

            mResVersion = resdata.data.unity_version;
            PTDebug.Log("当前远程资源版本号:{0}", mResVersion);
        }
コード例 #3
0
        public void AddComponent(IActorComponent actorComponent)
        {
            if (actorComponent == null)
            {
                return;
            }

            if (GetActorComponent(actorComponent.GetType()) != null)
            {
                PTDebug.LogWarning("Already Add Component:" + name);
                return;
            }

            mComponentList.Add(actorComponent);

            mComponentsNameList.Add(actorComponent.GetType().Name);

            mComponentList.Sort(ComWrapComparison);

            OnAddComponent(actorComponent);

            if (mHasAwake)
            {
                AwakeCom(actorComponent);
            }

            if (mHasStart)
            {
                StartComponent(actorComponent);
            }
        }
コード例 #4
0
    public GameObject CreateSticker(PPPrefabInfo info, Action loadFinish = null)
    {
        if (info == null)
        {
            throw new ArgumentNullException("PPPrefabInfo can't be null!");
        }
        string     matPath   = Path.Combine(AppBlockPath(BlockPath.Sticker_Material_Dir), info.Name);
        var        modelPath = Path.Combine(PrefixPath, info.Model + "/" + info.Model + ".gltf");
        GameObject sticker   = null;

        sticker = PTGLTFLoader.loadGltf(modelPath, () =>
        {
            var stickerRoot = sticker.transform.Find("Root Scene");
            var render      = stickerRoot == null ? null : stickerRoot.GetComponentInChildren <Renderer>(true);
            if (render != null)
            {
                Material mat             = PBMatLoader.LoadTextureMatAsset(matPath, info.Texture, true);
                render.receiveShadows    = false;
                render.shadowCastingMode = ShadowCastingMode.Off;
                render.sharedMaterial    = mat;
            }
            else
            {
                PTDebug.LogError("Sticker:<color=#FF00FF>{0}</color> load failed! Model:<color=#FF00FF>{1}</color>", info.Name, info.Model);
            }
            loadFinish.InvokeGracefully();
        }, OnInitializeGltfObject);
        blockObj.Add(sticker);

        return(sticker);
    }
コード例 #5
0
//		public static IEnumerator GetTextFromServer (string from, float timeout, Action<int,string> callback)
//		{
//			WWW loader = new WWW (from);
//
//			float duration = 0.0f;
//
//			while (!loader.isDone && duration < timeout)
//			{
//				duration += Time.deltaTime;
//				yield return 0;
//			}
//
//			if (duration >= timeout)
//			{
//				if (callback != null) {callback (-1,"请求超时");}
//			}
//			else if(loader.error!=null)
//			{
//				if (callback != null) {callback (-1,loader.error);}
//			}
//			else if(!string.IsNullOrEmpty(loader.text))
//			{
//				if (callback != null) {callback (0,loader.text);}
//			}
//			else
//			{
//				if (callback != null) {callback (-1,"未知错误");}
//			}
//
//			loader.Dispose ();
//		}

        public static void DirectoryCopy(string sourceDirName, string destDirName, bool copySubDirs, bool enableOverWrite)
        {
            var dir  = new DirectoryInfo(sourceDirName);
            var dirs = dir.GetDirectories();

            if (!dir.Exists)
            {
                PTDebug.LogError(string.Format("Source directory does not exist or could not be found: {0} ", sourceDirName));
            }
            if (!Directory.Exists(destDirName))
            {
                Directory.CreateDirectory(destDirName);
            }

            var files = dir.GetFiles();

            foreach (var file in files)
            {
                string tempPath = Path.Combine(destDirName, file.Name);

                file.CopyTo(tempPath, enableOverWrite);
            }
            if (copySubDirs)
            {
                foreach (var subDir in dirs)
                {
                    string tempPath = Path.Combine(destDirName, subDir.Name);

                    DirectoryCopy(subDir.FullName, tempPath, copySubDirs, enableOverWrite);
                }
            }
        }
コード例 #6
0
        protected virtual void OnAllExecuteNodeEnd()
        {
            PTDebug.Log("#BaseStartProcess: OnAllExecuteNodeEnd");
            mSequenceNode.OnEndedCallback -= OnAllExecuteNodeEnd;
            mSequenceNode.Dispose();
            mSequenceNode = null;

            mOnProcessFinish.InvokeGracefully();
            Actor.RemoveComponent(this);
        }
コード例 #7
0
        private void GetUpdateItemList()
        {
            if (mCheckVersion)
            {
                if (mLocalConfig.items != null && int.Parse(mLocalConfig.resversion) >= int.Parse(mServerConfig.resversion))
                {
                    ResUpdateCallback(UpdateStatus.Success, "没有新资源:RES_VERSOIN 一致");

                    return;
                }
            }

            int totalSize = 0;

            foreach (var item in mServerConfig.items)
            {
                ResItem localItem = mLocalConfig.FindItemWithPath(item.path);

                bool needUpdate = localItem == null || !item.EqualToItem(localItem);

                if (mCheckItemExist)
                {
                    var path = mLocalResPath + "/" + item.path;
                    if (File.Exists(path))
                    {
                        needUpdate = false;
                    }
                }

                if (needUpdate)
                {
                    totalSize += item.size;
                    mUpdateItems.Enqueue(item);
                }
            }

            PTDebug.Log(string.Format("{0} items need to be updated >>>>>", mUpdateItems.Count));

            if (mUpdateItems.Count == 0)
            {
                SaveServerConfig();

                ResUpdateCallback(UpdateStatus.Success, "没有新资源");

                return;
            }

            mResUpdateData.totalSize = (totalSize / 1024.0f) / 1024.0f;

            mResUpdateData.totalCount = mUpdateItems.Count;

            ResUpdateCallback(UpdateStatus.ReadyToDown, "准备更新");
        }
コード例 #8
0
        public IEnumerator Download()
        {
            if (isStop)
            {
                onCallback.InvokeGracefully(null);
                mFinish = true;
                if (mRequest != null)
                {
                    mRequest.Abort();
                    mRequest.Dispose();
                    mRequest = null;
                }
                yield break;
            }
            PTDebug.LogWarning("下载数据:" + Url);
            var requestFinish = false;

            mRequest = new HTTPRequest(new Uri(Url),
                                       (req, res) =>
            {
                requestFinish        = true;
                mDownInfo.StatusCode = res != null ? res.StatusCode : 22222222;
                mFinish         = true;
                mDownInfo.Error = req.Exception != null ? req.Exception.ToString() : (res != null ? (res.StatusCode == 404 ? "服务器不存在资源:" + Url : null) : null);
                mDownInfo.Data  = res == null || res.StatusCode == 404 ? null : res.Data;
                if (res != null)
                {
                    mItemSize = res.Data.Length / 8.0f / 1024.0f / 1024.0f;
                }
                if (mRequest != null)
                {
                    mRequest.Abort();
                    mRequest.Dispose();
                    mRequest = null;
                }
            })
            {
                ConnectTimeout = TimeSpan.FromSeconds(5),
                Timeout        = TimeSpan.FromSeconds(Timeout),
                DisableCache   = true
            };
            mRequest.Send();
            while (!requestFinish)
            {
                mTimeConsuming += Time.deltaTime;
                yield return(null);
            }
            mDownInfo.DownloadSpeed = DownloadSpeed;
            onCallback.InvokeGracefully(mDownInfo);
        }
コード例 #9
0
            private IEnumerator DownloadFileWebRequest(string remoteResPath, string localTempDir, ResItem resItem, Action <bool, string> callback)
            {
                string remoteUrl     = Path.Combine(remoteResPath, resItem.path);
                string localDestPath = Path.Combine(localTempDir, resItem.path);

                PTDebug.Log(string.Format("***********从{0}下载到{1}:", remoteUrl, localDestPath));

                var fileDir = Path.GetDirectoryName(localDestPath);

                if (!Directory.Exists(fileDir))
                {
                    Directory.CreateDirectory(fileDir);
                }

                mHttpRequest = new HTTPRequest(new Uri(remoteUrl),
                                               (req, resp) =>
                {
                    if (resp != null && req.Exception == null)
                    {
                        File.WriteAllBytes(localDestPath, resp.Data);
                        if (mHttpRequest != null)
                        {
                            mHttpRequest.Abort();
                            mHttpRequest.Dispose();
                            mHttpRequest = null;
                        }
                        callback(true, "success");
                    }
                    else
                    {
                        var errorInfo = "错误信息:" + req.Exception;
                        Debug.LogError(errorInfo);
                        if (mHttpRequest != null)
                        {
                            mHttpRequest.Abort();
                            mHttpRequest.Dispose();
                            mHttpRequest = null;
                        }
                        callback(false, errorInfo);
                    }
                })
                {
                    ConnectTimeout = TimeSpan.FromSeconds(5), Timeout = TimeSpan.FromSeconds(10), DisableCache = true
                };

                mHttpRequest.Send();

                yield return(0);
            }
コード例 #10
0
        public static RespUploadData Parse(string res)
        {
            RespUploadData resultData = null;

            try
            {
                resultData = JsonUtility.FromJson <RespUploadData>(res);
            }
            catch (Exception e)
            {
                PTDebug.LogError(string.Format("Type:{0} 解析出错,解析数据:{1}", "RespUploadData", res));
                return(null);
            }
            return(resultData);
        }
コード例 #11
0
        protected override void OnAddComponent(IActorComponent actorComponent)
        {
            if (actorComponent is IModule)
            {
                IModule module = actorComponent as IModule;
                string  name   = module.GetType().Name;
                if (mModuleMgrMap.ContainsKey(name))
                {
                    PTDebug.LogError("ModuleMgr Already Add Module:" + name);
                    return;
                }
                mModuleMgrMap.Add(name, module);

                OnModuleRegister(module);
            }
        }
コード例 #12
0
    public static IDisposable DownloadTexture(string filename, Action <Texture2D> onCallback)
    {
        var url     = GetDownloadFileUrl(filename);
        var dispose = ObservableWWW.GetAndGetBytes(url).Timeout(TimeSpan.FromSeconds(60)).Subscribe(bytes =>
        {
            PTDebug.Log("图片下载成功,url:" + url);
            var tex = new Texture2D(10, 10);
            tex.LoadImage(bytes);
            onCallback.InvokeGracefully(tex);
        }, e =>
        {
            PTDebug.LogError("Error,url:{0} error:{1}", url, e.ToString());
            onCallback.InvokeGracefully(null);
        });

        return(dispose);
    }
コード例 #13
0
 public void Stop()
 {
     isStop = true;
     try
     {
         if (mRequest != null)
         {
             mRequest.Abort();
             mRequest.Dispose();
             mRequest = null;
         }
     }
     catch (Exception e)
     {
         PTDebug.Log(e);
     }
 }
コード例 #14
0
    public GameObject CreateBlock(PPPrefabInfo info, Action loadFinish = null)
    {
        if (info == null)
        {
            throw new ArgumentNullException("PPPrefabInfo can't be null!");
        }
        var prefabName = info.Name;

        if (info.IsSticker)
        {
            return(CreateSticker(info, loadFinish));
        }

        var model     = info.Model;
        var modelPath = Path.Combine(PrefixPath, model + "/" + model + ".gltf");

        //load gltf
        GameObject block = null;

        block = PTGLTFLoader.loadGltf(modelPath, () =>
        {
            var blockRoot = block.transform.Find("Root Scene");
            if (blockRoot.GetComponentInChildren <Renderer>(true) != null)
            {
                AssignMaterials(blockRoot.gameObject, info.Material, info.MaterialInfos);
            }
            else
            {
                PTDebug.LogError("Block:<color=#FF00FF>{0}</color> load failed! Model:<color=#FF00FF>{1}</color>", prefabName, model);
            }
            loadFinish.InvokeGracefully();
        }, OnInitializeGltfObject);
        blockObj.Add(block);

        block.name = model;

        Animator animator = block.GetComponent <Animator>();

        if (animator != null)
        {
            GameObject.DestroyImmediate(animator);
        }
        return(block);
    }
コード例 #15
0
    private void OnDownItemFinish(DownInfo info)
    {
        counter++;
        if (info == null)
        {
            return;
        }
        bool isModel = info.Url.EndsWith(".bin") || info.Url.EndsWith(".gltf");
        var  resName = GetUrlResName(info.Url);

        if (!info.HasError)
        {
            if (isModel)
            {
                var modelPath = ProccessModel(info, resName);
                PTDebug.Log("完成下载模型文件: " + modelPath);
            }
            else
            {
                var texPath = ProccessTextures(info, resName);
                PTDebug.Log("完成下载贴图文件: " + texPath);
            }

            if (counter >= mUrls.Length)
            {
                OnFinish(true);
            }
        }
        else
        {
            var path = GetPath(info.Url, isModel, resName);
            if (File.Exists(path))
            {
                PTDebug.LogError("未下载成功,使用本地缓存,错误:{0}", info.Error);
            }
            else
            {
                PTDebug.LogError(info.Error);
                mDownloadPip.StopDownload();
                OnFinish(false);
            }
        }
    }
コード例 #16
0
        private void OnResLoadFinish(bool result, AudioClip res)
        {
            if (!result)
            {
                Release();
                return;
            }

            mAudioClip = res;

            if (mAudioClip == null)
            {
                PTDebug.LogError("Asset Is Invalid AudioClip:" + mAudioName);
                Release();
                return;
            }

            PlayAudioClip();
        }
コード例 #17
0
        public static void PlayMusic(AudioMusicData musicData)
        {
            CurrentMusic = new AudioMusicData
            {
                MusicName = musicData.MusicName,
                ABName    = musicData.ABName,
                Loop      = musicData.Loop,
                Volume    = musicData.Volume
            };

            var self = Instance;

            if (!IsMusicOn && musicData.AllowMusicOff)
            {
                musicData.OnMusicBegin.InvokeGracefully();
                musicData.OnMusicEnd.InvokeGracefully();
                return;
            }

            PTDebug.Log(">>>>>> Start Play Music");

            // TODO: 需要按照这个顺序去 之后查一下原因
            //需要先注册事件,然后再play
            self.mMainUnit.SetOnStartListener(musicUnit =>
            {
                musicData.OnMusicBegin.InvokeGracefully();

                //调用完就置为null,否则应用层每注册一个而没有注销,都会调用
                self.mMainUnit.SetOnStartListener(null);
            });

            self.mMainUnit.SetAudio(self.gameObject, musicData.MusicName, musicData.ABName,
                                    loop: musicData.Loop, volume: musicData.Volume);

            self.mMainUnit.SetOnFinishListener(musicUnit =>
            {
                musicData.OnMusicEnd.InvokeGracefully();

                //调用完就置为null,否则应用层每注册一个而没有注销,都会调用
                self.mMainUnit.SetOnFinishListener(null);
            });
        }
コード例 #18
0
    private void Init()
    {
#if BLOCK_MODEL || BLOCK_EDITOR
        string persistentPath = Application.persistentDataPath;
#else
        string persistentPath = PTUGame.persistentDataPath;
#endif

        var modelDatPath    = isApp?Path.Combine(persistentPath, MODEL_DATA_PATH_APP):MODEL_DATA_PATH;
        var prefabDataPath  = isApp?Path.Combine(persistentPath, Prefab_DATA_PATH_APP):Prefab_DATA_PATH;
        var colorDataPath   = isApp?Path.Combine(persistentPath, COLOR_DATA_PATH_APP):COLOR_DATA_PATH;
        var partNumDataPath = isApp?Path.Combine(persistentPath, PARTNUM_DATA_PATH_APP):PARTNUM_DATA_PATH;
        var textureDataPath = isApp?Path.Combine(persistentPath, TEXTURE_DATA_PATH_APP):TEXTURE_DATA_PATH;
        var stickerDataPath = isApp?Path.Combine(persistentPath, STICKER_DATA_PATH_APP):STICKER_DATA_PATH;
        var matDataPath     = isApp?Path.Combine(persistentPath, MAT_DATA_PATH_APP):MAT_DATA_PATH;

        blockModelDatas = LitJson.JsonMapper.ToObject <List <BlockModelData> >(File.ReadAllText(modelDatPath));
        PTDebug.LogWarning("{0} 解析完成。", modelDatPath);

        blockPrefabDatas = LitJson.JsonMapper.ToObject <List <BlockPrefabData> >(File.ReadAllText(prefabDataPath));
        PTDebug.LogWarning("{0} 解析完成。", prefabDataPath);

        blockColorDatas = LitJson.JsonMapper.ToObject <List <BlockColorData> >(File.ReadAllText(colorDataPath));
        PTDebug.LogWarning("{0} 解析完成。", colorDataPath);

        textureDatas = LitJson.JsonMapper.ToObject <List <PBTextureData> >(File.ReadAllText(textureDataPath));
        PTDebug.LogWarning("{0} 解析完成。", textureDataPath);

        stickerDatas = LitJson.JsonMapper.ToObject <List <StickerData> >(File.ReadAllText(stickerDataPath));
        PTDebug.LogWarning("{0} 解析完成。", stickerDataPath);

        matDatas = JsonUtility.FromJson <MaterialInfos>(File.ReadAllText(matDataPath)).materialInfos;

        if (!isApp)
        {
            CustomBlocks.GetCustomConfig(blockModelDatas);
            partNumDatas = LitJson.JsonMapper.ToObject <List <PartNumData> >(File.ReadAllText(partNumDataPath));
        }
        GenerateBlockDatas();
        mIsInitialize = true;
    }
コード例 #19
0
    public GameObject CreateTexture(PPPrefabTexInfo info, Action loadFinish = null)
    {
        if (info == null)
        {
            throw new ArgumentNullException("PPPrefabInfo can't be null!");
        }
        var    prefabName = info.Name;
        string matPath    = Path.Combine(AppBlockPath(BlockPath.Texture_Material_Dir), prefabName);

        var model     = info.Model;
        var modelPath = Path.Combine(AppBlockPath(BlockPath.Texture_Fbx_Dir), model);

        modelPath = modelPath + "/" + model + ".gltf";

        GameObject texObj = null;

        texObj = PTGLTFLoader.loadGltf(modelPath, () =>
        {
            var texRoot = texObj.transform.Find("Root Scene");
            var render  = texRoot == null ? null : texRoot.GetComponentInChildren <Renderer>(true);
            if (render != null)
            {
                Material mat             = PBMatLoader.LoadTextureMatAsset(matPath, info.Texture, false);
                render.receiveShadows    = false;
                render.shadowCastingMode = ShadowCastingMode.Off;
                render.material          = mat;
            }
            else
            {
                PTDebug.LogError("Texture:<color=#FF00FF>{0}</color> load failed! Model:<color=#FF00FF>{1}</color>", prefabName, model);
            }
            loadFinish.InvokeGracefully();
        }, OnInitializeGltfObject);

        texObj.name = prefabName;
        blockObj.Add(texObj);

        return(texObj);
    }
コード例 #20
0
    public static IDisposable GetUploadToken(Action <string> onCallback)
    {
        var tokenUrl = GetUploadTokenUrl();

        PTDebug.Log(tokenUrl);
        return(ObservableWWW.Get(tokenUrl).Timeout(TimeSpan.FromSeconds(10)).Subscribe(res =>
        {
            var resData = TokenData.Parse(res);
            if (resData.code == 0)
            {
                onCallback.InvokeGracefully(TokenData.GetUploadToken(res));
            }
            else
            {
                PTDebug.LogError(resData.message);
                onCallback.InvokeGracefully(null);
            }
        }, e =>
        {
            PTDebug.LogError("Error:" + e.ToString());
            onCallback.InvokeGracefully(null);
        }));
    }
コード例 #21
0
 public static IDisposable UploadFile(string filePath, Action <string, string> onCallback = null)
 {
     if (!File.Exists(filePath))
     {
         PTDebug.LogError("文件不存在!路径:{0}", filePath);
         onCallback.InvokeGracefully(filePath, null);
         return(null);
     }
     return(GetUploadToken(token =>
     {
         if (token.IsNullOrEmpty())
         {
             PTDebug.LogError("获取UploadToken失败!");
             onCallback.InvokeGracefully(filePath, null);
             return;
         }
         var data = GetUploadFliePostData(filePath, token);
         ObservableWWW.Post(data.Url, data.Form).Timeout(TimeSpan.FromSeconds(30)).Subscribe(res =>
         {
             var resData = RespUploadData.Parse(res);
             if (resData.code == 0)
             {
                 onCallback.InvokeGracefully(filePath, RespUploadData.GetFileName(res));
             }
             else
             {
                 PTDebug.LogError(resData.message);
                 onCallback.InvokeGracefully(filePath, null);
             }
         }, e =>
         {
             PTDebug.LogError("Error:" + e.ToString());
             onCallback.InvokeGracefully(filePath, null);
         });
     }));
 }
コード例 #22
0
        protected override void ProcessMsg(int key, PTMsg msg)
        {
            PTDebug.Log("{0}", msg.EventID);
            switch (key)
            {
            case (ushort)UIFilterEvent.DelayLock:
                PTDebug.Log("receive");
                var lockOnClickEventMsg = msg as UILockOnClickEventMsg;
                LockBtnOnClick = true;
                var delayNode = new DelayAction(lockOnClickEventMsg.LockTime)
                {
                    OnEndedCallback = delegate
                    {
                        LockBtnOnClick = false;
                    }
                };
                StartCoroutine(delayNode.Execute());
                break;

            case (ushort)UIFilterEvent.Lock:
                PTDebug.Log("Lock");
                Lock = true;
                break;

            case (ushort)UIFilterEvent.UnLock:
                PTDebug.Log("UnLock");
                Lock = false;
                break;

            case (int)UIFilterEvent.LockObjEvent:
            {
                var lockObjEventMsg = msg as UILockObjEventMsg;
                if (null == LockedObj)
                {
                    LockedObj = lockObjEventMsg.LockedObj;
                }
                else if (LockedObj == lockObjEventMsg.LockedObj)
                {
                    // maybe two finger in one obj
                    PTDebug.LogWarning("error: curLockedObj is already seted");
                }
                else if (LockedObj != lockObjEventMsg.LockedObj)
                {
                    throw new Exception("error: pre obj need unlocked");
                }
            }
            break;

            case (int)UIFilterEvent.UnlockObjEvent:
            {
                var unlockObjEventMsg = msg as UIUnlockObjEventMsg;
                if (unlockObjEventMsg.UnlockedObj == LockedObj)
                {
                    unlockObjEventMsg.UnlockedObj = null;
                    LockedObj = null;
                }
                else if (LockedObj == null)
                {
                    PTDebug.LogWarning("error: curLockedObj is already unlocked");
                }
                else if (LockedObj != unlockObjEventMsg.UnlockedObj)
                {
                    throw new Exception("error: pre obj need unlocked");
                }
            }
            break;
            }
        }
コード例 #23
0
        private static void AttachSerializeObj(GameObject obj, string behaviourName, System.Reflection.Assembly assembly,
                                               List <IUIMark> processedMarks = null)
        {
            if (null == processedMarks)
            {
                processedMarks = new List <IUIMark>();
            }

            var uiMark    = obj.GetComponent <IUIMark>();
            var className = string.Empty;

            if (uiMark != null)
            {
                className = GetProjectNamespace() + "." + uiMark.ComponentName;

                // 这部分
                if (uiMark.GetUIMarkType() != UIMarkType.DefaultUnityElement)
                {
                    var ptuimark = obj.GetComponent <PTUIMark>();
                    if (ptuimark != null)
                    {
                        UnityEngine.Object.DestroyImmediate(ptuimark, true);
                    }
                }
            }
            else
            {
                className = GetProjectNamespace() + "." + behaviourName;
            }

//			Debug.Log(">>>>>>>Class Name: " + className);
            var t = assembly.GetType(className);

            var com     = obj.GetComponent(t) ?? obj.AddComponent(t);
            var sObj    = new SerializedObject(com);
            var uiMarks = obj.GetComponentsInChildren <IUIMark>(true);

            foreach (var elementMark in uiMarks)
            {
                if (processedMarks.Contains(elementMark) || elementMark.GetUIMarkType() == UIMarkType.DefaultUnityElement)
                {
                    continue;
                }

                processedMarks.Add(elementMark);

                var uiType       = elementMark.ComponentName;
                var propertyName = string.Format("{0}", elementMark.Transform.gameObject.name);

                if (sObj.FindProperty(propertyName) == null)
                {
                    PTDebug.Log("sObj is Null:{0} {1}", propertyName, uiType);
                    continue;
                }

                sObj.FindProperty(propertyName).objectReferenceValue = elementMark.Transform.gameObject;
                AttachSerializeObj(elementMark.Transform.gameObject, elementMark.ComponentName, assembly, processedMarks);
            }

            var marks = obj.GetComponentsInChildren <IUIMark>(true);

            foreach (var elementMark in marks)
            {
                if (processedMarks.Contains(elementMark))
                {
                    continue;
                }

                processedMarks.Add(elementMark);

                var propertyName = elementMark.Transform.name;
                sObj.FindProperty(propertyName).objectReferenceValue = elementMark.Transform.gameObject;
            }

            sObj.ApplyModifiedPropertiesWithoutUndo();
        }
コード例 #24
0
 public void Init()
 {
     PTDebug.Log("AudioManager.Init");
 }
コード例 #25
0
        /// <summary>
        /// 创建UIPanel
        /// </summary>
        /// <param name="uiBehaviourName"></param>
        /// <param name="uiLevel"></param>
        /// <param name="initData"></param>
        /// <returns></returns>
        public GameObject CreateUIObj(string uiBehaviourName, UILevel uiLevel, string assetBundleName = null)
        {
            IUIView ui;

            if (mAllUI.TryGetValue(uiBehaviourName, out ui))
            {
                PTDebug.LogWarning("{0}: already exist", uiBehaviourName);
                // 直接返回,不要再调一次Init(),Init()应该只能调用一次
                return(ui.Transform.gameObject);
            }

            ui = UIView.Load(uiBehaviourName, assetBundleName);

            switch (uiLevel)
            {
            case UILevel.Bg:
                ui.Transform.SetParent(mBgTrans);
                break;

            case UILevel.AnimationUnderPage:
                ui.Transform.SetParent(mAnimationUnderPageTrans);
                break;

            case UILevel.Common:
                ui.Transform.SetParent(mCommonTrans);
                break;

            case UILevel.AnimationOnPage:
                ui.Transform.SetParent(mAnimationOnPageTrans);
                break;

            case UILevel.PopUI:
                ui.Transform.SetParent(mPopUITrans);
                break;

            case UILevel.Const:
                ui.Transform.SetParent(mConstTrans);
                break;

            case UILevel.Toast:
                ui.Transform.SetParent(mToastTrans);
                break;

            case UILevel.Forward:
                ui.Transform.SetParent(mForwardTrans);
                break;
            }

            var uiGoRectTrans = ui.Transform as RectTransform;

            uiGoRectTrans.offsetMin          = Vector2.zero;
            uiGoRectTrans.offsetMax          = Vector2.zero;
            uiGoRectTrans.anchoredPosition3D = Vector3.zero;
            uiGoRectTrans.anchorMin          = Vector2.zero;
            uiGoRectTrans.anchorMax          = Vector2.one;

            ui.Transform.LocalScaleIdentity();
            ui.Transform.gameObject.name = uiBehaviourName;

            ui.PanelInfo = new UIPanelInfo {
                AssetBundleName = assetBundleName, Level = uiLevel, PanelName = uiBehaviourName
            };
            return(ui.Transform.gameObject);
        }