缓动函数和转盘

http://www.xuanfengge.com/easeing/easeing/


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
using AssemblyCSharp;
using System.Collections;
using Proto;
public class LuckySpinPanel : MonoBehaviour
{
   // private UISprite spriteNeedle;
    private GameObject objectMiddle;

    private int startIndex = 2;
    private float startAngle = 22.5f;

    private UIAtlasSimpleBg spriteNeedle;


    private int eachAngle = 45;
    private int each = 8;//8份 

    private float needAngle = 0;//需要转的角度

   
    private LuckySpinPanel()
    {
        
    }
    public int windowIndex = 0;//0为消费,1为充值
    public void SetWindow(string name)
    {
        if (name == LuckySpinConfig.PurchaseSpin)
            windowIndex = 0;
        else
            windowIndex = 1;
    }
    private float GetNeedAngle(int _endIndex)
    {
        int spaceIndex = 0;

        if (startIndex > _endIndex)
            spaceIndex = (_endIndex + 7 - startIndex) + 8 * UnityEngine.Random.Range(3, 5);
        else
            spaceIndex = (_endIndex - startIndex - 1) + 8 * UnityEngine.Random.Range(3, 5);

        int _startAngle = UnityEngine.Random.Range(0, 44);
        needAngle = spaceIndex * 45 + (45 - startAngle) + _startAngle;

        startAngle = _startAngle;
        startIndex = _endIndex;
        return needAngle;
    }


    void Start()
    {
        gameObject.name = "LuckySpinPanel";
        InitUI();
    }
    private GameObject content;
    private GameObject eachContent;
    private List<LuckSpinPanelItem> itemList;
    private Button luckyOneBtn;
    private Button luckyTenBtn;
    private Button luckyFiveTenBtn;
    private CheckBox buySomething;
    private bool isEnableAnimation = true;
    private void OnStateChange(bool isEnable)
    {
        isEnableAnimation = !isEnable;
    }

    private void InitUI()
    {
        buySomething = UICreate.createCheckBox(gameObject);
        buySomething.setLabelEffect(UILabel.Effect.None);
        buySomething.name = "autoUseBox";
        buySomething.setLocation(549, -488);
        buySomething.setText("");
          
        buySomething.onStateChange = OnStateChange;

          
        luckyOneBtn = UICreate.createButton(gameObject,"抽1次",136,-548,154);
        luckyOneBtn.onClick = ClickBtn;
        luckyOneBtn.name = "luckyOneBtn";
        luckyOneBtn.styleName = "Button_yellow";

        luckyTenBtn = UICreate.createButton(gameObject, "抽10次", 356, -548, 154);
        luckyTenBtn.onClick = ClickBtn;
        luckyTenBtn.name = "luckyTenBtn";
        luckyTenBtn.styleName = "Button_yellow";
          
        luckyFiveTenBtn = UICreate.createButton(gameObject, "抽50次", 575, -548, 154);
        luckyFiveTenBtn.onClick = ClickBtn;
        luckyFiveTenBtn.name = "luckyFiveTenBtn";
        luckyFiveTenBtn.styleName = "Button_yellow";

        UIAtlasSimpleBg jump = UICreate.createUIAtlasSimpleBg(gameObject, UrlManager.ModuleAtlasPath("LuckySpin", "jumpAnimation"), 609, -488);
        jump.depth = 3;
      
 
        SimpleBg winTitleBg = UICreate.createSimpleBg(gameObject, UrlManager.GetImagesPath("LuckSpin/spin.png"), 356, -327);
        winTitleBg.depth = -1;
          
        itemList = new List<LuckSpinPanelItem>();

        content = UICreate.createGameObject(gameObject, 390, -327);
        content.name = "content";
         
        objectMiddle = UICreate.createGameObject(content, 0, 0);
        objectMiddle.name = "objectMiddle";
       // spriteNeedle = UICreate.createUISprite(objectMiddle, "setting_normal", 75);
       // objectMiddle.transform.localEulerAngles = new Vector3(0, 0, 90);


        spriteNeedle = UICreate.createUIAtlasSimpleBg(objectMiddle, UrlManager.ModuleAtlasPath("LuckySpin", "spin"), 14, 0);
        spriteNeedle.transform.localEulerAngles = new Vector3(0, 0, -90);
        objectMiddle.transform.localEulerAngles = new Vector3(0, 0, 90); 
         
        eachContent = UICreate.createGameObject(content, 0, 0);
        eachContent.name = "eachContent";

        for (int i = 0; i < 8; i++)
        {
            GameObject tempGo = UICreate.createGameObject(eachContent);
            tempGo.name = string.Format("tool{0}", i);  
 

            float rad = Mathf.Deg2Rad * (i * 45 ); 
            tempGo.transform.localPosition = new Vector3(150 * Mathf.Cos(rad), 150 * Mathf.Sin(rad));
            switch (i)
            {
                case 0: tempGo.transform.localPosition += new Vector3(-15f, 0, 0); break;
                case 2: tempGo.transform.localPosition += new Vector3(0, -15f, 0); break;
                case 4: tempGo.transform.localPosition += new Vector3(15f, 0, 0); break;
                case 6: tempGo.transform.localPosition += new Vector3(0, 15f, 0); break;
            }
            LuckSpinPanelItem item = tempGo.AddComponent<LuckSpinPanelItem>();
            itemList.Add(item); 
        }
       // AppFacade.getInstance().SendNotification(NotiConst.S_GET_SPIN_INFO, windowIndex); 
       //appfaced 
       // Invoke("SetData", 0.2f);   
    }
    private void ClickBtn(GameObject go)
    {
        if (!canClick)
            return;
        canClick = false;
        int type2 = 0;
        switch (go.name)
        {
            case "luckyOneBtn": /*SpinObject(0, new List<int>() { 0 });*/ type2 = 0; break;
            case "luckyTenBtn":/* SpinObject(1, new List<int>() { 0, 1, 2, 3, 4 });*/type2 = 1; break;
            case "luckyFiveTenBtn": /*SpinObject(2, new List<int>() { 0, 1, 2, 3, 4, 5, 6, 7 });*/type2 = 2; break;
        }
        Proto10101802 data = new Proto10101802();
        data.type1 = windowIndex;
        data.type2 = type2;
        AppFacade.getInstance().SendNotification(NotiConst.S_LOTTERY, data);
    }

    public void SetData(List<int> list)
    {
        for (int i = 0; i < itemList.Count; i++)
        {
            itemList[i].SetTool(list[i].ToString());
        }
        ShowSelect(new List<int>() { 2 });
    }
    public void SetLotteryData(List<int> list)
    {
        SpinObject(list[0], list);
        LoadManager.getInstance().LoadSceneUnity3d(UrlManager.ModelPath("GUI_luckeyRing", "effects"), loadUpDateEffectComplete); 
    } 
    private void loadUpDateEffectComplete(LoadParam param)
    {
        GameObject effectObejct;
        if (param.assetbundle.Load("GUI_luckeyRing", typeof(GameObject)) == null)
            return;
        effectObejct = GameObject.Instantiate(param.assetbundle.Load("GUI_luckeyRing", typeof(GameObject))) as GameObject;
        effectObejct.transform.parent = transform;
        effectObejct.transform.localScale = Vector3.one; 
        effectObejct.transform.localPosition = new Vector3(342, -76, -1);
    } 

    private bool canClick = true;

    float angle;
    public void SpinObject(int lastIndex,List<int> list)
    {
        if (!isEnableAnimation)
        {
            ShowSelect(list);
            canClick = true;
            return;
        }



        if (lastIndex >= 7)
            lastIndex = 7;
          
        angle = GetNeedAngle(lastIndex);
        //Debug.Log(angle % 360); 


         
         
        Hashtable args = new Hashtable();
        //args.Add("easeType", iTween.EaseType.easeOutSine);
        args.Add("easeType", iTween.EaseType.easeOutCubic); 
        args.Add("time", 3f);
        args.Add("z", angle);
        args.Add("onupdate", "AnimationUpdate");
        args.Add("onupdateparams", "z");
        args.Add("onupdatetarget", gameObject);
        args.Add("oncomplete", "AnimationComplete");
        args.Add("oncompletetarget", gameObject);
        args.Add("oncompleteparams", list);

        iTween.RotateAdd(objectMiddle, args);
      //  FrameTimerManager.getInstance().add(1, 0, AnimationUpdate);
    } 
    int i = 0;
    void AnimationComplete(List<int> list)
    {
        ShowSelect(list);
        canClick = true;
       // FrameTimerManager.getInstance().remove(AnimationUpdate); 
    } 


    void AnimationUpdate()
    {
        float z = objectMiddle.transform.localEulerAngles.z ; 
        if (z <= 0)
            z += 360;
        int index = 0;
        for (int i = 0; i < 8; i++)
        {
            if (z >= i * 45 - 22.5f && z < (i + 1) * 45 - 22.5f)
            {
                index = i;
            }
        }
        for (int i = 0; i < 8; i++)
        {
            if (i == index)
                itemList[i].SetEnable(true);
            else
                itemList[i].SetEnable(false);
        } 
    }



     
    private void ShowSelect(List<int> indexList)
    {
        for (int i = 0; i < itemList.Count; i++)
        {
            itemList[i].SetEnable(false);
        }
        for (int i = 0; i < indexList.Count; i++)
        {
            int index = indexList[i];
            itemList[index].SetEnable(true);
        }
    }

}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值