Пример #1
0
        // 根据对象类型获取相同类型变量列表.
        public List <object> GetVariableListByType(Type type, int idx = 0)
        {
            _tmpVarNames.Clear();
            GKToyData d = null;

            if (0 != idx && idx - 1 < externalDatas.Count)
            {
                d = externalDatas[idx - 1].data;
            }
            else
            {
                d = internalData.data;
            }

            if (null == d)
            {
                return(null);
            }

            foreach (var v in d.variableLst)
            {
                if (type == v.Value[0].GetType())
                {
                    return(v.Value);
                }
            }
            return(null);
        }
Пример #2
0
        public List <string> GetVariableNameListByType(Type type, int idx = 0)
        {
            _tmpVarNames.Clear();
            GKToyData d = null;

            if (0 != idx && idx - 1 < externalDatas.Count)
            {
                d = externalDatas[idx - 1].data;
            }
            else
            {
                d = internalData.data;
            }

            if (null == d)
            {
                return(_tmpVarNames);
            }

            foreach (var v in d.variableLst)
            {
                if (type == v.Value[0].GetType())
                {
                    foreach (var ele in v.Value)
                    {
                        _tmpVarNames.Add(((GKToyVariable)ele).Name);
                    }
                    return(_tmpVarNames);
                }
            }
            return(_tmpVarNames);
        }
Пример #3
0
        // 获取变量.
        public object GetVariable(string name, int idx = 0)
        {
            GKToyData d = null;

            if (0 != idx && idx - 1 < externalDatas.Count)
            {
                d = externalDatas[idx - 1].data;
            }
            else
            {
                d = internalData.data;
            }

            if (null == d)
            {
                return(null);
            }

            if (_varDict[idx].ContainsKey(name))
            {
                return(_varDict[idx][name]);
            }
            else
            {
                return(null);
            }
        }
Пример #4
0
        // Json转化为变量.
        public void LoadVariable(GKToyBaseOverlord overlord, GKToyData data)
        {
            variableLst.Clear();
            int i = 0;

            foreach (var d in variableData)
            {
                Type t = Type.GetType(variableTypeData[i]);
                var  v = JsonUtility.FromJson(d, t) as GKToyVariable;

                // 序列化后引用为堆内存, 需要重新指定.
                if (null != v)
                {
                    v.InitializePropertyMapping(overlord, data);
                }

                if (variableLst.ContainsKey(v.PropertyMapping))
                {
                    variableLst[v.PropertyMapping].Add(v);
                }
                else
                {
                    List <object> lst = new List <object>();
                    lst.Add(v);
                    variableLst.Add(v.PropertyMapping, lst);
                }
                i++;
            }
        }
Пример #5
0
        // 添加数据源变量信息至宿主中, 使宿主可直接进行操作.
        protected void _AddVariable(GKToyData d, int idx)
        {
            Dictionary <string, object> dict = new Dictionary <string, object>();

            foreach (var lst in d.variableLst.Values)
            {
                foreach (var obj in lst)
                {
                    if (!dict.ContainsKey(((GKToyVariable)obj).Name))
                    {
                        dict.Add(((GKToyVariable)obj).Name, obj);
                    }
                }
            }
            _varDict.Add(idx, dict);
        }
Пример #6
0
        // 反序列化及有限状态机初始化.
        protected void _InitData(GKToyData d)
        {
            d.Init(this);
            GKNodeStateMachine machine = new GKNodeStateMachine(d.nodeLst.Values.ToList());

            if (GKEditor.isUnityEditor())
            {
                List <GKStateListMachineBase <int> .NewStateStruct> groupIds = new List <GKStateListMachineBase <int> .NewStateStruct>();
                foreach (GKToyNode node in d.nodeLst.Values)
                {
                    if (NodeType.Group == node.nodeType)
                    {
                        groupIds.Add(new GKStateListMachineBase <int> .NewStateStruct(node.id, "", null));
                    }
                }
                machine.GoToState(groupIds);
            }
            stateMachines.Add(machine);
        }
Пример #7
0
        /// <summary>
        /// 导出服务器数据
        /// </summary>
        /// <param name="dataType">数据类型:1-客户端,2-服务器</param>
        static public void ExportServerData(GKToyData data, string destPath)
        {
            GameData    gameData = new GameData();
            NodeElement tmpItem;
            int         endID = 0;

            foreach (GKToyNode node in data.nodeLst.Values)
            {
                if ("GKToy.GKToyEnd" == node.className)
                {
                    endID = node.id;
                    break;
                }
            }
            if (!Directory.Exists(destPath))
            {
                GKFile.GKFileUtil.CreateDirectoryFromFileName(destPath);
            }
            foreach (GKToyNode node in data.nodeLst.Values)
            {
                tmpItem = new NodeElement();
                if (NodeType.Group == node.nodeType || NodeType.VirtualNode == node.nodeType)
                {
                    continue;
                }
                tmpItem.attrs = _GetFieldsWithAttribute(node, typeof(ExportServerAttribute), endID, node.id == endID);
                gameData.Add(tmpItem);
            }
            // 导出xml.
            XmlSerializer serializer = new XmlSerializer(typeof(GameData));
            FileStream    stream     = new FileStream(destPath, FileMode.Create);

            try
            {
                serializer.Serialize(stream, gameData);
            }
            finally
            {
                stream.Close();
            }
        }
Пример #8
0
        /// <summary>
        /// 导出客户端数据
        /// </summary>
        /// <param name="data">要导出的数据源</param>
        /// <param name="destPath"></param>
        static public void ExportClientData(GKToyData data, string destPath)
        {
            GameData    gameData = new GameData();
            NodeElement tmpItem;
            int         endID = 0;

            foreach (GKToyNode node in data.nodeLst.Values)
            {
                if ("GKToy.GKToyEnd" == node.className)
                {
                    endID = node.id;
                    break;
                }
            }
            if (!Directory.Exists(destPath))
            {
                GKFile.GKFileUtil.CreateDirectoryFromFileName(destPath);
            }
            foreach (GKToyNode node in data.nodeLst.Values)
            {
                tmpItem = new NodeElement();
                if (NodeType.Group == node.nodeType || NodeType.VirtualNode == node.nodeType)
                {
                    continue;
                }
                tmpItem.attrs = _GetFieldsWithAttribute(node, typeof(ExportClientAttribute), endID, node.id == endID);
                gameData.Add(tmpItem);
            }
            // 导出lua.
            StreamWriter stream = new StreamWriter(destPath, false);

            try
            {
                stream.Write(_DataToLua(data.name, gameData));
            }
            finally
            {
                stream.Close();
            }
        }
Пример #9
0
        // 设置变量值.
        public void SetVariableValue(string name, object val, int idx = 0)
        {
            GKToyData d = null;

            if (0 != idx && idx - 1 < externalDatas.Count)
            {
                d = externalDatas[idx - 1].data;
            }
            else
            {
                d = internalData.data;
            }

            if (null == d)
            {
                return;
            }

            if (_varDict[idx].ContainsKey(name))
            {
                ((GKToyVariable)(_varDict[idx][name])).SetValue(val);
            }
        }
Пример #10
0
 public virtual void InitializePropertyMapping(GKToyBaseOverlord overlord, GKToyData data)
 {
     PropertyMappingOwner = overlord;
     PropertyDataOwner    = data;
     PropertyMapping      = GetType().ToString();
 }