Ejemplo n.º 1
0
        private Material CreateMaterial()
        {
            var mat = new Material(Shader.Find("Standard (Specular setup)"));

            mat.mainTexture = atlas;
            mat.SetFloat("_Glossiness", 0);
            mat.SetColor("_SpecColor", new Color(0, 0, 0, 1));
            mat.SetFloat("_Mode", 1);

            mat.SetOverrideTag("RenderType", "TransparentCutout");
            mat.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One);
            mat.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.Zero);
            mat.SetInt("_ZWrite", 1);
            mat.EnableKeyword("_ALPHATEST_ON");
            mat.DisableKeyword("_ALPHABLEND_ON");
            mat.DisableKeyword("_ALPHAPREMULTIPLY_ON");
            mat.renderQueue = (int)RenderQueue.AlphaTest;

            mat.doubleSidedGI    = true;
            mat.enableInstancing = true;

            var matPath = AssetHelper.GetAssetPath(Path.Combine("Assets/models/materials", savePath), Path.GetFileNameWithoutExtension(baseName) + ".mat");

            AssetDatabase.CreateAsset(mat, matPath);

            return(mat);
        }
Ejemplo n.º 2
0
        public void TrySaveWorldConfig(string worldName)
        {
            string parentFolder = "Assets/Config";

            string newFolder = "Resources";

            string extension = "asset";

            string assetPath = AssetHelper.GetAssetPath(parentFolder, newFolder, worldName, extension);

            if (AssetHelper.DoesAssetExist <WorldConfig>(assetPath))
            {
                if (!EditorUtility.DisplayDialog(
                        "Config file already exists!",
                        "Do you wish to overwrite world config with name: " + worldName + "?",
                        "Yep!",
                        "Shit no! Take me back!"))
                {
                    return;
                }
            }

            AssetHelper.TryCreateFolder(parentFolder, newFolder);

            CreateWorldConfig(assetPath);
        }
Ejemplo n.º 3
0
        public void TrySaveWorldPrefab(string worldName)
        {
            string parentFolder = "Assets/Prefabs";

            string newFolder = "Worlds";

            string extension = "prefab";

            string assetPath = AssetHelper.GetAssetPath(parentFolder, newFolder, worldName, extension);

            if (AssetHelper.DoesAssetExist <GameObject>(assetPath))
            {
                if (!EditorUtility.DisplayDialog(
                        "Prefab already exists!",
                        "Do you wish to overwrite prefab with name: " + worldName + "?",
                        "Yep!",
                        "Shit no! Take me back!"))
                {
                    return;
                }
            }

            AssetHelper.TryCreateFolder(parentFolder, newFolder);

            CreateWorldPrefab(assetPath);
        }
Ejemplo n.º 4
0
        public static void OpenGameScenesInEditor()
        {
            SceneConfig sceneConfig = AssetHelper.LoadAsset <SceneConfig>("SceneConfig");

            if (sceneConfig == null)
            {
                UnityEngine.Debug.LogError("Trying to open Game Scenes in Editor, but no SceneConfig was created!");

                return;
            }

            if (sceneConfig.GameScenes.Length == 0)
            {
                UnityEngine.Debug.LogWarning("Trying to open Game Scenes in Editor, but no scenes were assigned in the SceneConfig!");
            }

            for (int i = 0; i < sceneConfig.GameScenes.Length; i++)
            {
                OpenSceneMode openSceneMode = OpenSceneMode.Single;

                bool makeSceneActive = i == 0;

                if (i > 0)
                {
                    openSceneMode = OpenSceneMode.Additive;
                }

                string assetPath = AssetHelper.GetAssetPath(sceneConfig.GameScenes[i]);

                OpenSceneInEditor(assetPath, openSceneMode, makeSceneActive);
            }
        }
Ejemplo n.º 5
0
        public GameObject CompileNode(GameObject parentGameObject, RsmNode node, Material mat)
        {
            var go = new GameObject(node.Name);
            var mf = go.AddComponent <MeshFilter>();
            var mr = go.AddComponent <MeshRenderer>();
            var mc = go.AddComponent <MeshCollider>();

            go.layer             = LayerMask.NameToLayer("Object");
            go.isStatic          = true;
            mr.material          = mat;
            mr.receiveGI         = ReceiveGI.Lightmaps;
            mr.shadowCastingMode = ShadowCastingMode.TwoSided;
            mc.cookingOptions    = MeshColliderCookingOptions.CookForFasterSimulation |
                                   MeshColliderCookingOptions.EnableMeshCleaning |
                                   MeshColliderCookingOptions.WeldColocatedVertices |
                                   MeshColliderCookingOptions.UseFastMidphase;

            go.transform.parent = parentGameObject.transform;

            var position = node.Position;
            var rotation = Quaternion.AngleAxis(node.RotationAngle * Mathf.Rad2Deg, node.RotationAxis).FlipY();
            var scale    = node.Scale;
            var offset   = node.Offset;

            if (node.PosKeyFrames.Count > 0)
            {
                position = node.PosKeyFrames[0].Position;
            }
            if (node.RotationKeyFrames.Count > 0)
            {
                rotation = node.RotationKeyFrames[0].Rotation;
            }

            go.transform.localPosition = position.FlipY();
            go.transform.localRotation = rotation;
            go.transform.localScale    = scale;

            var vTrans = new List <Vector3>();
            var tris   = new List <RsmTriangle>();

            foreach (var f in node.Faces)
            {
                var tri = new RsmTriangle()
                {
                    TwoSided = f.TwoSided
                };

                var realTexId = node.TextureIds[f.TextureId];

                for (var i = 0; i < 3; i++)
                {
                    var v = node.Vertices[f.VertexIds[i]].FlipY() + offset.FlipY();
                    vTrans.Add(go.transform.TransformPoint(v));
                    tri.Vertices[i] = v;
                    tri.UVs[i]      = VectorHelper.RemapUV(node.UVs[f.UVIds[i]], atlasRects[realTexId]);
                    tri.Colors[i]   = node.Colors[f.UVIds[i]];
                }

                tri.CalcNormals();
                tris.Add(tri);
            }

            if (model.ShadingType == RsmShadingType.Smooth)
            {
                SmoothNodeTriangles(node, tris);
            }

            if (vTrans.Count > 0)
            {
                node.Bounds = GeometryUtility.CalculateBounds(vTrans.ToArray(), Matrix4x4.identity);
            }
            else
            {
                node.Bounds = new Bounds(Vector3.zero, Vector3.zero);
            }

            var mb = new MeshBuilder();

            foreach (var t in tris)
            {
                mb.AddFullTriangle(t.Vertices, t.FlippedNormals, t.UVs, t.Colors, new[] { 2, 1, 0 });

                if (t.TwoSided)
                {
                    mb.AddFullTriangle(t.Vertices, t.Normals, t.UVs, t.Colors, new[] { 0, 1, 2 });
                }
            }

            var mesh = mb.Build(node.Name, true);

            mf.sharedMesh = mesh;
            mc.sharedMesh = mesh;
            if (tris.Any(t => t.TwoSided))
            {
                mr.shadowCastingMode = ShadowCastingMode.On;                 //disable two sided shadows if the model has any two sided faces
            }
            if (node.Children.Count > 0)
            {
                foreach (var child in node.Children)
                {
                    CompileNode(go, child, mat);
                }
            }

            if (node.RotationKeyFrames.Count != 0 || node.PosKeyFrames.Count != 0)
            {
                go.ChangeStaticRecursive(false);
            }

            if (string.IsNullOrWhiteSpace(node.ParentName))
            {
                var bounds = node.Bounds;
                foreach (var n in model.RsmNodes)
                {
                    bounds.Encapsulate(n.Bounds);
                }

                var centering = new Vector3(bounds.center.x, bounds.min.y, bounds.center.z);
                //Debug.Log(centering);
                go.transform.localPosition -= centering;
                go.transform.localPosition *= 0.2f;
                go.transform.localScale    *= 0.2f;
            }

            if (node.RotationKeyFrames.Count > 0)
            {
                var r         = go.AddComponent <RoKeyframeRotator>();
                var keyframes = new List <float>();
                var rotations = new List <Quaternion>();
                foreach (var k in node.RotationKeyFrames)
                {
                    keyframes.Add(k.Frame / 1000f);
                    rotations.Add(k.Rotation);
                }

                r.Keyframes = keyframes.ToArray();
                r.Rotations = rotations.ToArray();
            }

            //save Mesh
            var meshPath = AssetHelper.GetAssetPath(Path.Combine("Assets/models/mesh", savePath, baseName), Path.GetFileNameWithoutExtension(node.Name) + ".asset");

            AssetDatabase.CreateAsset(mesh, meshPath);

            return(go);
        }
Ejemplo n.º 6
0
 public static string GetConfigurationDataPath(ScriptableObject configurationAsset)
 {
     return(AssetHelper.GetAssetPath(configurationAsset, false) + "/Data");
 }