Beispiel #1
0
    /// <summary>
    ///
    /// </summary>
    /// <param name="confList"></param>
    public static void LoadAsync(string[] confList)
    {
        XRes.LoadMultiAsync(confList, delegate(Object[] objs)
        {
            confPvp = objs[0] as XCameraConfigure;
            if (confPvp)
            {
                confPvp.Initialize();
            }

            confPve = objs[1] as XCameraConfigure;
            if (confPve)
            {
                confPve.Initialize();
            }

            // joy config
            yo  = objs[2] as XCameraYo;
            joy = objs[3] as XCameraYo;

#if UNITY_EDITOR
            foreach (Object obj in objs)
            {
                GLog.Log("[XCameraHelper:LoadAsync] " + obj);
            }
#endif
        });
    }
Beispiel #2
0
    /// <summary>
    ///
    /// </summary>
    /// <param name="fileName"></param>
    /// <returns></returns>
    public static XBufferAsset          LoadBytecodeAsset(string fileName)
    {
        XBufferAsset bufferAsset = null;

#if UNITY_ANDROID && !UNITY_EDITOR
        string            name = fileName.ToLower();
        XSheet.XAssetInfo info = XSheet.Instance.Find(name);
        if (info != null && info.locationType == XSheet.XLocationType.Resource)
        {
            if (asset != null)
            {
                Debug.LogError(fileName);
                byte[] bytes = GetBytecodeByFileName(fileName);
                if (bytes != null)
                {
                    bufferAsset = ScriptableObject.CreateInstance <XBufferAsset>();
                    bufferAsset.init(bytes);
                }
            }
            else
            {
                bufferAsset = XRes.Load <XBufferAsset>(fileName);
            }
        }
        else
        {
            bufferAsset = XRes.Load <XBufferAsset>(fileName);
        }
#else
        bufferAsset = XRes.Load <XBufferAsset>(fileName);
#endif

        return(bufferAsset);
    }
Beispiel #3
0
    private IEnumerator GetBullet(string bulletPath, System.Action <XBulletComponent> callback)
    {
        BulletCache      bulletCache = null;
        XBulletComponent bullet      = null;

        TryGetBulletCache(bulletPath, out bulletCache);
        if (bulletCache == null)
        {
            bulletCache         = new BulletCache();
            bulletCache.loading = true;
            AddBulletCache(bulletPath, bulletCache);

            yield return(XRes.LoadAsync <GameObject>(bulletPath, delegate(Object obj) {
                bulletCache.queue = new Queue <XBulletComponent>();
                bulletCache.prefab = obj as GameObject;
                bulletCache.loading = false;
            }));
        }

        while (bulletCache.loading)
        {
            yield return(null);
        }

        if (bulletCache.prefab != null)
        {
            bullet = GenerateBullet(bulletPath, bulletCache);
        }

        callback(bullet);
    }
Beispiel #4
0
    private IEnumerator GetEffect(string effectPath, System.Action <XEffectCache, XEffectComponent> callback)
    {
        XEffectCache     effectCache = null;
        XEffectComponent effect      = null;

        TryGetEffectCache(effectPath, out effectCache);
        if (effectCache == null)
        {
            effectCache         = new XEffectCache();
            effectCache.loading = true;
            AddEffectCache(effectPath, effectCache);

            yield return(XRes.LoadAsync <GameObject>(effectPath, delegate(Object obj) {
                effectCache.queue = new Queue <XEffectComponent>();
                effectCache.prefab = obj as GameObject;
                effectCache.loading = false;
            }));
        }

        while (effectCache.loading)
        {
            yield return(null);
        }

        if (effectCache.prefab != null)
        {
            effect = GenerateEffect(effectPath, effectCache);
        }

        callback(effectCache, effect);
    }
Beispiel #5
0
 /// <summary>
 ///
 /// </summary>
 public void Load()
 {
     XRes.LoadAsync <XTextStyleSheetObject>(typeof(XTextStyleSheetObject).Name.ToLower(), delegate(Object obj)
     {
         styleSheet = obj as XTextStyleSheetObject;
     });
 }
Beispiel #6
0
    private IEnumerator DoPreloadBulletPrefabs(string[] resList, System.Action <bool> callback)
    {
        List <string> resLoad = new List <string>();

        for (int i = 0; i < resList.Length; i++)
        {
            string      effectPath  = resList[i];
            BulletCache bulletCache = null;
            TryGetBulletCache(effectPath, out bulletCache);
            if (bulletCache == null)
            {
                bulletCache = new BulletCache();
                AddBulletCache(effectPath, bulletCache);
            }

            if (!bulletCache.loading)
            {
                bulletCache.loading = true;
                resLoad.Add(effectPath);
            }
        }

        yield return(XRes.LoadMultiAsync(resLoad.ToArray(), delegate(Object[] obj) {
            for (int i = 0; i < obj.Length; i++)
            {
                BulletCache bulletCache = null;
                if (TryGetBulletCache(resLoad[i], out bulletCache))
                {
                    bulletCache.prefab = obj[i] as GameObject;
                    bulletCache.queue = new Queue <XBulletComponent>();
                    bulletCache.loading = false;
                }
            }

            if (callback != null)
            {
                callback(true);
            }
        }));
    }
Beispiel #7
0
 public static IEnumerator DoUpdate(Action <Stage, float, string> progressCallback)
 {
     yield return(XCoroutine.Run(XRes.Initialize(progressCallback)));
 }
Beispiel #8
0
    /// <summary>
    ///
    /// </summary>
    /// <returns></returns>
    static IEnumerator OnLoadAsync(string name, string[] elementList, System.Action <Object> callabck)
    {
        XAvatarCacheInfo cacheInfo = GetCacheAvatar(name, elementList);

        if (cacheInfo != null && cacheInfo.prefab != null)
        {
            if (callabck != null)
            {
                GameObject prefab = cacheInfo.prefab;

                prefab.transform.position   = Vector3.one * 1000;
                prefab.transform.localScale = Vector3.one;
                prefab.transform.rotation   = Quaternion.identity;

                callabck(prefab);
            }

            yield break;
        }

        List <Object> elements = new List <Object>();

        // load all elements
        yield return(XRes.LoadMultiAsync(elementList, delegate(Object[] objs)
        {
            for (int i = 0; i < objs.Length; i++)
            {
                elements.Add(objs[i]);
            }
        }));

        yield return(XRes.LoadAsync <GameObject>(name, delegate(Object obj)
        {
            GameObject skeleton = GameObject.Instantiate(obj) as GameObject;
            if (skeleton && elements.Count > 0)
            {
                List <CombineInstance> combineInstances = new List <CombineInstance>();
                Transform[] trans = skeleton.GetComponentsInChildren <Transform>();
                List <Matrix4x4> bindPoses = new List <Matrix4x4>();
                List <Transform> boneTrans = new List <Transform>();
                List <Material> shardMatList = new List <Material>();

                for (int i = 0; i < elements.Count; i++)
                {
                    XAvatarElement element = elements[i] as XAvatarElement;
                    if (element && element.Prefab)
                    {
                        GameObject prefab = GameObject.Instantiate(element.Prefab) as GameObject;
                        if (prefab)
                        {
                            SkinnedMeshRenderer skin = prefab.GetComponent <SkinnedMeshRenderer>();
                            CombineInstance ci = new CombineInstance();
                            ci.mesh = skin.sharedMesh;
                            ci.transform = element.SmrLocalToWorldMatrix;
                            combineInstances.Add(ci);

                            List <Transform> curBones = new List <Transform>();
                            foreach (string transName in element.BoneNames)
                            {
                                for (int transIndex = 0; transIndex < trans.Length; transIndex++)
                                {
                                    if (transName == trans[transIndex].name)
                                    {
                                        curBones.Add(trans[transIndex]);
                                        bindPoses.Add(trans[transIndex].worldToLocalMatrix * skeleton.transform.localToWorldMatrix);
                                        break;
                                    }
                                }
                            }

                            boneTrans.AddRange(curBones);

                            Dictionary <string, int> boneWeightDic = element.GenBoneWeightsDic();
                            foreach (BoneWeight boneWeight in skin.sharedMesh.boneWeights)
                            {
                                BoneWeight bw = boneWeight;

                                bw.boneIndex0 = boneWeightDic[curBones[boneWeight.boneIndex0].name];
                                bw.boneIndex1 = boneWeightDic[curBones[boneWeight.boneIndex1].name];
                                bw.boneIndex2 = boneWeightDic[curBones[boneWeight.boneIndex2].name];
                                bw.boneIndex3 = boneWeightDic[curBones[boneWeight.boneIndex3].name];
                            }

                            shardMatList.AddRange(element.SharedMaterials);

                            GameObject.DestroyImmediate(prefab);
                        }
                    }
                }

                skeleton.transform.position = Vector3.one * 1000;
                skeleton.name = obj.name;
                Transform model = skeleton.transform.Find(XActorElementName.shape.ToString());
                if (!model)
                {
                    model = skeleton.transform;
                }

                GameObject render = new GameObject(typeof(Renderer).Name);

                render.transform.parent = model;
                render.transform.localScale = Vector3.one;
                render.transform.localPosition = Vector3.zero;
                render.transform.localRotation = Quaternion.identity;

                SkinnedMeshRenderer smr = render.AddComponent <SkinnedMeshRenderer>();
                smr.sharedMesh = new Mesh();
                smr.sharedMesh.CombineMeshes(combineInstances.ToArray(), false, false);
                smr.bones = boneTrans.ToArray();
                smr.sharedMaterials = shardMatList.ToArray();

                Animator animator = skeleton.GetComponent <Animator>();
                if (animator)
                {
                    smr.rootBone = animator.GetBoneTransform(HumanBodyBones.Hips);
                }

                smr.sharedMesh.RecalculateBounds();

                // add avatar cache
                AddCacheAvatar(name, elementList, skeleton);
                if (callabck != null)
                {
                    callabck(skeleton);
                }
            }
        }));
    }