Exemplo n.º 1
0
    static void AddSelectorMoveRequestListeners(TileSelector selector, Dictionary <int, Controller> controllers)
    {
        for (var playerIndex = 1; playerIndex <= playersCount; ++playerIndex)
        {
            UnityEventTools.AddIntPersistentListener(
                controllers[playerIndex].DPadLeft.TurnOn,
                new UnityAction <int>(selector.RequestMoveLeft),
                playerIndex
                );

            UnityEventTools.AddIntPersistentListener(
                controllers[playerIndex].DPadRight.TurnOn,
                new UnityAction <int>(selector.RequestMoveRight),
                playerIndex
                );

            UnityEventTools.AddIntPersistentListener(
                controllers[playerIndex].DPadDown.TurnOn,
                new UnityAction <int>(selector.RequestMoveDown),
                playerIndex
                );

            UnityEventTools.AddIntPersistentListener(
                controllers[playerIndex].DPadUp.TurnOn,
                new UnityAction <int>(selector.RequestMoveUp),
                playerIndex
                );
        }
    }
Exemplo n.º 2
0
 static void AddSelectorDirectionChangeListeners(TileDirection direction, Dictionary <int, Controller> controllers)
 {
     for (var playerIndex = 1; playerIndex <= playersCount; ++playerIndex)
     {
         UnityEventTools.AddIntPersistentListener(
             controllers[playerIndex].DownButton.TurnOn,
             new UnityAction <int>(direction.ChangeDirection),
             playerIndex
             );
     }
 }
Exemplo n.º 3
0
            public void Bind(UnityEvent @event)
            {
#if UNITY_EDITOR
                if (value == null)
                {
                    System.Reflection.MethodInfo targetinfo = UnityEvent.GetValidMethodInfo(target, setMethodName, new Type[0]);
                    if (targetinfo == null)
                    {
                        Debug.LogError("no method " + setMethodName + "() in " + target.ToString());
                    }
                    UnityAction action = Delegate.CreateDelegate(typeof(UnityAction), target, targetinfo, false) as UnityAction;
                    UnityEventTools.AddVoidPersistentListener(@event, action);
                }
                else if (value is int)
                {
                    UnityEventTools.AddIntPersistentListener(@event, GetAction <int>(target, setMethodName), (int)value);
                }
                else if (value is float)
                {
                    UnityEventTools.AddFloatPersistentListener(@event, GetAction <float>(target, setMethodName), (float)value);
                }
                else if (value is string)
                {
                    UnityEventTools.AddStringPersistentListener(@event, GetAction <string>(target, setMethodName), (string)value);
                }
                else if (value is bool)
                {
                    UnityEventTools.AddBoolPersistentListener(@event, GetAction <bool>(target, setMethodName), (bool)value);
                }
                else if (value is GameObject)
                {
                    Bind <GameObject>(@event);
                }
                else if (value is Transform)
                {
                    Bind <Transform>(@event);
                }
                else
                {
                    Debug.LogError("unable to assign " + value.GetType());
                }
#else
                System.Reflection.MethodInfo targetinfo = UnityEvent.GetValidMethodInfo(target, setMethodName, new Type[0]);
                @event.AddListener(() => targetinfo.Invoke(target, new object[] { value }));
#endif
            }
Exemplo n.º 4
0
    /// <summary>
    /// Add an action to the UnityEvent displayed in the editor.
    /// </summary>
    /// <param name="button">The object that will listen to the event.</param>
    /// <param name="action">The action to trigger.</param>
    /// <returns>Success state.</returns>
    public static bool AddPersistentEvent(this UnityEvent @event, UnityEngine.Object caller, UnityAction <int> method, int argument)
    {
#if !UNITY_EDITOR
        return(false);
#else
        if (@event.HasCall(caller, method.Method.Name))
        {
            return(false);
        }
        var targetInfo = UnityEventBase.GetValidMethodInfo(caller, method.Method.Name, new Type[] { typeof(int) });
        UnityAction <int> methodDelegate = Delegate.CreateDelegate(typeof(UnityAction <int>), caller, targetInfo) as UnityAction <int>;
        UnityEventTools.AddIntPersistentListener(@event, methodDelegate, argument);

        UnityEditor.SceneManagement.EditorSceneManager.MarkAllScenesDirty();
#endif
        return(true);
    }
Exemplo n.º 5
0
    private void Start()
    {
        for (int i = 0; i < scenarios.Count; ++i)
        {
            Button cachedBtn = GameObject.Instantiate <Button>(btnPreset);

            UnityAction <int> action = Delegate.CreateDelegate(typeof(UnityAction <int>), this, "OnSelectedInScenario") as UnityAction <int>;
            UnityEventTools.AddIntPersistentListener(cachedBtn.onClick, action, i);

            Text cachedText = cachedBtn.GetComponentInChildren <Text>();
            cachedText.text = scenarios[i].GetDisplayName();

            RectTransform cachedTrans = cachedBtn.GetComponentInChildren <RectTransform>();
            cachedTrans.SetParent(this.transform);
            btns.Add(i, cachedTrans);
        }
        SyncPosition();
    }
    public void UnityEvent_EditMode_InvokeDoesNotCallRuntimeListener()
    {
        var _event = new UnityEvent();

        UnityEventTools.AddPersistentListener(_event, new UnityAction(Counter.Add));
        Assert.AreEqual(UnityEventCallState.RuntimeOnly, _event.GetPersistentListenerState(0));
        Assert.False(Application.isPlaying);

        _event.Invoke();

        Assert.AreEqual(0, Counter.m_Count, "Expected Event to not be called when not in play mode and event is marked as Runtime only");

        for (int i = 1; i < 5; ++i)
        {
            UnityEventTools.AddIntPersistentListener(_event, new UnityAction <int>(Counter.NoOp), i);
        }

        _event.Invoke();

        Assert.AreEqual(0, Counter.m_Count, "Expected Event to not be called when not in play mode and event is marked as Runtime only");
    }
    public void UnityEvent_InvokeCallsListenerOnce()
    {
        var _event = new UnityEvent();

        UnityEventTools.AddPersistentListener(_event, new UnityAction(Counter.Add));
        _event.SetPersistentListenerState(0, UnityEventCallState.EditorAndRuntime);

        _event.Invoke();

        Assert.AreEqual(1, Counter.m_Count);

        for (int i = 1; i < 5; ++i)
        {
            UnityEventTools.AddIntPersistentListener(_event, new UnityAction <int>(Counter.NoOp), i);
            _event.SetPersistentListenerState(i, UnityEventCallState.EditorAndRuntime);
        }

        _event.Invoke();

        Assert.AreEqual(2, Counter.m_Count);
    }
        /// <summary>
        /// Reorder menus according to swipyMenu.menus array.
        /// </summary>
        public void ReorderMenus()
        {
            for (int i = 0; i < swipyMenu.menus.Length; i++)
            {
                Transform headerToMove = swipyMenu.menus[i].header.transform;
                Transform menuToMove   = swipyMenu.menus[i].menu;

                headerToMove.SetAsLastSibling();
                menuToMove.SetAsLastSibling();

                Button headerButton = headerToMove.GetComponent <SwipyMenuHeader>().button;
                UnityEventTools.RemovePersistentListener <int>(headerButton.onClick, swipyMenu.HeaderClickHandler);
                UnityEventTools.AddIntPersistentListener(headerButton.onClick, swipyMenu.HeaderClickHandler, i + 1);
                if (swipyMenu.menus[i].Equals(firstToShowOnLoadMenu))
                {
                    swipyMenu.defaultMenuIndex = i;
                }

                ExpandHeaders();
            }
        }
Exemplo n.º 9
0
 public static void AddPersistentListener(this UnityEventBase self, UnityAction <int> unityAction, int argument)
 {
     UnityEventTools.AddIntPersistentListener(self, unityAction, argument);
 }
Exemplo n.º 10
0
    private void EcrireEffets()
    {
        SerializedProperty effet;
        SerializedProperty cible;
        SerializedProperty methode;
        SerializedProperty argumentFloat;
        SerializedProperty argumentInt;

        SerializedObject so = new SerializedObject(buff);

        effet = so.FindProperty("effets.m_PersistentCalls.m_Calls.Array");

        InitialiserListeRetour(buff.listeEffetsRetours, effet.arraySize);

        EffetBonus bonus = effetRef.GetComponent <EffetBonus>();

        for (int i = 0; i < effet.arraySize; i++)
        {
            cible         = effet.FindPropertyRelative("data[" + i + "].m_Target");
            methode       = effet.FindPropertyRelative("data[" + i + "].m_MethodName");
            argumentFloat = effet.FindPropertyRelative("data[" + i + "].m_Arguments.m_FloatArgument");
            argumentInt   = effet.FindPropertyRelative("data[" + i + "].m_Arguments.m_IntArgument");
            string retour = "";

            //Remet à 0 le nombre de listener persitent
            for (int j = 0; j < buff.antiEffets.GetPersistentEventCount(); j++)
            {
                UnityEventTools.RemovePersistentListener(buff.antiEffets, j);
            }

            if (methode.stringValue.Contains("Bonus"))
            {
                if (methode.stringValue.Contains("Attaque"))
                {
                    char pluriel = '\0';
                    if (Math.Abs(argumentInt.intValue) != 1)
                    {
                        pluriel = 's';
                    }
                    if (argumentInt.intValue > 0)
                    {
                        retour = "<color=#" + ColorUtility.ToHtmlStringRGBA(ListeCouleurs.Defaut.couleurTexteBonus) + ">+"
                                 + argumentInt.intValue + "<color=\"white\">" + " point" + pluriel + " d'attaque";
                    }
                    else if (argumentInt.intValue < 0)
                    {
                        retour = "<color=#" + ColorUtility.ToHtmlStringRGBA(ListeCouleurs.Defaut.couleurAlerteTexteInterface) + ">"
                                 + argumentInt.intValue + "<color=\"white\">" + " point" + pluriel + " d'attaque";
                    }

                    UnityAction <int> callback = new UnityAction <int>(bonus.ajouterBonusAttaque);
                    UnityEventTools.AddIntPersistentListener(buff.antiEffets, callback, argumentInt.intValue * -1);
                }
                else if (methode.stringValue.Contains("Defense"))
                {
                    char pluriel = '\0';
                    if (Math.Abs(argumentInt.intValue) != 1)
                    {
                        pluriel = 's';
                    }
                    if (argumentInt.intValue > 0)
                    {
                        retour = "<color=#" + ColorUtility.ToHtmlStringRGBA(ListeCouleurs.Defaut.couleurTexteBonus) + ">+"
                                 + argumentInt.intValue + "<color=\"white\">" + " point" + pluriel + " de défense";
                    }
                    else if (argumentInt.intValue < 0)
                    {
                        retour = "<color=#" + ColorUtility.ToHtmlStringRGBA(ListeCouleurs.Defaut.couleurAlerteTexteInterface) + ">"
                                 + argumentInt.intValue + "<color=\"white\">" + " point" + pluriel + " de défense";
                    }

                    UnityAction <int> callback = new UnityAction <int>(bonus.ajouterBonusDefense);
                    UnityEventTools.AddIntPersistentListener(buff.antiEffets, callback, argumentInt.intValue * -1);
                }
                else if (methode.stringValue.Contains("DegatMoral"))
                {
                    if (argumentInt.intValue > 0)
                    {
                        retour = "<color=#" + ColorUtility.ToHtmlStringRGBA(ListeCouleurs.Defaut.couleurTexteBonus) + ">++" +
                                 "<color=\"white\"> dégat moral";
                    }
                    else if (argumentInt.intValue < 0)
                    {
                        retour = "<color=#" + ColorUtility.ToHtmlStringRGBA(ListeCouleurs.Defaut.couleurAlerteTexteInterface) + ">--" +
                                 "<color=\"white\"> dégat moral";
                    }
                    UnityAction <int> callback = new UnityAction <int>(bonus.AjouterBonusDegatMoral);
                    UnityEventTools.AddIntPersistentListener(buff.antiEffets, callback, argumentInt.intValue * -1);
                }
                else if (methode.stringValue.Contains("Deplacement"))
                {
                    char pluriel = '\0';
                    if (Math.Abs(argumentInt.intValue) != 1)
                    {
                        pluriel = 's';
                    }
                    if (argumentInt.intValue > 0)
                    {
                        retour = "<color=#" + ColorUtility.ToHtmlStringRGBA(ListeCouleurs.Defaut.couleurTexteBonus) + ">+"
                                 + argumentInt.intValue + "<color=\"white\"> point" + pluriel + " de déplacement";
                    }
                    else if (argumentInt.intValue < 0)
                    {
                        retour = "<color=#" + ColorUtility.ToHtmlStringRGBA(ListeCouleurs.Defaut.couleurAlerteTexteInterface) +
                                 argumentInt.intValue + "<color=\"white\"> point" + pluriel + " de déplacement";
                    }

                    if (methode.stringValue.Contains("ToutesTribus"))
                    {
                        retour += " pour toutes les tribus";
                        UnityAction <int> callback = new UnityAction <int>(bonus.AjouterBonusDeplacementToutesTribus);
                        UnityEventTools.AddIntPersistentListener(buff.antiEffets, callback, argumentInt.intValue * -1);
                    }
                    else
                    {
                        UnityAction <int> callback = new UnityAction <int>(bonus.AjouterBonusDeplacement);
                        UnityEventTools.AddIntPersistentListener(buff.antiEffets, callback, argumentInt.intValue * -1);
                    }
                }

                else if (methode.stringValue.Contains("MultiplicateurCoutPop"))
                {
                    if (argumentFloat.floatValue > 1)
                    {
                        retour = "<color=#" + ColorUtility.ToHtmlStringRGBA(ListeCouleurs.Defaut.couleurAlerteTexteInterface) + ">" +
                                 "++<color=\"white\"> Cout d'une population";
                    }
                    else if (argumentFloat.floatValue < 1)
                    {
                        retour = "<color=#" + ColorUtility.ToHtmlStringRGBA(ListeCouleurs.Defaut.couleurTexteBonus) + ">" +
                                 "--<color=\"white\"> Cout d'une population";
                    }
                    if (argumentFloat.floatValue == 0)
                    {
                        retour = "Cout d'une populaiton< color =#" + ColorUtility.ToHtmlStringRGBA(ListeCouleurs.Defaut.couleurTexteBonus) + "> gratuit";
                    }

                    UnityAction <float> callback = new UnityAction <float>(bonus.AssignerMultiplicateurCoutPop);
                    UnityEventTools.AddFloatPersistentListener(buff.antiEffets, callback, argumentFloat.floatValue * -1);
                }
                else if (methode.stringValue.Contains("MultiplicateurStockage"))
                {
                    if (argumentFloat.floatValue > 1)
                    {
                        retour = "<color=#" + ColorUtility.ToHtmlStringRGBA(ListeCouleurs.Defaut.couleurAlerteTexteInterface) + ">" +
                                 "++<color=\"white\"> Capacité de stockage";
                    }
                    else if (argumentFloat.floatValue < 1)
                    {
                        retour = "<color=#" + ColorUtility.ToHtmlStringRGBA(ListeCouleurs.Defaut.couleurTexteBonus) + ">" +
                                 "--<color=\"white\"> Capacité de stockage";
                    }
                    if (argumentFloat.floatValue == 0)
                    {
                        retour = "Capacité de stockage< color =#" + ColorUtility.ToHtmlStringRGBA(ListeCouleurs.Defaut.couleurAlerteTexteInterface) + "> ANNULEE";
                    }

                    UnityAction <float> callback = new UnityAction <float>(bonus.AssignerMutliplicateurStockage);
                    UnityEventTools.AddFloatPersistentListener(buff.antiEffets, callback, argumentFloat.floatValue * -1);
                }
                else if (methode.stringValue.Contains("MultProd"))
                {
                    if (methode.stringValue.Contains("Nourriture"))
                    {
                        if (argumentFloat.floatValue > 1)
                        {
                            retour = "<color=#" + ColorUtility.ToHtmlStringRGBA(ListeCouleurs.Defaut.couleurAlerteTexteInterface) + ">" +
                                     "++<color=\"white\"> Production Nourriture";
                        }
                        else if (argumentFloat.floatValue < 1)
                        {
                            retour = "<color=#" + ColorUtility.ToHtmlStringRGBA(ListeCouleurs.Defaut.couleurTexteBonus) + ">" +
                                     "--<color=\"white\"> Production Nourriture";
                        }
                        if (argumentFloat.floatValue == 0)
                        {
                            retour = "Production Nourriture<color =#" +
                                     ColorUtility.ToHtmlStringRGBA(ListeCouleurs.Defaut.couleurAlerteTexteInterface) + "> ANNULEE";
                        }

                        if (methode.stringValue.Contains("ToutesTribus"))
                        {
                            retour += " pour toutes les tribus";
                            UnityAction <float> callback = new UnityAction <float>(bonus.AssignerMultProdNourritureToutesTribus);
                            UnityEventTools.AddFloatPersistentListener(buff.antiEffets, callback, argumentInt.intValue * -1);
                        }
                        else
                        {
                            UnityAction <float> callback = new UnityAction <float>(bonus.AssignerMultProdNourriture);
                            UnityEventTools.AddFloatPersistentListener(buff.antiEffets, callback, argumentInt.intValue * -1);
                        }
                    }
                    else if (methode.stringValue.Contains("Pierre"))
                    {
                        if (argumentFloat.floatValue > 1)
                        {
                            retour = "<color=#" + ColorUtility.ToHtmlStringRGBA(ListeCouleurs.Defaut.couleurAlerteTexteInterface) + ">" +
                                     "++<color=\"white\"> Production Pierre";
                        }
                        else if (argumentFloat.floatValue < 1)
                        {
                            retour = "<color=#" + ColorUtility.ToHtmlStringRGBA(ListeCouleurs.Defaut.couleurTexteBonus) + ">" +
                                     "--<color=\"white\"> Production Pierre";
                        }
                        if (argumentFloat.floatValue == 0)
                        {
                            retour = "Production Pierre<color =#" +
                                     ColorUtility.ToHtmlStringRGBA(ListeCouleurs.Defaut.couleurAlerteTexteInterface) + "> ANNULEE";
                        }

                        if (methode.stringValue.Contains("ToutesTribus"))
                        {
                            retour += " pour toutes les tribus";
                            UnityAction <float> callback = new UnityAction <float>(bonus.AssignerMultProdPierreToutesTribus);
                            UnityEventTools.AddFloatPersistentListener(buff.antiEffets, callback, argumentInt.intValue * -1);
                        }
                        else
                        {
                            UnityAction <float> callback = new UnityAction <float>(bonus.AssignerMultProdPierre);
                            UnityEventTools.AddFloatPersistentListener(buff.antiEffets, callback, argumentInt.intValue * -1);
                        }
                    }
                    else if (methode.stringValue.Contains("Peau"))
                    {
                        if (argumentFloat.floatValue > 1)
                        {
                            retour = "<color=#" + ColorUtility.ToHtmlStringRGBA(ListeCouleurs.Defaut.couleurAlerteTexteInterface) + ">" +
                                     "++<color=\"white\"> Production Peau";
                        }
                        else if (argumentFloat.floatValue < 1)
                        {
                            retour = "<color=#" + ColorUtility.ToHtmlStringRGBA(ListeCouleurs.Defaut.couleurTexteBonus) + ">" +
                                     "--<color=\"white\"> Production Peau";
                        }
                        if (argumentFloat.floatValue == 0)
                        {
                            retour = "Production Peau<color =#" +
                                     ColorUtility.ToHtmlStringRGBA(ListeCouleurs.Defaut.couleurAlerteTexteInterface) + "> ANNULEE";
                        }

                        if (methode.stringValue.Contains("ToutesTribus"))
                        {
                            retour += " pour toutes les tribus";
                            UnityAction <float> callback = new UnityAction <float>(bonus.AssignerMultProdPeauToutesTribus);
                            UnityEventTools.AddFloatPersistentListener(buff.antiEffets, callback, argumentInt.intValue * -1);
                        }
                        else
                        {
                            UnityAction <float> callback = new UnityAction <float>(bonus.AssignerMultProdPeau);
                            UnityEventTools.AddFloatPersistentListener(buff.antiEffets, callback, argumentInt.intValue * -1);
                        }
                    }
                    else if (methode.stringValue.Contains("Outil"))
                    {
                        if (argumentFloat.floatValue > 1)
                        {
                            retour = "<color=#" + ColorUtility.ToHtmlStringRGBA(ListeCouleurs.Defaut.couleurAlerteTexteInterface) + ">" +
                                     "++<color=\"white\"> Production Outil";
                        }
                        else if (argumentFloat.floatValue < 1)
                        {
                            retour = "<color=#" + ColorUtility.ToHtmlStringRGBA(ListeCouleurs.Defaut.couleurTexteBonus) + ">" +
                                     "--<color=\"white\"> Production Outil";
                        }
                        if (argumentFloat.floatValue == 0)
                        {
                            retour = "Production Outil<color =#" +
                                     ColorUtility.ToHtmlStringRGBA(ListeCouleurs.Defaut.couleurAlerteTexteInterface) + "> ANNULEE";
                        }

                        if (methode.stringValue.Contains("ToutesTribus"))
                        {
                            retour += " pour toutes les tribus";
                            UnityAction <float> callback = new UnityAction <float>(bonus.AssignerMultProdOutilToutesTribus);
                            UnityEventTools.AddFloatPersistentListener(buff.antiEffets, callback, argumentInt.intValue * -1);
                        }
                        else
                        {
                            UnityAction <float> callback = new UnityAction <float>(bonus.AssignerMultProdOutil);
                            UnityEventTools.AddFloatPersistentListener(buff.antiEffets, callback, argumentInt.intValue * -1);
                        }
                    }
                    else if (methode.stringValue.Contains("Pigment"))
                    {
                        if (argumentFloat.floatValue > 1)
                        {
                            retour = "<color=#" + ColorUtility.ToHtmlStringRGBA(ListeCouleurs.Defaut.couleurAlerteTexteInterface) + ">" +
                                     "++<color=\"white\"> Production Pigment";
                        }
                        else if (argumentFloat.floatValue < 1)
                        {
                            retour = "<color=#" + ColorUtility.ToHtmlStringRGBA(ListeCouleurs.Defaut.couleurTexteBonus) + ">" +
                                     "--<color=\"white\"> Production Pigment";
                        }
                        if (argumentFloat.floatValue == 0)
                        {
                            retour = "Production Pigment<color =#" +
                                     ColorUtility.ToHtmlStringRGBA(ListeCouleurs.Defaut.couleurAlerteTexteInterface) + "> ANNULEE";
                        }

                        if (methode.stringValue.Contains("ToutesTribus"))
                        {
                            retour += " pour toutes les tribus";
                            UnityAction <float> callback = new UnityAction <float>(bonus.AssignerMultProdPigmentToutesTribus);
                            UnityEventTools.AddFloatPersistentListener(buff.antiEffets, callback, argumentInt.intValue * -1);
                        }
                        else
                        {
                            UnityAction <float> callback = new UnityAction <float>(bonus.AssignerMultProdPigment);
                            UnityEventTools.AddFloatPersistentListener(buff.antiEffets, callback, argumentInt.intValue * -1);
                        }
                    }
                    else
                    {
                        if (argumentFloat.floatValue > 1)
                        {
                            retour = "<color=#" + ColorUtility.ToHtmlStringRGBA(ListeCouleurs.Defaut.couleurAlerteTexteInterface) + ">" +
                                     "++<color=\"white\"> Production";
                        }
                        else if (argumentFloat.floatValue < 1)
                        {
                            retour = "<color=#" + ColorUtility.ToHtmlStringRGBA(ListeCouleurs.Defaut.couleurTexteBonus) + ">" +
                                     "--<color=\"white\"> Production";
                        }
                        if (argumentFloat.floatValue == 0)
                        {
                            retour = "Production<color =#" +
                                     ColorUtility.ToHtmlStringRGBA(ListeCouleurs.Defaut.couleurAlerteTexteInterface) + "> ANNULEE";
                        }

                        if (methode.stringValue.Contains("ToutesTribus"))
                        {
                            retour += " pour toutes les tribus";
                            UnityAction <float> callback = new UnityAction <float>(bonus.AssignerMultProdToutesTribus);
                            UnityEventTools.AddFloatPersistentListener(buff.antiEffets, callback, argumentInt.intValue * -1);
                        }
                        else
                        {
                            UnityAction <float> callback = new UnityAction <float>(bonus.AssignerMultProd);
                            UnityEventTools.AddFloatPersistentListener(buff.antiEffets, callback, argumentInt.intValue * -1);
                        }
                    }
                }
            }
            if (buff.compteurTour)
            {
                if (!buff.name.Contains("SpawnTroupeau"))
                {
                    char pluriel = '\0';
                    if (buff.nombreTour > 0)
                    {
                        pluriel = 's';
                    }
                    retour += " pendant " + buff.nombreTour + " tour" + pluriel;
                }
                else
                {
                    retour = "";
                }
            }
            else if (buff.tpsDuneTechno)
            {
            }
            else if (buff.tpsDunEvent)
            {
                retour += " jusqu'à la fin de l'évenement";
            }

            buff.listeEffetsRetours[i] = retour;
        }
    }
    public void MyValidate(bool autoSetTriggers = false)
    {
        if (Elements == null)
        {
            return;
        }
        if (Application.isPlaying)
        {
            return;
        }
        if (gameObject.IsPrefab())
        {
#if UNITY_EDITOR
            Debug.LogError("MyValidate None");
            //Debug.LogError(mono.GetType()+"on +"+ mono.gameObject+ " PrefabType=" + prefabType);
#endif
            return;
        }
        if (!autoSetTriggers)
        {
            CheckError();
            return;
        }
        //countElements = Elements.Length;
        EventTrigger.Entry onDown, onUp;
        UIButtonInfo       _elem;
        for (int i = 0; i < Elements.Count; i++)
        {
            _elem = Elements[i];
            if (_elem.TriggerTarget == null)
            {
                Debug.LogWarning(GetType() + " error: " + gameObject + " TriggerTarget(self image on this) is null in element");
                continue;
            }
            EventTrigger[] triggers = _elem.TriggerTarget.GetComponents <EventTrigger>();
            for (int j = 1; j < triggers.Length; j++)
            {
                DestroyImmediate(triggers[j]);
            }
            if (_elem.Trigger == null)
            {
                _elem.Trigger = _elem.TriggerTarget.gameObject.AddComponent <EventTrigger>();
            }
            _elem.Trigger.triggers.Clear();
            onUp           = new EventTrigger.Entry();
            onUp.eventID   = EventTriggerType.PointerUp;
            onDown         = new EventTrigger.Entry();
            onDown.eventID = EventTriggerType.PointerDown;
            _elem.ID       = _elem.ID > -1 ? _elem.ID : i;
            UnityEventTools.AddIntPersistentListener(onUp.callback, UpTrigger, _elem.ID);
            UnityEventTools.AddIntPersistentListener(onDown.callback, DownTrigger, _elem.ID);
            _elem.Trigger.triggers.Add(onDown);
            _elem.Trigger.triggers.Add(onUp);
            _elem.isImage  = _elem.Image != null;
            _elem.isSprite = _elem.isImage && _elem.SpriteDown != null && _elem.SpriteUp != null;
            if (_elem.isSprite)
            {
                _elem.Image.sprite = _elem.SpriteUp;
            }
            if (!_elem.TriggerTarget.raycastTarget)
            {
                Debug.LogError(GetType() + " error: " + gameObject + " image is not raycastTarget true in element");
            }
        }

        CheckError();
    }
Exemplo n.º 12
0
    private void CreateScene()
    {
        AssetDatabase.SaveAssets();

        Type.GetType("UnityEditor.LogEntries,UnityEditor.dll")
        .GetMethod("Clear", BindingFlags.Static | BindingFlags.Public)
        .Invoke(null, null);



        newScene = EditorSceneManager.NewScene(NewSceneSetup.DefaultGameObjects, NewSceneMode.Additive);
        EditorSceneManager.CloseScene(EditorSceneManager.GetSceneAt(0), true);

        newScene.name = folderName;

        //GameObject canvasRoot = new GameObject("CanvasRoot");
        CreateEventSystem();
        GameObject rootObj = CreateCanvas();

        menuRoot = rootObj.AddComponent <MenuRoot>();

        //menuRoot.allMenus = new Dictionary<string, MenuManager>();

        int    tempI         = 0;
        string tempFolder    = "";
        string tempFolderA   = "";
        string tempFolderDel = "";

        while (tempI < 1000)
        {
            tempFolder = "assets/" + TEMP_DIR + tempI.ToString();
            if (!Directory.Exists(tempFolder))
            {
                tempFolderDel = tempFolder;
                tempFolderA   = tempFolder + "/Resources";
                Directory.CreateDirectory(tempFolderA);
                break;
            }
            else
            {
                tempI++;
            }
        }

        tempFolderA += "/" + TEMP_SUB_DIR;

        FileUtil.CopyFileOrDirectory(sceneDirectory, tempFolderA);
        //FileUtil.CopyFileOrDirectoryFollowSymlinks(sceneDirectory, tempFolderA);
        AssetDatabase.Refresh();

        MenuData[] menus = Resources.LoadAll <MenuData>(TEMP_SUB_DIR);
        tempMenus   = new Dictionary <string, MenuManager>();
        tempButtons = new Dictionary <Button, UiData>();

        tempUis = new Queue <KeyValuePair <Transform, List <UiSortData> > >();

        foreach (MenuData md in menus)
        {
            MenuManager menu = (MenuManager)CreateMenu(md, rootObj.transform);
            menuRoot.AddMenu(menu);
            tempMenus.Add(md.name, menu);
        }

        foreach (KeyValuePair <Button, UiData> bb in tempButtons)
        {
            Type[] arguments = new Type[1];
            arguments[0] = typeof(int);
            MethodInfo        method = UnityEventBase.GetValidMethodInfo(menuRoot, "ShowMenu", arguments);
            UnityAction <int> ua     = Delegate.CreateDelegate(typeof(UnityAction <int>), menuRoot, method) as UnityAction <int>;

            if (bb.Value.action == ButtonAction.ShowMenu)
            {
                Debug.Log(menuRoot.allMenus.IndexOf(tempMenus[bb.Value.goTo.name]));
                int index = menuRoot.allMenus.IndexOf(tempMenus[bb.Value.goTo.name]);
                UnityEventTools.AddIntPersistentListener(bb.Key.onClick, ua, index);
            }
        }

        while (tempUis.Count > 0)
        {
            KeyValuePair <Transform, List <UiSortData> > tempK = tempUis.Dequeue();
            List <UiSortData> tempList = tempK.Value;
            for (int i = 0; i < tempList.Count; i++)
            {
                //Debug.Log("^^^: " + tempList[i].layer);
                tempList[i].ui.SetAsFirstSibling();
            }
        }

        EditorSceneManager.SaveScene(UnityEngine.SceneManagement.SceneManager.GetSceneAt(0), sceneDirectory + "/" + folderName + ".unity");

        FileUtil.DeleteFileOrDirectory(tempFolderDel);

        AssetDatabase.Refresh();

        if (myWindow != null)
        {
            myWindow.Close();
        }



        return;

        Debug.Log(":: " + sceneDirectory + ", " + folderName);

        // You can either filter files to get only neccessary files by its file extension using LINQ.
        // It excludes .meta files from all the gathers file list.
        IEnumerable <string> assetFiles = GetFiles(GetSelectedPathOrFallback()).Where(str => str.Contains(".meta") == false);

        foreach (string f in assetFiles)
        {
            Debug.Log("Files: " + f);
        }
    }
Exemplo n.º 13
0
        // Try to create a link between two nodes.
        // Returns true if the link is established successfully.
        public static bool TryLinkNodes(
            Wiring.NodeBase nodeFrom, UnityEventBase triggerEvent,
            Wiring.NodeBase nodeTo, MethodInfo targetMethod
        )
        {
            // Determine the type of the target action.
            var actionType = GetUnityActionToInvokeMethod(targetMethod);

            if (actionType == null) return false; // invalid target method type

            // Create an action that is bound to the target method.
            var targetAction = System.Delegate.CreateDelegate(
                actionType, nodeTo, targetMethod
            );

            if (triggerEvent is UnityEvent)
            {
                // The trigger event has no parameter.
                // Add the action to the event with a default parameter.
                if (actionType == typeof(UnityAction))
                {
                    UnityEventTools.AddVoidPersistentListener(
                        triggerEvent, (UnityAction)targetAction
                    );
                    return true;
                }
                if (actionType == typeof(UnityAction<bool>))
                {
                    UnityEventTools.AddBoolPersistentListener(
                        triggerEvent, (UnityAction<bool>)targetAction, false
                    );
                    return true;
                }
                if (actionType == typeof(UnityAction<int>))
                {
                    UnityEventTools.AddIntPersistentListener(
                        triggerEvent, (UnityAction<int>)targetAction, 0
                    );
                    return true;
                }
                if (actionType == typeof(UnityAction<float>))
                {
                    UnityEventTools.AddFloatPersistentListener(
                        triggerEvent, (UnityAction<float>)targetAction, 0.0f
                    );
                    return true;
                }
            }
            else if (triggerEvent is UnityEvent<bool>)
            {
                // The trigger event has a bool parameter.
                // Then the target method should have a bool parameter too.
                if (actionType == typeof(UnityAction<bool>))
                {
                    // Add the action to the event.
                    UnityEventTools.AddPersistentListener(
                       (UnityEvent<bool>)triggerEvent,
                       (UnityAction<bool>)targetAction
                    );
                    return true;
                }
            }
            else if (triggerEvent is UnityEvent<int>)
            {
                // The trigger event has an int parameter.
                // Then the target method should have an int parameter too.
                if (actionType == typeof(UnityAction<int>))
                {
                    // Add the action to the event.
                    UnityEventTools.AddPersistentListener(
                       (UnityEvent<int>)triggerEvent,
                       (UnityAction<int>)targetAction
                    );
                    return true;
                }
            }
            else if (triggerEvent is UnityEvent<float>)
            {
                // The trigger event has a float parameter.
                // Then the target method should have a float parameter too.
                if (actionType == typeof(UnityAction<float>))
                {
                    // Add the action to the event.
                    UnityEventTools.AddPersistentListener(
                       (UnityEvent<float>)triggerEvent,
                       (UnityAction<float>)targetAction
                    );
                    return true;
                }
            }
            else if (triggerEvent is UnityEvent<Vector3>)
            {
                // The trigger event has a Vector3 parameter.
                // Then the target method should have a Vector3 parameter too.
                if (actionType == typeof(UnityAction<Vector3>))
                {
                    // Add the action to the event.
                    UnityEventTools.AddPersistentListener(
                       (UnityEvent<Vector3>)triggerEvent,
                       (UnityAction<Vector3>)targetAction
                    );
                    return true;
                }
            }
            else if (triggerEvent is UnityEvent<Color>)
            {
                // The trigger event has a color parameter.
                // Then the target method should have a color parameter too.
                if (actionType == typeof(UnityAction<Color>))
                {
                    // Add the action to the event.
                    UnityEventTools.AddPersistentListener(
                       (UnityEvent<Color>)triggerEvent,
                       (UnityAction<Color>)targetAction
                    );
                    return true;
                }
            }

            return false; // trigger-target mismatch
        }
Exemplo n.º 14
0
    static void CreateGrid()
    {
        var tilesCount        = Mathf.RoundToInt(gridSize.x * gridSize.y);
        var grid              = new GameObject("Arrowar Grid");
        var gridRectTransform = grid.AddComponent <RectTransform>();
        var setup             = grid.AddComponent <TileSetup>();
        var distributor       = grid.AddComponent <ItemDistributor>();
        var controllers       = new Dictionary <int, Controller>();
        var playerBases       = new List <PlayerBase> {
            CreatePlayerBase(
                Resources.Load <GameObject>("Player1"),
                grid,
                Vector2.zero
                ),
            CreatePlayerBase(
                Resources.Load <GameObject>("Player2"),
                grid,
                Vector2.right * (gridSize.x - playerBaseSize.x)
                )
        };

        for (var playerIndex = 1; playerIndex <= playersCount; ++playerIndex)
        {
            controllers[playerIndex]       = grid.AddComponent <Controller>();
            controllers[playerIndex].Index = playerIndex;
        }

        var tiles = CreateTiles(tilesCount, grid, controllers);

        UnityEventTools.AddIntPersistentListener(
            controllers[1].ReadyEvent,
            new UnityAction <int>(tiles.First().Value.GetComponent <TileSelector>().SelectForPlayer),
            1
            );

        UnityEventTools.AddIntPersistentListener(
            controllers[2].ReadyEvent,
            new UnityAction <int>(tiles.Last().Value.GetComponent <TileSelector>().SelectForPlayer),
            2
            );

        foreach (var tileItem in tiles)
        {
            var tile      = tileItem.Value;
            var direction = tile.GetComponent <TileDirection>();
            var selector  = tile.GetComponent <TileSelector>();

            ConnectNearTileMovedSelection(
                tiles,
                tileItem.Key + Vector2.left,
                selector,
                selector.Move.Left
                );

            ConnectNearTileMovedSelection(
                tiles,
                tileItem.Key + Vector2.right,
                selector,
                selector.Move.Right
                );

            ConnectNearTileMovedSelection(
                tiles,
                tileItem.Key + Vector2.down,
                selector,
                selector.Move.Down
                );

            ConnectNearTileMovedSelection(
                tiles,
                tileItem.Key + Vector2.up,
                selector,
                selector.Move.Up
                );

            ConnectNearTilePushedItems(
                tiles,
                tileItem.Key + Vector2.left,
                direction,
                direction.PushedItems.Left,
                playerBases
                );

            ConnectNearTilePushedItems(
                tiles,
                tileItem.Key + Vector2.right,
                direction,
                direction.PushedItems.Right,
                playerBases
                );

            ConnectNearTilePushedItems(
                tiles,
                tileItem.Key + Vector2.down,
                direction,
                direction.PushedItems.Down,
                playerBases
                );

            ConnectNearTilePushedItems(
                tiles,
                tileItem.Key + Vector2.up,
                direction,
                direction.PushedItems.Up,
                playerBases
                );
        }

        if (Selection.activeGameObject)
        {
            grid.transform.SetParent(Selection.activeGameObject.transform);
        }

        UnityEventTools.AddPersistentListener(
            distributor.Distributed,
            new UnityAction <Item.ItemType>(tiles.Last().Value.GetComponent <TileDirection>().InstantiateItem)
            );

        gridRectTransform.anchoredPosition = Vector2.zero;
        gridRectTransform.localPosition    = Vector2.zero;
        gridRectTransform.localScale       = Vector2.one;
    }
Exemplo n.º 15
0
        //
        void createWeaponFromPrefab()
        {
            pre      = Instantiate(prefab, new Vector3(0, 0, 0), Quaternion.identity) as GameObject;
            pre.name = prefab.name;
            weapons.Add(pre.name);                         // add new weapon to "Weapons" ScriptableObject.

            W = GameObject.FindWithTag("WeaponSelection"); // finding weaponSelection to parent new weapon to it.
            pre.transform.SetParent(W.transform);
            //
            // instantiate weapon prefab and parent it to weapon.

            // 2
            //
            //adding new new Weapon on weapons panel.
            // creating new "Weapon" Gameobject, parent it to weapon panel and add Button and Image components.
            b = new GameObject("" + pre.name);
            b.AddComponent <Image>();
            if (WeaponImage)
            {
                b.GetComponent <Image>().sprite         = WeaponImage;
                b.GetComponent <Image>().preserveAspect = true;
            }
            b.AddComponent <Button>();
            b.layer = 5;
            //Debug.Log("2");
            GameObject weaponpanel = GameObject.Find("Panel");// finding weapon Panel to parent new weapon to it.

            b.transform.SetParent(weaponpanel.transform);
            b.transform.localScale = new Vector3(1, 1, 1);
            //
            // create new Text GameObject and parent it to weapon.
            pb = new GameObject(pre.name + "Ammo");
            Debug.Log("3");
            pb.transform.SetParent(b.transform);
            pb.AddComponent <Text>();
            Debug.Log("4");
            Text text = pb.GetComponent <Text>();

            text.font      = w.MainFont;
            text.fontSize  = 30;
            text.color     = new Color32(50, 50, 50, 255);
            text.alignment = TextAnchor.MiddleCenter;
            pb.layer       = 5;
            RectTransform TEXTrect = pb.GetComponent <RectTransform>();

            TEXTrect.localScale = new Vector3(1, 1, 1);
            TEXTrect.anchorMin  = new Vector2(0.6187f, 0f);
            TEXTrect.anchorMax  = new Vector2(1, 1);
            TEXTrect.offsetMin  = new Vector2(0, 0);
            TEXTrect.offsetMax  = new Vector2(20, 0);
            //
            activeWeap = FindObjectOfType <ActiveWeapons>(); // Reference to ActiveWeapons.
            activeWeap.Weapons.Add(b);                       // Add Weapon to Activeweapons List.
            weaponIndex = activeWeap.Weapons.Count - 1;
            startWeap   = FindObjectOfType <StartWeapons>(); // Reference to StartWeapons.
            startWeap.Weapons.Add(b);                        // Add Weapon to Activeweapons List.
                                                             //
            Button            butten  = b.GetComponent <Button>();
            WeaponSelection   waepsel = FindObjectOfType <WeaponSelection>();
            UnityAction <int> action  = new UnityAction <int>(waepsel.Select);

            UnityEventTools.AddIntPersistentListener(butten.onClick, action, weaponIndex);
            GameManager gameManager = FindObjectOfType <GameManager>();

            gameManager.WeaponsDamage.Add(weaponDamage);
        }
Exemplo n.º 16
0
        //
        void createWeapon()
        {
            //
            // 1
            //
            // creating new "Weapon" Gameobject, parent it to weapon selection and add weaponMobile component.
            g = new GameObject("" + weaponName);
            g.AddComponent <weaponHolder>();
            if (WeaponImage)
            {
                g.GetComponent <SpriteRenderer>().sprite = WeaponImage;
            }
            W = GameObject.FindWithTag("WeaponSelection");// finding weaponSelection to parent new weapon to it.
            g.transform.SetParent(W.transform);
            //
            // create new GameObject and parent it to weapon.
            p = new GameObject("GameObject");
            p.transform.SetParent(g.transform);
            //
            // add name to new weapon
            string www = weaponName;

            g.name = www;
            weapons.Add(g.name); // add new weapon to "Weapons" ScriptableObject.
                                 //
            // 2
            //
            //adding new new Weapon on weapons panel.
            // creating new "Weapon" Gameobject, parent it to weapon panel and add Button and Image components.
            b = new GameObject("" + weaponName);
            b.AddComponent <Image>();
            b.GetComponent <Image>().sprite = WeaponImage;
            b.AddComponent <Button>();
            b.layer = 5;
            GameObject weaponpanel = GameObject.Find("Panel");// finding weapon Panel to parent new weapon to it.

            b.transform.SetParent(weaponpanel.transform);
            b.transform.localScale = new Vector3(1, 1, 1);
            //
            // create new Text GameObject and parent it to weapon.
            string[] results2             = AssetDatabase.FindAssets("_Weapons");
            string   ScriptableObjectpath = AssetDatabase.GUIDToAssetPath(results2[0]);

            w  = (Weapons)AssetDatabase.LoadAssetAtPath(ScriptableObjectpath, typeof(Weapons));
            pb = new GameObject(weaponName + "Ammo");
            pb.transform.SetParent(b.transform);
            pb.AddComponent <Text>();
            Text text = pb.GetComponent <Text>();

            text.font      = w.MainFont;
            text.fontSize  = 30;
            text.color     = new Color32(50, 50, 50, 255);
            text.alignment = TextAnchor.MiddleCenter;
            pb.layer       = 5;
            RectTransform TEXTrect = pb.GetComponent <RectTransform>();

            TEXTrect.localScale = new Vector3(1, 1, 1);
            TEXTrect.anchorMin  = new Vector2(0.6187f, 0f);
            TEXTrect.anchorMax  = new Vector2(1, 1);
            TEXTrect.offsetMin  = new Vector2(0, 0);
            TEXTrect.offsetMax  = new Vector2(20, 0);
            //
            activeWeap = FindObjectOfType <ActiveWeapons>(); // Reference to ActiveWeapons.
            activeWeap.Weapons.Add(b);                       // Add Weapon to Activeweapons List.
            weaponIndex = activeWeap.Weapons.Count - 1;
            startWeap   = FindObjectOfType <StartWeapons>(); // Reference to StartWeapons.
            startWeap.Weapons.Add(b);                        // Add Weapon to Activeweapons List.
                                                             //
            Button            butten  = b.GetComponent <Button>();
            WeaponSelection   waepsel = FindObjectOfType <WeaponSelection>();
            UnityAction <int> action  = new UnityAction <int>(waepsel.Select);

            UnityEventTools.AddIntPersistentListener(butten.onClick, action, weaponIndex);
            GameManager gameManager = FindObjectOfType <GameManager>();

            gameManager.WeaponsDamage.Add(weaponDamage);
        }
        /// <summary>
        /// Create each menu RectTransform and all necessary components.
        /// </summary>
        public void CreateMenu()
        {
            Undo.SetCurrentGroupName("Create Menu");
            int group = Undo.GetCurrentGroup();

            Undo.RecordObject(swipyMenu, "Create Menu");

            int index = swipyMenu.menus.Length;
            //create header
            var currentHeaderName = "Header " + (index + 1);
            var currentHeader     = CreateGOWithRectTransform(currentHeaderName, headersParent);

            Undo.RegisterCreatedObjectUndo(currentHeader.gameObject, "Header");
            currentHeader.gameObject.AddComponent <CanvasGroup>();
            var swipyMenuHeader = currentHeader.gameObject.AddComponent <SwipyMenuHeader>();
            var buttonRect      = CreateGOWithRectTransform("Button", currentHeader, offsetMin: new Vector2(2f, 2f), offsetMax: new Vector2(-2f, -2f));

            buttonRect.gameObject.AddComponent <Image>().color = new Color32(255, 255, 255, 80);
            var button = buttonRect.gameObject.AddComponent <Button>();
            var colors = button.colors;

            colors.normalColor      = new Color32(255, 255, 255, 20);
            colors.highlightedColor = new Color32(255, 255, 255, 80);
            colors.pressedColor     = new Color32(255, 255, 255, 255);
            colors.disabledColor    = new Color32(128, 128, 128, 20);
            button.colors           = colors;
            UnityEventTools.AddIntPersistentListener(button.onClick, swipyMenu.HeaderClickHandler, index + 1);
            swipyMenuHeader.button = button;
            button.navigation      = new Navigation()
            {
                mode = Navigation.Mode.None
            };

            var text = CreateGOWithRectTransform("Text", currentHeader).gameObject.AddComponent <Text>();

            text.raycastTarget   = false;
            text.text            = currentHeaderName;
            text.fontSize        = 14;
            text.alignment       = TextAnchor.MiddleCenter;
            swipyMenuHeader.text = text;

            // create menu
            var contentRect = menusParent.GetChild(0).GetComponent <RectTransform>();
            var currentMenu = CreateGOWithRectTransform("Menu" + (index + 1), contentRect);

            Undo.RegisterCreatedObjectUndo(currentMenu.gameObject, "Menu");
            var bgImage = CreateGOWithRectTransform("Bg", currentMenu, offsetMin: new Vector2(5f, 5f), offsetMax: new Vector2(-5f, -5f)).gameObject.AddComponent <Image>();

            bgImage.color = new Color32(255, 255, 255, 20);

            if (index == 0)
            {
                swipyMenu.menus = new SwipyMenu.Menu[1];
            }
            else
            {
                Array.Resize(ref swipyMenu.menus, swipyMenu.menus.Length + 1);
            }

            swipyMenu.menus[swipyMenu.menus.Length - 1].header = swipyMenuHeader;
            swipyMenu.menus[swipyMenu.menus.Length - 1].menu   = currentMenu;

            if (firstToShowOnLoadMenu.header == null && firstToShowOnLoadMenu.menu == null)
            {
                firstToShowOnLoadMenu      = swipyMenu.menus[0];
                swipyMenu.defaultMenuIndex = 0;
            }
            ExpandHeaders();

            Undo.CollapseUndoOperations(group);
        }