예제 #1
0
        private void SetConnectionToActionObject(IActionPointParent parent)
        {
            // Create new Line Connection between parent AO and child AP
            GameObject c = Instantiate(Scene.Instance.LineConnectionPrefab);

            c.transform.parent = transform;
            LineConnection newConnection = c.GetComponent <LineConnection>();

            newConnection.targets[0] = parent.GetTransform();
            newConnection.targets[1] = this.transform;

            // add the connection to connections manager
            Scene.Instance.AOToAPConnectionsManager.AddConnection(newConnection);

            ConnectionToParent = newConnection;

            // Add connection renderer into ChangeMaterialOnSelected script attached on parent AO
            ChangeMaterialOnSelected changeMaterial;

            changeMaterial = parent.GetGameObject().GetComponent <ChangeMaterialOnSelected>();

            // if the script is not attached on parent AO, then add it and initialize its click material
            if (changeMaterial == null)
            {
                changeMaterial = parent.GetGameObject().AddComponent <ChangeMaterialOnSelected>();
                changeMaterial.ClickMaterial = ConnectionToParent.ClickMaterial;
            }
            changeMaterial.AddRenderer(ConnectionToParent.GetComponent <LineRenderer>());
        }
예제 #2
0
 private void RemoveConnectionToParent()
 {
     // Remove connections to parent
     if (ConnectionToParent != null && ConnectionToParent.gameObject != null)
     {
         // remove renderer from ChangeMaterialOnSelected script attached on the AO
         ChangeMaterialOnSelected changeMaterial = Parent.GetGameObject().GetComponent <ChangeMaterialOnSelected>();
         changeMaterial.RemoveRenderer(ConnectionToParent.GetComponent <LineRenderer>());
         // remove connection from connectinos manager
         Scene.Instance.AOToAPConnectionsManager.RemoveConnection(ConnectionToParent);
         // destroy connection gameobject
         Destroy(ConnectionToParent.gameObject);
     }
 }