Beispiel #1
0
    public static IEnumerator LoadTexture(string path)
    {
        TLEditorWww www = TLEditorWww.Create(path);

        while (!www.Finished)
        {
            yield return(null);
        }
        www.GetAsset();
        instance_.TextureLoadDone = true;
    }
Beispiel #2
0
    public IEnumerator LoadCtrl(string path)
    {
        TLEditorWww www = TLEditorWww.Create(path);

        while (!www.Finished)
        {
            yield return(null);
        }
        www.GetAsset();
        isCtrlLoadDone = true;
        //www.Unload();
    }
Beispiel #3
0
    public IEnumerator LoadShader(string path)
    {
        TLEditorWww www = TLEditorWww.Create(path);

        while (!www.Finished)
        {
            yield return(null);
        }
        www.GetAsset();
        ModelLoader.sdWww = www;
        myshaderLoadDone  = true;
        //www.Unload();
    }
Beispiel #4
0
    public static IEnumerator LoadScene(string name)
    {
        TLEditorWww www = TLEditorWww.Create(string.Format("res/scenes/{0}.scene", name));

        while (!www.Finished)
        {
            yield return(null);
        }
        AssetBundle bundle = www.AssetBundle;

        yield return(new WaitForSeconds(1));

        var operation = SceneManager.LoadSceneAsync(name);
    }
Beispiel #5
0
    private IEnumerator LoadAudioClip(string path, Action <AudioClip> loadFinish)
    {
        TLEditorWww www = TLEditorWww.Create(path);

        while (!www.Finished)
        {
            yield return(null);
        }
        AudioClip clip = www.GetAsset() as AudioClip;

        yield return(null);

        www.Unload();
        loadFinish(clip);
    }
Beispiel #6
0
    private IEnumerator LoadTexture(string path, Action <Texture> loadFinish)
    {
        TLEditorWww effectWWW = TLEditorWww.Create(path);

        while (!effectWWW.Finished)
        {
            yield return(null);
        }
        Texture texture = effectWWW.GetAsset() as Texture;

        yield return(null);

        effectWWW.Unload();
        loadFinish(texture);
    }
Beispiel #7
0
    private IEnumerator LoadEffect(string path, Action <EffectObject> loadFinish)
    {
        TLEditorWww effectWWW = TLEditorWww.Create(path);

        while (!effectWWW.Finished)
        {
            yield return(null);
        }
        EffectObject effObj = new EffectObject();

        effObj.OnCreate(effectWWW.GetAsset());
        GameManager.ReplaceShader(effObj.gameObject, string.Empty);
        effectWWW.Unload();
        loadFinish(effObj);
    }
Beispiel #8
0
    private IEnumerator LoadRoleObject(string path, Action <RoleObject> loadFinish)
    {
        UnityEngine.Object role    = null;
        TLEditorWww        roleWww = null;

        if (!roleAssetsWww.TryGetValue(path, out roleWww))
        {
            roleWww = TLEditorWww.Create(path);
            roleAssetsWww.Add(path, roleWww);
        }

        while (!roleWww.Finished)
        {
            yield return(null);
        }

        if (!roleAssets.TryGetValue(path, out role))
        {
            role = roleWww.GetCachedAsset() as GameObject;
            GameManager.ReplaceShader(role, string.Empty);
            roleAssets.Add(path, role);
        }

        if (role == null)
        {
            Debug.LogError("Error, Load role Failed: " + path);
        }
        else
        {
            Role roleConfig = (role as GameObject).GetComponent <Role>();
            if (roleConfig == null)
            {
                Debug.Log("config==null");
            }
            GameObject roleGo    = ModelLoader.CreateRole(roleConfig).gameObject;
            var        performer = roleGo.GetComponent <ActionPerformer>();
            RoleObject roleObj   = roleGo.GetComponent <RoleObject>();
            roleObj.needAnimationButtonGui = false;
            roleObj.CheckAnimator();
            roleObj.enabled = true;
            //roleWww.Unload();
            loadFinish(roleObj);
        }
    }
Beispiel #9
0
    private IEnumerator LoadAniClip(string path, Action <AnimationClip> loadFinish)
    {
        curAniWWW = TLEditorWww.Create(path);
        while (!curAniWWW.Finished)
        {
            yield return(null);
        }
        AnimationClip clip = curAniWWW.GetAsset() as AnimationClip;

        yield return(null);

        curAniWWW.Unload();
        loadFinish(clip);
        curAniWWW = null;
        if (aniClipQueue.Count > 0)
        {
            XYCoroutineEngine.Execute(LoadAniClip(aniClipQueue.Dequeue(), loadFinishQueue.Dequeue()));
        }
    }
Beispiel #10
0
    private IEnumerator LoadTimeline(string path, Action <RoleObject> loadFinish)
    {
        TLEditorWww roleWww = TLEditorWww.Create(path);

        while (!roleWww.Finished)
        {
            yield return(null);
        }
        GameObject timeline = null;

        timeline = roleWww.GetAsset() as GameObject;
        if (timeline == null)
        {
            Debug.LogError("Error, Load role Failed: " + path);
        }
        else
        {
            Instantiate(timeline);
        }
    }
Beispiel #11
0
    private IEnumerator LoadActionObject(string path, Action <ModelAction> loadFinish)
    {
        TLEditorWww roleWww = TLEditorWww.Create(path);

        while (!roleWww.Finished)
        {
            yield return(null);
        }
        ModelAction actionConfig = roleWww.GetAsset() as Model.Action;

        if (actionConfig == null)
        {
            Debug.LogError("Error, Load role Failed: " + path);
        }
        else
        {
            Debug.Log(actionConfig.ActionEvents.Length);
        }
        roleWww.Unload();
        loadFinish(actionConfig);
    }
Beispiel #12
0
        public IEnumerator LoadRoleObject(string path, System.Action <MPObject> loadFinish)
        {
            TLEditorWww roleWww = TLEditorWww.Create(path);

            while (!roleWww.Finished)
            {
                yield return(null);
            }
            GameObject role = null;

            role = roleWww.GetAsset() as GameObject;
            ReplaceShader(role, string.Empty);
            if (role == null)
            {
                Debug.LogError("Error, Load role Failed: " + path);
                roleWww.Unload();
            }
            else
            {
                Role roleConfig = role.GetComponent <Role>();
                if (roleConfig == null)
                {
                    Debug.Log("Error,can't find role component");
                }
                GameObject roleGo = ModelLoader.CreateRole(roleConfig).gameObject;
                roleGo.gameObject.GetComponent <ActionPerformer>().enabled = false;
                roleGo.gameObject.GetComponent <RoleObject>().enabled      = false;
                roleWww.Unload();
                this.mapGO      = roleGo;
                this.mapGO.name = sn.ToString();
                BoxCollider bc = this.mapGO.AddComponent <BoxCollider>();
                bc.size   = new Vector3(1, 2, 1);
                bc.center = new Vector3(0, 1, 0);
                XYClientCommon.ChangeLayer(this.mapGO, XYDefines.Layer.Player, true);
                loadFinish(this);
            }
        }
Beispiel #13
0
    private static IEnumerator AsyncCreateEquip(GameObject root, Equip equip, bool load = true)
    {
        if (load)
        {
            TLEditorWww sdWww = TLEditorWww.Create("res/myshader.sd");
            while (!sdWww.Finished)
            {
                yield return(null);
            }
            sdWww.GetAsset();
            Shader.WarmupAllShaders();
        }
        TLEditorWww www = null;

        www = TLEditorWww.Create(equip.ModelPath);
        while (!www.Finished)
        {
            yield return(null);
        }

        GameObject modelObject = UnityEngine.Object.Instantiate(www.GetAsset()) as GameObject;
        Renderer   Renderer    = modelObject.GetComponentInChildren <Renderer>();

        Renderer.enabled = true;
        Renderer.sharedMaterial.shader = Shader.Find(Renderer.sharedMaterial.shader.name);
        yield return(null);

        yield return(null);//延迟两帧unload,避免unload太快,instantiate还没执行完导致贴图丢失

        RoleObject ro = root.GetComponent <RoleObject>();

        www.Unload();

        foreach (EffectConfig effectInfo in equip.Effects.Where(effectInfo => !string.IsNullOrEmpty(effectInfo.EffectAssetPath)))
        {
            TLEditorWww eff = TLEditorWww.Create(effectInfo.EffectAssetPath);
            while (!eff.Finished)
            {
                yield return(null);
            }

            GameObject effect = UnityEngine.Object.Instantiate(eff.GetAsset()) as GameObject;
            eff.Unload();
            if (effect)
            {
                Transform tf = RoleObject.FindChildTransformWithName(root, effectInfo.BindBone);
                if (!tf)
                {
                    tf = modelObject.transform;
                }

                effect.transform.parent           = tf;
                effect.transform.localPosition    = effectInfo.Position;
                effect.transform.localEulerAngles = effectInfo.Rotation;
                effect.transform.localScale       = effectInfo.Scale;
                TLEditorWww.ApplyParticleScale(effect.transform, effectInfo.Scale.x);
            }
        }

        Role config = root.gameObject.GetComponent <Role>();

        if (!config)
        {
            modelObject.transform.SetParent(root.transform);
            modelObject.transform.localPosition    = Vector3.zero;
            modelObject.transform.localEulerAngles = Vector3.zero;
            modelObject.transform.localScale       = Vector3.one;
            yield break;
        }

        SkinnedMeshRenderer skinrender = modelObject.GetComponentInChildren <SkinnedMeshRenderer>();

        if (skinrender)
        {
            if (equip.Bones != null && equip.Bones.Length > 0)
            {
                Transform[] bones = new Transform[equip.Bones.Length];
                for (int i = 0; i < equip.Bones.Length; i++)
                {
                    bones[i] = ModelLoader.FindChildByName(root.transform, equip.Bones[i]);
                }

                skinrender.bones    = bones;
                skinrender.rootBone = FindChildByName(config.transform, equip.RootBone);
            }
            skinrender.enabled = true;
        }

        Transform bindTF = FindChildByName(config.transform, equip.ParentBone);

        if (!bindTF)
        {
            bindTF = config.transform;
        }

        if (ro)
        {
            ro.Skins.Add(modelObject);
        }

        Animation ani = modelObject.GetComponent <Animation>();

        if (ani)
        {
            ro.Animations.Add(ani);
        }

        modelObject.transform.SetParent(bindTF);
        modelObject.transform.localPosition    = Vector3.zero;
        modelObject.transform.localEulerAngles = Vector3.zero;
        modelObject.transform.localScale       = Vector3.one;
        modelObject.layer = ro.modelLayer;
    }
Beispiel #14
0
    private static IEnumerator AsyncCreateRole(RoleObject ro, Role config)
    {
        if (sdWww == null)
        {
            sdWww = TLEditorWww.Create("res/myshader.sd");
            while (!sdWww.Finished)
            {
                yield return(null);
            }
            sdWww.GetAsset();
            Shader.WarmupAllShaders();
        }

        foreach (var equip in ro.Config.Equips)
        {
            TLEditorWww equipWww = TLEditorWww.Create(equip.Equip);
            while (!equipWww.Finished)
            {
                yield return(null);
            }
            Equip equipConfig = equipWww.GetAsset() as Equip;
            if (!equipConfig)
            {
                Debug.Log("Error, Load Equip Failed: " + equip);
            }
            else
            {
                AddEquip(ro.gameObject, equipConfig, false);
            }
            equipWww.Unload();
        }

        if (!string.IsNullOrEmpty(config.Mesh))
        {
            Debug.Log("setmash" + config.Mesh);
            TLEditorWww www = TLEditorWww.Create(config.Mesh);
            while (!www.Finished)
            {
                yield return(null);
            }

            if (config.Skin)
            {
                config.Skin.sharedMesh            = www.GetAsset() as Mesh;
                config.Skin.enabled               = true;
                config.Skin.sharedMaterial.shader = Shader.Find(config.Skin.sharedMaterial.shader.name);
            }
            else if (config.Filter)
            {
                config.Filter.sharedMesh = www.GetAsset() as Mesh;
            }
            www.Unload();
        }

        if (!string.IsNullOrEmpty(config.MainTex))
        {
            Debug.Log("setmaintext" + config.MainTex);
            TLEditorWww www = TLEditorWww.Create(config.MainTex);
            while (!www.Finished)
            {
                yield return(null);
            }

            if (config.Skin)
            {
                config.Skin.sharedMaterial.mainTexture = www.GetAsset() as Texture;
            }
            else if (config.Filter)
            {
                config.Filter.GetComponent <MeshRenderer>().sharedMaterial.mainTexture = www.GetAsset() as Texture;
            }
            www.Unload();
        }

        if (config.Skin)
        {
            config.Skin.enabled = true;
        }
    }