示例#1
0
        // Create object
        public static GameObject Create(RFSnapshot cap, float sizeFilter)
        {
            // Mesh and size filtering
            Mesh mesh = null;

            if (cap.mesh.subMeshCount > 0)
            {
                // Size filtering
                if (cap.mesh.bounds.size.magnitude < sizeFilter)
                {
                    return(null);
                }

                // Get mesh
                mesh = cap.mesh.GetMesh();
            }

            // Object
            GameObject go = new GameObject();

            go.name = cap.nm;
            go.transform.position   = cap.pos;
            go.transform.rotation   = cap.rot;
            go.transform.localScale = cap.scale;

            // Mesh
            if (mesh != null)
            {
                MeshFilter mf = go.AddComponent <MeshFilter>();
                mf.sharedMesh = mesh;
            }

            // Materials
            if (cap.mats.Count > 0)
            {
                MeshRenderer    mr        = go.AddComponent <MeshRenderer>();
                List <Material> materials = new List <Material>();
                foreach (var matPath in cap.mats)
                {
                    materials.Add((Material)AssetDatabase.LoadAssetAtPath(matPath, typeof(Material)));
                }
                mr.sharedMaterials = materials.ToArray();
            }

            cap.newId = go.GetInstanceID();
            cap.newTm = go.transform;

            return(go);
        }
示例#2
0
        // Load asset
        public static void Load(UnityEngine.Object snapshotAsset, GameObject gameObject, float sizeFilter)
        {
            // No asset
            if (snapshotAsset == null)
            {
                Debug.Log("RayFire Snapshot: " + gameObject.name + " Snapshot asset is not defined", gameObject);
                return;
            }

            // Get path
            string path1 = Application.dataPath;
            string path2 = AssetDatabase.GetAssetPath(snapshotAsset);

            path2 = path2.Remove(0, 6);

            // Read
            string          dataString = File.ReadAllText(path1 + path2);
            RFSnapshotAsset assetData  = JsonUtility.FromJson <RFSnapshotAsset> (dataString);

            // No asset
            if (assetData == null)
            {
                Debug.Log("RayFire Snapshot: " + gameObject.name + " Snapshot asset is not defined", gameObject);
                return;
            }

            // Create objects from asset
            if (assetData.assets.Count > 0)
            {
                foreach (var ast in assetData.assets)
                {
                    RFSnapshot.Create(ast, sizeFilter);
                }
            }

            // Set parents
            foreach (var snap in assetData.assets)
            {
                RFSnapshot.SetParent(assetData.assets, snap.parentOldId, snap.newTm, gameObject.transform);
            }
        }