Beispiel #1
0
 void Start()
 {
     movementDelegate += TrackInput;
     movementDelegate += Move;
     movementDelegate += Rotate;
     movementDelegate += Action;
 }
Beispiel #2
0
 public void ChangeDirection(Key newDirection)
 {
     if ((newDirection != currentDirection) && (newDirection != counterDirection))
     {
         if (newDirection == Key.Right)
         {
             this.currentDirection = Key.Right;
             this.counterDirection = Key.Left;
             this.currentMovement  = GoRight;
         }
         if (newDirection == Key.Left)
         {
             this.currentDirection = Key.Left;
             this.counterDirection = Key.Right;
             this.currentMovement  = GoLeft;
         }
         if (newDirection == Key.Up)
         {
             this.currentDirection = Key.Up;
             this.counterDirection = Key.Down;
             this.currentMovement  = GoUp;
         }
         if (newDirection == Key.Down)
         {
             this.currentDirection = Key.Down;
             this.counterDirection = Key.Up;
             this.currentMovement  = GoDown;
         }
     }
 }
Beispiel #3
0
        public Snake(Canvas boardOfGame)
        {
            this.board  = boardOfGame;
            head        = new SnakeSegment(300, 300);
            segments    = new Queue <SnakeSegment>();
            queueLength = 3;
            foodObject  = new Food();
            foodObject.moveToNewPlace(this.board, this);

            snakeTimer          = new System.Windows.Threading.DispatcherTimer();
            snakeTimer.Tick    += new EventHandler(dispatcherTimer_Tick);
            snakeTimer.Interval = new TimeSpan(0, 0, 0, 0, 80);
            snakeTimer.Start();

            this.currentMovement = GoUp;

            printMe();
        }
Beispiel #4
0
    // Update is called once per frame
    void FixedUpdate()
    {
        Vector3 newPos = transform.position;

        if (controller.isGrounded)
        {
            newPos += Physics.gravity;
        }
        if (state >= MonState.Derpy)
        {
            //Vector3 oldPos = transform.position;
            MovementDelegate f     = movementDelegates[(int)movementOptions];
            float            angle = f(this) * 360;
            rotation.eulerAngles = new Vector3(0, Mathf.Clamp(angle, -360f, 360f), 0);
            transform.rotation   = rotation;
            newPos             = newPos + transform.forward * Time.fixedDeltaTime * movementSpeed;
            transform.position = newPos;
        }
    }
Beispiel #5
0
        private static void Main(string[] args)
        {
            if (File.Exists(Path.Combine(System.Environment.CurrentDirectory, @"..\..\log.txt")))
            {
            File.Delete(Path.Combine(System.Environment.CurrentDirectory, @"..\..\log.txt"));
            }

            if (File.Exists(Path.Combine(System.Environment.CurrentDirectory, @"..\..\sortLog.txt")))
            {
                File.Delete(Path.Combine(System.Environment.CurrentDirectory, @"..\..\sortLog.txt"));
            }
            if (File.Exists(Path.Combine(System.Environment.CurrentDirectory, @"..\..\OpenCLDebugLog.txt")))
            {
                File.Delete(Path.Combine(System.Environment.CurrentDirectory, @"..\..\OpenCLDebugLog.txt"));
            }

            numElements--;
            numElements |= numElements >> 1;
            numElements |= numElements >> 2;
            numElements |= numElements >> 4;
            numElements |= numElements >> 8;
            numElements |= numElements >> 16;
            numElements++;

            Random generator = new Random();
            Console.SetWindowSize(Console.LargestWindowWidth/2,Console.LargestWindowHeight/2);
            /*
            ISpatialEntity[] testSpatials = new ISpatialEntity[numElements];
             for (int i = 2; i < testSpatials.Length; i++)
            {
                testSpatials[i] = new TestSpatialEntity(new Vector3(1, 1, 1));
                testSpatials[i].Shape = new Cuboid(new Vector3(1, 1, 1), new Vector3(generator.Next(1,100), generator.Next(1,100), generator.Next(1,100)), null);
                Console.WriteLine("GUID = "+ testSpatials[i].AgentGuid);
                Console.WriteLine(string.Format("Pos: x={0} , y ={1}, z={2} ", testSpatials[i].Shape.Bounds.Position.X, testSpatials[i].Shape.Bounds.Position.Y, testSpatials[i].Shape.Bounds.Position.Z));
                Console.WriteLine(string.Format("Min: x={0} , y ={1}, z={2} ", testSpatials[i].Shape.Bounds.LeftBottomFront.X, testSpatials[i].Shape.Bounds.LeftBottomFront.Y, testSpatials[i].Shape.Bounds.LeftBottomFront.Z, testSpatials[i].AgentGuid));
                Console.WriteLine(string.Format("Max: x={0} , y ={1}, z={2} ", testSpatials[i].Shape.Bounds.RightTopRear.X, testSpatials[i].Shape.Bounds.RightTopRear.Y, testSpatials[i].Shape.Bounds.RightTopRear.Z, testSpatials[i].AgentGuid));
                Console.WriteLine();
                // Console.Write(" " + testData[i]);#3##2#
            }
             testSpatials[0] = new TestSpatialEntity(new Vector3(1, 1, 1));
             testSpatials[0].Shape = new Cuboid(new Vector3(1, 1, 1), new Vector3(3, 3, 2), null);

             testSpatials[1] = new TestSpatialEntity(new Vector3(1, 1, 1));
             testSpatials[1].Shape = new Cuboid(new Vector3(1, 1, 1), new Vector3(3, 2.5, 2), null);

              testSpatials[0] = new TestSpatialEntity(new Vector3(1, 1, 1));
              testSpatials[0].Shape = new Cuboid(new Vector3(1, 1, 1), new Vector3(2,2,2), null);

              testSpatials[1] = new TestSpatialEntity(new Vector3(1, 1, 1));
              testSpatials[1].Shape = new Cuboid(new Vector3(1, 1, 1), new Vector3(2,2,2), null);

              testSpatials[2] = new TestSpatialEntity(new Vector3(1, 1, 1));
              testSpatials[2].Shape = new Cuboid(new Vector3(1, 1, 1), new Vector3(4,4,2), null);

              testSpatials[3] = new TestSpatialEntity(new Vector3(1, 1, 1));
              testSpatials[3].Shape = new Cuboid(new Vector3(1, 1, 1), new Vector3(4, 4, 2), null);#1#

               for (int i = 0; i < numElements; i++)
            {
                Console.WriteLine("GUID = " + testSpatials[i].AgentGuid);
                Console.WriteLine(string.Format("Pos: x={0} , y ={1}, z={2} ", testSpatials[i].Shape.Bounds.Position.X, testSpatials[i].Shape.Bounds.Position.Y, testSpatials[i].Shape.Bounds.Position.Z));
                Console.WriteLine(string.Format("Min: x={0} , y ={1}, z={2} ", testSpatials[i].Shape.Bounds.LeftBottomFront.X, testSpatials[i].Shape.Bounds.LeftBottomFront.Y, testSpatials[i].Shape.Bounds.LeftBottomFront.Z));
                Console.WriteLine(string.Format("Max: x={0} , y ={1}, z={2} ", testSpatials[i].Shape.Bounds.RightTopRear.X, testSpatials[i].Shape.Bounds.RightTopRear.Y, testSpatials[i].Shape.Bounds.RightTopRear.Z));
                Console.WriteLine();

            }
            #1#
               // compute the next highest power of 2 of 32-bit v

            /*

            #1#
            int[] testData = new int[numElements];
            int[] testResult = new int[numElements];
            for (int i = 0; i < testData.Length; i++)
            {
                testData[i] = generator.Next(1000000);
                // Console.Write(" " + testData[i]);#3#
            }
            Console.WriteLine();
            Program ins = new Program();
            ins.Setup();

            var radix = new GPURadixSort(cqCommandQueue, cxGPUContext, _device);

            Event eve;
            ErrorCode error;
            IMem inputBuff = Cl.CreateBuffer(cxGPUContext, MemFlags.ReadWrite, (IntPtr)(numElements * 4), testData,
                out error);
            ins.CheckErr(error, "Createbuffer");
            IMem outputBuff = Cl.CreateBuffer(cxGPUContext, MemFlags.ReadWrite, (IntPtr)(numElements * 4),
                out error);
            ins.CheckErr(error, "Createbuffer");

            error = Cl.EnqueueWriteBuffer(cqCommandQueue, inputBuff, Bool.True, IntPtr.Zero, (IntPtr)(numElements * 4),
                testData, 0, null,
                out eve);
            ins.CheckErr(error, "EnqBuffer");
            error = Cl.Finish(cqCommandQueue);
            ins.CheckErr(error, "Cl.Finish");
            */

            #region RadixSortTest

            /*            DateTime before = DateTime.Now;
            radix.sortKeysOnly(inputBuff, outputBuff, numElements);

            error = Cl.EnqueueWriteBuffer(cqCommandQueue, inputBuff, Bool.True, IntPtr.Zero, (IntPtr)(numElements * 4),
                testData, 0, null,
                out eve);
            ins.CheckErr(error, "EnqBuffer");

            radix.sortKeysOnly(inputBuff, outputBuff, numElements);*/

                //Collision Detection tests
            /*
            CollisionDetection detec = new CollisionDetection(cqCommandQueue,cxGPUContext,_device,radix,new Point3D(150,150,150),new Vector3(2,2,2) );
            IMem inp;
            IMem outp;
            detec.CreateCellIdArray(testSpatials,out inp, out outp);
            #1#

            */
            #endregion

            /*
               radix.sortKeysOnly(inputBuff, outputBuff, numElements);
            #1#

            error = Cl.EnqueueReadBuffer(cqCommandQueue, outputBuff, Bool.True, IntPtr.Zero, (IntPtr)(numElements * 4),
                testResult, 0, null, out eve);
            ins.CheckErr(error, "Cl.EnqueueReadBuffer");

            //Execute our kernel (OpenCL code)
            error = Cl.Finish(cqCommandQueue);
            ins.CheckErr(error, "Cl.Finish");
            Console.WriteLine("Execution time Gpu ="+( DateTime.Now- before ).TotalMilliseconds);
               /* for (int i = 0; i < numElements; i++)
            {
                Console.Write(" " + testResult[i]);
            }#1#
            before = DateTime.Now;
            Array.Sort(testData);
            Console.WriteLine("Execution time CPU =" + (DateTime.Now - before).TotalMilliseconds);
            int r = 0;

            */

               MovementDelegate moveDel = new MovementDelegate(dele1);
            ExploreDelegate expDel = new ExploreDelegate(dele2);
            generator = new Random();
            Console.SetWindowSize(Console.LargestWindowWidth / 2, Console.LargestWindowHeight / 2);

            ISpatialEntity[] testSpatials = new ISpatialEntity[numElements];

            GpuESC esc = new GpuESC(new Vector3(2, 2, 2), new Vector3(2000000, 8, 8));

            for (int i = 2; i < testSpatials.Length; i++)
            {
                testSpatials[i] = new TestSpatialEntity(new Vector3(0.5, 0.5, 0.5));
                Vector3 actos = new Vector3(i + 0.1, 1.5, 1.5);
                testSpatials[i].Shape = new Cuboid(new Vector3(0.5, 0.5, 0.5), actos, null);
                /*Console.WriteLine("GUID = " + testSpatials[i].AgentGuid);
                Console.WriteLine(string.Format("Pos: x={0} , y ={1}, z={2} ", testSpatials[i].Shape.Bounds.Position.X, testSpatials[i].Shape.Bounds.Position.Y, testSpatials[i].Shape.Bounds.Position.Z));
                Console.WriteLine(string.Format("Min: x={0} , y ={1}, z={2} ", testSpatials[i].Shape.Bounds.LeftBottomFront.X, testSpatials[i].Shape.Bounds.LeftBottomFront.Y, testSpatials[i].Shape.Bounds.LeftBottomFront.Z, testSpatials[i].AgentGuid));
                Console.WriteLine(string.Format("Max: x={0} , y ={1}, z={2} ", testSpatials[i].Shape.Bounds.RightTopRear.X, testSpatials[i].Shape.Bounds.RightTopRear.Y, testSpatials[i].Shape.Bounds.RightTopRear.Z, testSpatials[i].AgentGuid));
             */   // Console.WriteLine();
                // Console.Write(" " + testData[i]);#3##2#*/
                esc.Add(testSpatials[i], actos, null, moveDel);
            }
            testSpatials[0] = new TestSpatialEntity(new Vector3(1, 1, 1));
            testSpatials[0].Shape = new Cuboid(new Vector3(1, 1, 1), new Vector3(3, 3, 2), null);
            esc.Add(testSpatials[0], testSpatials[0].Shape.Position, null, moveDel);

            testSpatials[1] = new TestSpatialEntity(new Vector3(1, 1, 1));
            testSpatials[1].Shape = new Cuboid(new Vector3(1, 1, 1), new Vector3(3, 3, 2), null);
            Console.WriteLine(testSpatials[0].AgentGuid);
            Console.WriteLine(testSpatials[1].AgentGuid);

            esc.Add(testSpatials[1], testSpatials[1].Shape.Position, null, moveDel);
            var before = DateTime.Now;
            for (int i = 0; i <10; i++)
            {
                esc.Commit();
            }

            Console.WriteLine("Execution time Total =" + (DateTime.Now - before).TotalMilliseconds);
            Console.WriteLine(collisionCount);
            int asdcyxcsa = 2;
        }
Beispiel #6
0
        public void Resize(ISpatialEntity entity, IShape shape, MovementDelegate movementDelegate)
        {
            // TODO: Check if shape > cellsize
            if (gpuActive) gpuActiveWait.WaitOne();
            Interlocked.Increment(ref m_ActiveOperationCount);
            long objId = spatialObjIdMap[entity];
            var newEnt = entity;
            newEnt.Shape = shape;
            spatialObjIdMap.Remove(entity);
            spatialObjIdMap.Add(newEnt, objId);
            objIdSpatialMap[(int)objId].Shape = shape;
            shapeList.Remove(objIdClShapeMap[(int)objId]);
            m_MoveDelegates.Add(new Tuple<long, MovementDelegate>(objId, movementDelegate));

            clShapeObject act;
            clPoint center;
            center.x = (float)entity.Shape.Bounds.Position.X;
            center.y = (float)entity.Shape.Bounds.Position.Y;
            center.z = (float)entity.Shape.Bounds.Position.Z;
            clPoint front;
            front.x = (float)entity.Shape.Bounds.LeftBottomFront.X;
            front.y = (float)entity.Shape.Bounds.LeftBottomFront.Y;
            front.z = (float)entity.Shape.Bounds.LeftBottomFront.Z;
            clPoint rear;
            rear.x = (float)entity.Shape.Bounds.RightTopRear.X;
            rear.y = (float)entity.Shape.Bounds.RightTopRear.Y;
            rear.z = (float)entity.Shape.Bounds.RightTopRear.Z;
            act.center = center;
            act.leftBottomFront = front;
            act.rigthTopRear = rear;
            shapeList.Add(act);
            objIdClShapeMap[(int)objId] = act;
            Interlocked.Decrement(ref m_ActiveOperationCount);
        }
Beispiel #7
0
        public void Move(ISpatialEntity entity, Vector3 movementVector, Direction rotation, MovementDelegate movementDelegate)
        {
            if (gpuActive) gpuActiveWait.WaitOne();
            Interlocked.Increment(ref m_ActiveOperationCount);
            var objId = spatialObjIdMap[entity];
            objId &= (~(0xFFFFFFFF << 32));
            objId |= FLAG_MOVE;
            var newEnt = entity;
            var newShape = newEnt.Shape.Transform(movementVector, rotation);
            newEnt.Shape = newShape;
            spatialObjIdMap.Remove(entity);
            spatialObjIdMap.Add(newEnt, objId);
            objIdSpatialMap[(int)objId].Shape = newShape;

            //shapeList.Remove(objIdClShapeMap[objId]);

            envActEnvObjs.Remove(objId);
            // TODO Testen ob es auch mit Konstruktoren funktioniert
            clShapeObject act;
            clPoint center;
            center.x = (float)entity.Shape.Bounds.Position.X;
            center.y = (float)entity.Shape.Bounds.Position.Y;
            center.z = (float)entity.Shape.Bounds.Position.Z;
            clPoint front;
            front.x = (float)entity.Shape.Bounds.LeftBottomFront.X;
            front.y = (float)entity.Shape.Bounds.LeftBottomFront.Y;
            front.z = (float)entity.Shape.Bounds.LeftBottomFront.Z;
            clPoint rear;
            rear.x = (float)entity.Shape.Bounds.RightTopRear.X;
            rear.y = (float)entity.Shape.Bounds.RightTopRear.Y;
            rear.z = (float)entity.Shape.Bounds.RightTopRear.Z;
            act.center = center;
            act.leftBottomFront = front;
            act.rigthTopRear = rear;
            envActEnvObjs[objId] = act;
            //shapeList.Add(act);
            objIdClShapeMap[(int)objId] = act;
            Interlocked.Decrement(ref m_ActiveOperationCount);
        }
Beispiel #8
0
        public void AddWithRandomPosition(ISpatialEntity entity, Vector3 min, Vector3 max, bool grid, MovementDelegate movementDelegate)
        {
            //Evaluate dimesions
            var shapeTmp = new Vector3(entity.Shape.Bounds.Length / 2, entity.Shape.Bounds.Height / 2, entity.Shape.Bounds.Width / 2);
            if (!checkBoundarys(min - shapeTmp, max + shapeTmp))
            {
                movementDelegate.Invoke(new MovementResult());
                return;
            }
            if (gpuActive) gpuActiveWait.WaitOne();
            Interlocked.Increment(ref m_ActiveOperationCount);
            Vector3 freepos = GetNextFreeCell(min, max);
            if (freepos == Vector3.Null)
            {
                var rnd = new Random();
                freepos = new Vector3((double)rnd.Next((int)min.X, (int)max.X), (double)rnd.Next((int)min.Y, (int)max.Y), (double)rnd.Next((int)min.Z, (int)max.Z));
            }
            var objId = getNextObjId();
            var objData = objId | FLAG_NEW;
            m_AddDelegates.Add(new Tuple<long, MovementDelegate>(objData, movementDelegate));
            objIdList.Add(objId);
            spatialObjIdMap.Add(entity, objId);
            objIdSpatialMap.Add(objId, entity);
            entity.Shape = new Cuboid(entity.Shape.Bounds.Dimension, freepos);

            clShapeObject act;
            clPoint center;
            center.x = (float)entity.Shape.Bounds.Position.X;
            center.y = (float)entity.Shape.Bounds.Position.Y;
            center.z = (float)entity.Shape.Bounds.Position.Z;
            clPoint front;
            front.x = (float)entity.Shape.Bounds.LeftBottomFront.X;
            front.y = (float)entity.Shape.Bounds.LeftBottomFront.Y;
            front.z = (float)entity.Shape.Bounds.LeftBottomFront.Z;
            clPoint rear;
            rear.x = (float)entity.Shape.Bounds.RightTopRear.X;
            rear.y = (float)entity.Shape.Bounds.RightTopRear.Y;
            rear.z = (float)entity.Shape.Bounds.RightTopRear.Z;
            act.center = center;
            act.leftBottomFront = front;
            act.rigthTopRear = rear;

            envFreshAddedObjs.Add(objData, act);
            /*
                        shapeList.Add(act);
                        objIdClShapeMap.Add(objId, act);
                        */
            // Added Element -> Now wait until the CollisionDetection did its work at the LayerTick
            Interlocked.Decrement(ref m_ActiveOperationCount);

               // envActEnvObjs.Add(objId, act);

            // We need the list with free positions first
        }
Beispiel #9
0
        public void Add(ISpatialEntity entity, Vector3 position, Direction rotation, MovementDelegate movementDelegate)
        {
            entity.Shape.Transform(position - entity.Shape.Position, null);
            // First check boundarys
            if (!checkBoundarys(entity.Shape.Bounds.LeftBottomFront,entity.Shape.Bounds.RightTopRear))
            {
                movementDelegate.Invoke(new MovementResult());
                return;
            }
            bool res;
            if (gpuActive) gpuActiveWait.WaitOne();
            Interlocked.Increment(ref m_ActiveOperationCount);
            int objId = getNextObjId();
            long objData = objId | FLAG_NEW;
            m_AddDelegates.Add(new Tuple<long,MovementDelegate>(objData,movementDelegate));
            objIdList.Add(objId);
            spatialObjIdMap.Add(entity, objId);
            objIdSpatialMap.Add(objId, entity);

            clShapeObject act;
            clPoint center;
            center.x = (float)entity.Shape.Bounds.Position.X;
            center.y = (float)entity.Shape.Bounds.Position.Y;
            center.z = (float)entity.Shape.Bounds.Position.Z;
            clPoint front;
            front.x = (float)entity.Shape.Bounds.LeftBottomFront.X;
            front.y = (float)entity.Shape.Bounds.LeftBottomFront.Y;
            front.z = (float)entity.Shape.Bounds.LeftBottomFront.Z;
            clPoint rear;
            rear.x = (float)entity.Shape.Bounds.RightTopRear.X;
            rear.y = (float)entity.Shape.Bounds.RightTopRear.Y;
            rear.z = (float)entity.Shape.Bounds.RightTopRear.Z;
            act.center = center;
            act.leftBottomFront = front;
            act.rigthTopRear = rear;
            objIdClShapeMap.Add(objId, act);
            envFreshAddedObjs.Add(objData, act);
            /*
                        shapeList.Add(act);
                        objIdClShapeMap.Add(objId, act);
                        */

               Interlocked.Decrement(ref m_ActiveOperationCount);
        }
    // Use this for initialization
    protected void UnitMovementStart()
    {
        m_MovementDelegates[(int)MovementMessage.MOVE_BACKWARD] = new MovementDelegate(MoveBackward);
        m_MovementDelegates[(int)MovementMessage.MOVE_FORWARD] = new MovementDelegate(MoveForward);
        m_MovementDelegates[(int)MovementMessage.ROTATE] = new MovementDelegate(MoveRotate);
        m_MovementDelegates[(int)MovementMessage.RUN] = new MovementDelegate(MoveRun);
        m_MovementDelegates[(int)MovementMessage.STOP] = new MovementDelegate(MoveStop);
        m_MovementDelegates[(int)MovementMessage.JUMP] = new MovementDelegate(MoveJump);
        m_MovementDelegates[(int)MovementMessage.NONE] = new MovementDelegate(MoveNone);

        m_CurrMovementFunction = m_MovementDelegates[(int)MovementMessage.STOP];

        m_startTime = Time.time;
        m_Controller = this.GetComponent<CharacterController>();
        m_Collider = this.GetComponent<BoxCollider>();

        m_vecEnd = Position;
        m_vecEnd.y = 0;

        if (Controller != null)
        {
            m_colliderHeight = m_Controller.height;
        }

        //MovePut();
    }
 public void SetMovementMessage(MovementMessage msg)
 {
     if (m_currMsg == msg)
         return;
     m_currMsg = msg;
     m_CurrMovementFunction = m_MovementDelegates[(int)m_currMsg];
     //Debug.Log(msg);
 }
 public void MoveStop()
 {
     SetMovementMessage(MovementMessage.STOP);
     m_movementState = MovementState.STANDING;
     m_vecEnd = m_vecCurrPos;
     m_CurrMovementFunction = m_MovementDelegates[(int)MovementMessage.NONE];
 }
    IEnumerator Move()
    {
        yield return new WaitForSeconds(path.stepTime);

        if (currentStep >= path.steps.Count)
        {
            currentStep = 0;
        }

        switch (path.steps[currentStep])
        {
            case Step.UP:

                startMarker = new Vector3(transform.position.x, transform.position.y, transform.position.z);
                endMarker = new Vector3(transform.position.x, transform.position.y + yDistance, transform.position.z);
                journeyLength = Vector3.Distance(startMarker, endMarker);
                startTime = Time.time;
                mDelegate += LerpTo;
                StartCoroutine(NextStep());
                break;
            case Step.DOWN:

                startMarker = new Vector3(transform.position.x, transform.position.y, transform.position.z);
                endMarker = new Vector3(transform.position.x, transform.position.y - yDistance, transform.position.z);
                journeyLength = Vector3.Distance(startMarker, endMarker);
                startTime = Time.time;
                mDelegate += LerpTo;
                StartCoroutine(NextStep());
                break;
            case Step.RIGHT:

                startMarker = new Vector3(transform.position.x, transform.position.y, transform.position.z);
                endMarker = new Vector3(transform.position.x + xDistance, transform.position.y, transform.position.z);
                journeyLength = Vector3.Distance(startMarker, endMarker);
                startTime = Time.time;
                mDelegate += LerpTo;
                StartCoroutine(NextStep());
                break;
            case Step.LEFT:

                startMarker = new Vector3(transform.position.x, transform.position.y, transform.position.z);
                endMarker = new Vector3(transform.position.x - xDistance, transform.position.y, transform.position.z);
                journeyLength = Vector3.Distance(startMarker, endMarker);
                startTime = Time.time;
                mDelegate += LerpTo;
                StartCoroutine(NextStep());
                break;
            case Step.FORWARD:

                startMarker = new Vector3(transform.position.x, transform.position.y, transform.position.z);
                endMarker = new Vector3(transform.position.x, transform.position.y, transform.position.z + zDistance);
                journeyLength = Vector3.Distance(startMarker, endMarker);
                startTime = Time.time;
                mDelegate += LerpTo;
                StartCoroutine(NextStep());
                break;
            case Step.BACKWARD:

                startMarker = new Vector3(transform.position.x, transform.position.y, transform.position.z);
                endMarker = new Vector3(transform.position.x, transform.position.y, transform.position.z - zDistance);
                journeyLength = Vector3.Distance(startMarker, endMarker);
                startTime = Time.time;
                mDelegate += LerpTo;
                StartCoroutine(NextStep());
                break;
            case Step.WAIT:
                StartCoroutine(Wait());
                break;
            case Step.STOP:
                path.steps.Clear();
                break;
        }

        currentStep++;
    }
Beispiel #14
0
    void Update()
    {
        if (!UIClickBlocker.isHovered)
        {
            // If we press the left mouse button, save mouse location and begin selection
            if (Input.GetMouseButtonDown(0))
            {
                isSelecting      = true;
                mousePosition1   = Input.mousePosition;
                movementDelegate = null;
                foreach (var selectableObject in FindObjectsOfType <SelectableUnitComponent>())
                {
                    if (selectableObject.selectionCircle != null)
                    {
                        Destroy(selectableObject.selectionCircle.gameObject);
                        selectableObject.selectionCircle = null;
                    }
                }
            }
            // If we let go of the left mouse button, end selection
            if (Input.GetMouseButtonUp(0))
            {
                selectedObjects = new List <SelectableUnitComponent>();
                foreach (var objects in FindObjectsOfType <SelectableUnitComponent>())
                {
                    if (IsWithinSelectionBounds(objects.gameObject))
                    {
                        selectedObjects.Add(objects);
                        movementDelegate += objects.moveTo;
                    }
                }

                foreach (var objects in selectedObjects)
                {
                    Debug.Log(objects.gameObject.name);
                }

                //this calls the Update UI method in the dynamicUI
                if (onCallUpdateUI != null)
                {
                    onCallUpdateUI(selectedObjects);
                }

                isSelecting = false;
            }
        }

        if (isSelecting)
        {
            foreach (var selectableObject in FindObjectsOfType <SelectableUnitComponent>())
            {
                if (IsWithinSelectionBounds(selectableObject.gameObject))
                {
                    if (selectableObject.selectionCircle == null)
                    {
                        selectableObject.selectionCircle = Instantiate(selectionCirclePrefab);
                        selectableObject.selectionCircle.transform.SetParent(selectableObject.transform, false);
                        selectableObject.selectionCircle.transform.eulerAngles = new Vector3(90, 0, 0);
                    }
                }
                else
                {
                    if (selectableObject.selectionCircle != null)
                    {
                        Destroy(selectableObject.selectionCircle.gameObject);
                        selectableObject.selectionCircle = null;
                    }
                }
            }
        }
    }