static RuntimeHandles()
        {
            LinesMaterial                  = new Material(Shader.Find("Battlehub/RTHandles/VertexColor"));
            LinesMaterial.color            = Color.white;
            LinesMaterial.enableInstancing = true;

            LinesMaterialZTest       = new Material(Shader.Find("Battlehub/RTHandles/VertexColor"));
            LinesMaterialZTest.color = Color.white;
            LinesMaterialZTest.SetFloat("_ZTest", (float)UnityEngine.Rendering.CompareFunction.LessEqual);
            LinesMaterialZTest.enableInstancing = true;

            LinesClipMaterial                  = new Material(Shader.Find("Battlehub/RTHandles/VertexColorClip"));
            LinesClipMaterial.color            = Color.white;
            LinesClipMaterial.enableInstancing = true;

            LinesBillboardMaterial                  = new Material(Shader.Find("Battlehub/RTHandles/VertexColorBillboard"));
            LinesBillboardMaterial.color            = Color.white;
            LinesBillboardMaterial.enableInstancing = true;

            ShapesMaterial                  = new Material(Shader.Find("Battlehub/RTHandles/Shape"));
            ShapesMaterial.color            = Color.white;
            ShapesMaterial.enableInstancing = true;


            ShapesMaterialZTest       = new Material(Shader.Find("Battlehub/RTHandles/Shape"));
            ShapesMaterialZTest.color = new Color(1, 1, 1, 0);
            ShapesMaterialZTest.SetFloat("_ZTest", (float)UnityEngine.Rendering.CompareFunction.LessEqual);
            ShapesMaterialZTest.SetFloat("_ZWrite", 1.0f);
            ShapesMaterialZTest.enableInstancing = true;

            ShapesMaterialZTestOffset       = new Material(Shader.Find("Battlehub/RTHandles/Shape"));
            ShapesMaterialZTestOffset.color = new Color(1, 1, 1, 1);
            ShapesMaterialZTestOffset.SetFloat("_ZTest", (float)UnityEngine.Rendering.CompareFunction.LessEqual);
            ShapesMaterialZTestOffset.SetFloat("_ZWrite", 1.0f);
            ShapesMaterialZTestOffset.SetFloat("_OFactors", -1.0f);
            ShapesMaterialZTestOffset.SetFloat("_OUnits", -1.0f);
            ShapesMaterialZTestOffset.enableInstancing = true;

            ShapesMaterialZTest2       = new Material(Shader.Find("Battlehub/RTHandles/Shape"));
            ShapesMaterialZTest2.color = new Color(1, 1, 1, 0);
            ShapesMaterialZTest2.SetFloat("_ZTest", (float)UnityEngine.Rendering.CompareFunction.LessEqual);
            ShapesMaterialZTest2.SetFloat("_ZWrite", 1.0f);
            ShapesMaterialZTest2.enableInstancing = true;

            ShapesMaterialZTest3       = new Material(Shader.Find("Battlehub/RTHandles/Shape"));
            ShapesMaterialZTest3.color = new Color(1, 1, 1, 0);
            ShapesMaterialZTest3.SetFloat("_ZTest", (float)UnityEngine.Rendering.CompareFunction.LessEqual);
            ShapesMaterialZTest3.SetFloat("_ZWrite", 1.0f);
            ShapesMaterialZTest3.enableInstancing = true;

            ShapesMaterialZTest4       = new Material(Shader.Find("Battlehub/RTHandles/Shape"));
            ShapesMaterialZTest4.color = new Color(1, 1, 1, 0);
            ShapesMaterialZTest4.SetFloat("_ZTest", (float)UnityEngine.Rendering.CompareFunction.LessEqual);
            ShapesMaterialZTest4.SetFloat("_ZWrite", 1.0f);
            ShapesMaterialZTest4.enableInstancing = true;

            XMaterial                  = new Material(Shader.Find("Battlehub/RTCommon/Billboard"));
            XMaterial.color            = Color.white;
            XMaterial.mainTexture      = Resources.Load <Texture>("Battlehub.RuntimeHandles.x");
            XMaterial.enableInstancing = true;
            YMaterial                  = new Material(Shader.Find("Battlehub/RTCommon/Billboard"));
            YMaterial.color            = Color.white;
            YMaterial.mainTexture      = Resources.Load <Texture>("Battlehub.RuntimeHandles.y");
            YMaterial.enableInstancing = true;
            ZMaterial                  = new Material(Shader.Find("Battlehub/RTCommon/Billboard"));
            ZMaterial.color            = Color.white;
            ZMaterial.mainTexture      = Resources.Load <Texture>("Battlehub.RuntimeHandles.z");
            ZMaterial.enableInstancing = true;

            GridMaterial       = new Material(Shader.Find("Battlehub/RTHandles/Grid"));
            GridMaterial.color = Color.white;
            GridMaterial.SetFloat("_ZTest", (float)UnityEngine.Rendering.CompareFunction.Never);
            GridMaterial.enableInstancing = true;

            Mesh selectionArrowMesh = CreateConeMesh(RTHColors.SelectionColor, HandleScale);
            Mesh disableArrowMesh   = CreateConeMesh(RTHColors.DisabledColor, HandleScale);

            CombineInstance yArrow = new CombineInstance();

            yArrow.mesh      = selectionArrowMesh;
            yArrow.transform = Matrix4x4.TRS(Vector3.up * HandleScale, Quaternion.identity, Vector3.one);
            SelectionArrowY  = new Mesh();
            SelectionArrowY.CombineMeshes(new[] { yArrow }, true);
            SelectionArrowY.RecalculateNormals();

            yArrow.mesh      = disableArrowMesh;
            yArrow.transform = Matrix4x4.TRS(Vector3.up * HandleScale, Quaternion.identity, Vector3.one);
            DisabledArrowY   = new Mesh();
            DisabledArrowY.CombineMeshes(new[] { yArrow }, true);
            DisabledArrowY.RecalculateNormals();

            yArrow.mesh      = CreateConeMesh(RTHColors.YColor, HandleScale);
            yArrow.transform = Matrix4x4.TRS(Vector3.up * HandleScale, Quaternion.identity, Vector3.one);
            ArrowY           = new Mesh();
            ArrowY.CombineMeshes(new[] { yArrow }, true);
            ArrowY.RecalculateNormals();

            CombineInstance xArrow = new CombineInstance();

            xArrow.mesh      = selectionArrowMesh;
            xArrow.transform = Matrix4x4.TRS(Vector3.right * HandleScale, Quaternion.AngleAxis(-90, Vector3.forward), Vector3.one);
            SelectionArrowX  = new Mesh();
            SelectionArrowX.CombineMeshes(new[] { xArrow }, true);
            SelectionArrowX.RecalculateNormals();

            xArrow.mesh      = disableArrowMesh;
            xArrow.transform = Matrix4x4.TRS(Vector3.right * HandleScale, Quaternion.AngleAxis(-90, Vector3.forward), Vector3.one);
            DisabledArrowX   = new Mesh();
            DisabledArrowX.CombineMeshes(new[] { xArrow }, true);
            DisabledArrowX.RecalculateNormals();

            xArrow.mesh      = CreateConeMesh(RTHColors.XColor, HandleScale);
            xArrow.transform = Matrix4x4.TRS(Vector3.right * HandleScale, Quaternion.AngleAxis(-90, Vector3.forward), Vector3.one);
            ArrowX           = new Mesh();
            ArrowX.CombineMeshes(new[] { xArrow }, true);
            ArrowX.RecalculateNormals();

            Vector3         zAxis     = Forward * HandleScale;
            Quaternion      zRotation = InvertZAxis ? Quaternion.AngleAxis(-90, Vector3.right) : Quaternion.AngleAxis(90, Vector3.right);
            CombineInstance zArrow    = new CombineInstance();

            zArrow.mesh      = selectionArrowMesh;
            zArrow.transform = Matrix4x4.TRS(zAxis, zRotation, Vector3.one);
            SelectionArrowZ  = new Mesh();
            SelectionArrowZ.CombineMeshes(new[] { zArrow }, true);
            SelectionArrowZ.RecalculateNormals();

            zArrow.mesh      = disableArrowMesh;
            zArrow.transform = Matrix4x4.TRS(zAxis, zRotation, Vector3.one);
            DisabledArrowZ   = new Mesh();
            DisabledArrowZ.CombineMeshes(new[] { zArrow }, true);
            DisabledArrowZ.RecalculateNormals();

            zArrow.mesh      = CreateConeMesh(RTHColors.ZColor, HandleScale);
            zArrow.transform = Matrix4x4.TRS(zAxis, zRotation, Vector3.one);
            ArrowZ           = new Mesh();
            ArrowZ.CombineMeshes(new[] { zArrow }, true);
            ArrowZ.RecalculateNormals();

            yArrow.mesh = CreateConeMesh(RTHColors.YColor, HandleScale);
            xArrow.mesh = CreateConeMesh(RTHColors.XColor, HandleScale);
            zArrow.mesh = CreateConeMesh(RTHColors.ZColor, HandleScale);
            Arrows      = new Mesh();
            Arrows.CombineMeshes(new[] { yArrow, xArrow, zArrow }, true);
            Arrows.RecalculateNormals();

            SelectionCube = RuntimeGraphics.CreateCubeMesh(RTHColors.SelectionColor, Vector3.zero, HandleScale, 0.1f, 0.1f, 0.1f);
            DisabledCube  = RuntimeGraphics.CreateCubeMesh(RTHColors.DisabledColor, Vector3.zero, HandleScale, 0.1f, 0.1f, 0.1f);
            CubeX         = RuntimeGraphics.CreateCubeMesh(RTHColors.XColor, Vector3.zero, HandleScale, 0.1f, 0.1f, 0.1f);
            CubeY         = RuntimeGraphics.CreateCubeMesh(RTHColors.YColor, Vector3.zero, HandleScale, 0.1f, 0.1f, 0.1f);
            CubeZ         = RuntimeGraphics.CreateCubeMesh(RTHColors.ZColor, Vector3.zero, HandleScale, 0.1f, 0.1f, 0.1f);
            CubeUniform   = RuntimeGraphics.CreateCubeMesh(RTHColors.AltColor, Vector3.zero, HandleScale, 0.1f, 0.1f, 0.1f);

            SceneGizmoSelectedAxis = CreateSceneGizmoHalfAxis(RTHColors.SelectionColor, Quaternion.AngleAxis(90, Vector3.right));
            SceneGizmoXAxis        = CreateSceneGizmoAxis(RTHColors.XColor, RTHColors.AltColor, Quaternion.AngleAxis(-90, Vector3.forward));
            SceneGizmoYAxis        = CreateSceneGizmoAxis(RTHColors.YColor, RTHColors.AltColor, Quaternion.identity);
            SceneGizmoZAxis        = CreateSceneGizmoAxis(RTHColors.ZColor, RTHColors.AltColor, zRotation);
            SceneGizmoCube         = RuntimeGraphics.CreateCubeMesh(RTHColors.AltColor, Vector3.zero, 1);
            SceneGizmoSelectedCube = RuntimeGraphics.CreateCubeMesh(RTHColors.SelectionColor, Vector3.zero, 1);
            SceneGizmoQuad         = RuntimeGraphics.CreateQuadMesh();
        }
Exemplo n.º 2
0
        private void Update()
        {
            if (InputController._GetKeyDown(AddAssetBundleKey2))
            {
                ProjectItem rootFolder = m_projectManager.Project;
                m_projectManager.AddBundledResources(rootFolder, "bundledemo",
                                                     (obj, assetName) =>
                {
                    return(true);
                },
                                                     addedItems =>
                {
                    for (int i = 0; i < addedItems.Length; ++i)
                    {
                        Debug.Log(addedItems[i].ToString() + " added");
                    }
                });
            }


            if (InputController._GetKeyDown(AddAssetBundleKey))
            {
                ProjectItem rootFolder = m_projectManager.Project;
                m_projectManager.AddBundledResource(rootFolder, "bundledemo", "monkey", addedItems =>
                {
                    for (int i = 0; i < addedItems.Length; ++i)
                    {
                        Debug.Log(addedItems[i].ToString() + " added");
                    }
                });
            }

            if (InputController._GetKeyDown(AddWithDependenciesKey))
            {
                ProjectItem        rootFolder = m_projectManager.Project;
                List <UnityObject> objects    = new List <UnityObject>();

                Material material = new Material(Shader.Find("Standard"));
                material.color = Color.yellow;

                Mesh mesh = RuntimeGraphics.CreateCubeMesh(Color.white, Vector3.zero, 1);
                mesh.name = "TestMesh";

                GameObject   go         = new GameObject();
                MeshRenderer renderer   = go.AddComponent <MeshRenderer>();
                MeshFilter   meshFilter = go.AddComponent <MeshFilter>();

                go.name = "TestGO";
                renderer.sharedMaterial = material;
                meshFilter.sharedMesh   = mesh;

                //objects.Add(material);
                //objects.Add(mesh);
                objects.Add(go);

                bool includingDependencies      = true;
                Func <UnityObject, bool> filter = o =>
                {
                    if (o is Shader)
                    {
                        return(false);
                    }
                    return(true);
                };

                m_projectManager.AddDynamicResources(rootFolder, objects.ToArray(), includingDependencies, filter, addedItems =>
                {
                    for (int i = 0; i < addedItems.Length; ++i)
                    {
                        Debug.Log(addedItems[i].ToString() + " added");
                    }

                    for (int i = 0; i < objects.Count; ++i)
                    {
                        Destroy(objects[i]);
                    }
                });
            }


            if (InputController._GetKeyDown(AddInstantiatedObjectKey))
            {
                ProjectItem        rootFolder = m_projectManager.Project;
                List <UnityObject> objects    = new List <UnityObject>();

                Material material = new Material(Shader.Find("Standard"));
                material.color = Color.yellow;

                Mesh mesh = RuntimeGraphics.CreateCubeMesh(Color.white, Vector3.zero, 1);
                mesh.name = "TestMesh";

                GameObject   go       = new GameObject();
                MeshRenderer renderer = go.AddComponent <MeshRenderer>();
                MeshFilter   filter   = go.AddComponent <MeshFilter>();

                go.name = "TestGO";
                renderer.sharedMaterial = material;
                filter.sharedMesh       = mesh;

                objects.Add(material);
                objects.Add(mesh);
                objects.Add(go);

                m_projectManager.AddDynamicResources(rootFolder, objects.ToArray(), addedItems =>
                {
                    for (int i = 0; i < addedItems.Length; ++i)
                    {
                        Debug.Log(addedItems[i].ToString() + " added");
                    }

                    for (int i = 0; i < objects.Count; ++i)
                    {
                        Destroy(objects[i]);
                    }
                });
            }

            if (InputController._GetKeyDown(KeyCode.Keypad7))
            {
                ProjectItem projectItem = m_projectManager.Project.FlattenHierarchy().Where(item => item.Name == "TestGO").FirstOrDefault();
                m_projectManager.GetOrCreateObjects(new[] { projectItem }, result =>
                {
                    Instantiate(result.First().Object);
                });
            }

            if (InputController._GetKeyDown(AddPrefabKey))
            {
                ProjectItem        rootFolder = m_projectManager.Project;
                List <UnityObject> objects    = new List <UnityObject>();

                if (Prefab != null)
                {
                    objects.Add(Prefab);
                }

                bool includingDependencies      = true;
                Func <UnityObject, bool> filter = o =>
                {
                    if (o is Shader)
                    {
                        return(false);
                    }
                    return(true);
                };

                m_projectManager.AddDynamicResources(rootFolder, objects.ToArray(), includingDependencies, filter, addedItems =>
                {
                    for (int i = 0; i < addedItems.Length; ++i)
                    {
                        Debug.Log(addedItems[i].ToString() + " added");
                    }
                });
            }

            if (InputController._GetKeyDown(AddTextureKey))
            {
                ProjectItem        rootFolder = m_projectManager.Project;
                List <UnityObject> objects    = new List <UnityObject>();

                string    path      = Application.streamingAssetsPath + "/" + ImagePath;
                Texture2D texture2D = LoadPNG(path);
                if (texture2D == null)
                {
                    Debug.LogErrorFormat("File {0} not found", path);
                    return;
                }

                texture2D.name = "TestTexture";
                objects.Add(texture2D);

                m_projectManager.AddDynamicResources(rootFolder, objects.ToArray(), addedItems =>
                {
                    for (int i = 0; i < addedItems.Length; ++i)
                    {
                        Debug.Log(addedItems[i].ToString() + " added");
                    }
                });
            }
        }