游戏内容要求:
按 adapter模式 设计图修改飞碟游戏
使它同时支持物理运动与运动学(变换)运动
跟之前的简单打飞碟相比,这次的多了个Adapter类和plane,plane是用来体现飞碟的物理运动的。
public interface SceneController
{
void load();
void game(int Round);
int Choose(float[] probe);
}
using UnityEngine;
using System.Collections;
public class move1 : MonoBehaviour {
public float speedX = 5.0F;
public float speedY = 5.0F;
public float speedZ = 5.0F;
// Use this for initialization
float rand1 = Random.Range(-1.0f, 1.0f);
float rand2 = Random.Range(-1.0f, 1.0f);
float rand3 = Random.Range(-1.0f, 1.0f);
float randx;
float randy;
void Start () {
randx = Random.Range(-1.0f, 1.0f);
randy = Random.Range(-1.0f, 1.0f);
//Debug.Log(randx);
//Debug.Log(randy);
if (randx>0)
randx = 1.0f;
else
randx = -1.0f;
if (randy >0)
randy = 1.0f;
else
randy = -1.0f;
}
// Update is called once per frame
void Update () {
float translationY = 1 * speedY*rand1*randx;
float translationX = 1 * speedX*rand2*randy;
float translationZ = 1 * speedZ;
translationY *= Time.deltaTime;
translationX *= Time.deltaTime;
//transform.Translate(0, translationY, 0);
//transform.Translate(translationX, 0, 0);
transform.Translate(translationX, translationY, translationZ);
}
}
using UnityEngine;
using Adapter;
namespace SimpleFactory
{
#region 产品
public interface UFO
{
GameObject Version(int round);
}
public class UFO1 : UFO
{
float x = Random.Range(0.0f, 5.0f);
public virtual GameObject Version(int round)
{
GameObject UFO1;
Vector3 UFO1Pos = new Vector3(x, 0, 0);
UFO1 = Object.Instantiate(Resources.Load("UFO1", typeof(GameObject)), UFO1Pos, Quaternion.identity) as GameObject;
UFO1.name = "UFO1";
UFO1.AddComponent<PickupObject>();
//UFO1.AddComponent<Rigidbody>();
move1 test = UFO1.AddComponent<move1>();
test.speedX *= (float)round;
test.speedY *= (float)round;
test.speedZ = 0.0f ;
return UFO1;
}
}
public class UFO2 : UFO
{
float x = Random.Range(0.0f, 5.0f);
public virtual GameObject Version(int round)
{
GameObject UFO1;
Vector3 UFO1Pos = new Vector3(x, 0, 0);
UFO1 = Object.Instantiate(Resources.Load("UFO2", typeof(GameObject)), UFO1Pos, Quaternion.identity) as GameObject;
UFO1.name = "UFO2";
UFO1.AddComponent<PickupObject>();
//UFO1.AddComponent<Rigidbody>();
move1 test = UFO1.AddComponent<move1>();
test.speedX *= (float)round;
test.speedY *= (float)round;
test.speedZ = 0.0f;
return UFO1;
}
public virtual void Add_Component_Rigidbody(GameObject ufo)
{
ufo.AddComponent<Rigidbody>();
}
}
public class UFO3 : UFO
{
float x = Random.Range(0.0f, 5.0f);
public virtual GameObject Version(int round)
{
GameObject UFO1;
Vector3 UFO1Pos = new Vector3(x, 0, 0);
UFO1 = Object.Instantiate(Resources.Load("UFO3", typeof(GameObject)), UFO1Pos, Quaternion.identity) as GameObject;
UFO1.name = "UFO3";
UFO1.AddComponent<PickupObject>();
//UFO1.AddComponent<Rigidbody>();
move1 test = UFO1.AddComponent<move1>();
test.speedX *= (float)round;
test.speedY *= (float)round;
test.speedZ = 0.0f;
return UFO1;
}
}
public class UFO4 : UFO
{
float x = Random.Range(0.0f, 5.0f);
public virtual GameObject Version(int round)
{
GameObject UFO1;
Vector3 UFO1Pos = new Vector3(x, 0, 0);
UFO1 = Object.Instantiate(Resources.Load("UFO4", typeof(GameObject)), UFO1Pos, Quaternion.identity) as GameObject;
UFO1.name = "UFO4";
UFO1.AddComponent<PickupObject>();
//UFO1.AddComponent<Rigidbody>();
move1 test = UFO1.AddComponent<move1>();
test.speedX *= (float)round;
test.speedY *= (float)round;
test.speedZ = 0.0f;
return UFO1;
}
}
public class UFO5 : UFO
{
float x = Random.Range(0.0f, 5.0f);
public virtual GameObject Version(int round)
{
GameObject UFO1;
Vector3 UFO1Pos = new Vector3(x, 0, 0);
UFO1 = Object.Instantiate(Resources.Load("UFO5", typeof(GameObject)), UFO1Pos, Quaternion.identity) as GameObject;
UFO1.name = "UFO5";
UFO1.AddComponent<PickupObject>();
//UFO1.AddComponent<Rigidbody>();
move1 test = UFO1.AddComponent<move1>();
test.speedX *= (float)round;
test.speedY *= (float)round;
test.speedZ = 0.0f;
return UFO1;
}
}
#endregion
#region 工厂
public interface IFactory
{
UFO Create();
}
public class UFO1Factory : IFactory
{
public virtual UFO Create()
{
return new UFO1();
}
}
public class UFO2Factory : IFactory
{
public virtual UFO Create()
{
return new UFO2();
}
}
public class UFO3Factory : IFactory
{
public virtual UFO Create()
{
return new UFO3();
}
}
public class UFO4Factory : IFactory
{
public virtual UFO Create()
{
return new UFO4();
}
}
public class UFO5Factory : IFactory
{
public virtual UFO Create()
{
return new UFO5();
}
}
#endregion
}
}
using UnityEngine;
using System.Collections;
public class Singleton<T> : MonoBehaviour where T : MonoBehaviour
{
protected static T instance;
public static T Instance
{
get
{
if (instance == null)
{
instance = (T)FindObjectOfType(typeof(T));
if (instance == null)
{
Debug.LogError("An instance of " + typeof(T) +
" is needed in the scene, but there is none.");
}
}
return instance;
}
}
}
场景单实例的使用很简单,你仅需要将 MonoBehaviour 子类对象挂载任何一个游戏对象上即可。
然后在任意位置使用代码 Singleton <>.Instance 获得该对象。
public class PickupMultiObjects : MonoBehaviour {
public GameObject cam;
// Update is called once per frame
void Update () {
if (Input.GetButtonDown("Fire1")) {
Debug.Log ("Fired Pressed");
Debug.Log (Input.mousePosition);
Vector3 mp = Input.mousePosition; //get Screen Position
//create ray, origin is camera, and direction to mousepoint
Camera ca;
if (cam != null ) ca = cam.GetComponent<Camera> ();
else ca = Camera.main;
Ray ray = ca.ScreenPointToRay(Input.mousePosition);
//Return the ray's hits
RaycastHit[] hits = Physics.RaycastAll (ray);
foreach (RaycastHit hit in hits) {
print (hit.transform.gameObject.name);
if (hit.collider.gameObject.tag.Contains("Finish")) {
//plane tag
Debug.Log ("hit " + hit.collider.gameObject.name +"!" );
}
Destroy (hit.transform.gameObject);
}
}
}
}
Adater类():
using UnityEngine;
using System.Collections;
using SimpleFactory;
namespace Adapter
{
public class adapter
{
public void Add_Component_Rigidbody(SimpleFactory.UFO ufo,int i)
{
ufo.Version(i).AddComponent<Rigidbody>();
}
}
}
成品图:
文章浏览阅读2.1k次。基于百度智能云平台的情感倾向计算_百度智能云算法原理在哪找
文章浏览阅读273次。LoRa无线模块作为近年来最火热的低功耗远距离的无线模块,在市场上是非常受欢迎的。合理规范安装使用是LoRa无线模块可以长期稳定工作的重要因素之一,同时也可以避免产生损坏,减少维护和项目运维成本。那么LoRa模块在使用安装过程中,要注意什么,下面就来简单介绍一下。_lora模块没有天线头能用吗
文章浏览阅读4.8k次,点赞2次,收藏6次。很有用但是不不知道怎么说,写个例子,总之方便多了,并且容易管理,重复利用强1、自定一个类,实现 javax.servlet.jsp.tagext.Tag;(PageTag.java)2、建立一个tld文件(myfTag.tld)3、建立一个freemaker文件*.ftl(page.ftl)4、建立jsp页面,导入标签(%@taglib prefix="myf" uri="/m_public class goodsgallytag extends basefreemarkertag这是什么写法
文章浏览阅读6次。所需工具 : cmake for windows 和 git for windows原理:protobuf 是google的一个开源项目,其源代码在github上可以下载到,并且源码都采用cmake来构建,所以我们可以把源码下载到本地,然后了利用cmake构建本地工程,然后编译.步骤一:下载源码 复制以下代码,保存到download_protobuf_source.bat 文件中...
文章浏览阅读1.6k次,点赞2次,收藏13次。系列文章目录(一)ILRuntime基础使用(二)Addressable基础使用目录系列文章目录简介流程DLL 转换代码DLL 加载代码简介把热更项目的 DLL 作为 addressable 的资源来实现热更新流程资源部分(1)addressable 是不支持 dll 的,所以需要把 dll 文件加工成 addressable 支持的格式(2)直接 File.ReadAllBytes 读取成 bytes 然后 File.WriteAllBytes 保存(3)保存文件的后缀为 .b_unity dll 和 addresable 一起使用
文章浏览阅读154次。g2o optimizeAre you looking to add Google Optimize on your WordPress site? 您是否要在WordPress网站上添加Google Optimize? Google Optimize is a free tool by Google that helps website owners optimize their site..._google optimize
文章浏览阅读3.3k次,点赞2次,收藏3次。在浏览器地址栏输入javascript:alert (document. cookie)会话(Session) 跟踪是Web程序中常用的技术,用来跟踪用户的整个会话。常用的会话跟踪技术是Cookie与Session。Cookie通过在客户端记录信息确定用户 身份,Session通过在服务器端记录信息确定用户身份。本章将系统地讲述Cookie与Session机制,并比较说明什么时候不能用Cook_session和cookie原理
文章浏览阅读2.0k次。前言需要一个可以编辑代码展示的富文本编辑器,对比其他的富文本编辑器,最后选择了wangEditor。原因:小巧且能满足我的需求1.创建编辑器<div class="layui-form-item layui-form-text"> <label class="layui-form-label">文章内容<em>*</em></label> <div class="layui-input-block"&_wangeditor 怎么定义代码类型
文章浏览阅读3.1k次。Linux备份系统镜像并对镜像中LVM分区文件的修改_dd 备份lvm
文章浏览阅读201次。 tcpdump是一个网络抓包工具,用于捕获和分析网络数据包。它可以在 Unix/Linux 系统上通过命令行进行使用。tcpdump能够截获网络传输过程中的数据包,并将这些数据包的内容以及相关的信息显示出来,方便网络管理员和分析师进行网络故障排查、网络性能分析、网络安全监控等任务。_tcpdump使用方法
文章浏览阅读2.3k次。说明:本文中使用的例子均在下面的数据库表tt2下执行:一、concat()函数1、功能:将多个字符串连接成一个字符串。2、语法:concat(str1, str2,...)返回结果为连接参数产生的字符串,如果有任何一个参数为null,则返回值为null。3、举例:例1:select concat (id, name, score) as info from tt2;中间有一行为null是因为tt2..._mysql concat将查询到的list拼接
文章浏览阅读1.1w次,点赞2次,收藏20次。1.修改router中index.js文件中每个路由加上meta:{ title: ‘首页’}const router = new Router({ mode: '', routes: [ { path: '/', name: '', component: , meta:{ // title: '首页'