Exemplo n.º 1
0
    public void saveAttribute()
    {
        //Find seleted obj
        myObject = GameObject.FindGameObjectWithTag("Selected");
        MyScript myScriptVariable = myObject.GetComponent <MyScript>();

        //Find obj panel in obj
        ScriptActive myPanelVariable = myObject.GetComponent <ScriptActive>();

        myPanel = myPanelVariable.scriptBox;


        //This part should generate or sent something to [MyScript.cs] of [seleted object(myObject)]

        foreach (Transform obj in myPanel.transform)
        {
            if (obj.name == "Slot" || obj.name == "Slot(Clone)")
            {
                SlotAttachment slotVariable = obj.GetComponent <SlotAttachment>();
                if (slotVariable.script)
                {
                    GameObject slotScripts = slotVariable.script;
                    Debug.Log("FOUND: " + slotScripts.name);

                    /////////sent SCRIPTS to OBJ down here////////
                }
                else
                {
                    break;
                }
            }
        }

        myScriptVariable.isResetScript = true;
    }
Exemplo n.º 2
0
 private void SlideUpScript(SlotAttachment nextSlot)
 {
     /*Debug.Log("Bye: " + script.name);
      * Debug.Log("Slide up: " + nextSlot.script.name);*/
     script = nextSlot.script;
     SetScriptPosition();
     nextSlot.script = null;
 }
Exemplo n.º 3
0
    public void save()
    {
        itemContent = GameObject.Find("ContentForJSON");

        ItemListAdder     itemVariable = itemContent.GetComponent <ItemListAdder>();
        List <GameObject> itemList     = itemVariable.itemGOList;

        foreach (GameObject item in itemList)
        {
            PrefabData x = new PrefabData();
            x.name = item.name;
            //save position
            x.posX = item.transform.position.x;
            x.posY = item.transform.position.y;
            x.posZ = item.transform.position.z;
            //save rotation
            x.rotX = item.transform.rotation.x;
            x.rotY = item.transform.rotation.y;
            x.rotZ = item.transform.rotation.z;
            //save scale
            x.sizeX = item.transform.localScale.x;
            x.sizeY = item.transform.localScale.y;
            x.sizeZ = item.transform.localScale.z;
            //save grav --> need to be set soon !!!!!
            x.grav = false;
            //save slot
            ScriptActive sa = item.GetComponent <ScriptActive>(); //find ScriptPanel of this obj
            GameObject   sp = sa.scriptBox;                       //Script panel
            foreach (Transform child in sp.transform)
            {
                if (child.name == "Slot" || child.name == "Slot(Clone)")
                {
                    Debug.Log("YEE");
                    //this is slot
                    x.slot.Add(child.name);
                    Debug.Log("YEET");
                    //this is its script
                    if (child.GetComponent <SlotAttachment>().script)
                    {
                        SlotAttachment sac = child.GetComponent <SlotAttachment>();
                        x.scriptSlot.Add(sac.script.name);
                    }
                }
            }



            prefabData.Add(x);
        }

        Debug.Log(prefabData);

        string json = JsonUtility.ToJson(this); //this = this Script

        File.WriteAllText(Application.dataPath + "/saveFile.json", json);
        Debug.Log(json);
    }
Exemplo n.º 4
0
    public void OnEndDrag(PointerEventData eventData)
    {
        if (item.tag != "Object" && onDropArea && GameObject.FindGameObjectWithTag("Selected") != null && dropBox.GetComponent <ScriptsManager>().correctType)
        {
            //script attaching
            item.transform.SetParent(dropBox.GetComponent <ScriptsManager>().scriptAttachedPoint.transform);
            itemScript.currentItem = null;

            //find slot in dropbox
            Transform slot = dropBox.GetComponent <ScriptsManager>().slot.transform;
            item.transform.localPosition = new Vector3(slot.localPosition.x, slot.localPosition.y, slot.localPosition.z);

            SlotAttachment currentSlot = slot.GetComponent <SlotAttachment>();
            currentSlot.attached = true;
            currentSlot.script   = item;

            onDropArea = false;
        }
        else if (item.tag != "Object" && (!onDropArea || GameObject.FindGameObjectWithTag("Selected") == null || !dropBox.GetComponent <ScriptsManager>().correctType))
        {
            Destroy(item);
        }
        else if (item.tag == "Object" && onDropArea)
        {
            Destroy(item);
        }

        /*GameObject item = Instantiate(model, new Vector3(transform.position.x, transform.position.y, transform.position.z), Quaternion.identity);
         */
        //item.transform.SetParent(null);
        if (item)
        {
            SetSortingLayer("Object");
            transform.localPosition = FixPosition;
            if (item.tag == "Object")
            {
                itemList.GetComponent <ItemListAdder>().newItem  = item;
                itemList.GetComponent <ItemListAdder>().itemName = model.name;

                //add item and script panel to scriptsmanager's list

                /*ScriptsManager scriptsManagerVariable = scriptsManager.GetComponent<ScriptsManager>();
                 * scriptsManagerVariable.itemList.Add(item);*/
                scp = Instantiate(scriptsPanel, new Vector3(0, 0, 0), Quaternion.identity);
                item.GetComponent <ScriptActive>().scriptBox = scp;
                //scriptsManagerVariable.panelList.Add(scp);
            }
        }

        item = null;
        if (dropBox)
        {
            dropBox.GetComponent <ScriptsManager>().currentScript = null;
        }
    }
Exemplo n.º 5
0
    private void SlideDownScript()
    {
        SlotAttachment prevSlot = prev.GetComponent <SlotAttachment>();

        if (prevSlot.script)
        {
            script = prevSlot.script;
            SetScriptPosition();
            if (!prevSlot.attached)
            {
                prevSlot.script = null;
            }
        }
    }
Exemplo n.º 6
0
    // Update is called once per frame
    void Update()
    {
        if (gameObject.GetComponent <ScriptPlay>().play)
        {
            whileCol = gameObject.transform.Find("whileCol").gameObject.GetComponent <SlotAttachment>();
            doCol    = gameObject.transform.Find("doCol").gameObject.GetComponent <SlotAttachment>();
            if (whileCol && doCol)
            {
                if (!doCol.script.GetComponent <ScriptPlay>().thisObject || !whileCol.script.GetComponent <ScriptPlay>().thisObject)
                {
                    whileCol.script.GetComponent <ScriptPlay>().thisObject = gameObject.GetComponent <ScriptPlay>().thisObject;
                    doCol.script.GetComponent <ScriptPlay>().thisObject    = gameObject.GetComponent <ScriptPlay>().thisObject;
                }

                whileCol.script.GetComponent <ScriptPlay>().play = true;
                if (whileCol.script.GetComponent <ScriptPlay>().outVal)
                {
                    doCol.script.GetComponent <ScriptPlay>().play = true;
                }
                else
                {
                    doCol.script.GetComponent <ScriptPlay>().play = false;
                }
            }
        }
        else
        {
            whileCol = gameObject.transform.Find("whileCol").gameObject.GetComponent <SlotAttachment>();
            doCol    = gameObject.transform.Find("doCol").gameObject.GetComponent <SlotAttachment>();
            if (whileCol && doCol)
            {
                if (!doCol.script.GetComponent <ScriptPlay>().thisObject || !whileCol.script.GetComponent <ScriptPlay>().thisObject)
                {
                    whileCol.script.GetComponent <ScriptPlay>().thisObject = gameObject.GetComponent <ScriptPlay>().thisObject;
                    doCol.script.GetComponent <ScriptPlay>().thisObject    = gameObject.GetComponent <ScriptPlay>().thisObject;
                }

                whileCol.script.GetComponent <ScriptPlay>().play = false;
                if (whileCol.script.GetComponent <ScriptPlay>().outVal)
                {
                    doCol.script.GetComponent <ScriptPlay>().play = false;
                }
                else
                {
                    doCol.script.GetComponent <ScriptPlay>().play = false;
                }
            }
        }
    }
Exemplo n.º 7
0
    private void Resizing(GameObject script)
    {
        BoxCollider slotCollider   = GetComponent <BoxCollider>();
        BoxCollider scriptCollider = script.GetComponent <BoxCollider>();

        if (next)
        {
            SlotAttachment nextSlot = next.GetComponent <SlotAttachment>();
            nextSlot.resize = true;
        }
        Debug.Log("Resizing: " + script.name);

        transform.localScale = new Vector3(script.transform.localScale.x, script.transform.localScale.y, script.transform.localScale.z);
        float temp = slotCollider.size.y;

        slotCollider.size = new Vector3(slotCollider.size.x, scriptCollider.size.y, slotCollider.size.z);

        if (prev)
        {
            BoxCollider prevCollider = prev.GetComponent <BoxCollider>();
            transform.localPosition = new Vector3(transform.localPosition.x,
                                                  prev.transform.localPosition.y - 1.5f - (slotCollider.size.y * transform.localScale.y + prevCollider.size.y * prev.transform.localScale.y) / 2,
                                                  transform.localPosition.z);
            SetScriptPosition();
        }
        else
        {
            if (temp <= scriptCollider.size.y)
            {
                transform.localPosition = new Vector3(transform.localPosition.x,
                                                      transform.localPosition.y - Mathf.Abs(slotCollider.size.y - temp) * transform.localScale.y / 2,
                                                      transform.localPosition.z);
            }
            else
            {
                transform.localPosition = new Vector3(transform.localPosition.x,
                                                      transform.localPosition.y + Mathf.Abs(slotCollider.size.y - temp) * transform.localScale.y / 2,
                                                      transform.localPosition.z);
            }
            SetScriptPosition();
        }
        resize = false;
    }
Exemplo n.º 8
0
    // Update is called once per frame
    void Update()
    {
        SlotAttachment currentSlot = slot.GetComponent <SlotAttachment>();
        SlotAttachment latestSlot  = latest.GetComponent <SlotAttachment>();

        if (currentScript)
        {
            if (currentSlot.gameObject.name == "whileCol" && currentScript.GetComponent <ScriptType>().type == ScriptType.Type.Argument)
            {
                correctType = true;
            }
            else if (currentSlot.gameObject.name != "whileCol" && currentScript.GetComponent <ScriptType>().type == ScriptType.Type.Action)
            {
                correctType = true;
            }
            else
            {
                correctType = false;
            }
        }

        if (currentSlot.attached)
        {
            if (slot == latest)
            {
                GameObject newSlot = Instantiate(slotPrefab, new Vector3(latestSlot.transform.position.x,
                                                                         latest.transform.position.y - 8.5f, latestSlot.transform.position.z), Quaternion.identity, gameObject.transform);
                latestSlot.next = newSlot;
                SlotAttachment nextSlot = newSlot.GetComponent <SlotAttachment>();
                nextSlot.prev = latest;
                slot          = newSlot;
                latest        = slot;
            }
            else
            {
                slot = latest;
            }
            split      = false;
            splitPoint = null;
        }
    }
Exemplo n.º 9
0
    public void OnEndDrag(PointerEventData eventData)
    {
        if (onDropArea && dropBox.GetComponent <ScriptsManager>().correctType)
        {
            //Attach with dropbox ("Collider")
            gameObject.transform.SetParent(dropBox.GetComponent <ScriptsManager>().scriptAttachedPoint.transform);

            //find slot in dropbox
            Transform slot = dropBox.GetComponent <ScriptsManager>().slot.transform;
            gameObject.transform.localPosition = new Vector3(slot.localPosition.x, slot.localPosition.y, slot.localPosition.z);

            SlotAttachment slotAvail = slot.GetComponent <SlotAttachment>();
            slotAvail.attached = true;
            slotAvail.script   = gameObject;
        }
        else
        {
            Destroy(gameObject);
        }
        itemScript.currentScript = null;
        dropBox.GetComponent <ScriptsManager>().currentScript = null;
    }
Exemplo n.º 10
0
    // Update is called once per frame
    void Update()
    {
        if (scriptsManager.slot == gameObject)
        {
            scriptsManager.scriptAttachedPoint = transform.parent.gameObject;
        }

        //Resizing slot
        if (script)
        {
            BoxCollider slotCollider   = GetComponent <BoxCollider>();
            BoxCollider scriptCollider = script.GetComponent <BoxCollider>();

            if (slotCollider.size.y != scriptCollider.size.y || resize)
            {
                Resizing(script);
            }

            if (scriptsManager && scriptsManager.onSelected)
            {
                script.GetComponent <Canvas>().enabled = true;
            }
            else if (!scriptsManager.onSelected)
            {
                script.GetComponent <Canvas>().enabled = false;
            }
        }

        //Slide script up
        if (attached && script)
        {
            if (Mathf.Abs(script.transform.position.x - gameObject.transform.position.x) > disX ||
                Mathf.Abs(script.transform.position.y - gameObject.transform.position.y) > disY)
            {
                SlotAttachment nextSlot = next.GetComponent <SlotAttachment>();
                if (nextSlot.script)
                {
                    SlideUpScript(nextSlot);
                }
                else
                {
                    SetCurrentSlot();
                }
            }
        }
        else if (attached && !script)
        {
            SlotAttachment nextSlot = next.GetComponent <SlotAttachment>();
            if (nextSlot.script)
            {
                SlideUpScript(nextSlot);
            }
            else
            {
                SetCurrentSlot();
            }
        }

        //while & if
        if (script)
        {
            GameObject whileCol = script.transform.Find("whileCol").gameObject;
            GameObject doCol    = script.transform.Find("doCol").gameObject;

            SlotAttachment whileSlot = whileCol.GetComponent <SlotAttachment>();
            SlotAttachment doSlot    = doCol.GetComponent <SlotAttachment>();

            if (!whileSlot)
            {
                whileSlot = whileCol.AddComponent <SlotAttachment>();
            }
            if (!doSlot)
            {
                doSlot = doCol.AddComponent <SlotAttachment>();
            }

            if (whileCol || doCol && scriptsManager.currentScript)
            {
                float whileY = Mathf.Abs(whileCol.transform.position.y - scriptsManager.currentScript.transform.position.y);
                float whileX = Mathf.Abs(whileCol.transform.position.x - scriptsManager.currentScript.transform.position.x);
                float doY    = Mathf.Abs(doCol.transform.position.y - scriptsManager.currentScript.transform.position.y);
                float doX    = Mathf.Abs(doCol.transform.position.x - scriptsManager.currentScript.transform.position.x);

                if ((whileY <= 5 && whileX <= 15) && ((doY > 5 && doX > 15) || whileY < doY))
                {
                    Debug.Log("Entering while collider");
                    scriptsManager.slot = whileCol;
                }
                else if ((doY <= 5 && doX <= 15) && ((whileY > 5 && whileX > 15) || whileY > doY))
                {
                    Debug.Log("Entering do collider");
                    scriptsManager.slot = doCol;
                }
                else
                {
                    Debug.Log("Exiting while collider");
                    scriptsManager.slot = scriptsManager.latest;
                }
            }
        }

        //init new script in between old ones

        /*ScriptsManager scriptsManager = GetComponentInParent<ScriptsManager>();
         * GameObject currentScript = scriptsManager.currentScript;
         * float diffY = Mathf.Abs(transform.position.y - currentScript.transform.position.y);
         * float diffX = Mathf.Abs(transform.position.x - currentScript.transform.position.x);
         * if (script && currentScript && gameObject != scriptsManager.slot
         *  && diffY <= disY && diffX <= disX && transform.position.y < currentScript.transform.position.y)
         * {
         *  scriptsManager.split = true;
         *  scriptsManager.splitPoint = gameObject;
         * }
         * /*else if (gameObject == scriptsManager.slot && gameObject != scriptsManager.latest && (diffY > disY || diffX > disX))
         * {
         *  scriptsManager.split = false;
         * }
         *
         * if (!scriptsManager.split && scriptsManager.splitPoint)
         * {
         *  if (transform.position.y <= scriptsManager.splitPoint.transform.position.y)
         *  {
         *      if (next)
         *      {
         *          SlotAttachment nextSlot = next.GetComponent<SlotAttachment>();
         *          SlideUpScript(nextSlot);
         *      }
         *      else
         *      {
         *          SetCurrentSlot();
         *      }
         *
         *      if (gameObject == scriptsManager.splitPoint)
         *      {
         *          attached = true;
         *          scriptsManager.splitPoint = null;
         *      }
         *  }
         * }
         *
         * if(scriptsManager.split && scriptsManager.splitPoint  && currentScript)
         * {
         *  if(prev && scriptsManager.splitPoint != gameObject && transform.position.y < currentScript.transform.position.y)
         *  {
         *      SlideDownScript();
         *      Resizing(script);
         *  }
         *  else if(scriptsManager.splitPoint == gameObject)
         *  {
         *      attached = false;
         *      scriptsManager.slot = gameObject;
         *      Resizing(currentScript);
         *  }
         * }*/
    }