private void Start()
    {
        //DeclaredVariable = GameObject.Find("gameObjectName").GetComponent<ComponentName>();
        ballGM = GameObject.FindObjectOfType <ballmanager>();

        destructNow = GameObject.FindObjectOfType <selfdestruct>();
    }
    public int AddinTab(selfdestruct[] tab, int max, selfdestruct me)
    {
        int index = FindEmptyCase(tab, max);

        if (index == -1)
        {
            Debug.Log(" probleme tente d'ajouter objet sans avoir la place");
            return(-1);
        }

        tab[index] = me;
        return(index);
    }
    public void SetReactivation(selfdestruct obj, int index, bool state)
    {
        if (index < 0)
        {
            Debug.Log(" probleme d'indice");
            return;
        }


        switch (obj.me.name)
        {
        case "obj_gate or":
            tab_or[index].SetReactivation(state);
            break;

        case "obj_gate and":
            tab_and[index].SetReactivation(state);
            break;

        case "obj_gate no":
            tab_no[index].SetReactivation(state);
            break;

        case "obj_gate nand":
            tab_nand[index].SetReactivation(state);
            break;

        case "obj_gate xor":
            tab_xor[index].SetReactivation(state);
            break;

        case "obj_gate nor":
            tab_nor[index].SetReactivation(state);
            break;


        case "obj_input":
            tab_giver[index].SetReactivation(state);
            break;

        case "obj_output":
            tab_taker[index].SetReactivation(state);
            break;

        default:
            Debug.Log(" Appel annormal car rien ne correspond (  default )");
            break;
        }
    }
    public int CanAddObj(selfdestruct obj)// revoie 0 si on à le droit d'instancier l'objet et 1 si c'est interdit
    {
        if (obj.me.name == "obj_gate or" && nb_g_or < max_g_no)
        {
            return(0);
        }

        if (obj.me.name == "obj_gate and" && nb_g_and < max_g_and)
        {
            return(0);
        }
        if (obj.me.name == "obj_gate no" && nb_g_no < max_g_no)
        {
            return(0);
        }
        if (obj.me.name == "obj_gate nand" && nb_g_nand < max_g_nand)
        {
            return(0);
        }
        if (obj.me.name == "obj_gate xor" && nb_g_xor < max_g_xor)
        {
            return(0);
        }
        if (obj.me.name == "obj_gate nor" && nb_g_nor < max_g_nor)
        {
            return(0);
        }
        if (obj.me.name == "obj_input" && nb_giver < max_giver)
        {
            return(0);
        }
        if (obj.me.name == "obj_output" && nb_taker < max_taker)
        {
            return(0);
        }

        return(1);
    }
    public int DeleteObj(selfdestruct obj)// renvoie 0 si on ne doit pas remettre une instance dans le stock , et 1 si on doit le faire
    {
        int ret_value = 0;

        if (obj.me.name == "obj_gate or")
        {
            if (nb_g_or == max_g_or)
            {
                ret_value = 1;
            }
            tab_or[obj.GetIndex()] = null;
            nb_g_or--;
        }

        if (obj.me.name == "obj_gate and")
        {
            if (nb_g_and == max_g_and)
            {
                ret_value = 1;
            }
            tab_and[obj.GetIndex()] = null;
            nb_g_and--;
        }
        if (obj.me.name == "obj_gate no")
        {
            if (nb_g_no == max_g_no)
            {
                ret_value = 1;
            }
            tab_no[obj.GetIndex()] = null;
            nb_g_no--;
        }
        if (obj.me.name == "obj_gate nand")
        {
            if (nb_g_nand == max_g_nand)
            {
                ret_value = 1;
            }
            tab_nand[obj.GetIndex()] = null;
            nb_g_nand--;
        }
        if (obj.me.name == "obj_gate xor")
        {
            if (nb_g_xor == max_g_xor)
            {
                ret_value = 1;
            }
            tab_xor[obj.GetIndex()] = null;
            nb_g_xor--;
        }
        if (obj.me.name == "obj_gate nor")
        {
            if (nb_g_nor == max_g_nor)
            {
                ret_value = 1;
            }
            tab_nor[obj.GetIndex()] = null;
            nb_g_nor--;
        }
        if (obj.me.name == "obj_input")
        {
            if (nb_giver == max_giver)
            {
                ret_value = 1;
            }
            tab_giver[obj.GetIndex()] = null;
            nb_giver--;
        }
        if (obj.me.name == "obj_output")
        {
            if (nb_taker == max_taker)
            {
                ret_value = 1;
            }
            tab_taker[obj.GetIndex()] = null;
            nb_taker--;
        }

        return(ret_value);
    }
    public void Addobj(selfdestruct obj)
    {
        int ret;

        switch (obj.me.name)
        {
        case "obj_gate or":
            ret = AddinTab(tab_or, max_g_or, obj);
            if (ret != -1)
            {
                obj.SetIndex(ret);
                nb_g_or++;
            }
            else
            {
                Debug.Log("non ajouté");
            }
            break;

        case "obj_gate and":
            ret = AddinTab(tab_and, max_g_and, obj);
            if (ret != -1)
            {
                obj.SetIndex(ret);
                nb_g_and++;
            }
            else
            {
                Debug.Log("non ajouté");
            }
            break;

        case "obj_gate no":
            ret = AddinTab(tab_no, max_g_no, obj);
            if (ret != -1)
            {
                obj.SetIndex(ret);
                nb_g_no++;
            }
            else
            {
                Debug.Log("non ajouté");
            }
            break;

        case "obj_gate nand":
            ret = AddinTab(tab_nand, max_g_nand, obj);
            if (ret != -1)
            {
                obj.SetIndex(ret);
                nb_g_nand++;
            }
            else
            {
                Debug.Log("non ajouté");
            }
            break;

        case "obj_gate xor":
            ret = AddinTab(tab_xor, max_g_xor, obj);
            if (ret != -1)
            {
                obj.SetIndex(ret);
                nb_g_xor++;
            }
            else
            {
                Debug.Log("non ajouté");
            }
            break;

        case "obj_gate nor":
            ret = AddinTab(tab_nor, max_g_nor, obj);
            if (ret != -1)
            {
                obj.SetIndex(ret);
                nb_g_nor++;
            }
            else
            {
                Debug.Log("non ajouté");
            }
            break;


        case "obj_input":
            ret = AddinTab(tab_giver, max_giver, obj);
            if (ret != -1)
            {
                obj.SetIndex(ret);
                nb_giver++;
            }
            else
            {
                Debug.Log("non ajouté");
            }
            break;

        case "obj_output":
            ret = AddinTab(tab_taker, max_taker, obj);
            if (ret != -1)
            {
                obj.SetIndex(ret);
                nb_taker++;
            }
            else
            {
                Debug.Log("non ajouté");
            }
            break;

        default:
            Debug.Log(" Appel annormal car rien ne correspond (  default )");
            break;
        }
    }
    //public Vector2 startingPosition = new Vector2 (7.0f, 0.0f);

    //[Space]
    #endregion

    //================================

    #region Unity Methods:

    // Start is called before the first frame update
    private void Awake()
    {
        ballGM   = GameObject.FindObjectOfType <ballmanager>();
        GM       = GameObject.FindObjectOfType <GameMaster>();
        destruct = GameObject.FindObjectOfType <selfdestruct>();
    }
Beispiel #8
0
    public void OnTriggerEnter2D(Collider2D coll)
    {
        selfdestruct me = coll.GetComponent <selfdestruct>();

        Destroy(me.me);
    }