/// <summary> /// Try to place the primitive in parameter /// </summary> /// <param name="primitive">Primitive to place</param> /// <param name="cursor">Cursor position</param> public virtual bool PushPrimitive(Primitive primitive, Vector2 cursor) { // Debug.Log ("PushPrimitive"); if (this.GlobalArea.Contains(cursor)) { PrimitiveContainer pc = this.FirstParentContainer(); if (pc != null) { if (pc is PrimitiveContainer) { // Debug.Log ("est dans un PrimitiveContainer"); if (pc.Inner_Container && primitive.Instruction is Condition) { // Debug.Log ("PushPrimitive condition ok"); this.Next = primitive; List <Condition> conditions = new List <Condition> (); Primitive p = pc.First.Next; while (p != null) { conditions.Add((Condition)p.Instruction); p = p.Next; } ((Control)((Primitive)pc.parent).Instruction).setConditions(conditions); return(true); } else if (!pc.Inner_Container && (primitive.Instruction is Action || primitive.Instruction is If)) { // Debug.Log ("PushPrimitive action ok"); this.Next = primitive; List <Instruction> actions = new List <Instruction> (); Primitive p = pc.First.Next; while (p != null) { if (p is Action || p is If) { actions.Add((Action)p.Instruction); } p = p.Next; } if (((Primitive)pc.parent).Instruction is Task) { ((Task)((Primitive)pc.parent).Instruction).setActions(actions); } else if (((Primitive)pc.parent).Instruction is If) { if (pc.Equals(((Primitive)pc.parent).Outer)) { ((If)((Primitive)pc.parent).Instruction).setActions(actions); } else if (pc.Equals(((Primitive)pc.parent).ElseOuter)) { ((If)((Primitive)pc.parent).Instruction).setElseActions(actions); } } return(true); } else { // Debug.Log ("Primitive au mauvais endroit..."); return(false); } } } // Debug.Log ("Pas dans un PrimitiveContainer PushPrimitive ok"); this.Next = primitive; return(true); } else { foreach (Widget w in this.childs) { if (typeof(Primitive).Equals(w.GetType())) { // Debug.Log ("PushPrimitive fils ?"); if (((Primitive)w).PushPrimitive(primitive, cursor)) { return(true); } } else if (typeof(PrimitiveContainer).Equals(w.GetType())) { // Debug.Log ("PushPrimitiveContainer fils ?"); if (((PrimitiveContainer)w).PushPrimitive(primitive, cursor)) { return(true); } } } } // Debug.Log ("Primitive tombée dans le vide..."); return(false); }