Пример #1
0
    /// <summary>
    /// 
    /// </summary>
    /// <param name="c">condition</param>
    /// <param name="a">action</param>
    /// <param name="proxyRule">if true, rule will be created without display, etc.</param>
    public GameRule(GameRuleCondition c, GameRuleAction a, bool proxyRule = false)
    {
        condition = c;
        action = a;
        if (proxyRule)
            return;

        ruleDisplay = GameRules.instance.generateNewRuleDisplay();
        RectTransform t = (RectTransform)ruleDisplay.transform;

        flashImage = t.FindChild("Flash").gameObject.GetComponent<Image>();
        ((RectTransform)(flashImage.transform)).sizeDelta = t.sizeDelta;
        animationStartTime = Time.realtimeSinceStartup;
        t.localPosition = startPosition;
        t.localScale = startScale;

        t.FindChild("Save Name").gameObject.GetComponent<Text>().text = GameRuleSerializer.packRuleToString(this);

        Transform tText = t.FindChild("Rule Text");
        Transform tImage = t.FindChild("Rule Icons");

        if (GameRules.instance.useRuleIcons) {
            tText.gameObject.SetActive(false);

            //build out the list of icons to display
            List<GameObject> iconList = new List<GameObject>();
            condition.addIcons(iconList);
            iconList.Add(GameRuleIconStorage.instance.resultsInIcon);
            action.addIcons(iconList);

            //clone our base image object so that we have one per icon (including the base image)
            GameObject parentObject = tImage.FindChild("Image").gameObject;
            List<GameObject> imageObjects = new List<GameObject>();
            float x = 0;
            for (int i = 0; i < iconList.Count; i++) {
                GameObject imageObject = GameObject.Instantiate(iconList[i]);
                //set parent to the parentObject, making sure to use the prefab's local position (not world)
                imageObject.transform.SetParent(parentObject.transform, false);
                imageObjects.Add(imageObject);
                //space out the icons
                RectTransform r = imageObject.GetComponent<RectTransform>();
                r.localPosition = r.localPosition + new Vector3(x, 0, 0);
                x += r.rect.width;
            }
            Debug.Log("If " + condition.ToString() + " => Then " + action.ToString());
        } else {
            tImage.gameObject.SetActive(false);
            tText.GetChild(0).gameObject.GetComponent<Text>().text = "If " + condition.ToString();
            tText.GetChild(1).gameObject.GetComponent<Text>().text = "Then " + action.ToString();
        }
    }
Пример #2
0
 public GameRule(GameRuleCondition c, GameRuleAction a)
 {
     condition = c;
     action = a;
 }