Unity 配置静态excel 工作流程
TP:FCEE652B
cause
在游戏开发的过程中,很多时候需要策划填的一些静态数据表(比如英雄表,技能表等等),而策划一般都习惯使用excel。
excel在unity里面是不能直接读取的,所以我们一般要另存为txt读取,然后一行一行解析进行读取。
***.txt
id name price
1 张三 3.0
2 李四 4.0
但是有一点问题,策划改表是很频繁的,总不能每次策划改动我们另存为一次吧。
这个时候我们可以采用python写一个脚本动态批处理即可
how
1.安装mysql并且安装MySQLdb模块
测试环境win7 推荐python 编辑器pycharm
2.安装Navicat Premium导入excel表

3.配置读取参数
{
"db":{
"host":"127.0.0.1",
"user":"root",
"passwd":"",
"port":3306,
"db":"testdb"
},
"exp_sep":"\t",
"exp_suffix":".txt",
"tables":[
"test_table"
],
"vos":[
"test_table"
]
}
4.动态生成txt和静态配置类
#! /usr/bin/env python
#coding:utf8
import sys
import MySQLdb
import json
reload(sys)
sys.setdefaultencoding('utf-8')
# tables = ('test_table',)
# vo = ('test_table',)
# ('test_table') is interpreted as using algebraic grouping and simply as max_price and not a tuple.
# Adding a comma, i.e. ('test_table',) forces it to make a tuple.
head = '''using UnityEngine;
using System;
using System.Text;
using System.Reflection;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
'''
class_part1 = '''public class %s
{
'''
field = ''' public %s %s;
'''
ctor_par1 = ''' public %s(string[] args)
{
'''
ctor_field = ''' this.%s=%s(arr[%s]);
'''
ctor_par2 = ''' }
'''
class_part2 = '}'
def ConvetType(typeid):
if typeid == 3:
return 'int'
elif typeid == 4:
return 'float'
else:
return 'string'
def ConvertCtorType(typeid):
if typeid == 3:
return 'int.Parse'
elif typeid == 4:
return 'float.Parse'
else:
return ''
# description (('id', 3, 1, 11, 11, 0, 0), ('name', 253, 6, 765, 765, 0, 0), ('price', 4, 1, 12, 12, 31, 0))
def CreateCS(index, description):
vo = curconifg['vos']
with open('%s.cs'% vo[index],"w+") as my_cs:
my_cs.write(head)
my_cs.write(class_part1 % vo[index])
for colIndex in range(len(description)):
curCol = description[colIndex]
my_cs.write(field % (ConvetType(curCol[1]),curCol[0]))
my_cs.write(ctor_par1 % vo[index])
for colIndex in range(len(description)):
curCol = description[colIndex]
my_cs.write(ctor_field % (curCol[0],ConvertCtorType(curCol[1]),colIndex))
my_cs.write(ctor_par2)
my_cs.write(class_part2)
def CreateConfig():
con = MySQLdb.connect(curconifg['db']['host'],curconifg['db']['user'],curconifg['db']['passwd'],curconifg['db']['db'],charset='utf8');
# notice ,charset='utf8'
with con:
cur = con.cursor()
tables = curconifg['tables']
for index in range(len(tables)):
table = tables[index]
# cur.execute("select * from %s where id = %s",('test_table',1))
# DB API requires you to pass in any parameters as a sequence
# but sql query is select * from \\'test_table\\' where id = 1
# like below error
# http://blog.xupeng.me/2013/09/25/mysqldb-args-processing
# so you can do it below,but not safe
query = 'select * from %s '%(table);
cur.execute(query)
with open('%s.txt'%(table),'w+') as my_txt:
# create file if not exits
description = cur.description
CreateCS(index,description)
# description (('id', 3, 1, 11, 11, 0, 0), ('name', 253, 6, 765, 765, 0, 0), ('price', 4, 1, 12, 12, 31, 0))
# create txt
line = curconifg['exp_sep'].join(str(curCol[0]) for curCol in description)
# id name price
my_txt.write(line+'\n')
for i in range(cur.rowcount):
row = cur.fetchone()
line = curconifg['exp_sep'].join(str(col) for col in row)
# 1 张三 3.0
if(i <= (cur.rowcount - 1)):
my_txt.write(line+'\n')
else:
my_txt.write(line)
with open("config.json","r") as jsonFile:
curconifg = json.load(jsonFile)
CreateConfig()
结果如图:

improvement
向上面那样考虑生成txt然后一行一行解析其实还是有点麻烦的,因为这个解析规则还是依赖于我们
其实我们可以考虑在生成的时候转换一下
***.txt
id name price
1 张三 3.0
{"id":1,"name":"张三","price":3.0}
是不是有很多想法啦,骚年!
参考工程 Pratices1
Unity 配置静态excel 工作流程的更多相关文章
- Sitecore 8.2 工作流程
假设您的新Sitecore项目的所有开发都已完成.现在的下一步是在网站上填写内容并准备上线.客户通知您他们希望使用专门的网站管理员团队负责整个内容管理流程,并要求您为他们准备实例以便能够执行此操作. ...
- ecshop 工作流程加载配置介绍
ecshop 工作流程加载配置介绍 分类: ecshop2014-09-14 09:36 729人阅读 评论(2) 收藏 举报 模板引擎工作流 这里简单介绍下echsop工作流程: 首先,你会发现一般 ...
- 工作流程,编程,调试,性能:Unity游戏开发者应该学习的20个改进技巧
Unity 是一个备受欢迎的游戏开发平台.它的功能令人印象深刻,同时也迎合了不同的游戏开发需求.游戏开发者可以使用 Unity 创建任何类型的游戏,从世界级的 RPG 游戏到最流行的增强现实游戏 Po ...
- KaliLinux常用服务配置教程DHCP服务工作流程
KaliLinux常用服务配置教程DHCP服务工作流程 DHCP服务工作流程如图1.1所示. 具体的工作流程如下所示: (1)DHCP客户端以广播的方式发出DHCP Discover报文. (2)所有 ...
- SpringMVC-DispatcherServlet工作流程及web.xml配置
工作流程: Web中,无非是请求和响应: 在SpringMVC中,请求的第一站是DispatcherServlet,充当前端控制器角色: DispatcherServlet会查询一个或多个处理器映射( ...
- GIT使用—安装配置及工作流程
一.Git 与 SVN 区别 GIT不仅仅是个版本控制系统,它也是个内容管理系统(CMS),工作管理系统等. 1.GIT是分布式的,SVN不是:这是GIT和其它非分布式的版本控制系统,例如SVN,CV ...
- Excel催化剂开源第10波-VSTO开发之用户配置数据与工作薄文件一同存储
在传统的VBA开发中,若是用的是普通加载项方法,是可以存储数据在xlam上的,若用的是Com加载项方法同时是Addins程序级别的项目开发的,配置文件没法保存到工作薄中,一般另外用配置文件来存放供调用 ...
- Git 安装配置及工作流程
在使用Git前我们需要先安装 Git.Git 目前支持 Linux/Unix.Solaris.Mac和 Windows 平台上运行. Git 各平台安装包下载地址为:http://git-scm.co ...
- 03.AOF持久化机制配置与工作流程
一.AOF持久化的配置 配置文件redis.conf,AOF持久化默认是关闭的,默认是打开RDB持久化 appendonly yes 二.工作流程: 打开AOF持久化机制之后,redis每次接 ...
随机推荐
- django添加导包路径
在设置文件里: import sys sys.path.insert(0,os.path.join(BASE_DIR,"要导包的目录名")) 用pycharm时,如果导包后没有自动 ...
- Android 用AsyncTask下载网络图片并显示百分比
1.添加布局文件:activity_main.xml <LinearLayout xmlns:android="http://schemas.android.com/apk/res/a ...
- Laravel查询技巧
1.同时增加几个字段的数量 DB::table('project') ->where('id',$yewuid) ->increment('count', 1, [ 'click'=> ...
- Laravel项目使用腾讯云对象存储上传图片(cos-php-sdk-v5版本)
为了加快网站访问速度.降低网站负载,现在越来越多的网站选择把图片等静态文件放在云上,这里介绍一下腾讯云对象存储在Laravel项目中的使用 1.申请腾讯云对象存储.创建Bucket.获取APPID等参 ...
- magento 搬家
1.删除浏览记录: log_customer log_visitor log_visitor_info log_url log_url_info log_quote report_viewed_pro ...
- 拓扑排序(Topological Order)UVa10305 Ordering Tasks
2016/5/19 17:39:07 拓扑排序,是对有向无环图(Directed Acylic Graph , DAG )进行的一种操作,这种操作是将DAG中的所有顶点排成一个线性序列,使得图中的任意 ...
- Html5+CSS
1. 内联样式是为元素添加样式的最简单有效的方式,但是更易于维护的方式是使用层叠样式表CSS(Cascading Style Sheets). <style> 选择器 {属性名称: 属性 ...
- java中的3大特性之继承
继承的特点:继承父类的属性和方法.单继承(多层继承)c++里的继承是多继承 特性 :方法的复写(重写) java中的继承和OC中一样. 比如:人可以养狗; 人---->狗 :整体和部分(拥有)关 ...
- 2014 非常好用的开源 Android 测试工具
http://www.php100.com/html/it/mobile/2014/1015/7495.html 当前有很大的趋势是转向移动应用平台,Android 是最广泛使用的移动操作系统,201 ...
- java.lang.NoSuchMethodError:org.hibernate.SessionFactory.openSession()Lorg/hibernate/classic/Session
项目配置了spring 4.0.6.RELEASE 和hibernate4.2.0.Final ,出错原因是因为在Spring 3.1开始没有了HibernateDaoSupport类,而我的却Dao ...