コード例 #1
0
        protected T OnDeSerialize <T>(Transform parent = null) where T : hLevelObject
        {
            hLevelObject prefab      = hDatabase.current.GetLevelObject(System.Type.GetType(type));
            hLevelObject levelObject = Instantiate(prefab, parent);

            serializedTransform.DeSerialize(levelObject.transform);

            return((T)levelObject);
        }
コード例 #2
0
        public hLevel DeSerialize(Transform parent)
        {
            GameObject gob = new GameObject();

            gob.name = "Level";
            gob.transform.SetParent(parent);
            gob.transform.localPosition = Vector3.zero;
            gob.transform.localRotation = Quaternion.Euler(Vector3.zero);
            gob.transform.localScale    = Vector3.one;

            var collider = gob.AddComponent <BoxCollider>();

            collider.isTrigger = true;
            var level = gob.AddComponent <hLevel>();

            level.levelNum   = levelNum;
            level.difficulty = (Difficulty)difficulty;

            List <hPortal> portals = new List <hPortal>();

            hLevelObject[] levelObjects = new hLevelObject[this.levelObjects.Length];
            for (int i = 0; i < levelObjects.Length; ++i)
            {
                levelObjects[i] = this.levelObjects[i].DeSerialize(gob.transform);
                if (levelObjects[i].GetType() == typeof(hPortal))
                {
                    portals.Add((hPortal)levelObjects[i]);
                }
            }

            while (portals.Count > 0)
            {
                var portal1 = portals[0];
                portals.RemoveAt(0);
                for (int i = 0; i < portals.Count; ++i)
                {
                    var portal2 = portals[i];
                    if (portal1.nextPortalId == portal2.id)
                    {
                        portal1.nextPortal = portal2;
                        if (portal2.nextPortalId == portal1.id)
                        {
                            portal2.nextPortal = portal1;
                            portals.RemoveAt(i);
                        }
                        break;
                    }
                }
            }

            level.Initialize(levelObjects);
            Physics.SyncTransforms();

            return(level);
        }