Beispiel #1
0
    public void NextState(IOnPointObject obj)
    {
        if (obj.GetObjType() != ObjectType.Reflector)
        {
            return;
        }

        Vector2Int index    = obj.GetCurrentIndex();
        int        state    = obj.GetCurrentState();
        int        pivotNum = state;

        int setState = state;

        for (int i = 0; i < 6; i++)
        {
            setState++;
            setState %= 6;

            int pointIndex = pointIndex = index.x + index.y * 10;

            if (setState == 0)
            {
                GetPointData(pointIndex, (Pivot)Enum.ToObject(typeof(Pivot), state - 1)).SetObjectType(ObjectType.None);
                obj.SetState(-1);
                return;
            }

            pivotNum = setState;
            if (setState != 0)
            {
                pivotNum--;
            }


            Pivot     pivot = (Pivot)Enum.ToObject(typeof(Pivot), pivotNum);
            PointData data  = GetPointData(pointIndex, pivot);

            if (data == null)
            {
                continue;
            }

            if (data.CanSetObject())
            {
                GetPointData(pointIndex, (Pivot)Enum.ToObject(typeof(Pivot), state != 0 ? state - 1 : state)).SetObjectType(ObjectType.None);
                obj.SetState(setState);
                obj.SetPosition(data.GetPosition());
                obj.SetPointIndex(index);
                data.SetObjectType(obj.GetObjType());
                return;
            }
            else if (setState == 1)
            {
                if (state == 0)
                {
                    obj.SetState(setState);
                    obj.SetPosition(data.GetPosition());
                    obj.SetPointIndex(index);
                    data.SetObjectType(obj.GetObjType());
                    return;
                }
            }
        }
    }
Beispiel #2
0
    public void SetObjPointData(IOnPointObject obj, Vector2Int index, int state)
    {
        int pointIndex = index.x + index.y * 10;


        int pivotNum;


        Pivot pivot;

        PointData data = null;

        switch (obj.GetObjType())
        {
        case ObjectType.Reflector:

            int setState = state;

            for (int i = 0; i < 6; i++)
            {
                setState %= 6;

                pivotNum = setState;
                if (setState != 0)
                {
                    pivotNum--;
                }

                pivot = (Pivot)Enum.ToObject(typeof(Pivot), pivotNum);

                data = GetPointData(pointIndex, pivot);

                if (data == null)
                {
                    setState++;
                    continue;
                }

                if (data.CanSetObject())
                {
                    obj.SetState(setState);
                    obj.SetPosition(data.GetPosition());
                    obj.SetPointIndex(index);
                    data.SetObjectType(obj.GetObjType());
                    return;
                }
                setState++;
            }
            obj.SetState(-1);

            break;

        case ObjectType.Goal:
        case ObjectType.Start:
        case ObjectType.Wall:
        case ObjectType.Coin:

            for (int i = 0; i < Enum.GetNames(typeof(Pivot)).Length; i++)
            {
                data = GetPointData(pointIndex, (Pivot)Enum.ToObject(typeof(Pivot), i));

                if (data == null)
                {
                    continue;
                }

                if (!data.CanSetObject())
                {
                    if (i == 0 || data.GetCurrentObjType() == ObjectType.Reflector)
                    {
                        return;
                    }
                }
            }

            for (int i = 0; i < Enum.GetNames(typeof(Pivot)).Length; i++)
            {
                data = GetPointData(pointIndex, (Pivot)Enum.ToObject(typeof(Pivot), i));

                if (data == null)
                {
                    continue;
                }

                data.SetObjectType(obj.GetObjType());
            }

            Vector3 offset = new Vector3(0, 0, 0);

            if (obj.GetObjType() == ObjectType.Goal)
            {
                offset = m_pivotPoses[state % 4];
            }

            if (obj.GetObjType() == ObjectType.Start)
            {
                offset = m_pivotPoses[(state + 2) % 4];
            }

            data = GetPointData(pointIndex, Pivot.Center);
            obj.SetState(state);
            obj.SetPointIndex(index);
            obj.SetPosition(data.GetPosition() + offset);
            data.SetObjectType(obj.GetObjType());


            break;
        }
    }