标签:执行 unity cti 委托 方法 bsp engines raw name
可以用委托来搞定
using System; using System.Collections.Generic; using System.Text; using UnityEngine; public delegate void u3d(string name); public class DM02Brridge:MonoBehaviour { private void Start() { u3d AA = new DirectX().Render ; Sphere l_Sphere = new Sphere(); l_Sphere.Draw(new DirectX().Render);这样的话只需要添加新执行方法的话,new一下即可 l_Sphere.Draw(new OpenGL().Render); Cube l_Cube = new Cube(); l_Cube.Draw(); } } public class Sphere //球体的类,有自己的属性 { public string name = "Sphere"; public OpenGL openGL = new OpenGL(); public void Draw(u3d AA) { AA(name); } } public class OpenGL//绘制的引擎 { public void Render(string name) { Debug.Log("OpenGL绘制了:" + name); } } public class Cube //球体的类,有自己的属性 { public string name = "Cube"; public OpenGL openGL = new OpenGL(); public void Draw() { openGL.Render(name); } } public class DirectX { public void Render(string name) { Debug.Log("DrectX绘制了:" + name); } }
也可以使用父类为接口继承的方法
using System; using System.Collections.Generic; using System.Text; using UnityEngine; public delegate void u3d(string name); public class DM02Brridge:MonoBehaviour { private void Start() { EngineSystem AA = new OpenGL(); Cube BB = new Cube(AA); BB.Draw(); AA = new DirectX(); Sphere SP = new Sphere(AA); SP.Draw(); } } public class IHshaPe { public string name; public EngineSystem Eng; public IHshaPe(EngineSystem l_eng) { Eng = l_eng; } public void Draw() { Eng.DrawEng(name); } } public abstract class EngineSystem { public abstract void DrawEng(string name); } public class Sphere : IHshaPe { public Sphere(EngineSystem l_eng) : base(l_eng) { base.name = "Sphere"; } } public class OpenGL:EngineSystem { public override void DrawEng(string name) { Debug.Log("OpenGL绘制了:" + name); } } public class Cube:IHshaPe //球体的类,有自己的属性 { public Cube(EngineSystem l_eng) : base(l_eng) { name = "Cube"; } } public class DirectX:EngineSystem { public override void DrawEng(string name) { Debug.Log("DrectX绘制了:" + name); } }
标签:执行 unity cti 委托 方法 bsp engines raw name
原文地址:http://www.cnblogs.com/signzun/p/7455511.html