Ejemplo n.º 1
0
 static public int get_id(IntPtr l)
 {
     try {
         UnityEngine.UI.Extensions.SceneObject self = (UnityEngine.UI.Extensions.SceneObject)checkSelf(l);
         pushValue(l, self.id);
         return(1);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Ejemplo n.º 2
0
 static public int constructor(IntPtr l)
 {
     try {
         UnityEngine.UI.Extensions.SceneObject o;
         o = new UnityEngine.UI.Extensions.SceneObject();
         pushValue(l, o);
         return(1);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Ejemplo n.º 3
0
 static public int set_id(IntPtr l)
 {
     try {
         UnityEngine.UI.Extensions.SceneObject self = (UnityEngine.UI.Extensions.SceneObject)checkSelf(l);
         System.String v;
         checkType(l, 2, out v);
         self.id = v;
         return(0);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Ejemplo n.º 4
0
 static public int set_objectComponents(IntPtr l)
 {
     try {
         UnityEngine.UI.Extensions.SceneObject self = (UnityEngine.UI.Extensions.SceneObject)checkSelf(l);
         System.Collections.Generic.List <UnityEngine.UI.Extensions.ObjectComponent> v;
         checkType(l, 2, out v);
         self.objectComponents = v;
         return(0);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Ejemplo n.º 5
0
 static public int set_rotation(IntPtr l)
 {
     try {
         UnityEngine.UI.Extensions.SceneObject self = (UnityEngine.UI.Extensions.SceneObject)checkSelf(l);
         UnityEngine.Quaternion v;
         checkType(l, 2, out v);
         self.rotation = v;
         return(0);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Ejemplo n.º 6
0
 static public int set_localScale(IntPtr l)
 {
     try {
         UnityEngine.UI.Extensions.SceneObject self = (UnityEngine.UI.Extensions.SceneObject)checkSelf(l);
         UnityEngine.Vector3 v;
         checkType(l, 2, out v);
         self.localScale = v;
         return(0);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Ejemplo n.º 7
0
        public void UnpackComponents(ref GameObject go, SceneObject sceneObject)
        {
            //Go through the stored object's component list and reassign all values in each component, and add components that are missing
            foreach (ObjectComponent obc in sceneObject.objectComponents)
            {

                if (go.GetComponent(obc.componentName) == false)
                {
                    Type componentType = Type.GetType(obc.componentName);
                    go.AddComponent(componentType);
                }

                object obj = go.GetComponent(obc.componentName) as object;

                var tp = obj.GetType();
                foreach (KeyValuePair<string, object> p in obc.fields)
                {

                    var fld = tp.GetField(p.Key,
                                          BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic |
                                          BindingFlags.SetField);
                    if (fld != null)
                    {

                        object value = p.Value;
                        fld.SetValue(obj, value);
                    }
                }
            }
        }
Ejemplo n.º 8
0
        public GameObject UnpackGameObject(SceneObject sceneObject)
        {
            //This is where our prefabDictionary above comes in. Each GameObject that was saved needs to be reconstucted, so we need a Prefab,
            //and we know which prefab it is because we stored the GameObject's prefab name in it's ObjectIdentifier/SceneObject script/class.
            //Theoretically, we could even reconstruct GO's that have no prefab by instatiating an empty GO and filling it with the required components... I'lll leave that to you.
            if (prefabDictionary.ContainsKey(sceneObject.prefabName) == false)
            {
                Debug.Log("Can't find key " + sceneObject.prefabName + " in SaveLoadMenu.prefabDictionary!");
                return null;
            }
            //instantiate the gameObject
            GameObject go = Instantiate(prefabDictionary[sceneObject.prefabName], sceneObject.position, sceneObject.rotation) as GameObject;

            //Reassign values
            go.name = sceneObject.name;
            go.transform.localScale = sceneObject.localScale;
            go.SetActive(sceneObject.active);

            if (go.GetComponent<ObjectIdentifier>() == false)
            {
                //ObjectIdentifier oi = go.AddComponent<ObjectIdentifier>();
                go.AddComponent<ObjectIdentifier>();
            }

            ObjectIdentifier idScript = go.GetComponent<ObjectIdentifier>();
            idScript.id = sceneObject.id;
            idScript.idParent = sceneObject.idParent;

            UnpackComponents(ref go, sceneObject);

            //Destroy any children that were not referenced as having a parent
            ObjectIdentifier[] childrenIds = go.GetComponentsInChildren<ObjectIdentifier>();
            foreach (ObjectIdentifier childrenIDScript in childrenIds)
            {
                if (childrenIDScript.transform != go.transform)
                {
                    if (string.IsNullOrEmpty(childrenIDScript.id) == true)
                    {
                        Destroy(childrenIDScript.gameObject);
                    }
                }
            }

            return go;
        }
Ejemplo n.º 9
0
        public SceneObject PackGameObject(GameObject go)
        {

            ObjectIdentifier objectIdentifier = go.GetComponent<ObjectIdentifier>();

            //Now, we create a new instance of SceneObject, which will hold all the GO's data, including it's components.
            SceneObject sceneObject = new SceneObject();
            sceneObject.name = go.name;
            sceneObject.prefabName = objectIdentifier.prefabName;
            sceneObject.id = objectIdentifier.id;
            if (go.transform.parent != null && go.transform.parent.GetComponent<ObjectIdentifier>() == true)
            {
                sceneObject.idParent = go.transform.parent.GetComponent<ObjectIdentifier>().id;
            }
            else
            {
                sceneObject.idParent = null;
            }

            //in this case, we will only store MonoBehavior scripts that are on the GO. The Transform is stored as part of the ScenObject isntance (assigned further down below).
            //If you wish to store other component types, you have to find you own ways to do it if the "easy" way that is used for storing components doesn't work for them.
            List<string> componentTypesToAdd = new List<string>() {
            "UnityEngine.MonoBehaviour"
        };

            //This list will hold only the components that are actually stored (MonoBehavior scripts, in this case)
            List<object> components_filtered = new List<object>();

            //Collect all the components that are attached to the GO.
            //This includes MonoBehavior scripts, Renderers, Transform, Animator...
            //If it
            object[] components_raw = go.GetComponents<Component>() as object[];
            foreach (object component_raw in components_raw)
            {
                if (componentTypesToAdd.Contains(component_raw.GetType().BaseType.FullName))
                {
                    components_filtered.Add(component_raw);
                }
            }

            foreach (object component_filtered in components_filtered)
            {
                sceneObject.objectComponents.Add(PackComponent(component_filtered));
            }

            //Assign all the GameObject's misc. values
            sceneObject.position = go.transform.position;
            sceneObject.localScale = go.transform.localScale;
            sceneObject.rotation = go.transform.rotation;
            sceneObject.active = go.activeSelf;

            return sceneObject;
        }