コード例 #1
0
    public void InsertAt(int Order, GameObject GameObj)
    {
        GameObj.GetComponent <Drag>().order = Order;
        //Debug.Log("Inserting " + GameObj + " at " + Order);
        //TODO: When inserting/removing a block inside a resizable block, the block after the resizable block won't change pos most of the time
        int SkipsPoint = 0;

        temporary = obj;
        int  StartPoint = 0;
        int  V          = 0;
        Drag res        = null;
        bool Skip       = false;
        bool Reset      = false;

        int AdvencementPoints = 0;

        if (temporary.Count == 0)
        {
            Skip = true;
        }
        for (int i = 0; !Skip; i++)
        {
            //Debug.Log("I is " + i);
            if (Reset && 0 < temporary.Count)
            {
                //Debug.Log("I is 0");
                i     = 0;
                Reset = false;
            }
            else if (Reset && 0 >= temporary.Count)
            {
                //Debug.Log("Out of sequence");
                V = 0;
                break;
            }
            //First, check to see if the block is inside a resizable block (Or inside a resizable that is inside a resizable block...)
            //Debug.Log("Is " + temporary.ToArray()[i].name + " a resizable block? " + temporary.ToArray()[i].GetComponent<Resize>());
            if (temporary.ToArray()[i].GetComponent <Resize>())             //order was order-startpoint
            //Debug.Log("Checking if " + (Order-StartPoint) + " is > than " + (AdvencementPoints-1) + " and < than " + (AdvencementPoints+temporary.ToArray()[i].GetComponent<Resize>().Steps));
            {
                if (Order > AdvencementPoints - 1 /* + i*/ && Order < AdvencementPoints + temporary.ToArray()[i].GetComponent <Resize>().Steps)
                {
                    AdvencementPoints++;
                    //Debug.Log("What is temporairy?");
                    //Debug.Log("res: " + temporary.ToArray()[i].GetComponent<Drag>().strsources[0] + ", temporary: " + temporary.ToArray()[i].GetComponent<Drag>().childs.Count);
                    res       = temporary.ToArray()[i].GetComponent <Drag>();
                    temporary = temporary.ToArray()[i].GetComponent <Drag>().childs;
                    V         = i;
                    //Debug.Log("Adding " + (i+1) + " to the StartPoint");
                    StartPoint += i /*+1*/;
                    Reset       = true;
                    //Debug.Log("Iteration: " + i);
                }
                else
                {
                    AdvencementPoints += temporary.ToArray()[i].GetComponent <Resize>().Steps + 1;
                }
            }
            else
            {
                AdvencementPoints++;
            }
            //StartPoint += i+1;
            if ((i + 1 >= temporary.Count) && !Reset)
            {
                //Debug.Log("Breaking");
                break;
            }
        }
        if (res != null)
        {
            res.AddChild(GameObj, Mathf.Clamp((Order - (StartPoint)), 0, res.GetComponent <Resize>().Steps - 2));

            //res is GOOD!

            //res.Replace();
            return;
        }

        obj.Insert(Mathf.Clamp(Order, 0, obj.Count), GameObj);
        for (int i = 0; i < obj.Count; i++)
        {
            obj.ToArray()[i].GetComponent <RectTransform>().localPosition = new Vector3(GetComponent <RectTransform>().sizeDelta.x / 2 + 6 + (24 * obj.ToArray()[i].GetComponent <Drag>().Aligment), -20 - ((i + SkipsPoint) * 27), 0);
            if (obj.ToArray()[i].GetComponent <Resize>())
            {
                SkipsPoint += obj.ToArray()[i].GetComponent <Resize>().Steps;
            }
        }
        RedistributeReplaceAction();
    }