Beispiel #1
0
    private void Start()
    {
        // Fetch all triggers
        foreach (Transform child in transform)
        {
            TriggerCounter trigger = child.GetComponent <TriggerCounter> ();
            if (trigger)
            {
                triggers.Add(child.name, trigger);
                if (child.name == "Feet")
                {
                    feet = trigger;
                }
            }
        }

        rb = GetComponent <Rigidbody> ();
    }
    // Create a playfield using a PlayfieldLayoutValues value
    private void SetPlayfield(int vLayout)
    {
        if ((vLayout < 0) || (vLayout >= PlayfieldLayoutValues.Length))
        {
            Debug.Log("Invalid playfield layout identifier specified");
            return;
        }

        if (!(FloorObject))
        {
            Debug.Log("FloorObject has not been assigned");
            return;
        }

        if (!(HoleObject))
        {
            Debug.Log("HoleObject has not been assigned");
            return;
        }
        else if (!(HoleObject.GetComponentInChildren <TriggerCounter>()))
        {
            Debug.Log("HoleObject requires a child with a TriggerCounter component");
            return;
        }

        if (!(BallObject))
        {
            Debug.Log("BallObject has not been assigned");
            return;
        }

        if (!(ResetObject))
        {
            Debug.Log("ResetObject has not been assigned");
            return;
        }

        ResetObject.ForceReset();
        ResetObject.gameObject.SetActive(false);

        // Destroy previous tiles
        for (int i = 0; i < pPlayfieldObjects.Length; i++)
        {
            Destroy(pPlayfieldObjects[i]);
        }

        // Destroy previous balls
        for (int i = 0; i < pBalls.Length; i++)
        {
            Destroy(pBalls[i]);
        }

        // Create new tiles
        pPlayfieldObjects = new GameObject[Size * Size];

        float lHalfSize = 0.5f * (Size - 1);
        int   lValue    = PlayfieldLayoutValues[vLayout];

        pHoles = 0;

        for (int i = 0; i < Size * Size; i++)
        {
            Vector3 lPos = new Vector3(Mathf.Floor(i / Size) - lHalfSize, 0f, (float)(i % Size) - lHalfSize) * Spacing;

            // Check if bit at index i of lValue is set to determine if a HoleObject should be spawned
            if (((1 << i) & lValue) != 0)
            {
                pPlayfieldObjects[i] = Instantiate(HoleObject, lPos, Quaternion.identity);

                pHoles++;
            }
            else
            {
                pPlayfieldObjects[i] = Instantiate(FloorObject, lPos, Quaternion.identity);
            }

            // Make it look cleaner in the editor
            pPlayfieldObjects[i].gameObject.transform.SetParent(this.transform);
        }

        // Get all trigger counters
        pHoleTriggers = new TriggerCounter[pHoles];
        lValue        = 0;

        for (int i = 0; i < pPlayfieldObjects.Length; i++)
        {
            TriggerCounter lTrigger = pPlayfieldObjects[i].GetComponentInChildren <TriggerCounter>();

            if (lTrigger)
            {
                pHoleTriggers[lValue] = lTrigger;
                lValue++;
            }
        }

        pBalls    = new GameObject[pHoles];
        lHalfSize = -0.5f * (pHoles - 1);

        // Spawn a ball for each hole
        for (int i = 0; i < pHoles; i++)
        {
            Vector3 lPos = new Vector3(-0.5f * (Size - 1) - 3f, 0.5f, lHalfSize + i);

            pBalls[i] = Instantiate(BallObject, lPos, Quaternion.identity);
        }

        if (Indicator)
        {
            Indicator.SetWaiting();
        }

        pLastPlayfield   = vLayout;
        pWaitingForReset = false;
    }
Beispiel #3
0
 void Start()
 {
     render         = GetComponent <Renderer>();
     triggercounter = GameObject.Find("TriggerCounter").GetComponent <TriggerCounter>();
 }
        public void ReloadList()
        {
            listView.BeginUpdate();

            listView.Items.Clear();

            var newListItems = ManualOrdering ? _itemListEnumerator : _itemListEnumerator.OrderBy(x => x.Name);

            Func <IBasicInfo, ListViewItem> createLvi =
                x => new ListViewItem(new[] { x.Name, x.Enabled.ToString(), x.GetDetails(), TriggerCounter.GetCounter(x).ToString() })
            {
                Tag = x
            };

            if (_groupKeyGetter != null)
            {
                var groups       = new Dictionary <string, ListViewGroup>();
                var defaultGroup = new ListViewGroup("Ungrouped");
                groups.Add("Ungrouped", defaultGroup);
                foreach (var item in newListItems)
                {
                    var lvi      = createLvi(item);
                    var groupKey = _groupKeyGetter(item);
                    if (string.IsNullOrEmpty(groupKey))
                    {
                        defaultGroup.Items.Add(lvi);
                    }
                    else
                    {
                        ListViewGroup result;
                        if (!groups.TryGetValue(groupKey, out result))
                        {
                            result = new ListViewGroup(groupKey);
                            groups.Add(groupKey, result);
                        }
                        result.Items.Add(lvi);
                    }

                    listView.Items.Add(lvi);
                }

                listView.Groups.AddRange(groups.OrderBy(x => x.Key).Select(x => x.Value).ToArray());
            }
            else
            {
                listView.Items.AddRange(newListItems.Select(createLvi).ToArray());
            }

            listView.EndUpdate();
        }
Beispiel #5
0
 private void Start()
 {
     child = transform.GetComponentInChildren <TriggerCounter> ();
 }