Example #1
0
        private void InitFromSelection()
        {
            GameObject selected = null;

            foreach (GameObject o in Selection.SelectedObjects)
            {
                selected = o;
                break;
            }
            if (null != selected)
            {
                GrassController controller = selected.GetComponent <GrassController>();
                if (null != controller)
                {
                    grass = controller;

                    // DEBUG - rebuild debug arrays and mesh from controller
                    grass.RebuildDebugMesh();

                    // switch ON the record button
                    uiActiveButton.Checked = true;

                    return;
                }
            }

            grass = null;
        }
Example #2
0
        public GrassController Create()
        {
            GameObject gobject = new GameObject();

            gobject.name = Utils.CreateUniqueName("Grass");
            gobject.transform.localPosition = Vector3.zero;
            gobject.transform.localRotation = Quaternion.identity;
            gobject.transform.localScale    = Vector3.one;
            gobject.tag = "PhysicObject";

            GrassController controller = gobject.AddComponent <GrassController>();

            controller.cameraXf         = vrCamera;
            controller.interactorXf     = paletteController;
            controller.material         = Resources.Load <Material>("Grass/Grass");
            controller.computeShader    = Resources.Load <ComputeShader>("Grass/GrassComputeShader");
            controller.overrideMaterial = true;
            controller.topColor         = uiTopColorButton.ImageColor;
            controller.bottomColor      = uiBottomColorButton.ImageColor;
            controller.castShadow       = true;
            controller.Clear();
            controller.InitDebugData();      // DEBUG

            SceneManager.AddObject(gobject); // add to right handed and fire object added.

            return(controller);
        }
Example #3
0
        private void StartPainting()
        {
            if (grass != null)
            {
                StopPainting(); // NOTE: sets grass to null
            }

            // Create the object holding a set of grass
            grass = Create();
            grass.transform.position = hitPosGizmo;

            SelectGrassObject(grass.gameObject); // TODO: also select the grassItem in the list.

            // switch ON the record button
            uiActiveButton.Checked = true;
        }
Example #4
0
        private void StopPainting()
        {
            if (grass == null)
            {
                return;
            }

            // Unparent from RIGHT_HANDED so that CommandAddGameObject can RE-ADD.
            grass.transform.SetParent(null, false);
            CommandAddGameObject command = new CommandAddGameObject(grass.gameObject);

            command.Submit();

            grass = null;

            uiActiveButton.Checked = false; // may be useless, StopPainting come from clicking on that button.
        }
Example #5
0
        private void OnGrassRemoved(GameObject gObject)
        {
            GrassController grassController = gObject.GetComponent <GrassController>();

            if (null == grassController)
            {
                return;
            }
            foreach (var item in grassList.GetItems())
            {
                GrassItem grassItem = item.Content.GetComponent <GrassItem>();
                if (grassItem.grassObject == gObject)
                {
                    grassList.RemoveItem(item);
                    return;
                }
            }
        }
Example #6
0
        private void OnGrassAdded(GameObject gObject)
        {
            GrassController grassController = gObject.GetComponent <GrassController>();

            if (null == grassController)
            {
                return;
            }

            // Grass is added two times. Dont duplicate.
            bool grassFound = false;

            foreach (var it in grassList.GetItems())
            {
                GrassItem gIt = it.Content.GetComponentInChildren <GrassItem>();
                if (gIt != null)
                {
                    if (gIt.grassObject.name == gObject.name)
                    {
                        grassFound = true;
                    }
                }
            }

            if (!grassFound)
            {
                GameObject grassItemObject = Instantiate(grassItemPrefab);
                GrassItem  grassItem       = grassItemObject.GetComponentInChildren <GrassItem>();
                grassItem.SetGrassObject(gObject);
                Transform         t    = grassItem.transform;
                UIDynamicListItem item = grassList.AddItem(t);
                item.UseColliderForUI = true;
            }
            else
            {
                // TODO: Update image of the item, now that the painting is done.
            }
        }