예제 #1
0
        // 创建实例.
        public override GKToyBaseOverlord _CreateData(string path)
        {
            // 生成数据源.
            var       obj   = ScriptableObject.CreateInstance <GKToyExternalData>();
            GKToyData tData = new GKToyData();

            obj.data = tData.Clone() as GKToyData;
            GKEditor.CreateAsset(obj, path);
            var externalData = AssetDatabase.LoadMainAssetAtPath(path) as GKToyExternalData;

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

            string myName = Path.GetFileNameWithoutExtension(path);

            // 创建宿主.
            GameObject go          = new GameObject();
            var        tmpOverload = GK.GetOrAddComponent <GKToyBaseOverlord>(go);

            tmpOverload.internalData           = externalData;
            tmpOverload.name                   = myName;
            tmpOverload.internalData.data.name = myName;

            // 初始化首次数据.
            GKToyMakerChapterInfo.Create(this, position.min, ToyMakerBase._minWidth, ToyMakerBase._minHeight, _GetTaskLocalization("Chapter Infomation"), tmpOverload, go);
            return(tmpOverload);
        }
예제 #2
0
        GameObject _CreateDialogueData(string path, int taskId, string dfgType)
        {
            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }
            // 生成数据源.
            var       obj   = ScriptableObject.CreateInstance <GKToyExternalData>();
            GKToyData tData = new GKToyData();

            obj.data = tData.Clone() as GKToyData;
            string assetPath = string.Format("{0}{1}_{2}.Asset", path, dfgType, taskId);

            GKEditor.CreateAsset(obj, assetPath);
            var externalData = AssetDatabase.LoadMainAssetAtPath(assetPath) as GKToyExternalData;

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

            string myName = string.Format("{0}_{1}", dfgType, taskId);

            // 创建宿主.
            GameObject go          = new GameObject();
            var        tmpOverload = GK.GetOrAddComponent <GKToyBaseOverlord>(go);

            tmpOverload.internalData           = externalData;
            tmpOverload.name                   = myName;
            tmpOverload.internalData.data.name = myName;

            // 初始化首次数据.
            GKToyNode node = new GKToyStart(_GenerateGUID(tmpOverload.internalData.data.nodeGuid++));
            Type      type = node.GetType();

            node.className = string.Format("{0}.{1}", type.Namespace, type.Name);
            node.pos.x     = (_contentScrollPos.x + ToyMakerBase._minWidth * 0.5f) / Scale;
            node.pos.y     = (_contentScrollPos.y + ToyMakerBase._minHeight * 0.5f) / Scale;
            node.id        = node.ID;
            node.nodeType  = NodeType.Action;
            node.name      = "开始-1";
            node.Init(tmpOverload);
            node.comment = "";
            tmpOverload.internalData.data.nodeLst.Add(node.id, node);
            node           = new GKToyEnd(_GenerateGUID(_GenerateGUID(tmpOverload.internalData.data.nodeGuid++)));
            type           = node.GetType();
            node.className = string.Format("{0}.{1}", type.Namespace, type.Name);
            node.pos.x     = -10;
            node.pos.y     = -10;
            node.id        = node.ID;
            node.nodeType  = NodeType.Action;
            node.name      = "结束-2";
            node.Init(tmpOverload);
            node.comment = "";
            tmpOverload.internalData.data.nodeLst.Add(node.id, node);
            tmpOverload.Save();
            tmpOverload.Backup();
            string     prefabPath = string.Format("{0}{1}_{2}.prefab", path, dfgType, taskId);
            GameObject prefab;

            if (!File.Exists(prefabPath))
            {
                prefab = PrefabUtility.CreatePrefab(prefabPath, go);
            }
            else
            {
                prefab = AssetDatabase.LoadAssetAtPath <GameObject>(prefabPath);
                prefab = PrefabUtility.ReplacePrefab(go, prefab);
            }
            DestroyImmediate(go);
            return(prefab);
        }