public void displayOptions()
        {
            optionIconPrefabs = new List <GenericIcon>();
            lines             = new List <GameObject>();
            var prefabs = GetOperator().Observer.GetOperatorPrefabs();

            operatorPrefabs = new List <GameObject>();

            foreach (GameObject prefab in prefabs)
            {
                //first validate if the respective prefab can be used with the current parent
                if (prefab.GetComponent <GenericOperator>().ValidateIfOperatorPossibleForParents(ClickedOp))
                {
                    optionIconPrefabs.Add(prefab.GetComponent <GenericOperator>().GetComponentInChildren <GenericIcon>());
                    operatorPrefabs.Add(prefab);
                }
            }

            optionIcons = new List <GenericIcon>();
            foreach (GenericIcon optionIcon in optionIconPrefabs)
            {
                GenericIcon  instance = GameObject.Instantiate(optionIcon);
                Targetable[] scripts  = instance.GetComponentsInChildren <Targetable>();
                foreach (Targetable script in scripts)
                {
                    Destroy(script);
                }

                instance.transform.parent     = ClickedOp.GetIcon().transform.parent;
                instance.transform.localScale = ClickedOp.GetIcon().transform.localScale;
                instance.transform.position   = getSpawnPositionOffsetForButton(ClickedOp.GetIcon().transform, optionIcons.Count, optionIconPrefabs.Count);

                foreach (Transform child in instance.gameObject.GetComponentsInChildren <Transform>())
                {
                    child.gameObject.AddComponent <NewIconInteractionButton>();
                    child.gameObject.GetComponent <NewIconInteractionButton>().controller = this;
                    child.gameObject.GetComponent <NewIconInteractionButton>().id         = optionIcons.Count;
                }

                optionIcons.Add(instance);

                // add lines between the icons
                GameObject   line         = new GameObject();
                LineRenderer lineRenderer = line.AddComponent <LineRenderer>();
                lineRenderer.SetWidth(0.01f, 0.01f);
                lineRenderer.SetPositions(new Vector3[] {
                    GetOperator().GetIcon().transform.position + new Vector3(0, 0, 0.001f), instance.transform.position + new Vector3(0, 0, 0.001f)
                });

                lines.Add(line);
            }
            optionsDisplayed = true;
        }
Example #2
0
        public virtual void Start()
        {
            Visualization = GetComponentInChildren <GenericVisualization>();
            Icon          = GetComponentInChildren <GenericIcon>();

            //properties for Layout algorithms
            Icon.gameObject.AddComponent <IconProperties>();
            Observer = FindObjectOfType <Observer>();



            GameObject iconHighlight = Resources.Load <GameObject>("Highlights/IconHighlight");

            isSelectedHighlighting = Instantiate(iconHighlight);
            isSelectedHighlighting.transform.parent   = Icon.transform;
            isSelectedHighlighting.transform.position = Icon.transform.position;
            isSelectedHighlighting.SetActive(false);



            ProperInitializedStart = true;

            Observer.notifyObserverOperatorInitComplete(this);

            Icon.GetComponent <IconProperties>().acceleration = new Vector3(0, 0, 0);
            //increase the depth of the node
            if (Parents.Count != 0 && Parents != null)
            {
                Icon.GetComponent <IconProperties>().depth = Parents[0].GetIcon().GetComponent <IconProperties>().depth + 1;
            }
            else
            {
                //only root node has depth 1
                Icon.GetComponent <IconProperties>().depth = 1;
            }
        }