Пример #1
0
 // Use this for initialization
 void Start()
 {
     BoneLoader        = new CharacterBoneLoader();
     CharElementLoader = new CharacterElementLoader();
     loaders           = new ArrayList()
     {
         BoneLoader,
         CharElementLoader,
     };
 }
Пример #2
0
    /// <summary>
    /// 更新部件
    /// </summary>
    private void UpdateElement(GameObject root, string partName, string eleName)
    {
        if (string.IsNullOrEmpty(eleName))
        {
            Debug.LogError("AssetbundleAssembler UpdateElement partName: " + partName + " eleName: " + eleName);
            return;
        }

        Transform[] hips = root.GetComponentsInChildren <Transform>();

        GameObject part = FindGameObject(root, partName);

        if (part == null)
        {
            part                  = new GameObject();
            part.name             = partName;
            part.transform.parent = root.transform;
            part.AddComponent <SkinnedMeshRenderer>();
        }

        SkinnedMeshRenderer smr = s_CharacterElementLoaders[eleName].GetSkinnedMeshRenderer();

        List <Transform>       bones  = new List <Transform>();
        CharacterElementLoader loader = (CharacterElementLoader)s_CharacterElementLoaders[eleName];
        //test
        var loaders = loader.GetBoneNames();

        foreach (string bone in loaders)
        {
            foreach (Transform hip in hips)
            {
                if (hip.name != bone)
                {
                    continue;
                }

                bones.Add(hip);
                break;
            }
        }

        SkinnedMeshRenderer partSmr = part.GetComponent <SkinnedMeshRenderer>();

        if (partSmr != null)
        {
            partSmr.sharedMesh = smr.sharedMesh;
            partSmr.bones      = bones.ToArray();
            partSmr.materials  = smr.materials;
            partSmr.rootBone   = (bones == null || bones.Count == 0) ? null : bones[0];
        }
        UnityEngine.Object.Destroy(smr.gameObject);
    }
Пример #3
0
    public void Update(uint id, AssemblerInfo info)
    {
        if (info == null) return;

        //Debug.Log(".Update  " + id + " " + JsonWriter.Serialize(info));

        info.m_ID = id;

        if (!string.IsNullOrEmpty(info.m_Character)
            && !s_CharacterLoaders.ContainsKey(info.m_Character))
        {
            CharacterLoader cl = new CharacterLoader(info.m_Character + "_" + AssemblerConstant.CHARACTER_BASE_NAME + AssemblerConstant.ASSETBUNDLE_SUFFIX);
            s_CharacterLoaders.Add(info.m_Character, cl);
        }

        if (!string.IsNullOrEmpty(info.m_HeadElement)
            && !s_CharacterElementLoaders.ContainsKey(info.m_HeadElement))
        {
            CharacterElementLoader cel = new CharacterElementLoader(info.m_HeadElement, info.m_HeadElement + AssemblerConstant.ASSETBUNDLE_SUFFIX);
            s_CharacterElementLoaders.Add(info.m_HeadElement, cel);
        }

        if (!string.IsNullOrEmpty(info.m_BodyElement)
            && !s_CharacterElementLoaders.ContainsKey(info.m_BodyElement))
        {
            CharacterElementLoader cel = new CharacterElementLoader(info.m_BodyElement, info.m_BodyElement + AssemblerConstant.ASSETBUNDLE_SUFFIX);
            s_CharacterElementLoaders.Add(info.m_BodyElement, cel);
        }

        if (!string.IsNullOrEmpty(info.m_FootElement)
            && !s_CharacterElementLoaders.ContainsKey(info.m_FootElement))
        {
            CharacterElementLoader cel = new CharacterElementLoader(info.m_FootElement, info.m_FootElement + AssemblerConstant.ASSETBUNDLE_SUFFIX);
            s_CharacterElementLoaders.Add(info.m_FootElement, cel);
        }

        if (!string.IsNullOrEmpty(info.m_Character)
            && !s_AnimationAssemblers.ContainsKey(info.m_Character + AssemblerConstant.ANIMATION_SUFFIX))
        {
            AnimationLoader aa = new AnimationLoader(info.m_Character + AssemblerConstant.ANIMATION_SUFFIX + AssemblerConstant.ASSETBUNDLE_SUFFIX);
            s_AnimationAssemblers.Add(info.m_Character + AssemblerConstant.ANIMATION_SUFFIX, aa);
        }

        if (!string.IsNullOrEmpty(info.m_WeaponR)
            && !s_ModelLoaders.ContainsKey(info.m_WeaponR))
        {
            ModelLoader ml = new ModelLoader(info.m_WeaponR + "_" + AssemblerConstant.CHARACTER_BASE_NAME + AssemblerConstant.ASSETBUNDLE_SUFFIX);
            s_ModelLoaders.Add(info.m_WeaponR, ml);
        }

        if (!string.IsNullOrEmpty(info.m_WeaponL)
            && !s_ModelLoaders.ContainsKey(info.m_WeaponL))
        {
            ModelLoader ml = new ModelLoader(info.m_WeaponL + "_" + AssemblerConstant.CHARACTER_BASE_NAME + AssemblerConstant.ASSETBUNDLE_SUFFIX);
            s_ModelLoaders.Add(info.m_WeaponL, ml);
        }

        //if (!string.IsNullOrEmpty(info.m_Wing)
        //    && !s_CharacterLoaders.ContainsKey(info.m_Wing))
        //{

        //}

        if (!string.IsNullOrEmpty(info.m_WingElement)
            && !s_CharacterElementLoaders.ContainsKey(info.m_WingElement))
        {

            CharacterLoader ml = new CharacterLoader(info.m_WingElement + "_" + AssemblerConstant.CHARACTER_BASE_NAME + AssemblerConstant.ASSETBUNDLE_SUFFIX);
            s_CharacterLoaders.Add(info.m_WingElement, ml);

            AnimationLoader aa = new AnimationLoader(info.m_WingElement + AssemblerConstant.ANIMATION_SUFFIX + AssemblerConstant.ASSETBUNDLE_SUFFIX);
            s_AnimationAssemblers.Add(info.m_WingElement + AssemblerConstant.ANIMATION_SUFFIX, aa);

            CharacterElementLoader cel = new CharacterElementLoader(info.m_WingElement, info.m_WingElement + AssemblerConstant.ASSETBUNDLE_SUFFIX);
            s_CharacterElementLoaders.Add(info.m_WingElement, cel);
        }

        //if (!string.IsNullOrEmpty(info.m_Wing)
        //    && !s_AnimationAssemblers.ContainsKey(info.m_Wing + AssemblerConstant.ANIMATION_SUFFIX))
        //{

        //}

        info.m_IsDone = false;
        if (m_Assemblers.ContainsKey(id))
        {
            m_Assemblers[id] = new AssemblerInfo(ref info);
            //m_Assemblers.Remove(id);
        }
        else
        {
            m_Assemblers.Add(id, info);
        }

        if (!mCorout_isRunning)
        {
            mCorout_isRunning = true;
            StartCoroutine(LoadCoroutine());
        }

        //Debug.Log("Create assemble: " + DecToHex(id) + " status: " + info.m_IsDone);

        return;
    }
Пример #4
0
    public void CleanByScene()
    {
        //Debug.Log("Assembler.Clean ");

        mCorout_isRunning = false;

        this.StopCoroutine("LoadCoroutine");

        //StopAllCoroutines();

        foreach (var gameObj in m_Objects.Values)
        {
            GameObject go = (GameObject)gameObj;
            if (go != null)
            {
                go.SetActive(true);
                UnityEngine.Object.DestroyImmediate(go);
                go = null;
            }
        }
        m_Objects.Clear();

        foreach (CharacterLoader item in s_CharacterLoaders.Values)
        {
            CharacterLoader loader = (CharacterLoader)item;
            loader.Dispose();
            loader = null;
        }
        s_CharacterLoaders.Clear();

        foreach (ModelLoader item in s_ModelLoaders.Values)
        {
            ModelLoader loader = (ModelLoader)item;
            loader.Dispose();
            loader = null;
        }
        s_ModelLoaders.Clear();

        foreach (CharacterElementLoader item in s_CharacterElementLoaders.Values)
        {
            CharacterElementLoader loader = (CharacterElementLoader)item;
            loader.Dispose();
            loader = null;
        }
        s_CharacterElementLoaders.Clear();

        foreach (AnimationLoader item in s_AnimationAssemblers.Values)
        {
            AnimationLoader loader = (AnimationLoader)item;
            loader.Dispose();
            loader = null;
        }
        s_AnimationAssemblers.Clear();

        foreach (var item in m_Assemblers.Values)
        {
            AssemblerInfo loader = (AssemblerInfo)item;
            loader = null;
        }
        m_Assemblers.Clear();

        mUniqueID = 1;

        OnFinishLoading = null;
    }
Пример #5
0
    public void Update(uint id, AssemblerInfo info)
    {
        if (info == null)
        {
            return;
        }

        //Debug.Log(".Update  " + id + " " + JsonWriter.Serialize(info));

        info.m_ID = id;

        if (!string.IsNullOrEmpty(info.m_Character) &&
            !s_CharacterLoaders.ContainsKey(info.m_Character))
        {
            CharacterLoader cl = new CharacterLoader(info.m_Character + "_" + AssemblerConstant.CHARACTER_BASE_NAME + AssemblerConstant.ASSETBUNDLE_SUFFIX);
            s_CharacterLoaders.Add(info.m_Character, cl);
        }

        if (!string.IsNullOrEmpty(info.m_HeadElement) &&
            !s_CharacterElementLoaders.ContainsKey(info.m_HeadElement))
        {
            CharacterElementLoader cel = new CharacterElementLoader(info.m_HeadElement, info.m_HeadElement + AssemblerConstant.ASSETBUNDLE_SUFFIX);
            s_CharacterElementLoaders.Add(info.m_HeadElement, cel);
        }

        if (!string.IsNullOrEmpty(info.m_BodyElement) &&
            !s_CharacterElementLoaders.ContainsKey(info.m_BodyElement))
        {
            CharacterElementLoader cel = new CharacterElementLoader(info.m_BodyElement, info.m_BodyElement + AssemblerConstant.ASSETBUNDLE_SUFFIX);
            s_CharacterElementLoaders.Add(info.m_BodyElement, cel);
        }

        if (!string.IsNullOrEmpty(info.m_FootElement) &&
            !s_CharacterElementLoaders.ContainsKey(info.m_FootElement))
        {
            CharacterElementLoader cel = new CharacterElementLoader(info.m_FootElement, info.m_FootElement + AssemblerConstant.ASSETBUNDLE_SUFFIX);
            s_CharacterElementLoaders.Add(info.m_FootElement, cel);
        }

        if (!string.IsNullOrEmpty(info.m_Character) &&
            !s_AnimationAssemblers.ContainsKey(info.m_Character + AssemblerConstant.ANIMATION_SUFFIX))
        {
            AnimationLoader aa = new AnimationLoader(info.m_Character + AssemblerConstant.ANIMATION_SUFFIX + AssemblerConstant.ASSETBUNDLE_SUFFIX);
            s_AnimationAssemblers.Add(info.m_Character + AssemblerConstant.ANIMATION_SUFFIX, aa);
        }

        if (!string.IsNullOrEmpty(info.m_WeaponR) &&
            !s_ModelLoaders.ContainsKey(info.m_WeaponR))
        {
            ModelLoader ml = new ModelLoader(info.m_WeaponR + "_" + AssemblerConstant.CHARACTER_BASE_NAME + AssemblerConstant.ASSETBUNDLE_SUFFIX);
            s_ModelLoaders.Add(info.m_WeaponR, ml);
        }

        if (!string.IsNullOrEmpty(info.m_WeaponL) &&
            !s_ModelLoaders.ContainsKey(info.m_WeaponL))
        {
            ModelLoader ml = new ModelLoader(info.m_WeaponL + "_" + AssemblerConstant.CHARACTER_BASE_NAME + AssemblerConstant.ASSETBUNDLE_SUFFIX);
            s_ModelLoaders.Add(info.m_WeaponL, ml);
        }

        //if (!string.IsNullOrEmpty(info.m_Wing)
        //    && !s_CharacterLoaders.ContainsKey(info.m_Wing))
        //{

        //}

        if (!string.IsNullOrEmpty(info.m_WingElement) &&
            !s_CharacterElementLoaders.ContainsKey(info.m_WingElement))
        {
            CharacterLoader ml = new CharacterLoader(info.m_WingElement + "_" + AssemblerConstant.CHARACTER_BASE_NAME + AssemblerConstant.ASSETBUNDLE_SUFFIX);
            s_CharacterLoaders.Add(info.m_WingElement, ml);

            AnimationLoader aa = new AnimationLoader(info.m_WingElement + AssemblerConstant.ANIMATION_SUFFIX + AssemblerConstant.ASSETBUNDLE_SUFFIX);
            s_AnimationAssemblers.Add(info.m_WingElement + AssemblerConstant.ANIMATION_SUFFIX, aa);

            CharacterElementLoader cel = new CharacterElementLoader(info.m_WingElement, info.m_WingElement + AssemblerConstant.ASSETBUNDLE_SUFFIX);
            s_CharacterElementLoaders.Add(info.m_WingElement, cel);
        }

        //if (!string.IsNullOrEmpty(info.m_Wing)
        //    && !s_AnimationAssemblers.ContainsKey(info.m_Wing + AssemblerConstant.ANIMATION_SUFFIX))
        //{

        //}

        info.m_IsDone = false;
        if (m_Assemblers.ContainsKey(id))
        {
            m_Assemblers[id] = new AssemblerInfo(ref info);
            //m_Assemblers.Remove(id);
        }
        else
        {
            m_Assemblers.Add(id, info);
        }

        if (!mCorout_isRunning)
        {
            mCorout_isRunning = true;
            StartCoroutine(LoadCoroutine());
        }

        //Debug.Log("Create assemble: " + DecToHex(id) + " status: " + info.m_IsDone);

        return;
    }