コード例 #1
0
ファイル: Player.cs プロジェクト: thilinanjana/Space-RPG-Game
    private void InitPlayerObject()
    {
        ProceduralCube cube = gameObject.AddComponent <ProceduralCube>();

        cube.CreateCube(0.75f);
        cube.transform.Translate(new Vector3(0, 1f, 0));
    }
コード例 #2
0
ファイル: ElevatorAbility.cs プロジェクト: yutosin/EdgeGame
    private void CubeSpawn()
    {
        cubePrefab = GameManager.SharedInstance.matSelect.cubePrefab;

        cubeChild = Instantiate(cubePrefab);
        cScript   = cubeChild.GetComponent <ProceduralCube>();
        cScript.SetInitialPos(AbilityFace.Vertices, AbilityFace._rend.material);
    }
コード例 #3
0
        public void AddTestUnitCube(Vector3 vector3)
        {
            ProceduralCube s = new ProceduralCube();

            s.SetColor(Color.White);
            s.Translate(vector3);
            AddAndInitialiseGameObject(GameObjectFactory.CreateRenderableGameObjectFromShape(s, EffectLoader.LoadSM5Effect("flatshaded")));
        }
コード例 #4
0
ファイル: CubeGridController.cs プロジェクト: leelnfei/Radius
    // Use this for initialization
    void Start()
    {
        this.proCube = GetComponent <ProceduralCube>();

        this.boxCollider = GetComponent <BoxCollider>();

        this.UpdateColliderSize();
        this.UpdateProceduralCube();
    }
コード例 #5
0
    // Use this for initialization
    void Start()
    {
        this.proCube = GetComponent<ProceduralCube>();

        this.boxCollider = GetComponent<BoxCollider>();

        this.UpdateColliderSize();
        this.UpdateProceduralCube();
    }
コード例 #6
0
ファイル: SystemCoreHelper.cs プロジェクト: veyvin/SystemWars
        /// <summary>
        /// Sets up default ambient and a single diffuse light for the scene, adds a cube at Vector3.Zero. For scene testing at the start of a project.
        /// </summary>
        public static void SetUpTestCubeAndLighting()
        {
            SystemCore.ActiveScene.SetUpBasicAmbientAndKey();
            ProceduralCube cube = new ProceduralCube();

            cube.SetColor(Color.OrangeRed);
            GameObject.GameObject testObject = GameObjectFactory.CreateRenderableGameObjectFromShape(cube, EffectLoader.LoadSM5Effect("flatshaded"));
            testObject.AddComponent(new RotatorComponent(Vector3.Up, 0.0001f));
            SystemCore.GameObjectManager.AddAndInitialiseGameObject(testObject);
        }
コード例 #7
0
ファイル: OutdoorScene.cs プロジェクト: NickMcCrea/SystemWars
        private void AddPhysicsCube()
        {
            ProceduralCube shape      = new ProceduralCube();
            var            gameObject = new GameObject();

            gameObject.AddComponent(new RenderGeometryComponent(BufferBuilder.VertexBufferBuild(shape),
                                                                BufferBuilder.IndexBufferBuild(shape), shape.PrimitiveCount));
            gameObject.AddComponent(new EffectRenderComponent(EffectLoader.LoadSM5Effect("flatshaded")));
            gameObject.AddComponent(new ShadowCasterComponent());
            gameObject.AddComponent(new PhysicsComponent(true, true, PhysicsMeshType.box));
            gameObject.Transform.SetPosition(RandomHelper.GetRandomVector3(10, 100));
            SystemCore.GetSubsystem <GameObjectManager>().AddAndInitialiseGameObject(gameObject);
        }
コード例 #8
0
        private static void AddCube(ProceduralCube shape, Effect effect, Vector3 position)
        {
            var gameObject = new GameObject();

            gameObject.AddComponent(new RenderGeometryComponent(BufferBuilder.VertexBufferBuild(shape),
                                                                BufferBuilder.IndexBufferBuild(shape), shape.PrimitiveCount));
            gameObject.AddComponent(new EffectRenderComponent(effect));
            gameObject.AddComponent(new ShadowCasterComponent());
            gameObject.AddComponent(new PhysicsComponent(true, true, PhysicsMeshType.box));
            gameObject.Transform.SetPosition(position);
            gameObject.GetComponent <PhysicsComponent>().Simulated = RandomHelper.CoinToss();
            SystemCore.GetSubsystem <GameObjectManager>().AddAndInitialiseGameObject(gameObject);
        }
コード例 #9
0
        public SimpleEnemy()
        {
            ProceduralCube shape = new ProceduralCube();

            AddComponent(new RenderGeometryComponent(BufferBuilder.VertexBufferBuild(shape),
                                                     BufferBuilder.IndexBufferBuild(shape), shape.PrimitiveCount));
            AddComponent(new EffectRenderComponent(EffectLoader.LoadSM5Effect("flatshaded")));
            AddComponent(new ShadowCasterComponent());
            var physicsComponent = new PhysicsComponent(true, true, PhysicsMeshType.box);

            AddComponent(physicsComponent);

            AddComponent(new SimpleEnemyComponent(physicsComponent));
        }
コード例 #10
0
    void UpdateProceduralCube()
    {
        if(!this.proCube)
            this.proCube = GetComponent<ProceduralCube>();

        if(this.proCube)
        {
            this.proCube.BlockCountX = this.BlockCountX;
            this.proCube.BlockCountY = this.BlockCountY;
            this.proCube.BlockCountZ = this.BlockCountZ;
            this.proCube.BlockSize = this.BlockSize;

            this.proCube.RecalculateRingCubeMesh();
        }
    }
コード例 #11
0
ファイル: CubeGridController.cs プロジェクト: leelnfei/Radius
    void UpdateProceduralCube()
    {
        if (!this.proCube)
        {
            this.proCube = GetComponent <ProceduralCube>();
        }

        if (this.proCube)
        {
            this.proCube.BlockCountX = this.BlockCountX;
            this.proCube.BlockCountY = this.BlockCountY;
            this.proCube.BlockCountZ = this.BlockCountZ;
            this.proCube.BlockSize   = this.BlockSize;

            this.proCube.RecalculateRingCubeMesh();
        }
    }
コード例 #12
0
        public override void OnInitialise()
        {
            SystemCore.CursorVisible = false;
            SystemCore.ActiveScene.SetUpBasicAmbientAndKey();
            SystemCore.ActiveScene.SetDiffuseLightDir(0, new Vector3(1, 1, 1));
            colorScheme = SystemCore.ActiveColorScheme;
            SystemCore.ActiveScene.FogEnabled = false;

            SystemCore.PhysicsSimulation.ForceUpdater.Gravity = new BEPUutilities.Vector3(0, -9.81f, 0);


            mouseCamera = new MouseFreeCamera(new Vector3(10, 10, 10));
            SystemCore.SetActiveCamera(mouseCamera);


            var effect = EffectLoader.LoadSM5Effect("FlatShaded");

            //ground plane
            var groundShape = new ProceduralCuboid(100, 100, 0.5f);

            groundShape.SetColor(colorScheme.Color5);
            var gameObjectPlane = new GameObject();

            gameObjectPlane.AddComponent(new RenderGeometryComponent(BufferBuilder.VertexBufferBuild(groundShape), BufferBuilder.IndexBufferBuild(groundShape), groundShape.PrimitiveCount));
            gameObjectPlane.AddComponent(new EffectRenderComponent(effect));
            var groundPhysicsComponent = new PhysicsComponent(false, true, PhysicsMeshType.box);

            gameObjectPlane.AddComponent(groundPhysicsComponent);


            SystemCore.GameObjectManager.AddAndInitialiseGameObject(gameObjectPlane);
            groundPhysicsComponent.PhysicsEntity.IsAffectedByGravity = false;


            var shape = new ProceduralCube();

            shape.SetColor(colorScheme.Color4);

            for (int i = 0; i < 100; i++)
            {
                AddCube(shape, effect, RandomHelper.GetRandomVector3(new Vector3(-10, 2, -10), new Vector3(10, 20, 10)));
            }

            AddInputBindings();
            base.OnInitialise();
        }
コード例 #13
0
        public override void OnInitialise()
        {
            base.OnInitialise();

            SystemCore.ActiveScene.SetUpBasicAmbientAndKey();
            mouseCamera.moveSpeed = 0.01f;

            ProceduralCube cube = new ProceduralCube();

            cube.SetColor(Color.OrangeRed);
            testObject = GameObjectFactory.CreateRenderableGameObjectFromShape(cube, EffectLoader.LoadSM5Effect("flatshaded"));
            testObject.AddComponent(new RotatorComponent(Vector3.Up, 0.0001f));
            SystemCore.GameObjectManager.AddAndInitialiseGameObject(testObject);

            ProceduralPlane plane = new ProceduralPlane();

            plane.Scale(10f);
            plane.SetColor(Color.LightBlue);
            planeToDrawOn = GameObjectFactory.CreateRenderTextureSurface(plane,
                                                                         EffectLoader.LoadSM5Effect("rendertexturesurface"));

            planeToDrawOn.Transform.Rotate(Vector3.Forward, MathHelper.ToRadians(90));
            planeToDrawOn.Transform.Rotate(Vector3.Left, MathHelper.ToRadians(-90));
            //planeToDrawOn.Transform.Rotate(Vector3.Up, MathHelper.ToRadians(-90));
            planeToDrawOn.Transform.SetPosition(new Vector3(-5, 0, 0));

            GameObject.InitialiseAllComponents(planeToDrawOn);

            spriteBatch  = new SpriteBatch(SystemCore.GraphicsDevice);
            renderTarget = new RenderTarget2D(SystemCore.GraphicsDevice, 500, 500);

            renderTextureCamera = new DummyCamera();
            renderTextureCamera.SetPositionAndLookDir(new Vector3(-5, 0, 0), Vector3.Zero, Vector3.Up);
            SystemCore.AddCamera("renderTextureCamera", renderTextureCamera);

            var secondCube = GameObjectFactory.CreateRenderableGameObjectFromShape(new ProceduralCube(),
                                                                                   EffectLoader.LoadSM5Effect("flatshaded"));

            secondCube.Transform.SetPosition(new Vector3(-20, 0, 0));
            SystemCore.GameObjectManager.AddAndInitialiseGameObject(secondCube);

            font = SystemCore.ContentManager.Load <SpriteFont>("Fonts/neuropolitical");
        }
コード例 #14
0
ファイル: Chip8Screen.cs プロジェクト: NickMcCrea/SystemWars
        public override void OnInitialise()
        {
            SystemCore.CursorVisible = false;

            SystemCore.ActiveScene.AddKeyLight(Vector3.Up, Color.White, 1f, false);
            camera       = new DummyOrthographicCamera(SystemCore.Viewport.Width / 10, SystemCore.Viewport.Height / 10, 0.3f, 50f);
            camera.World = Matrix.CreateWorld(new Vector3(0, 20, 0), new Vector3(0, -1, 0), new Vector3(0, 0, 1));
            camera.View  = Matrix.Invert(camera.World);
            SystemCore.SetActiveCamera(camera);


            for (int i = 1; i < 64 * 32; i++)
            {
                var cube = new ProceduralCube();
                cube.SetColor(RandomHelper.RandomColor);
                var ball = GameObjectFactory.CreateRenderableGameObjectFromShape(cube, EffectLoader.LoadSM5Effect("flatshaded"));

                int column = i % 64;
                int row    = i / 64;

                ball.Transform.SetPosition(new Vector3(-(column - 1), 0, row));


                SystemCore.GameObjectManager.AddAndInitialiseGameObject(ball);
            }

            //var cube = new ProceduralCube();
            //cube.SetColor(Color.White);
            //ball = GameObjectFactory.CreateRenderableGameObjectFromShape(cube, EffectLoader.LoadSM5Effect("flatshaded"));
            //ball.Transform.SetPosition(Vector3.Zero);

            //SystemCore.GameObjectManager.AddAndInitialiseGameObject(ball);


            //Initialise
            InitialiseEmulator();


            //load ROM
            LoadRom("PONG");

            base.OnInitialise();
        }
コード例 #15
0
ファイル: Building.cs プロジェクト: NickMcCrea/SystemWars
        public MainBase()
        {
            Health = 100;
            Size   = 8;

            ProceduralCube shape = new ProceduralCube();

            shape.Scale(Size);
            shape.SetColor(Color.Blue);
            AddComponent(new RenderGeometryComponent(BufferBuilder.VertexBufferBuild(shape),
                                                     BufferBuilder.IndexBufferBuild(shape), shape.PrimitiveCount));
            AddComponent(new EffectRenderComponent(EffectLoader.LoadSM5Effect("flatshaded")));
            AddComponent(new ShadowCasterComponent());
            var physicsComponent = new PhysicsComponent(false, false, PhysicsMeshType.box);

            AddComponent(physicsComponent);

            SystemCore.GameObjectManager.AddAndInitialiseGameObject(this);
            GetComponent <PhysicsComponent>().PhysicsEntity.CollisionInformation.Events.DetectingInitialCollision += Events_DetectingInitialCollision;
        }
コード例 #16
0
    /// <summary>
    /// Spawns a procedural cube
    /// </summary>
    /// <param name="location">Where in the world to spawn the cube</param>
    /// <param name="size">The size of the cube (default is 1x1x1)</param>
    public static ProceduralCube Create(Vector3 location, Vector3 size, float gridSize)
    {
        GameObject cube = new GameObject("Procedural Cube");

        cube.transform.position = Grid.Snap(location, gridSize);
        Material       mat  = Instantiate(Resources.Load <Material>("DefaultMaterial"));
        ProceduralCube proc = cube.AddComponent <ProceduralCube>();

        proc.EndPosition = cube.transform.position + size;
        MeshFilter   filter   = cube.AddComponent <MeshFilter>();
        MeshRenderer renderer = cube.AddComponent <MeshRenderer>();

        renderer.material = mat;

        cube.AddComponent <BoxCollider>();

        proc.UpdateMesh(gridSize);

        return(proc);
    }
コード例 #17
0
    public void MakeDiscreteProceduralCubeGrid()
    {
        _vertices  = new Vector3[GridSize * GridSize * 4];
        _triangles = new int[GridSize * GridSize * 6];

        float vertexOffset = CellSize * 0.5f; // Multiplication is not as intensive as division.

        for (int x = 0; x < GridSize; x++)
        {
            for (int z = 0; z < GridSize; z++)
            {
                Vector3 cellOffset = new Vector3(x * CellSize, x + z, z * CellSize);

                GameObject     cubeObject = new GameObject();
                ProceduralCube cube       = cubeObject.AddComponent <ProceduralCube>();
                //cube.CreateCube(cube.scale * 0.5f);
                cubeObject.transform.position = cellOffset;
            }
        }
    }
コード例 #18
0
ファイル: GridWarrior.cs プロジェクト: veyvin/SystemWars
        protected override void Initialise()
        {
            ProceduralCube playerShape = new ProceduralCube();

            playerShape.Scale(5f);

            AddComponent(new RenderGeometryComponent(BufferBuilder.VertexBufferBuild(playerShape),
                                                     BufferBuilder.IndexBufferBuild(playerShape), playerShape.PrimitiveCount));

            AddComponent(new EffectRenderComponent(EffectLoader.LoadSM5Effect("flatshaded")));

            AddComponent(new PhysicsComponent(true, false, PhysicsMeshType.box));

            Name = "player";


            AddComponent(new TopDownMouseAndKeyboardController());
            SystemCore.GameObjectManager.AddAndInitialiseGameObject(this);
            physicsComponent = GetComponent <PhysicsComponent>();
            base.Initialise();
        }
コード例 #19
0
        public override void OnInitialise()
        {
            SystemCore.CursorVisible = false;

            SystemCore.ActiveScene.AddKeyLight(Vector3.Up, Color.White, 1f, false);
            camera       = new DummyOrthographicCamera(SystemCore.Viewport.Width / 10, SystemCore.Viewport.Height / 10, 0.3f, 50f);
            camera.World = Matrix.CreateWorld(new Vector3(0, 20, 0), new Vector3(0, -1, 0), new Vector3(0, 0, 1));
            camera.View  = Matrix.Invert(camera.World);
            SystemCore.SetActiveCamera(camera);


            var cube = new ProceduralCube();

            cube.SetColor(Color.White);
            ball = GameObjectFactory.CreateRenderableGameObjectFromShape(cube, EffectLoader.LoadSM5Effect("flatshaded"));
            ball.Transform.SetPosition(Vector3.Zero);

            SystemCore.GameObjectManager.AddAndInitialiseGameObject(ball);

            base.OnInitialise();
        }
コード例 #20
0
ファイル: ModelEditor.cs プロジェクト: veyvin/SystemWars
        public void AddVoxel(Color color)
        {
            if (!RenderGrid)
            {
                return;
            }

            if (currentbuildPoint.X < -modellingAreaSize / 2 || currentbuildPoint.X > modellingAreaSize / 2)
            {
                return;
            }
            if (currentbuildPoint.Y < -modellingAreaSize / 2 || currentbuildPoint.Y > modellingAreaSize / 2)
            {
                return;
            }
            if (currentbuildPoint.Z < -modellingAreaSize / 2 || currentbuildPoint.Z > modellingAreaSize / 2)
            {
                return;
            }

            ProceduralCube c = new ProceduralCube();

            c.SetColor(color);

            //this object is for visualisation in the editor only. The procedural shape will be
            //cached and used to bake the final shape for serialization
            var tempObject = GameObjectFactory.CreateRenderableGameObjectFromShape(c,
                                                                                   EffectLoader.LoadSM5Effect("flatshaded"));

            tempObject.AddComponent(new PhysicsComponent(false, false, PhysicsMeshType.box));

            SystemCore.GameObjectManager.AddAndInitialiseGameObject(tempObject);
            tempObject.Transform.SetPosition(currentbuildPoint);

            //shape is translated
            c.Translate(currentbuildPoint);
            shapesToBake.Add(tempObject, c);
        }
コード例 #21
0
    public void CreateNewCubeObject()
    {
        ProceduralCube shape = new ProceduralCube(Subdivisions);

        shape.GenerateUVs();

        Mesh mesh = new Mesh
        {
            name      = "Cube_Mesh",
            vertices  = shape.Vertices.Select(v => v.Position).ToArray(),
            uv        = shape.Vertices.Select(v => v.UV).ToArray(),
            triangles = ProceduralShape.TriFace.TriFaceListToIndexArray(shape.TriFaces),
        };

        mesh.Optimize();
        mesh.RecalculateNormals();
        mesh.RecalculateTangents();

        GameObject cube = new GameObject("Cube", typeof(MeshFilter), typeof(MeshRenderer));

        cube.GetComponent <MeshFilter>().sharedMesh = mesh;
        cube.GetComponent <MeshRenderer>().material = DefaultMaterial;
    }
コード例 #22
0
ファイル: DuneBuggy.cs プロジェクト: NickMcCrea/SystemWars
        public DuneBuggy(PlayerIndex player, Color color, Microsoft.Xna.Framework.Vector3 position)
        {
            this.playerIndex = player;

            this.vehicle = VehicleFactory.Create(position.ToBepuVector());
            SystemCore.PhysicsSimulation.Add(vehicle);

            var shape = new ProceduralCuboid(2.5f / 2, 4.5f / 2, .75f / 2);

            shape.SetColor(color);
            BuggyObject = GameObjectFactory.CreateRenderableGameObjectFromShape(shape, EffectLoader.LoadSM5Effect("flatshaded"));
            BuggyObject.AddComponent(new ShadowCasterComponent());

            SystemCore.GameObjectManager.AddAndInitialiseGameObject(BuggyObject);

            wheels = new List <GameObject>();
            foreach (Wheel w in vehicle.Wheels)
            {
                var cube = new ProceduralCube();
                cube.SetColor(Color.Maroon);
                var wheel = GameObjectFactory.CreateRenderableGameObjectFromShape(cube, EffectLoader.LoadSM5Effect("flatshaded"));
                wheel.AddComponent(new ShadowCasterComponent());

                var particles = new SquareParticleSystem();

                wheel.AddComponent(particles);

                SystemCore.GameObjectManager.AddAndInitialiseGameObject(wheel);

                particles.settings.Duration = TimeSpan.FromSeconds(2f);

                wheels.Add(wheel);
            }

            uprightSpringConstraint = new UprightSpring(vehicle.Body, BEPUutilities.Vector3.Up, 0.1f, (float)Math.PI, 1000f);
            SystemCore.PhysicsSimulation.Add(uprightSpringConstraint);
        }
コード例 #23
0
 private void MoveOutByOne()
 {
     if (cubeChild == null)
     {
         cubeChild = Instantiate(cubePrefab);
         cScript   = cubeChild.GetComponent <ProceduralCube>();
         cScript.SetInitialPos(AbilityFace.Vertices, AbilityFace._rend.material);
     }
     if (cubeChild.transform.parent != null)
     {
         cubeChild.transform.parent = null;
     }
     if (xMove)
     {
         targetPos.x += 1;
     }
     else
     {
         targetPos.z += 1;
     }
     AbilityTimes--;
     IsActing = true;
     GameManager.SharedInstance.AudioManager.PlaySoundEffect(GameManager.SharedInstance.AudioManager.CubeRaiseShort);
 }
コード例 #24
0
    void OnGUI()
    {
        GetSceneResources();
        //Check for window resizing and update rendertexture accordingly.
        if (position.width != lastSize.x || position.height != lastSize.y)
        {
            Resize();
        }

        foreach (var cube in FindObjectsOfType <ProceduralCube>())
        {
            int newVal = 0;
            if (Selection.gameObjects.Contains(cube.gameObject))
            {
                newVal = 1;
            }

            cube.GetComponent <MeshRenderer>().sharedMaterial.SetInt("_selected", newVal);
            Repaint();
        }

        //Get Input
        mouseScreenPos   = Event.current.mousePosition;
        mouseScreenPos.y = viewCamera.pixelHeight - Event.current.mousePosition.y;

        if (Event.current.type == EventType.KeyDown)
        {
            if (Event.current.keyCode == KeyCode.Tab)
            {
                switch (currentCamDirection)
                {
                case cameraDirection.Top:
                    currentCamDirection = cameraDirection.Left;
                    break;

                case cameraDirection.Left:
                    currentCamDirection = cameraDirection.Right;
                    break;

                case cameraDirection.Right:
                    currentCamDirection = cameraDirection.Front;
                    break;

                case cameraDirection.Front:
                    currentCamDirection = cameraDirection.Back;
                    break;

                case cameraDirection.Back:
                    currentCamDirection = cameraDirection.Top;
                    break;
                }

                UpdateViewDirection();
                ShowNotification(new GUIContent(currentCamDirection.ToString()));
            }
            else if (Event.current.keyCode == KeyCode.A)
            {
                currentCamDirection = cameraDirection.Front;
                UpdateViewDirection();
                ShowNotification(new GUIContent(currentCamDirection.ToString()));
            }
            else if (Event.current.keyCode == KeyCode.D)
            {
                currentCamDirection = cameraDirection.Back;
                UpdateViewDirection();
                ShowNotification(new GUIContent(currentCamDirection.ToString()));
            }
            else if (Event.current.keyCode == KeyCode.E)
            {
                currentCamDirection = cameraDirection.Right;
                UpdateViewDirection();
                ShowNotification(new GUIContent(currentCamDirection.ToString()));
            }
            else if (Event.current.keyCode == KeyCode.Q)
            {
                currentCamDirection = cameraDirection.Left;
                UpdateViewDirection();
                ShowNotification(new GUIContent(currentCamDirection.ToString()));
            }
            else if (Event.current.keyCode == KeyCode.W)
            {
                currentCamDirection = cameraDirection.Top;
                UpdateViewDirection();
                ShowNotification(new GUIContent(currentCamDirection.ToString()));
            }
            else if (Event.current.keyCode == KeyCode.Equals)
            {
                if (gridSize < 64)
                {
                    gridSize = gridSize * 2;
                }

                ShowNotification(new GUIContent(gridSize.ToString()));
                Repaint();
            }
            else if (Event.current.keyCode == KeyCode.Minus)
            {
                if (gridSize > 0.0625)
                {
                    gridSize = gridSize / 2;
                }

                ShowNotification(new GUIContent(gridSize.ToString()));
                Repaint();
            }
            else if (Event.current.keyCode == KeyCode.Delete)
            {
                foreach (var gameObject in Selection.gameObjects)
                {
                    DestroyImmediate(gameObject);
                }
                Repaint();
            }
            else if (Event.current.keyCode == KeyCode.X)
            {
                wireFrame = !wireFrame;
            }
        }

        if (Event.current.type == EventType.MouseDrag && Event.current.button == 2)
        {
            viewCamera.transform.position += GetMoveDirection(Event.current.delta) * (viewCamera.orthographicSize / 5);
            Repaint();
        }

        if (Event.current.type == EventType.MouseDrag)
        {
            if (isLeftClickDown)
            {
                mouseDragDelta  = mouseScreenPos - mouseDragStartScreenPos;
                wasMouseDragged = true;
            }
        }

        if (Event.current.type == EventType.MouseDown && Event.current.button == 0)
        {
            var  ray = viewCamera.ScreenPointToRay(mouseScreenPos);
            bool didClickOnObject = false;
            if (Physics.Raycast(ray, out RaycastHit hit, Single.PositiveInfinity))
            {
                if (hit.transform.gameObject.GetComponent <ProceduralCube>())
                {
                    if (Event.current.shift)
                    {
                        Selection.activeGameObject = hit.transform.gameObject;
                    }

                    if (hit.transform.gameObject == Selection.activeGameObject)
                    {
                        didClickOnObject = true;
                    }
                }
            }

            if (didClickOnObject)
            {
                transformationOperation = TransformationOperation.Move;
            }
            else
            {
                transformationOperation = TransformationOperation.Resize;
            }

            mouseDragStartScreenPos = mouseScreenPos;

            isLeftClickDown = true;
        }

        if (Event.current.type == EventType.MouseUp && Event.current.button == 0)
        {
            var  ray     = viewCamera.ScreenPointToRay(mouseScreenPos);
            bool raycast = Physics.Raycast(ray, out RaycastHit hit, Single.PositiveInfinity);

            if (Selection.gameObjects.Length == 0 && !raycast)
            {
                Create();
            }
            else
            {
                if (!raycast && !wasMouseDragged)
                {
                    Selection.activeGameObject = null;
                }
            }

            void Create()
            {
                var pos = ConvertToCameraRelative(viewCamera.ScreenToWorldPoint(mouseScreenPos));

                if (ProceduralCube.Create(pos, gridSize * Vector3.one, gridSize) != null)
                {
                    Repaint();
                }

                var scene = SceneManager.GetActiveScene();

                EditorSceneManager.MarkSceneDirty(scene);
            }

            mouseDragStartScreenPos = Vector3.zero;
            isLeftClickDown         = false;
            wasMouseDragged         = false;
        }

        if (Event.current.type == EventType.ScrollWheel)
        {
            var d = Event.current.delta.y;
            viewCamera.orthographicSize += d / 5;
            viewCamera.orthographicSize  = Mathf.Clamp(viewCamera.orthographicSize, .5f, 100);

            Repaint();
        }

        if (Event.current.type == EventType.Repaint)
        {
            gridPlane.transform.localScale  = new Vector3(position.width / position.height, 1, 1);
            gridPlane.transform.localScale *= (viewCamera.orthographicSize / 5f);

            gridMaterial.SetFloat("_GridSize", gridSize);

            var clearFlags = viewCamera.clearFlags;

            viewCamera.targetTexture = renderTexture;

            if (wireFrame)
            {
                GL.wireframe = true;
            }
            else
            {
                gridPlane.SetActive(true);
            }

            viewCamera.Render();
            gridPlane.SetActive(false);

            RenderTexture rt = RenderTexture.active;

            RenderTexture.active = selectionRenderTexture;
            GL.Clear(true, true, Color.clear);

            RenderTexture.active = rt;

            viewCamera.clearFlags = CameraClearFlags.Depth;
            viewCamera.SetReplacementShader(replacementShader, "RenderType");
            viewCamera.targetTexture = selectionRenderTexture;
            GL.wireframe             = false;
            viewCamera.Render();
            viewCamera.SetReplacementShader(null, "");
            viewCamera.clearFlags = clearFlags;

            viewCamera.targetTexture = renderTexture;
        }

        //Selection.activeObject = renderTexture;
        GUI.DrawTexture(new Rect(0, 0, position.width, position.height), renderTexture);
        GUI.DrawTexture(new Rect(0, 0, position.width, position.height), selectionRenderTexture);
    }
コード例 #25
0
 private void Test()
 {
     ProceduralCube cube = gameObject.AddComponent <ProceduralCube>();
 }