Example #1
0
 private void addLoading(NifLoadJob job)
 {
     // Add a loading capsule to the location of the job
     if (!job.IsDone)
     {
         telara_obj obj     = job.parent;
         GameObject loading = (GameObject)GameObject.Instantiate(Resources.Load("LoadingCapsule"));
         loading.name = "Loading";
         SphereCollider sp = obj.GetComponent <SphereCollider>();
         if (sp != null)
         {
             loading.transform.localScale = Vector3.one * 3;
         }
         loading.transform.parent        = obj.gameObject.transform;
         loading.transform.localPosition = Vector3.zero;
         loading.transform.localRotation = Quaternion.identity;
         //applyLOD(loading);
     }
 }
Example #2
0
    protected override void OnFinished()
    {
        GameObject go = null;

        try
        {
            if (filename.Contains("_terrain_"))
            {
                TerrainObj tobj = parent.gameObject.GetComponent <TerrainObj>();
                if (tobj == null)
                {
                    parent.gameObject.AddComponent <TerrainObj>();
                }
                else
                {
                    tobj.enabled = true;
                }
            }
            count--;
            // This is executed by the Unity main thread when the job is finished
            if (niffile != null)
            {
                go = NIFLoader.loadNIF(niffile, filename);
                if (lodfile != null)
                {
                    GameObject lodgo = NIFLoader.loadNIF(lodfile, filename);

                    // terrain lod
                    LODGroup group = parent.gameObject.GetComponent <LODGroup>();
                    if (group == null)
                    {
                        group = parent.gameObject.AddComponent <LODGroup>();
                    }
                    group.enabled            = true;
                    group.animateCrossFading = true;
                    group.fadeMode           = LODFadeMode.SpeedTree;
                    LOD[]      lods         = new LOD[2];
                    Renderer[] renderersMax = go.GetComponentsInChildren <Renderer>();
                    Renderer[] renderersLow = lodgo.GetComponentsInChildren <Renderer>();
                    lods[0] = new LOD(0.6f, renderersMax);
                    lods[1] = new LOD(0.03f, renderersLow);
                    //lods[1] = new LOD(1f - LODCutoff, renderers);
                    group.SetLODs(lods);

                    GameObject lodObj = new GameObject();
                    lodObj.name = "LOD-" + filename;
                    lodgo.transform.SetParent(lodObj.transform);
                    lodObj.transform.SetParent(go.transform);
                }

                lock (originals)
                {
                    originals[filename] = go;
                }
            }
            else
            {
                go = getCachedObject(filename);
            }

            if (go != null)
            {
                if (Assets.GameWorld.useColliders)
                {
                    GameObject.Destroy(parent.GetComponent <BoxCollider>());
                    GameObject.Destroy(parent.GetComponent <SphereCollider>());
                }
                go.transform.SetParent(parent.transform);
                go.transform.localScale    = Vector3.one;
                go.transform.localPosition = Vector3.zero;
                go.transform.localRotation = Quaternion.identity;

                if (parent.gameObject.GetComponent <LODGroup>() != null)
                {
                    parent.gameObject.GetComponent <LODGroup>().RecalculateBounds();
                }
            }
        }
        catch (Exception ex)
        {
            Debug.LogWarning("Unable to load nif:" + niffile + " " + filename);
            Debug.Log(ex);
            if (null != go)
            {
                GameObject.Destroy(go);
            }
        }
        finally
        {
            if (cacheWait.ContainsKey(filename))
            {
                cacheWait[filename].Release();
            }
        }
    }