コード例 #1
0
ファイル: Whell.cs プロジェクト: popboyhsf/Unity
    void CallBackBtnStartClick()
    {
        itemID = WheelData.GetRandomItemID();

        Debug.Log("item ==== " + itemID);



        perPrizeAngle = 360 / prizeCount;
        _isRuning     = true;
        if (itemID != modeEnum.UnKnow)
        {
            StartRotate((int)itemID - 1);
        }
    }
コード例 #2
0
ファイル: WheelData.cs プロジェクト: popboyhsf/Unity
    /// <summary>
    /// 返回随机出来的游戏模式枚举
    /// </summary>
    /// <returns>游戏模式枚举</returns>
    public static modeEnum GetRandomItemID()
    {
        var weightMax = 0;

        foreach (var item in WheelInfoList)
        {
            //TODO 减去当前累计数额
            item.weight = item.weight > item.limitWeight ? item.weight : 0;
            weightMax  += item.weight;
        }


        WheelInfoList.Sort((x, y) => {
            if (x.weight > y.weight)
            {
                return(-1);
            }
            else
            if (x.weight == y.weight)
            {
                return(0);
            }
            else
            {
                return(1);
            }
        });

        int rankA = UnityEngine.Random.Range(1, weightMax);
        ////Debug.Log("rankA ===== " + rankA);

        int _index = 0;

        while (rankA > 0)
        {
            rankA -= WheelInfoList[_index].weight;
            _index++;
        }

        var i = WheelInfoList[_index - 1].gameMode;

        modeEnum type = (modeEnum)Enum.Parse(typeof(modeEnum), i);

        Debug.Log("Random Mode == " + type);

        return(type);
    }
コード例 #3
0
        public void OnDrawGizmosBase(float height, modeEnum mode)
        {
#if UNITY_EDITOR
            if (mode == modeEnum.Area)
            {
                if (isActive)
                {
                    if (Selection.activeGameObject == gameObject)
                    {
                        Handles.color = Color.green;
                    }
                    else
                    {
                        Handles.color = Color.yellow;
                    }
                }
                else
                {
                    Handles.color = Color.gray;
                }
                if (areaInnerRadius < 0)
                {
                    areaInnerRadius = 0;
                }
                if (areaOuterRadius < 0)
                {
                    areaOuterRadius = 0;
                }
                if (areaOuterRadius < areaInnerRadius)
                {
                    areaInnerRadius = areaOuterRadius;
                }

                Vector3 center = transform.position;
                Handles.DrawWireDisc(center, Vector3.up, areaOuterRadius);
                Vector3[] innerPoints = new Vector3[iconNoiseSteps + 1];
                Vector2   local       = new Vector2(transform.position.x, transform.position.z);
                float     angleStep   = 2 * Mathf.PI / iconNoiseSteps;
                for (int i = 0; i < iconNoiseSteps; i++)
                {
                    Vector2 point = new Vector2(areaInnerRadius * Mathf.Cos(i * angleStep), areaInnerRadius * Mathf.Sin(i * angleStep)) + local;
                    innerPoints[i] = new Vector3(point.x, GetHeightInner(point), point.y);
                }
                innerPoints[iconNoiseSteps] = innerPoints[0];
                Handles.DrawPolyLine(innerPoints);
                for (int i = 0; i < iconNoiseSteps; i++)
                {
                    Handles.DrawLine(new Vector3(areaOuterRadius * Mathf.Cos(i * angleStep), 0f, areaOuterRadius * Mathf.Sin(i * angleStep)) + center, innerPoints[i]);
                }
            }
            else if (mode == modeEnum.Infinite)
            {
                if (isActive)
                {
                    if (Selection.activeGameObject == gameObject)
                    {
                        Handles.color = Color.green;
                    }
                    else
                    {
                        Handles.color = Color.yellow;
                    }
                }
                else
                {
                    Handles.color = Color.gray;
                }

                Vector3   localPosition = new Vector3(transform.position.x, 0f, transform.position.z);
                Vector3[] basePoints    = new Vector3[5];
                basePoints[0] = new Vector3(-1 * iconSize / 2, 0, -1 * iconSize / 2) + localPosition;
                basePoints[1] = new Vector3(-1 * iconSize / 2, 0, iconSize / 2) + localPosition;
                basePoints[2] = new Vector3(iconSize / 2, 0, iconSize / 2) + localPosition;
                basePoints[3] = new Vector3(iconSize / 2, 0, -1 * iconSize / 2) + localPosition;
                basePoints[4] = new Vector3(-1 * iconSize / 2, 0, -1 * iconSize / 2) + localPosition;
                Handles.DrawPolyLine(basePoints);

                Vector2 point0      = new Vector2(transform.position.x - iconSize / 2, transform.position.z - iconSize / 2);
                Vector2 local       = new Vector2(transform.position.x, transform.position.z);
                Vector2 point0Local = new Vector2(-iconSize / 2, -iconSize / 2) + local;
                Vector2 point1      = new Vector2(transform.position.x - iconSize / 2, transform.position.z + iconSize / 2);
                Vector2 point1Local = new Vector2(-iconSize / 2, iconSize / 2) + local;
                Vector2 point2Local = new Vector2(iconSize / 2, iconSize / 2) + local;
                Vector2 point3      = new Vector2(transform.position.x + iconSize / 2, transform.position.z - iconSize / 2);
                Vector2 point3Local = new Vector2(iconSize / 2, -iconSize / 2) + local;
                //draw lines along z direction
                for (int i = 0; i < iconNoiseSteps; i++)
                {
                    float     t    = i / (float)(iconNoiseSteps - 1);
                    Vector3[] line = new Vector3[iconNoiseSteps];
                    for (int j = 0; j < iconNoiseSteps; j++)
                    {
                        float u = j / (float)(iconNoiseSteps - 1);
                        line[j] = new Vector3(point0.x * (1 - t) + point3.x * t, GetHeightInner((point0Local * (1 - t) + point3Local * t) * (1 - u) + (point1Local * (1 - t) + point2Local * t) * u), point0.y * (1 - u) + point1.y * u);
                    }
                    Handles.DrawPolyLine(line);
                }
                //also draw lines in x direction
                for (int i = 0; i < iconNoiseSteps; i++)
                {
                    float     t    = i / (float)(iconNoiseSteps - 1);
                    Vector3[] line = new Vector3[iconNoiseSteps];
                    for (int j = 0; j < iconNoiseSteps; j++)
                    {
                        float u = j / (float)(iconNoiseSteps - 1);
                        line[j] = new Vector3(point0.x * (1 - u) + point3.x * u, GetHeightInner((point0Local * (1 - t) + point1Local * t) * (1 - u) + (point3Local * (1 - t) + point2Local * t) * u), point0.y * (1 - t) + point1.y * t);
                    }
                    Handles.DrawPolyLine(line);
                }
                Handles.DrawLine(basePoints[0], new Vector3(basePoints[0].x, GetHeightInner(point0Local), basePoints[0].z));
                Handles.DrawLine(basePoints[1], new Vector3(basePoints[1].x, GetHeightInner(point1Local), basePoints[1].z));
                Handles.DrawLine(basePoints[2], new Vector3(basePoints[2].x, GetHeightInner(point2Local), basePoints[2].z));
                Handles.DrawLine(basePoints[3], new Vector3(basePoints[3].x, GetHeightInner(point3Local), basePoints[3].z));
            }
#endif
            Gizmos.DrawIcon(transform.position, "gizmos_mountains_01.png", false);
        }
コード例 #4
0
 public void SetCopyMode()
 {
     this._mode = modeEnum.copy;
 }
コード例 #5
0
 public void SetUpdateMode()
 {
     this._mode = modeEnum.update;
 }
コード例 #6
0
 public void SetEntryMode()
 {
     this._mode = modeEnum.entry;
 }