using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using Carrie.Net;
using CommonUI.Editor.UI;
using CommonUI_Unity3D.Impl;
using JsonFx.Json;
using System; public class Character3DController : MonoBehaviour, IScene
{
public class CharactorCell
{
public byte prof;
public uint ID;
public GameObject GO;
} public AssemblerInfo m_Data_AvatarInfo_SS = new AssemblerInfo(, NetConstant.CHARACTER_NAME_ARCANEARCHER, NetConstant.CHARACTER_NAME_ARCANEARCHER + "_head_0000", NetConstant.CHARACTER_NAME_ARCANEARCHER + "_body_0000", "", "", "weapon2001", "", "wing_0001");
public AssemblerInfo m_Data_AvatarInfo_ZS = new AssemblerInfo(, NetConstant.CHARACTER_NAME_UNKNOW, NetConstant.CHARACTER_NAME_UNKNOW + "_head_0000", NetConstant.CHARACTER_NAME_UNKNOW + "_body_0000", "", "weapon0001", "", "", "wing_0001"); private static Dictionary<byte, CharactorCell> mCharactorCellList = new Dictionary<byte, CharactorCell>();
private static Dictionary<OpenType, DeployData> mDeployData = new Dictionary<OpenType, DeployData>(); UECanvas mUECanvas;
Texture2D mTex = null;
RenderTexture targetTexture;
UnityImage image; private static Character3DController m_Instance = null; void Awake()
{
int w = Screen.width;
Load(w.ToString());
m_Instance = this;
SceneManager.Instance.AddListener(this);
} void OnApplicationQuit()
{
Assembler.GetInstance().OnFinishLoading -= HandleModelProf; m_Instance = null;
} IEnumerator Start()
{
Assembler.GetInstance().OnFinishLoading += HandleModelProf; LoadProfModel(NetConstant.CHARACTER_TYPE_WARRIOR);
LoadProfModel(NetConstant.CHARACTER_TYPE_THIEF);
LoadProfModel(NetConstant.CHARACTER_TYPE_ARCANEARCHER); yield return ; } public void HandleOnEnterScene(SceneManager sender)
{ } public void HandleOnLeaveScene(SceneManager sender)
{
if (mCharactorCellList != null)
{
foreach (CharactorCell cell in mCharactorCellList.Values)
{
if (cell.GO != null)
{
cell.GO.SetActive(false);
UnityEngine.Object.Destroy(cell.GO);
}
}
mCharactorCellList.Clear();
}
Assembler.GetInstance().OnFinishLoading -= HandleModelProf;
} /// <summary>
/// Load Cell For Prof
/// </summary>
/// <param name="prof"></param>
void LoadProfModel(byte prof)
{
if (!mCharactorCellList.ContainsKey(prof))
{
CharactorCell cell = new CharactorCell();
cell.prof = prof;
{
AssemblerInfo info = null;
switch (prof)
{
case NetConstant.CHARACTER_TYPE_WARRIOR:
info = m_Instance.m_Data_AvatarInfo_ZS;
break;
case NetConstant.CHARACTER_TYPE_THIEF:
break;
case NetConstant.CHARACTER_TYPE_ARCANEARCHER:
info = m_Instance.m_Data_AvatarInfo_SS;
break;
case NetConstant.CHARACTER_TYPE_UNKNOW:
info = null;
break;
default:
Debug.LogError("prof error");
break;
}
cell.ID = Assembler.GetInstance().Create(info);
}
{
// default is null,
cell.GO = null; } mCharactorCellList.Add(prof, cell);
}
else
{
Debug.LogWarning("Repeat Add");
}
} /// <summary>
/// show model for prof
/// </summary>
/// <param name="prof"></param>
void ShowProModel(bool open, byte prof, DeployData deployData)
{
if (open)
{
m_Camera.SetActive(true);
m_Model.SetActive(true);
m_Camera.GetComponent<Camera>().orthographicSize = deployData.size;
}
else
{
m_Camera.SetActive(false);
m_Model.SetActive(false);
} foreach (CharactorCell cell in mCharactorCellList.Values)
{
if (cell.GO != null)
{
if (prof == cell.prof)
{
cell.GO.SetActive(true);
cell.GO.transform.localPosition = new Vector3(deployData.x,deployData.y,);
Play(cell.GO);
}
else
cell.GO.SetActive(false);
}
} m_Camera.camera.Render();
} /// <summary>
/// Udpate GameObject of Cell
/// </summary>
/// <param name="open"></param>
/// <param name="prof"></param>
/// <param name="info"></param>
/// <param name="canvas"></param>
static public void Update3D(bool open, byte prof,OpenType type,AssemblerInfo info = null)
{
if (info != null)
{
string data = JsonWriter.Serialize(info);
Debug.Log(open + " " + NetConstant.GetResNameByProf(prof) + " " + data);
}
DeployData deployData = mDeployData[type];
m_Instance.ShowProModel(open, prof,deployData); ///
/// if null, info is deafult
///
if (info == null)
{
switch (prof)
{
case NetConstant.CHARACTER_TYPE_WARRIOR:
info = m_Instance.m_Data_AvatarInfo_ZS;
break;
case NetConstant.CHARACTER_TYPE_THIEF:
break;
case NetConstant.CHARACTER_TYPE_ARCANEARCHER:
info = m_Instance.m_Data_AvatarInfo_SS;
break;
case NetConstant.CHARACTER_TYPE_UNKNOW:
info = null;
break;
default:
Debug.LogError("prof error");
break;
}
} if (!open) return; CharactorCell cell = (CharactorCell)mCharactorCellList[prof]; //
// Control
//
// if (canvas != m_Instance.mUECanvas)
// {
// m_Instance.mUECanvas = canvas;
//
// int width = (int)canvas.Width;
// int height = (int)canvas.Height;
// m_Instance.mTex = new Texture2D(width, height);
// m_Instance.targetTexture = new RenderTexture(width, height, 24);
// m_Instance.m_Camera.camera.targetTexture = m_Instance.targetTexture;
//
// m_Instance.image = new UnityImage(m_Instance.mTex, width, height);
// m_Instance.mUECanvas.SetImage(m_Instance.image);
// } Assembler.GetInstance().Update(cell.ID, info);
} public GameObject m_Model;
public GameObject m_Camera; void HandleModelProf(uint id)
{
if (m_Instance == null)
return; foreach (CharactorCell cell in mCharactorCellList.Values)
{
if (id == cell.ID)
{
// first create
if (cell.GO == null)
{
cell.GO = Assembler.GetInstance().GetObject(cell.ID);
cell.GO.SetActive(true);
cell.GO.transform.parent = m_Model.transform;
cell.GO.transform.localPosition = Vector3.zero;
cell.GO.transform.localEulerAngles = Vector3.zero; foreach (Transform t in cell.GO.GetComponentsInChildren<Transform>())
if (t.gameObject != null)
t.gameObject.layer = m_Model.layer;
}
// Play(cell.GO);
}
} if (m_Camera!= null && m_Camera.camera != null && m_Camera.camera.enabled)
m_Camera.camera.Render(); } public delegate void PostRenderDelegate();
public PostRenderDelegate PostRender; /// <summary>
/// update render texutre
/// </summary>
public void OnPostRender()
{
if (mUECanvas == null)
return;
// m_Camera.GetComponent<Camera>().orthographicSize = cameraSize;
// mTex.ReadPixels(new Rect(0, 0, targetTexture.width, targetTexture.height), 0, 0);
// mTex.Apply();
} #region 播放动画
private void Play(GameObject obj)
{
Animation anim = obj.GetComponent<Animation>();
if (anim != null)
{
AnimationState animState = anim[Bundle_Animation.n_idle];
if (animState != null)
animState.wrapMode = WrapMode.Loop; anim.Play(Bundle_Animation.n_idle); PlayAnimation(obj);
}
} void PlayAnimation(GameObject o)
{
Transform[] hips = o.GetComponentsInChildren<Transform>(); foreach (Transform hip in hips)
{
if (hip.name.Equals("wing"))
{
GameObject wing = hip.gameObject;
wing.animation.wrapMode = WrapMode.Loop;
wing.animation.Play("n_run"); break;
}
}
}
#endregion public void HandlePrepareEnterScene(SceneManager sender, PrepareDone done)
{
done(this);
} public void HandlePrepareLeaveScene(SceneManager sender, PrepareDone done)
{
done(this);
} IniParser parser = null;
float cameraSize = 1.0f;
public void Load(string width)
{
int wight = Screen.width;
TextAsset ta = (TextAsset)Resources.Load("Data/test", typeof(TextAsset));
parser = new IniParser(ta);
LoadInfo(OpenType.CHARATOR_VIEW, width);
LoadInfo(OpenType.CHARATOR_PACK, width); }
private void LoadInfo(OpenType type,string width)
{
String str = parser.GetSetting(type.ToString(), width);
string[] strArray = str.Split(new char[] { ',' });
DeployData data = new DeployData();
data.x = float.Parse(strArray[]);
data.y = float.Parse(strArray[]);
data.size = float.Parse(strArray[]);
mDeployData.Add(type, data);
} //3D人物使用配置数据
private void SetCameraSize(float value)
{
m_Camera.GetComponent<Camera>().orthographicSize = value;
} private void SetCharactorPos(float x,float y)
{ }
private void SetMaterial()
{
//renderer.material.mainTexture
} public class DeployData
{
public float x;
public float y;
public float size;
} public enum OpenType
{
CHARATOR_VIEW,
CHARATOR_PACK,
} }

3D角色渲染到2D界面上的更多相关文章

  1. CSharpGL(8)使用3D纹理渲染体数据 (Volume Rendering) 初探

    CSharpGL(8)使用3D纹理渲染体数据 (Volume Rendering) 初探 2016-08-13 由于CSharpGL一直在更新,现在这个教程已经不适用最新的代码了.CSharpGL源码 ...

  2. 关于Unity中NGUI的3D角色血条的实现

    首先要到Unity的Assets Store里面去下载一个扩展的Package叫NGUI HUD Text v1.13(81),注意如果没有安装NGUI就必须先安装NGUI插件,否则会用不了,因为HU ...

  3. 新书《Cocos2dx 3.x 3D图形学渲染技术讲解》问世

    笔者介绍:姜雪伟,IT公司技术合伙人,IT高级讲师,CSDN社区专家,特邀编辑,畅销书作者,已出版书籍:<手把手教你架构3D游戏引擎>电子工业出版社和<Unity3D实战核心技术详解 ...

  4. [Selenium]等待元素出现之后再消失,界面上的loading icon都属于这种类型,之前的方法总是卡死,换这种方法目前还好用的

    等待元素出现之后再消失,界面上的loading icon都属于这种类型,之前的方法总是卡死,换这种方法目前还好用的 /** * Check if the element present with cu ...

  5. Unity代码里的Position和界面上的Position

    代码里的Position = 世界坐标 this.gameObject.transform.position 界面上的Position = localPosition

  6. 使用 jquery 的 上传文件插件 uploadify 3.1 配合 java 来做一个简单的文件上次功能。并且在界面上有radio 的选择内容也要上传

    使用 jquery 的 上传文件插件 uploadify 3.1 配合 java 来做一个简单的文件上次功能.并且在界面上有radio 的选择内容也要上传 uploadify 插件的 下载和文档地址  ...

  7. 无界面上(linux)生成测试报告(3)

    无界面上(linux)生成测试报告 1.待jmx文件运行完成后,键入命令进入到jtl文件下: #cd testresult#bin目录下使用此命令,进入到jtl文件下 #jmeter -g pushG ...

  8. 无界面上(linux)运行jmeter(2)

    无界面上(linux)运行jmeter 1.先在bin目录下面创建一个文件夹testplan用来存放脚本(.jmx文件),然后在创建一个文件夹testresult用来存放脚本执行后的结果(.jtl文件 ...

  9. CSS 3 学习——transform 3D转换渲染

    以下内容根据官方规范翻译,没有翻译关于SVG变换的内容和关于矩阵计算的内容. 一般情况下,元素在一个无景深无立体感的平面(flat plane)上渲染,这个平面就是其包含块所处的平面.同时,页面上的其 ...

随机推荐

  1. 【转】DirectUI 资源提取器

    转自 http://www.cnblogs.com/Alberl/p/3378413.html   二.DirectUI 资源提取器     由于不能用传统工具,那么怎么办呢?可能有很多网友都知道QQ ...

  2. js函数的伪重载

    这也是今天写东西是遇到的一个问题,导致我联想起了函数重载的问题. 在javascript中是没有函数重载机制的,对于用惯了java开发的同学可能就表示吃惊了,我屮艸芔茻,函数 没有重载?那怎么搞?!! ...

  3. flowable EngineConfiguration的实现分析(2)

    EngineConfiguration的实现类是一个抽象类:AbstractEngineConfiguration 一.引擎配置的分类 继承 AbsractEngineConfiguration的子类 ...

  4. Python中方法的缺省参数问题分析

    引言: 在Python中可以缺省给方法制定缺省值,但是这个缺省值在某些情况下确是和我们预期不太一致的-... 这个诡异的问题,曾经困然了我几天时间,才最终定位出来-.. 测试代码 from datet ...

  5. hdu6230 Palindrome(manacher+树状数组)

    题目链接: Palindrome Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Other ...

  6. java入门学习(6)—封装,继承,多态,this,super,初始代码块

    1.[封装]:将对象的状态信息隐藏,不允许直接访问,而是通过该类提供的的方法阿里实现内部信息的访问和操作. 使用到的修饰符:private,不用修饰符(default),protected,publi ...

  7. IOS开发 Application Kit框架的线程安全

    以下部分介绍了Application Kit框架的线程安全. 非线程安全类 以下这些类和函数通常是非线程安全的.大部分情况下,你可以在任何线程使用这些类,只要你在同一时间只有一个线程使用它们.查看这些 ...

  8. 解决TensorFlow最新代码编译错误问题

    老是有个习惯,看到开源代码更新了,总是想更新到最新版,如果置之不理的话,就感觉自己懒惰了或有的不负责任了,这个也可能是一种形式的强迫症吧: 前几天晚上git pull TensorFlow,完事后也没 ...

  9. 我在ubuntu14.04安装使用的软件

    搜狗拼音sougoupinyin:sudo add-apt-repository ppa:fcitx-team/nightly && sudo apt-get updatesudo a ...

  10. Bezier曲线原理—动态解释

    公式线性公式给定点P0.P1,线性贝兹曲线只是一条两点之间的直线.且其等同于线性插值.这条线由下式给出: 一阶贝赛尔曲线上的由两个点确定 P0 和P1,当t在0--->1区间上递增时,根据此会得 ...