Exemplo n.º 1
0
    public override void OnEnter()
    {
        m_Cube = controller.player.cube;
        m_StartPosition = controller.player.transform.position;
        m_StartRotation = controller.player.transform.rotation;
        m_EndPosition = m_StartPosition;
        m_EndRotation = m_StartRotation;
        m_StartTime = Time.time;

        UseItem(m_Cube.itemDict[controller.player.upAxis]);
    }
Exemplo n.º 2
0
    public void SetCube(CubeItem cube, AxisType rightAxis, AxisType upAxis, AxisType forwardAxis)
    {
        this.cube = cube;
        this.rightAxis = rightAxis;
        this.upAxis = upAxis;
        this.forwardAxis = forwardAxis;

        Vector3 forward = AxisUtil.Axis2Direction(cube.transform, forwardAxis);
        Vector3 right = AxisUtil.Axis2Direction(cube.transform, rightAxis);
        Vector3 up = AxisUtil.Axis2Direction(cube.transform, upAxis);

        transform.SetParent(cube.transform);
        transform.rotation = Quaternion.LookRotation(forward, up);
        transform.position = cube.transform.position + transform.up * cube.size * 0.5f;
    }
Exemplo n.º 3
0
    private static void Create()
    {
        if (null == s_MagicCube)
        {
            GameObject gameObject = new GameObject(typeof(MagicCube).Name);
            s_MagicCube = gameObject.AddComponent<MagicCube>();
        }

        s_MagicCube.Generate(s_Id, s_Step, s_Size, s_Space, 0);
        s_DestCube = s_MagicCube.destCube;

        List<CubeItem> cubeList = s_MagicCube[s_MagicCube.layer];
        CubeItem cube = cubeList[UnityEngine.Random.Range(0, cubeList.Count)];

        List<AxisType> axisTypes = new List<AxisType>(cube.itemDict.Keys);
        int index = UnityEngine.Random.Range(0, axisTypes.Count);
        AxisType upAxis = axisTypes[index];

        axisTypes = new List<AxisType>(Enum.GetValues(typeof(AxisType)) as AxisType[]);

        axisTypes.Remove(upAxis);
        axisTypes.Remove((AxisType)(-(int)upAxis));

        index = UnityEngine.Random.Range(0, axisTypes.Count);
        AxisType rightAxis = axisTypes[index];

        axisTypes.Remove(rightAxis);
        axisTypes.Remove((AxisType)(-(int)rightAxis));

        index = UnityEngine.Random.Range(0, axisTypes.Count);
        AxisType forwardAxis = axisTypes[index];

        s_SpawnInfo = new SpawnInfo();
        s_SpawnInfo.id = cube.id;
        s_SpawnInfo.right = rightAxis;
        s_SpawnInfo.up = upAxis;
        s_SpawnInfo.forward = forwardAxis;

        Selection.activeGameObject = s_MagicCube.gameObject;
    }
Exemplo n.º 4
0
    private void AddCube(CubeItem cube)
    {
        if (null == cube
            || controller.selectDict.ContainsKey(cube))
        {
            return;
        }

        SelectCube select = new SelectCube();
        select.cube = cube;
        select.position = cube.transform.localPosition;
        select.rotation = cube.transform.localRotation;

        controller.selectDict[cube] = select;

        int num = controller.magicCube.step * controller.magicCube.step;
        if (num <= controller.selectDict.Count)
        {
            controller.cubeTrigger.gameObject.SetActive(false);
            controller.magicCube.enableCollision = false;
            controller.stateMachine.Enter<RollState>();
        }
    }
Exemplo n.º 5
0
    private Dictionary<AxisType, int> RandomCube(CubeItem cube)
    {
        Dictionary<AxisType, int> itemDict = new Dictionary<AxisType, int>();

        AxisType[] axisTypes = Enum.GetValues(typeof(AxisType)) as AxisType[];
        ItemData[] itemDatas = itemDatabase.GetAll();
        for (int i = axisTypes.Length; --i >= 0;)
        {
            AxisType axis = axisTypes[i];
            Vector3 direction = AxisUtil.Axis2Direction(cube.transform, axis);
            if (Physics.Linecast(cube.transform.position,
                                 cube.transform.position + direction * (cube.collider.size.x * 1.5f),
                                 1 << LayerDefine.CUBE))
            {
                continue;
            }

            ItemData itemData = itemDatas[UnityEngine.Random.Range(0, itemDatas.Length)];
            itemDict[axis] = itemData.id;
        }

        return itemDict;
    }
Exemplo n.º 6
0
    private void OnDrawSave()
    {
        GUILayout.BeginVertical("Current Settings", EditorStyles.helpBox);
        GUILayout.Space(15);

        EditorGUILayout.LabelField("Id", s_MagicCube.id.ToString());
        EditorGUILayout.LabelField("Step", s_MagicCube.step.ToString());
        EditorGUILayout.LabelField("Size", s_MagicCube.size.ToString());
        EditorGUILayout.LabelField("Space", s_MagicCube.space.ToString());

        s_DestCube = EditorGUILayout.ObjectField("DestCube", s_DestCube, typeof(CubeItem), true) as CubeItem;
        s_SpawnInfo.id = EditorGUILayout.IntField("SpawnId", s_SpawnInfo.id);
        s_SpawnInfo.right = (AxisType)EditorGUILayout.EnumPopup("SpawnRight", s_SpawnInfo.right);
        s_SpawnInfo.up = (AxisType)EditorGUILayout.EnumPopup("SpawnUp", s_SpawnInfo.up);
        s_SpawnInfo.forward = (AxisType)EditorGUILayout.EnumPopup("SpawnForward", s_SpawnInfo.forward);

        if (GUILayout.Button("Save"))
        {
            Save();
        }

        GUILayout.EndVertical();
    }
Exemplo n.º 7
0
    private void Load()
    {
        MapData mapData = mapDatabase.Get(s_LoadId);
        if (null == mapData)
        {
            return;
        }

        s_MagicCube.Load(mapData);
        s_DestCube = s_MagicCube.destCube;
        s_SpawnInfo = mapData.spawnInfo;
    }
Exemplo n.º 8
0
 public void Spawn(CubeItem cube, SpawnInfo spawnInfo)
 {
     SetCube(cube, spawnInfo.right, spawnInfo.up, spawnInfo.forward);
 }
Exemplo n.º 9
0
    private void OnInputStart(InputStartEvent evt)
    {
        controller.magicCube.enableCollision = true;
        CubeItem select = null;

        float distance = (controller.magicCube.layer + 1) * controller.magicCube.distance * controller.viewDistance;
        Ray ray = controller.camera.ScreenPointToRay(evt.gesture.position);
        RaycastHit[] raycastHits = Physics.RaycastAll(ray,
                                                      distance,
                                                      1 << LayerDefine.CUBE,
                                                      QueryTriggerInteraction.Collide);

        controller.magicCube.enableCollision = false;

        for (int i = 0; i < raycastHits.Length; ++i)
        {
            RaycastHit raycastHit = raycastHits[i];
            CubeItem cube = raycastHit.collider.GetComponent<CubeItem>();
            if (null == cube
                || cube.layer != controller.magicCube.layer)
            {
                continue;
            }

            if (null == select)
            {
                select = cube;
            }
            else if (Vector3.Distance(ray.origin, select.transform.position)
                     > Vector3.Distance(ray.origin, cube.transform.position))
            {
                select = cube;
            }
        }

        if (null != select)
        {
            if (int.MinValue == m_RollInputId)
            {
                m_RollInputId = evt.gesture.inputId;
                m_StartPosition = evt.gesture.position;
                m_SelectCube = select;
            }
        }
        else
        {
            if (int.MinValue == m_ViewInputId)
            {
                m_ViewInputId = evt.gesture.inputId;
            }
        }
    }
Exemplo n.º 10
0
    private void UseItem(ItemData itemData)
    {
        if (ItemType.FORWARD == itemData.id)
        {
        }
        else if (ItemType.TURN_LEFT == itemData.id)
        {
            controller.player.transform.Rotate(Vector3.up, -90);
            m_EndRotation = controller.player.transform.rotation;
            controller.player.transform.rotation = m_StartRotation;
        }
        else if (ItemType.TURN_RIGHT == itemData.id)
        {
            controller.player.transform.Rotate(Vector3.up, 90);
            m_EndRotation = controller.player.transform.rotation;
            controller.player.transform.rotation = m_StartRotation;
        }
        else if (ItemType.TURN_BACK == itemData.id)
        {
            controller.player.transform.Rotate(Vector3.up, 180);
            m_EndRotation = controller.player.transform.rotation;
            controller.player.transform.rotation = m_StartRotation;
        }
        else if (ItemType.TURN_UP == itemData.id)
        {
            controller.magicCube.enableCollision = true;

            RaycastHit raycastHit;
            if (Physics.Raycast(controller.player.cube.transform.position,
                controller.player.transform.up,
                out raycastHit,
                controller.magicCube.distance,
                1 << LayerDefine.CUBE))
            {
                CubeItem cube = raycastHit.collider.GetComponent<CubeItem>();
                if (null != cube)
                {
                    m_Cube = cube;
                    m_EndPosition = cube.transform.position + controller.player.transform.up * cube.size * 0.5f;
                    ++controller.magicCube.layer;
                }
                else
                {
                    controller.stateMachine.Enter<IdleState>();
                }
            }

            controller.magicCube.enableCollision = false;
        }
        else if (ItemType.TURN_DOWN == itemData.id)
        {
            controller.magicCube.enableCollision = true;

            RaycastHit raycastHit;
            if (Physics.Raycast(controller.player.cube.transform.position,
                                -controller.player.transform.up,
                                out raycastHit,
                                controller.magicCube.distance,
                                1 << LayerDefine.CUBE))
            {
                CubeItem cube = raycastHit.collider.GetComponent<CubeItem>();
                if (null != cube)
                {
                    m_Cube = cube;
                    m_EndPosition = cube.transform.position + controller.player.transform.up * cube.size * 0.5f;
                    --controller.magicCube.layer;
                }
                else
                {
                    controller.stateMachine.Enter<IdleState>();
                }
            }

            controller.magicCube.enableCollision = false;
        }
    }
Exemplo n.º 11
0
 private void OnEnable()
 {
     m_Cube = target as CubeItem;
 }