コード例 #1
0
    //=====================================================

    public void OnOutfitSelected(int Index)
    {
        // Move into 'buy?' overlay mode
        // Only allow outfits to be selected on bought fairies
        FairyData CurFairy = GameDataManager.Instance.GetFairyData((eFairy)m_CurrentFairyIndex);

        if (CurFairy != null)
        {
            List <ClothingItemData> CurClothingList = ClothingItemsManager.GetClothingItems((eFairy)m_CurrentFairyIndex);
            m_BuyOutfit = CurClothingList[Index];

            // If we own this outfit just wear it, otherwise show the 'buy' overlay
            if (CurFairy.OutfitOwned(m_BuyOutfit.id))
            {
                // Twirl anim
                bool bDoTwirl = false;
                if (CurFairy.Outfit != m_BuyOutfit.id)
                {
                    bDoTwirl = true;
                }

                // Wear
                CurFairy.Outfit    = m_BuyOutfit.id;
                m_bBuyOutfitActive = false;
                UpdateSelectedFairy();
                GameDataManager.Instance.SaveGameData();

                // Analytics event
                Dictionary <string, object> EventDictionary = new Dictionary <string, object>();
                EventDictionary["outfitID"] = m_BuyOutfit.id;
                Analytics.CustomEvent("WearOutfit", EventDictionary);

                if (bDoTwirl)
                {
                    m_InspectOufitTimer = UnityEngine.Random.Range(3.0f, 6.0f);
                    m_CurrentFairyObj.GetComponent <Animator>().SetTrigger("IsChangingOutfit");
                }
            }
            else
            {
                // Buy - show preview of outfit
                UpdateSelectedFairy(m_BuyOutfit.id);
                m_bBuyOutfitActive = true;
            }
        }
        else
        {
            // Fairy not owned, allow outfits to be tested anyway
            List <ClothingItemData> CurClothingList = ClothingItemsManager.GetClothingItems((eFairy)m_CurrentFairyIndex);
            m_BuyOutfit = CurClothingList[Index];
            UpdateSelectedFairy(m_BuyOutfit.id);
        }
    }
コード例 #2
0
ファイル: RackScroller.cs プロジェクト: vladfaust/butterflix
    //=====================================================

    public void Update()
    {
        if (m_bSwiping)
        {
            Vector3 WorldPos = m_GUI2DCamera.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, 1.0f));
            WorldPos *= 800.0f;
            float SwipingDeltaX = WorldPos.x - m_SwipingStartX;

            m_SwipingAccel = (WorldPos - m_LastWorldPos[3]).x;
            for (int MIdx = 3; MIdx > 0; MIdx--)
            {
                m_LastWorldPos[MIdx] = m_LastWorldPos[MIdx - 1];
            }
            m_LastWorldPos[0] = WorldPos;

            m_DestinationItemIndex = m_SwipingStartItemIndex - (SwipingDeltaX * 0.0079f);

            List <ClothingItemData> CurClothingList = ClothingItemsManager.GetClothingItems(m_CurrentFairy);
            int MaxItems = CurClothingList.Count;

            float MinSwipePos = (float)-2.0f;
            float MaxSwipePos = (float)(MaxItems - 4);
            if (MaxSwipePos < 0.0f)
            {
                MaxSwipePos = 0.0f;
            }
            //MinSwipePos -= 0.4f;
            MaxSwipePos += 0.4f;

            if (m_DestinationItemIndex < MinSwipePos)
            {
                m_DestinationItemIndex = MinSwipePos;
            }
            if (m_DestinationItemIndex > MaxSwipePos)
            {
                m_DestinationItemIndex = MaxSwipePos;
            }

            if (Input.GetMouseButtonUp(0))
            {
                m_bSwiping = false;
                //m_DestinationItemIndex = (float)((int)(m_DestinationItemIndex + 0.5f));

                m_SwipingAccel = Mathf.Clamp(m_SwipingAccel, -25.0f, 25.0f);
            }
        }
        else
        {
            // Not swiping
            Vector3 WorldPos = m_GUI2DCamera.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, 1.0f));
            WorldPos *= 800.0f;
            for (int MIdx = 3; MIdx > 0; MIdx--)
            {
                m_LastWorldPos[MIdx] = WorldPos;
            }

            m_SwipingStartX         = WorldPos.x;
            m_SwipingStartItemIndex = m_DestinationItemIndex;

            //Debug.Log( WorldPos );
            if (Input.GetMouseButtonDown(0))
            {
                if ((WorldPos.y > 1004.0f) && (WorldPos.y < 1345.0f))
                {
                    if ((WorldPos.x > -497.0f) && (WorldPos.x < 314.0f))
                    {
                        m_bSwiping     = true;
                        m_SwipingAccel = 0.0f;
                    }
                }
            }
            else
            {
                //m_DestinationItemIndex -= m_SwipingAccel * Time.deltaTime * 0.35f;
                m_SwipingAccel *= 0.92f;
            }
        }

        PreHelpers.DeltaTend(ref m_CurrentItemIndex, m_DestinationItemIndex, 7.5f, Time.deltaTime);

        // Update renderer
        if (RackRenderer.instance != null)
        {
            RackRenderer.instance.m_CurItem = m_CurrentItemIndex;
        }
    }
コード例 #3
0
    //=====================================================

    public void Update()
    {
        // Render if page has changed
        bool bUpdateResources = false;

        // Position the rack with the correct offset
        float Offset = m_CurItem % 1.0f;

        Offset *= m_RackSpacing;
        this.transform.localPosition = new Vector3(-Offset + m_RackBasePosition.x, m_RackBasePosition.y, m_RackBasePosition.z);

        // Load the correct sprites for each piece of clothing into the render slots we have
        int ItemOffset = (int)m_CurItem;

        if (ItemOffset != m_LastItemOffsetRendered)
        {
            //Debug.Log("RES");
            bUpdateResources = true;
        }

        m_LastItemOffsetRendered = ItemOffset;

        List <ClothingItemData> CurClothingList = ClothingItemsManager.GetClothingItems(m_CurrentFairy);
        int MaxItems = CurClothingList.Count;

        for (int Idx = 0; Idx < 8; Idx++)
        {
            // Valid outfit?
            int OutfitIndex = Idx + ItemOffset;

            bool bValidOutfit = false;

            ClothingItemData CurOutfit = null;
            if (OutfitIndex < 0)
            {
                bValidOutfit = false;
            }
            else
            {
                if (OutfitIndex < MaxItems)
                {
                    CurOutfit = CurClothingList[OutfitIndex];
                    if (CurOutfit == null)
                    {
                        bValidOutfit = false;
                    }
                    else
                    {
                        bValidOutfit = true;
                    }
                }
            }

            if (bValidOutfit)
            {
                m_RackItems[Idx].SetActive(true);

                // Update sprite for this outfit
                UnityEngine.SpriteRenderer RenderOutfitImage = m_RackItems[Idx].GetComponent(typeof(UnityEngine.SpriteRenderer)) as UnityEngine.SpriteRenderer;
                CurOutfit.currentRotation += Time.deltaTime * 1.4f;

                if (bUpdateResources)
                {
                    string Filename     = "Clothing/GUITextures/" + CurOutfit.guiTexture2D;
                    Sprite RenderSprite = (Sprite)Resources.Load(Filename, typeof(Sprite));
                    RenderOutfitImage.sprite  = RenderSprite;
                    RenderOutfitImage.enabled = true;
                }

                float outfitRotation = Mathf.Sin(CurOutfit.currentRotation) * 7.0f;
                m_RackItems[Idx].transform.eulerAngles = new Vector3(0.0f, 344.0f + outfitRotation, 0.0f);
            }
            else
            {
                m_RackItems[Idx].SetActive(false);
            }
        }
    }