Esempio n. 1
0
        private void SnapAt(ProgramBlock block, int newZoneIndex)
        {
            VRTK_SnapDropZone nextVrtkZone = _zones[newZoneIndex].GetComponent <VRTK_SnapDropZone>();

            nextVrtkZone.ForceSnap(block.gameObject);

            block.ZoneId = nextVrtkZone.GetComponent <SnapDropZone>().ZoneId;
        }
Esempio n. 2
0
 private void DoChildTriggerExit(Collider other)
 {
     if (other != null && other.gameObject.tag.CompareTo(Constant.TAG_BLOCK_PROGRAM) == 0)
     {
         ProgramBlock otherBlock = other.gameObject.GetComponent <ProgramBlock>();
         if (otherBlock.IsGrabbed() && otherBlock.HoverZoneId == ZoneId && otherBlock.State == State.UnsnapHover && State == State.SnapIdle)
         {
             otherBlock.HoverZoneId = -1;
             Unhover(ZoneId);
         }
     }
 }
Esempio n. 3
0
        private void MoveSnappedBlock(int fromIndex, int toIndex, bool isTemporary)
        {
            ProgramBlock block = GetProgramBlockByObject(GetGameObjectBySnapIndex(fromIndex));

            SnapRemove(block);
            SnapAt(block, toIndex);

            if (isTemporary)
            {
                block.State = State.SnapTempMove;
            }
            else
            {
                block.State = State.SnapIdle;
            }
        }
Esempio n. 4
0
        GameObject CreateRotateLeftBlock(Vector3 position)
        {
            var rotateleftBlock = (GameObject)Instantiate(
                _rotateLeftBlockPrefab,
                position,
                Quaternion.identity);

            rotateleftBlock.tag = Constant.TAG_BLOCK_PROGRAM;

            ProgramBlock block = rotateleftBlock.GetComponent <ProgramBlock>();

            block.Type = ProgramBlockType.RotateLeft;
            block.PauseSweepChildTrigger();
            RegisterProgramBlockEventHandler(block);

            return(rotateleftBlock);
        }
Esempio n. 5
0
        private void DoProgramBlockZoneSnapped(object sender, SnapDropZoneEventArgs e)
        {
            //Debug.Log("== SnapDropZone: SNAPPED >>>> [ ] <<<<");
            if (sender is VRTK_SnapDropZone)
            {
                VRTK_SnapDropZone originZone = (VRTK_SnapDropZone)sender;
                int zoneId = originZone.GetComponent <SnapDropZone>().ZoneId;
                DecreaseZoneHeight(zoneId);
                Destroy(GetTemporaryPositionObjectByZoneId(zoneId));

                ProgramBlock block = GetProgramBlockByObject(GetGameObjectBySnapIndex(zoneId));
                //Debug.Log("== SnapDropZone: SNAPPED block state = " + block.State.ToString());
                if (block.State != State.SnapTempMove)
                {
                    if (IsPreviousZoneEmpty(zoneId))
                    {
                        MoveSnappedBlock(zoneId, zoneId - 1, false);
                    }
                }
            }
        }
Esempio n. 6
0
        private void DoChildTriggeredEnter(Collider other)
        {
            // My SweepTestChild collide with other.gameobject which is a ProgramBlock
            if (other != null && other.gameObject.tag.CompareTo(Constant.TAG_BLOCK_PROGRAM) == 0)
            {
                ProgramBlock otherBlock = other.gameObject.GetComponent <ProgramBlock>();

                if (otherBlock.IsGrabbed())
                {
                    Debug.Log("DoChildTriggeredEnter: other program block HoverZoneId " + otherBlock.HoverZoneId);
                    if (ZoneId > -1 && ZoneId != otherBlock.HoverZoneId)
                    {
                        if (otherBlock.HoverZoneId > -1)
                        {
                            // has hovered on other zone currently
                            Unhover(otherBlock.HoverZoneId);
                            otherBlock.HoverZoneId = -1;
                        }

                        Hover(ZoneId);
                        // Set my current state to SnapTempMove
                        State = State.SnapTempMove;

                        // Set other block HoverZoneId and state to UnsnapHover
                        otherBlock.HoverZoneId = ZoneId;
                        otherBlock.State       = State.UnsnapHover;
                    }
                }
                else
                {
                    if (ZoneId > -1 && ZoneId == otherBlock.HoverZoneId)
                    {
                        Snap(other.gameObject, ZoneId);
                    }
                }
            }
        }
Esempio n. 7
0
 private void RegisterProgramBlockEventHandler(ProgramBlock block)
 {
     block.Hover   += new ProgramBlock.HoverEventHandler(DoProgramBlockHover);
     block.Unhover += new ProgramBlock.HoverEventHandler(DoProgramBlockUnhover);
     block.Snap    += new ProgramBlock.SnapEventHandler(DoProgramBlockSnap);
 }
Esempio n. 8
0
 //Called after program blocks are encoded
 //Calls Character api
 //Decodes the program blocks that were encoded according to the type of program block
 public bool Decode(List <ProgramBlock> blockchain)
 {
     blockEnumerator = blockchain.GetEnumerator();
     try
     {
         //blockchain should not be modified, added or remove in order for blockEnumberator to work.
         while (blockEnumerator.MoveNext())
         {
             //Checks if reset was called
             if (reset)
             {
                 //Checks if list is null or empty
                 //Sets reset to false if the current enumerator is at the desired for loop
                 if (listForLoopStart != null && listForLoopStart.Count > 0)
                 {
                     int          latestForwardLoopIndex = listForLoopStart.Count;
                     ProgramBlock latestForwardLoopBlock = (ProgramBlock)listForLoopStart[latestForwardLoopIndex - 1];
                     if (blockEnumerator.Current.Equals(latestForwardLoopBlock))
                     {
                         reset = false;
                     }
                 }
             }
             else
             {
                 ProgramBlock block = (ProgramBlock)blockEnumerator.Current;
                 if (block.Type == ProgramBlockType.Forward)
                 {
                     Debug.Log("Decode Character Forward");
                     _character.Forward();
                 }
                 else if (block.Type == ProgramBlockType.RotateLeft)
                 {
                     Debug.Log("Decode Character Rotate Left");
                     _character.RotateLeft();
                 }
                 else if (block.Type == ProgramBlockType.RotateRight)
                 {
                     Debug.Log("Decode Character Rotate Right");
                     _character.RotateRight();
                 }
                 else if (block.Type == ProgramBlockType.Jump)
                 {
                     Debug.Log("Decode Character Jump");
                     _character.Jump();
                 }
                 else if (block.Type == ProgramBlockType.ForLoopStart)
                 {
                     //++forLoopCounter;
                     ProgramBlock tempBlock = block;
                     listForLoopStart.Add(tempBlock);
                 }
                 else if (block.Type == ProgramBlockType.ForLoopEnd)
                 {
                     //--forLoopCounter;
                     int latestForwardLoopIndex = listForLoopStart.Count;
                     --listForLoopStart[latestForwardLoopIndex - 1].Value;
                     if (listForLoopStart[latestForwardLoopIndex - 1].Value > 0)
                     {
                         reset = true;
                         blockEnumerator.Reset();
                     }
                     else
                     {
                         listForLoopStart.RemoveAt(latestForwardLoopIndex - 1);
                     }
                 }
             }
         }
     }
     catch (InvalidOperationException e)
     {
         throw new InvalidOperationException("BlockChain is modified, iterator not functioning!", e);
     }
     return(true);
 }
Esempio n. 9
0
 private VRTK_SnapDropZone GetProgramBlockVRTKSnappedDropZone(ProgramBlock block)
 {
     return(block.GetVRTKSnapDropZone());
 }
Esempio n. 10
0
 private SnapDropZone GetProgramBlockSnappedDropZone(ProgramBlock block)
 {
     return(block.GetSnapDropZone());
 }
Esempio n. 11
0
        private void SnapRemove(ProgramBlock block)
        {
            VRTK_SnapDropZone currentVrtkZone = block.GetVRTKSnapDropZone();

            currentVrtkZone.ForceUnsnap();
        }