2017-01-17 00:16:38 qq_26651375 阅读数 3443
  • Unity 值得看的500+ 技术内容列表

    Unity3D是由Unity Technologies开发的一个让玩家轻松创建诸如三维视频游戏、建筑可视化、实时三维动画等类型互动内容的多平台的综合型游戏开发工具,是一个全面整合的专业游戏引擎。

导入模型、贴图和材质

导入资源包文件

1.新建Unity3d项目SpaceShoot。

2.从Asset Store下载SpaceShoot资源包。https://www.assetstore.unity3d.com/cn/#!/content/13866


3.在浏览器中点击【在Unity中打开】按钮,会跳转到Unity3d软件界面。


4.点击下载,同意协议,当下载完毕后,弹出导入资源包界面。选择【Import】。


5.导入完成,在Project栏出现多个目录,_Completed-Assets目录下为已经完成的Demo,其他文件夹为资源文件夹,双击Scenes文件夹下的Done_Main场景,即可打开该场景,点击运行,游戏Demo运行。


6.依次点击File->New Scene,创建一个新场景,然后再次点击File->Save Scene或者【Ctrl+S】保存场景。在弹出的对话窗中新建文件夹“_Scene_Self”,打开文件夹,文件名Main,单击【保存】按钮。


7.此时可看到Project视图中文件夹”_Scene_Self”和空场景文件“Main”。


9.依次单击菜单项File->Build Setting->PlayerSetting。取消Default Is Full Screen的勾选,然后依次设置Width为400,Height为600。


10.这时在Game窗口中,可以看到Standalone模式下运行窗口的尺寸为400 x 600。


创建飞船对象

1.从Project视图下Asset/Models拖动模型文件vehicle_playerShip到Hierarchy视图,重命名为Player,按图重置Transform组件。

2.添加Rigidbody(刚体)组件:在Hierarchy视图中选择Player,在右侧的Inspector视图中点击Add Component->Physics->Rigidbody。刚体的作用是提供作用力,受到力的作用。另外取消Use Gravity的勾选,否则开始游戏,飞船将受到重力的作用而下坠。


3.添加Mesh Collider组件:选择Player,在Inspector视图中点击Add Component->Physics->Mesh Collider(碰撞体)。作用是让飞船可以玉其他物体产生碰撞,并触发碰撞后的事件(比如销毁等)。还需勾选Convex和Is Trigger,从而将Mesh Collider设置为触发器。

4.添加飞船尾部的粒子效果:在Project/Prefads/VFX/Engine下的预制体engine_player拖动到Hierarchy视图下的Player上,使其成为Player的子对象,并重置Transform组件,其Position的Z为-0.8。


设置摄像机参数

1.在Hierarchy视图中选中Main Camera,将其Transform组件的Rotation设置为(90,0,0),使摄像机处于俯视视角。调整Position(0,10,5),此时飞船处于Game窗口下方。

2.设置投影方式(Projection)为正交投影(Orthographic),并设置size为10,Clear Flags改为SolidColor,Background设为黑色,此时飞船处于合适的位置。



添加背景图片

1.单击GameObject->3DObject->Quad,创建一个平面,重命名Background,重置Transform,移出Mesh Collider,背景不需要碰撞体。此时平面垂直飞船,看不到,须设置其Transform组件的Rotation为(90,0,0),绕X轴逆时针旋转90度。

2.为Background添加纹理图片。将Assets/Textures目录下的tile_nebla_green_dff拖动到Background上。注意图片宽高比是1:2,放大平面时须遵守该比例,不然会失真。

3.选中Background,将Shader改为Unlit/Texture。

4.改变Background大小,Transform组件的Scale为(15,30,0)时,基本充满窗口。此时,飞船与Background重叠,将Background的Transform组件的Position的Y设为-10,使飞船处于Background上方。

添加粒子效果

从Project视图中Assets/VFX/Starfield目录下,拖动预制体Starfield到Hierarchy视图中,Transform组件默认不便,运行游戏,繁星点点。

2018-12-05 17:21:00 qq_32416529 阅读数 825
  • Unity 值得看的500+ 技术内容列表

    Unity3D是由Unity Technologies开发的一个让玩家轻松创建诸如三维视频游戏、建筑可视化、实时三维动画等类型互动内容的多平台的综合型游戏开发工具,是一个全面整合的专业游戏引擎。

解决Unity3D发布后软件界面右下角出现Trial Version

1.选择Help->Manage License
在这里插入图片描述

2.点击Manual Activation在这里插入图片描述

3.选择Save License Request
在这里插入图片描述

4.将.alf文件保存到本地

5.在浏览器打开 https://license.unity3d.com/manual

6.将.alf文件上传,生成一个新的许可证,并下载.ulf文件

7.在步骤三的界面点击Load License,再将下载的.ulf文件导入

8.重新启动Unity,再重新打包,水印已经不存在了。

2015-05-10 22:31:08 wangyao1052 阅读数 7802
  • Unity 值得看的500+ 技术内容列表

    Unity3D是由Unity Technologies开发的一个让玩家轻松创建诸如三维视频游戏、建筑可视化、实时三维动画等类型互动内容的多平台的综合型游戏开发工具,是一个全面整合的专业游戏引擎。

要想启用,需要手动在Chrome浏览器中输入以下命令开启
chrome://flags/#enable-npapi

援引Chrome官方博客的一片文章来解释下Chrome与unity3d webplayer插件默认不兼容的原因:

The Final Countdown for NPAPI

Posted: Monday, November 24, 2014

Last September we announced our plan to remove NPAPI support from Chrome, a change that will improve Chrome’s security, speed, and stability as well as reduce complexity in the code base. Since our last update, NPAPI usage has continued its decline. Given this usage data, we will continue with our deprecation plan.

Monthly Plug-in Launch Percentage
这里写图片描述

Currently Chrome supports NPAPI plugins, but they are blocked by default unless the user chooses to allow them for specific sites (via the page action UI). A small number of the most popular plugins are whitelisted and allowed by default. In January 2015 we will remove the whitelist, meaning all plugins will be blocked by default.

In April 2015 NPAPI support will be disabled by default in Chrome and we will unpublish extensions requiring NPAPI plugins from the Chrome Web Store. Although plugin vendors are working hard to move to alternate technologies, a small number of users still rely on plugins that haven’t completed the transition yet. We will provide an override for advanced users (via chrome://flags/#enable-npapi) and enterprises (via Enterprise Policy) to temporarily re-enable NPAPI while they wait for mission-critical plugins to make the transition.

In September 2015 we will remove the override and NPAPI support will be permanently removed from Chrome. Installed extensions that require NPAPI plugins will no longer be able to load those plugins.

For more details on the timeline, including guidance for NPAPI plugin developers, see the NPAPI deprecation guide. With each step in this transition, we get closer to a safer, more mobile-friendly web.

2018-10-06 19:41:59 luoyikun 阅读数 1660
  • Unity 值得看的500+ 技术内容列表

    Unity3D是由Unity Technologies开发的一个让玩家轻松创建诸如三维视频游戏、建筑可视化、实时三维动画等类型互动内容的多平台的综合型游戏开发工具,是一个全面整合的专业游戏引擎。

java代码

package com.luo.yikun.getfilepath;


import android.app.Activity;
import android.app.Fragment;
import android.content.ContentUris;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;

import android.provider.DocumentsContract;
import android.provider.MediaStore;


import com.unity3d.player.UnityPlayer;


import java.io.File;




public class GetFilePath extends Fragment {
    String m_gameObjectName;
    String m_funcName;

    private Context unityContext;
    private Activity unityActivity;

    private static final String TAG = "GetFilePath";

    public void UnityFunc(String gameObjectName, String funcName)
    {
        m_gameObjectName = gameObjectName;
        m_funcName = funcName;
    }

    private static GetFilePath Instance = null;
    //private String gameObjectName;

    public static GetFilePath GetInstance()
    {
        if(Instance == null)
        {
            Instance = new GetFilePath();
            //Instance.gameObjectName = gameObject;
            Instance.unityActivity = UnityPlayer.currentActivity;
            if (Instance.unityActivity == null)
            {
                Instance.CallUnity("Instance.unityActivity == null");
            }
            Instance.unityContext = Instance.unityActivity.getBaseContext();
            if (Instance.unityContext == null)
            {
                Instance.CallUnity("Instance.unityContext == null");
            }
            UnityPlayer.currentActivity.getFragmentManager().beginTransaction().add(Instance, TAG).commit();

        }
        return Instance;
    }

    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setRetainInstance(true);  // 这一句很重要,保存对该Fragment的引用,防止在旋转屏幕等操作时时丢失引用(Fragment隶属于Activity)
    }

    // 调用 Unity
    // gameObjectName 为接受消息的Unity 中 GameObject 的名字
    // functionName   为接受消息的GameObject 挂载 C# 脚本中的函数名
    // _content       为发送给Unity 的内容
    public void CallUnity( String _content)
    {
        UnityPlayer.UnitySendMessage(m_gameObjectName, m_funcName, _content);
    }

    public void fileBrower()
    {
        Intent myintent = new Intent(Intent.ACTION_GET_CONTENT);
        myintent.setType("*/*");
        myintent.addCategory(Intent.CATEGORY_OPENABLE);
        startActivityForResult(Intent.createChooser(myintent, "选择文件"), 1);
    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        // TODO Auto-generated method stub
        if (resultCode != Activity.RESULT_OK) {
            super.onActivityResult(requestCode, resultCode, data);
            return;
        }
        if (requestCode == 1) {
            Uri uri = data.getData();
            String path = getPath(unityContext, uri);
            if (path != null) {
                File file = new File(path);
                if (file.exists()) {
                    String upLoadFilePath = file.toString();
                    String upLoadFileName = file.getName();
                    CallUnity(upLoadFilePath);
                }
            }

        }
        super.onActivityResult(requestCode, resultCode, data);
    }

    public String getPath(final Context context, final Uri uri) {

        final boolean isKitKat = Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT;

        // DocumentProvider
        if (isKitKat && DocumentsContract.isDocumentUri(context, uri)) {
            // ExternalStorageProvider
            if (isExternalStorageDocument(uri)) {
                final String docId = DocumentsContract.getDocumentId(uri);
//                Log.i(TAG,"isExternalStorageDocument***"+uri.toString());
//                Log.i(TAG,"docId***"+docId);
//                以下是打印示例:
//                isExternalStorageDocument***content://com.android.externalstorage.documents/document/primary%3ATset%2FROC2018421103253.wav
//                docId***primary:Test/ROC2018421103253.wav
                final String[] split = docId.split(":");
                final String type = split[0];

                if ("primary".equalsIgnoreCase(type)) {
                    return Environment.getExternalStorageDirectory() + "/" + split[1];
                }
            }
            // DownloadsProvider
            else if (isDownloadsDocument(uri)) {
//                Log.i(TAG,"isDownloadsDocument***"+uri.toString());
                final String id = DocumentsContract.getDocumentId(uri);
                final Uri contentUri = ContentUris.withAppendedId(
                        Uri.parse("content://downloads/public_downloads"), Long.valueOf(id));

                return getDataColumn(context, contentUri, null, null);
            }
            // MediaProvider
            else if (isMediaDocument(uri)) {
//                Log.i(TAG,"isMediaDocument***"+uri.toString());
                final String docId = DocumentsContract.getDocumentId(uri);
                final String[] split = docId.split(":");
                final String type = split[0];

                Uri contentUri = null;
                if ("image".equals(type)) {
                    contentUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
                } else if ("video".equals(type)) {
                    contentUri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI;
                } else if ("audio".equals(type)) {
                    contentUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
                }

                final String selection = "_id=?";
                final String[] selectionArgs = new String[]{split[1]};

                return getDataColumn(context, contentUri, selection, selectionArgs);
            }
        }
        // MediaStore (and general)
        else if ("content".equalsIgnoreCase(uri.getScheme())) {
//            Log.i(TAG,"content***"+uri.toString());
            return getDataColumn(context, uri, null, null);
        }
        // File
        else if ("file".equalsIgnoreCase(uri.getScheme())) {
//            Log.i(TAG,"file***"+uri.toString());
            return uri.getPath();
        }
        return null;
    }

    /**
     * Get the value of the data column for this Uri. This is useful for
     * MediaStore Uris, and other file-based ContentProviders.
     *
     * @param context       The context.
     * @param uri           The Uri to query.
     * @param selection     (Optional) Filter used in the query.
     * @param selectionArgs (Optional) Selection arguments used in the query.
     * @return The value of the _data column, which is typically a file path.
     */
    public String getDataColumn(Context context, Uri uri, String selection,
                                String[] selectionArgs) {

        Cursor cursor = null;
        final String column = "_data";
        final String[] projection = {column};

        try {
            cursor = context.getContentResolver().query(uri, projection, selection, selectionArgs,
                    null);
            if (cursor != null && cursor.moveToFirst()) {
                final int column_index = cursor.getColumnIndexOrThrow(column);
                return cursor.getString(column_index);
            }
        } finally {
            if (cursor != null)
                cursor.close();
        }
        return null;
    }


    public boolean isExternalStorageDocument(Uri uri) {
        return "com.android.externalstorage.documents".equals(uri.getAuthority());
    }

    public boolean isDownloadsDocument(Uri uri) {
        return "com.android.providers.downloads.documents".equals(uri.getAuthority());
    }

    public boolean isMediaDocument(Uri uri) {
        return "com.android.providers.media.documents".equals(uri.getAuthority());
    }
}

AndroidMainfest文件增加权限

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.luo.yikun.getfilepath">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
</manifest>

demo下载
https://pan.baidu.com/s/16KOk1Nt7Eri4JPsXsHwm7A
demo是早期的,可能跟上面的不同,但是测试过unity打包出apk能浏览到文件的真实路径

Unity3d内置浏览器

阅读数 60

没有更多推荐了,返回首页