Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void CreateStaticGraphicsObject(GameObject container, JSONNode graphicsObjectJSON)
- {
- string name, path;
- int index;
- float x, y, w, h, r;
- // Get the data
- name = graphicsObjectJSON["data"]["name"];
- x = graphicsObjectJSON["x"].AsFloat;
- y = graphicsObjectJSON["y"].AsFloat;
- w = graphicsObjectJSON["w"].AsFloat;
- h = graphicsObjectJSON["h"].AsFloat;
- r = graphicsObjectJSON["r"].AsFloat;
- path = graphicsObjectJSON["data"]["graphics path"].Value;
- index = graphicsObjectJSON["data"]["graphics index"].AsInt;
- // Create the static graphics object
- GameObject graphicsObject = InstantiatePrefab(_prefabManager.StaticGraphicsObject);
- // Set its parent
- graphicsObject.transform.parent = container.transform;
- // Set its position, scale and rotation
- graphicsObject.transform.localScale = new Vector3(w, h, 1);
- graphicsObject.transform.localPosition = new Vector3(x, y, 0);
- graphicsObject.transform.rotation = Quaternion.Euler(0, 0, r);
- // Give it a name
- graphicsObject.name = name;
- // Get a reference to the static graphics object
- StaticGraphicsObject staticGraphicsObject = graphicsObject.GetComponent<StaticGraphicsObject>();
- // Set the sprite
- staticGraphicsObject.GraphicsPath = path;
- staticGraphicsObject.GraphicsIndex = index;
- // Update the graphics
- staticGraphicsObject.UpdateGraphic();
- }
- private GameObject InstantiatePrefab(UnityEngine.Object prefab)
- {
- if (Application.isEditor)
- {
- return (GameObject)UnityEditor.PrefabUtility.InstantiatePrefab(prefab);
- }
- else
- return (GameObject)Instantiate(prefab);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement