Ejemplo n.º 1
0
    void OnEnable()
    {
        BoxCollider bc = gameObject.AddComponent <BoxCollider>();

        JMFUtils.autoScale(gameObject);
        bc.center = new Vector3(0, 0, 10); // send the collider to the back, so it wont interfere with PieceTracker
    }
Ejemplo n.º 2
0
    // to create the foreground visual...
    void createFrontPanel()
    {
        if (!pnd.isInFront || pnd.hasNoSkin)
        {
            return; // not a front panel... no need to proceed
        }
        if (pnd.skin.Length > 0)
        { // if the prefab exists
            frontPanel = (GameObject)Object.Instantiate(pnd.skin[Mathf.Min(
                                                                     pnd.skin.Length - 1, Mathf.Abs(durability))]);
        }
        else
        {
            Debug.Log("No panel skin available. Have you forgotten to skin the panel script?");
        }

        if (frontPanel != null)
        {
            // re-parent the object to the gameManager panel
            frontPanel.transform.parent        = master.gm.gameObject.transform;
            frontPanel.transform.localPosition = master.localPos;
            JMFUtils.autoScale(frontPanel);
            // minor code just to arrange the Z order to always be at the front
            frontPanel.transform.localPosition += new Vector3(0, 0, -2 * master.gm.size * frontPanel.transform.localScale.z);
        }
    }
Ejemplo n.º 3
0
    //void CreateBackgroundPanel()
    //{
    //    Debug.Log("abcd");
    //    GameObject prefab = null;
    //    if (pnd.hasDefaultPanel2)
    //    {
    //        if (JMFUtils.vm.defaultSquareBackPanel != null)
    //        {
    //            prefab = JMFUtils.vm.defaultSquareBackPanel2;
    //        }
    //    }
    //    if (pnd.hasDefaultPanel)
    //    {
    //        if (JMFUtils.vm.defaultSquareBackPanel != null)
    //        {
    //            prefab = JMFUtils.vm.defaultSquareBackPanel;
    //        }
    //    }
    //    defaultPanel = (GameObject)Object.Instantiate(prefab);
    //    // re-parent the object to the gameManager panel
    //    defaultPanel.transform.parent = master.gm.gameObject.transform;
    //    defaultPanel.transform.localPosition = master.localPos;
    //    JMFUtils.autoScale(defaultPanel);
    //    // minor code just to arrange the Z order to always be at the back
    //    defaultPanel.transform.localPosition +=
    //        new Vector3(0, 0, 4 * master.gm.size * defaultPanel.transform.localScale.z);
    //}

    // to create the background visual...
    void createBackPanel()
    {
        if (pnd.hasDefaultPanel2)
        {
            createDefaultPanel(1);
        }
        if (pnd.hasDefaultPanel)
        {
            createDefaultPanel(0); // creates the default panel when specified
        }

        if (pnd.isInFront || pnd.hasNoSkin)
        {
            return; // already created a front panel, do not make this back panel
        }

        if (pnd.skin.Length > 0)
        { // if the prefab exists
            backPanel = (GameObject)Object.Instantiate(pnd.skin[Mathf.Min(pnd.skin.Length - 1, Mathf.Abs(durability))]);
        }
        else
        {
            Debug.Log("No panel skin available. Have you forgotten to skin the panel script?");
        }

        if (backPanel != null)
        {
            // re-parent the object to the gameManager panel
            backPanel.transform.parent        = master.gm.gameObject.transform;
            backPanel.transform.localPosition = master.localPos;
            JMFUtils.autoScale(backPanel);
            // positioning code
            backPanel.transform.localPosition += new Vector3(0, 0, 2 * master.gm.size * backPanel.transform.localScale.z);
        }
    }
Ejemplo n.º 4
0
    // function to create the default panel - in case of tranparency backPanels
    protected void createDefaultPanel(int i)
    {
        GameObject prefab = null;

        if (JMFUtils.vm.defaultSquareBackPanel != null)
        { // if the prefab exists
            switch (i)
            {
            case 0:
                prefab = JMFUtils.vm.defaultSquareBackPanel;
                break;

            case 1:
                prefab = JMFUtils.vm.defaultSquareBackPanel2;
                break;

            default:
                break;
            }
        }
        else
        {
            Debug.Log("whoops? have you forgotten to provide a default panel prefab?");
            return; // do not continue...
        }
        defaultPanel = (GameObject)Object.Instantiate(prefab);
        // re-parent the object to the gameManager panel
        defaultPanel.transform.parent        = master.gm.gameObject.transform;
        defaultPanel.transform.localPosition = master.localPos;

        JMFUtils.autoScale(defaultPanel);

        // minor code just to arrange the Z order to always be at the back
        //defaultPanel.transform.localPosition +=
        //    new Vector3(0, 0, 4 * master.gm.size * defaultPanel.transform.localScale.z);
        defaultPanel.transform.localPosition +=
            new Vector3(0, 0, 1);
    }
Ejemplo n.º 5
0
    // visual representation of the game piece to the player
    public void dressMe()
    {
        destroyCall(1);
        if (pd == null)
        {
            return; // no piece definition... quit
        }
        if (pd is TreasurePiece)
        {
            Debug.Log("sinh con sau");
            int a = Random.Range(0, 100);
            Debug.Log("b=" + a);
            if (a % 2 == 0)
            {
                if (wc.countSpwanTreasure1 > 0)
                {
                    thisPiece = (GameObject)Object.Instantiate(pd.getSkin(0));
                    wc.countSpwanTreasure1--;
                    Debug.Log("sinh sau1");
                }
                else
                {
                    thisPiece = (GameObject)Object.Instantiate(pd.getSkin(1));
                    wc.countSpwanTreasure2--;
                    Debug.Log("sinh sau2");
                }
            }
            else
            {
                if (wc.countSpwanTreasure2 > 0)
                {
                    thisPiece = (GameObject)Object.Instantiate(pd.getSkin(1));
                    wc.countSpwanTreasure2--;
                    Debug.Log("sinh sau2");
                }
                else
                {
                    thisPiece = (GameObject)Object.Instantiate(pd.getSkin(0));
                    wc.countSpwanTreasure1--;
                    Debug.Log("sinh sau2");
                }
            }
        }
        else
        {
            thisPiece = (GameObject)Object.Instantiate(pd.getSkin(slotNum));
        }


        if (pd is HorizontalPiece || pd is VerticalPiece || pd is SpecialFive || pd is BombPiece)
        {
            gm.animScript.doAnim(animType.CONVERTSPEC, master.arrayRef);
        }
        pd.onPieceCreated(this);                                       // piece is created, call the onCreate (if any)
        thisPiece.transform.parent   = master.gm.gameObject.transform; // re-parent the object to the gameManager panel
        thisPiece.transform.position = position;

        if (thisPiece.GetComponent <CircleCollider2D>() == null)
        {
            thisPiece.AddComponent <CircleCollider2D>(); // add a box collider if not present
        }

        JMFUtils.autoScalePadded(thisPiece); // auto scaling feature
        pd.extraPiecePositioning(thisPiece);

        // prefab properties to sync-up ( don't forget the PieceTracker script )
        PieceTracker pt = thisPiece.GetComponent <PieceTracker>();

        if (pt == null)
        { // if the prefab doesnt have the script, add it dynamically...
            pt = thisPiece.AddComponent <PieceTracker>();
        }

        thisPiece.AddComponent <GP_PieceScripts>();
        pt.arrayRef = master.arrayRef;
    }