Example #1
0
    public IEnumerator OnLoad()
    {
        string   assetRootPath = Core.IO.Path.Combine(Application.streamingAssetsPath, "iOS");
        string   objAssetPath  = System.IO.Path.Combine(assetRootPath, "apple.obj");
        ObjAsset objAsset      = new ObjAsset();

        yield return(objAsset.AsyncBuild(objAssetPath));

        while (null == objAsset.objList)
        {
            yield return(null);
        }
        List <GameObject>             meshObjectList = objAsset.objList;
        Dictionary <string, Material> mtlDictionary  = new Dictionary <string, Material>();

        if (false != objAsset.hasMaterial)
        {
            string   mtlAssetPath = System.IO.Path.Combine(assetRootPath, objAsset.mtlAssetName);
            MtlAsset mtlAsset     = new MtlAsset();
            yield return(mtlAsset.AsyncBuild(mtlAssetPath));

            mtlDictionary = mtlAsset.mtlList;
        }
        foreach (GameObject meshObject in meshObjectList)
        {
            meshObject.transform.parent     = this.gameObject.transform;
            meshObject.transform.position   = this.gameObject.transform.position;
            meshObject.transform.localScale = Vector3.one;
            Renderer[] renderers = meshObject.GetComponentsInChildren <Renderer>(true);
            if (0 == renderers.Length)
            {
                continue;
            }
            foreach (Renderer renderer in renderers)
            {
                string groupPath    = Path.Combine(meshObject.name, renderer.gameObject.name);
                string materialName = objAsset.GetMtlAssetName(groupPath);
                if (false == string.IsNullOrEmpty(materialName) && false != mtlDictionary.ContainsKey(materialName))
                {
                    renderer.material = mtlDictionary[materialName];
                }
                renderer.enabled = false;
            }
            yield return(null);
        }
        Rigidbody rigidBody = this.gameObject.AddComponent <Rigidbody>();

        rigidBody.useGravity = false;
        SphereCollider collider = this.gameObject.AddComponent <SphereCollider>();

        collider.radius  = 1f * 0.5f;
        collider.center += new Vector3(0f, 0.2f, 0f);
        Notifier notifier = Notifier.GetInstance();

        notifier.Notify(NotifyMessage.OnLoadingComplete);
        yield return(null);
    }
Example #2
0
    public IEnumerator OnLoad()
    {
        string assetRootPath     = string.Empty;
        string assetDestRootPath = string.Empty;
        string objAssetPath      = string.Empty;

        this.scaleRate = 1.0f;
        if (RuntimePlatform.Android == Application.platform)
        {
            string destPath = Core.IO.Path.Combine(Application.temporaryCachePath, "Android");
            Core.IO.Directory.Create(destPath);
            string[] files = new string[] { "android.obj", "android.mtl", "android.png" };
            foreach (string file in files)
            {
                string originPath = Core.IO.Path.Combine(Application.streamingAssetsPath, "Android", file);
                Core.IO.File.Copy(originPath, destPath);
            }
            assetRootPath  = Core.IO.Path.Combine(Application.temporaryCachePath, "Android");
            objAssetPath   = System.IO.Path.Combine(assetRootPath, "android.obj");
            this.scaleRate = IconBehaviour.SCALE_RATE_ANDROID;
        }
        else
        {
            assetRootPath  = Core.IO.Path.Combine(Application.streamingAssetsPath, "Android");
            objAssetPath   = System.IO.Path.Combine(assetRootPath, "android.obj");
            this.scaleRate = IconBehaviour.SCALE_RATE_ANDROID;
        }
        if (false != string.IsNullOrEmpty(assetRootPath) || false != string.IsNullOrEmpty(objAssetPath))
        {
            string message = string.Format("not found streaming assets::{0}/{1}", assetRootPath, objAssetPath);
            Debug.LogError(message);
        }
        else
        {
            ObjAsset objAsset = new ObjAsset();
            yield return(objAsset.AsyncBuild(objAssetPath));

            while (null == objAsset.objList)
            {
                yield return(null);
            }
            List <GameObject>             meshObjectList = objAsset.objList;
            Dictionary <string, Material> mtlDictionary  = new Dictionary <string, Material>();
            if (false != objAsset.hasMaterial)
            {
                string   mtlAssetPath = System.IO.Path.Combine(assetRootPath, objAsset.mtlAssetName);
                MtlAsset mtlAsset     = new MtlAsset();
                yield return(mtlAsset.AsyncBuild(mtlAssetPath));

                mtlDictionary = mtlAsset.mtlList;
            }
            foreach (GameObject meshObject in meshObjectList)
            {
                meshObject.transform.parent     = this.gameObject.transform;
                meshObject.transform.position   = this.gameObject.transform.position;
                meshObject.transform.localScale = Vector3.one * this.scaleRate;
                Renderer[] renderers = meshObject.GetComponentsInChildren <Renderer>(true);
                if (0 == renderers.Length)
                {
                    continue;
                }
                foreach (Renderer renderer in renderers)
                {
                    string groupPath    = Path.Combine(meshObject.name, renderer.gameObject.name);
                    string materialName = objAsset.GetMtlAssetName(groupPath);
                    if (false == string.IsNullOrEmpty(materialName) && false != mtlDictionary.ContainsKey(materialName))
                    {
                        renderer.material = mtlDictionary[materialName];
                    }
                    renderer.enabled = false;
                }
                yield return(null);
            }
            Rigidbody rigidBody = this.gameObject.AddComponent <Rigidbody>();
            rigidBody.useGravity = false;
            SphereCollider collider = this.gameObject.AddComponent <SphereCollider>();
            collider.radius  = 1f / this.scaleRate * 0.5f;
            collider.center += new Vector3(0f, 0.2f, 0f);
            Notifier notifier = Notifier.GetInstance();
            notifier.Notify(NotifyMessage.OnLoadingComplete);
        }
        yield return(null);
    }