Example #1
0
    void LoadObject(GameObject parent, GameObjectClass goc)
    {
        foreach (var childClass in goc.children)
        {
            GameObject prefab = GetPrefab(childClass.Type, childClass.SubType);
            GameObject childGO;
            if (prefab != null)
            {
                childGO = Instantiate(prefab);
            }
            else
            {
                childGO = new GameObject(childClass.Name);
            }

            if (parent != null)
            {
                childGO.transform.parent = parent.transform;
            }
            childGO.transform.localPosition = childClass.transformClass.position;
            childGO.transform.localScale    = childClass.transformClass.scale;
            childGO.transform.localRotation = childClass.transformClass.rotation;

            LoadObject(childGO, childClass);
        }
    }
    public static void LoadScene(string fileName)
    {
        string jsonText = System.IO.File.ReadAllText(fileName);
        var    settings = new JsonSerializerSettings {
            TypeNameHandling = TypeNameHandling.All
        };
        GameObjectClass root = JsonConvert.DeserializeObject <GameObjectClass>(jsonText, settings);

        //GameObjectClass root = JsonUtility.FromJson<GameObjectClass>( jsonText );

        if (root != null)
        {
            EditorSceneManager.NewScene(NewSceneSetup.EmptyScene);

            UnityEngine.SceneManagement.Scene activeScene = EditorSceneManager.GetActiveScene();
            activeScene.name = root.Name;

            foreach (GameObjectClass goc in root.children)
            {
                GameObject go = new GameObject(goc.Name);
                go.transform.localPosition = goc.transformClass.position;
                go.transform.localScale    = goc.transformClass.scale;
                go.transform.localRotation = goc.transformClass.rotation;

                LoadObject(go, goc);
            }
        }
    }
Example #3
0
    /// <summary>
    /// Creates the  graphical game object and play the corresponding animation of that graphic if it is set to onStart
    /// </summary>
    /// <param name="gameObjectData">Game object data.</param>

    public void CreateGameObject(GameObjectClass gameObjectData)
    {
        Vector3    position = new Vector3(gameObjectData.posX, gameObjectData.posY);
        Vector3    scale    = new Vector3(gameObjectData.scaleX, gameObjectData.scaleY);
        GameObject go       = new GameObject(gameObjectData.label);

        go.transform.position   = position;
        go.transform.localScale = scale;
        go.AddComponent <SpriteRenderer>();
        go.GetComponent <SpriteRenderer>().sortingOrder = gameObjectData.orderInLayer;
        go.AddComponent <GTinkerGraphic>();
        go.GetComponent <GTinkerGraphic>().dataTinkerGraphic = gameObjectData;
        go.GetComponent <GTinkerGraphic>().sceneManager      = GameObject.Find("SceneManager" + (pageNumber)).GetComponent <GSManager>();
        go.GetComponent <GTinkerGraphic>().myCanvas          = GameObject.Find("Canvas").GetComponent <Canvas>();
        go.GetComponent <GTinkerGraphic>().SetDraggable(gameObjectData.draggable);
        if (gameObjectData.anim.Length > 0)
        {
            LoadAssetImages(go.GetComponent <GTinkerGraphic>(), gameObjectData.anim[0].animName, gameObjectData.anim[0].startIndex, gameObjectData.anim[0].endIndex, gameObjectData.anim[0].startX, gameObjectData.anim[0].startY); // call the LoadAssetImages function which load the anim images from bundle and fill the array of sprites with it
            go.GetComponent <GTinkerGraphic>().secPerFrame = gameObjectData.anim[0].secPerFrame;                                                                                                                                    // set the secperframe field of tinkergraphic class

            if (gameObjectData.anim[0].onStart)
            {             // if the animation is set to on start play it
                go.GetComponent <GTinkerGraphic>().secPerFrame = gameObjectData.anim[0].secPerFrame;
                go.GetComponent <GTinkerGraphic>().sequences   = gameObjectData.anim[0].sequences;
                //go.GetComponent<GTinkerGraphic> ().PlayAnimation ();
            }
            else
            {
                LoadAssetImage(go.GetComponent <GTinkerGraphic>(), gameObjectData.imageName);                // if not anim load the image
            }
        }
        else
        {
            LoadAssetImage(go.GetComponent <GTinkerGraphic>(), gameObjectData.imageName);
        }

        if (gameObjectData.destroyOnCollision != "NIL")
        {
            var rigidbody = go.AddComponent <Rigidbody2D>();
            rigidbody.isKinematic = true;
            //rigidbody.bodyType = RigidbodyType2D.Static;
            //rigidbody.useFullKinematicContacts = true;
        }
        //add BoxCollider after adding the sprite for proper size!
        PolygonCollider2D col = go.AddComponent <PolygonCollider2D>();

        // BoxCollider col = go.AddComponent<BoxCollider>();
        col.isTrigger = true;
        tinkerGraphicObjects.Add(go);
    }
    static void SaveObject(GameObject go, GameObjectClass parent)
    {
        Component[] comps = go.GetComponents <Component>();
        foreach (var comp in comps)
        {
            ComponentClass childComp = ComponentFactory.CreateComponentClass(comp);
            parent.components.Add(childComp);
        }
        for (var i = 0; i < go.transform.childCount; i++)
        {
            GameObject      child   = go.transform.GetChild(i).transform.gameObject;
            GameObjectClass childGO = new GameObjectClass(child);
            parent.children.Add(childGO);

            SaveObject(child, childGO);
        }
    }
Example #5
0
    void SaveObject(GameObject go, GameObjectClass parent)
    {
        var primitiveObj = go.GetComponent <PrimitiveObject>();

        if (primitiveObj != null)
        {
            parent.Type    = "Primitive";
            parent.SubType = primitiveObj.type.ToString();
        }
        for (var i = 0; i < go.transform.childCount; i++)
        {
            GameObject      child   = go.transform.GetChild(i).transform.gameObject;
            GameObjectClass childGO = new GameObjectClass(child);
            parent.children.Add(childGO);

            SaveObject(child, childGO);
        }
    }
Example #6
0
    public void SaveScene(string filepath)
    {
        string filename = System.IO.Path.GetFileNameWithoutExtension(filepath);

        GameObjectClass root = new GameObjectClass(filename);

        root.Type = "Scene";
        foreach (var go in objectsInScene)
        {
            GameObjectClass childGO = new GameObjectClass(go);
            root.children.Add(childGO);
            SaveObject(go, childGO);
        }

        JsonConverter[] converters = new JsonConverter[] { new VectorConverter(), new QuaternionConverter(), new Matrix4x4Converter(), new ColorConverter() };
        string          jsonText   = JsonConvert.SerializeObject(root, Formatting.Indented, converters);

        System.IO.File.WriteAllText(filepath, jsonText);
    }
    static void LoadObject(GameObject go, GameObjectClass parent)
    {
        foreach (var compClass in parent.components)
        {
            go.CreateComponent(compClass);
        }

        foreach (var childClass in parent.children)
        {
            GameObject childGO = new GameObject(childClass.Name);
            childGO.transform.parent        = go.transform;
            childGO.transform.localPosition = childClass.transformClass.position;
            childGO.transform.localScale    = childClass.transformClass.scale;
            childGO.transform.localRotation = childClass.transformClass.rotation;


            LoadObject(childGO, childClass);
        }
    }
    public static void SaveScene(string fileName)
    {
        GameObjectClass root = new GameObjectClass(EditorSceneManager.GetActiveScene().name);

        object[] children = EditorSceneManager.GetActiveScene().GetRootGameObjects();
        foreach (object o in children)
        {
            GameObject      go      = (GameObject)o;
            GameObjectClass childGO = new GameObjectClass(go);
            root.children.Add(childGO);
            SaveObject(go, childGO);
        }

        JsonConvert.DefaultSettings = () => new JsonSerializerSettings
        {
            TypeNameHandling = TypeNameHandling.All
        };

        JsonConverter[] converters = new JsonConverter[] { new VectorConverter(), new QuaternionConverter(), new Matrix4x4Converter(), new ColorConverter() };
        string          jsonText   = JsonConvert.SerializeObject(root, Formatting.Indented, converters);

        System.IO.File.WriteAllText(fileName, jsonText);
    }
Example #9
0
    public void LoadScene(string filepath)
    {
        string jsonText = System.IO.File.ReadAllText(filepath);
        var    settings = new JsonSerializerSettings {
            TypeNameHandling = TypeNameHandling.All
        };
        GameObjectClass root = JsonConvert.DeserializeObject <GameObjectClass>(jsonText, settings);

        //GameObjectClass root = JsonUtility.FromJson<GameObjectClass>( jsonText );

        if (root != null)
        {
            ClearScene();

            foreach (var childClass in root.children)
            {
                GameObject prefab = GetPrefab(childClass.Type, childClass.SubType);
                GameObject childGO;
                if (prefab != null)
                {
                    childGO = Instantiate(prefab);
                }
                else
                {
                    childGO = new GameObject(childClass.Name);
                }

                childGO.transform.localPosition = childClass.transformClass.position;
                childGO.transform.localScale    = childClass.transformClass.scale;
                childGO.transform.localRotation = childClass.transformClass.rotation;

                LoadObject(childGO, childClass);
                objectsInScene.Add(childGO);
            }
        }
    }
Example #10
0
 public GameObjectItem(GameObjectClass classification, string purpose)
 {
     Classification = classification;
     Purpose        = purpose;
 }