Ejemplo n.º 1
0
        /*
         * SUPERCEEDED by dragging (or is it ?)
         * public void TryPlacingBlueprint()
         * {
         *  //TO DO : SHould check if we are on UI, don't click if we are
         *  if (ActiveBlueprint!=null)
         *  {
         *      if ( Constraint.CheckRootConstraint(ActiveBlueprint))
         *      {
         *          GameObject PlacedObject = Instantiate(ActiveBlueprint , ActiveBlueprint.transform.position , ActiveBlueprint.transform.rotation);
         *
         *          // Copy BeyondComponent values from the blueprint to the PlacedObject
         *          BeyondComponent blueprintBC = ActiveBlueprint.GetComponent<BeyondComponent>();
         *          BeyondComponent bc = PlacedObject.GetComponent<BeyondComponent>();
         *          bc.SetValues(blueprintBC.Template, State.Ghost , blueprintBC.BuildingMaterials);
         *
         *          // Remove Outline, disable "isTrigger", set layer, name object
         *          PlacedObject.GetComponent<BoxCollider>().isTrigger = false;
         *          PlacedObject.layer = LayerMask.NameToLayer("Buildings");
         *          PlacedObject.name = bc.Template.Name;
         *          CreateNewBeyondGroup(bc);
         *      }
         *      DestroyActiveBlueprint();
         *  }
         * }
         */

        public void StartDragging()
        {
            if (ActiveBlueprint != null)
            {
                if (Constraint.CheckRootConstraint(ActiveBlueprint))
                {
                    GameObject_DragFrom = Instantiate(ActiveBlueprint, ActiveBlueprint.transform.position, ActiveBlueprint.transform.rotation);
                    BeyondComponent bc = ActiveBlueprint.GetComponent <BeyondComponent>();
                    GameObject_DragFrom.GetComponent <BeyondComponent>().CopyValues(bc);

                    dragDirections = Utility.RotatedAxes(GameObject_DragFrom.transform.rotation);

                    // Clearing & initialising the pool of DraggedObjects
                    for (int i = 0; i < MaxDraggedObjects; i++)
                    {
                        GameObject go = Instantiate(ActiveBlueprint);
                        go.SetActive(false);
                        // I need to initialise the BC of each dragged object so I know what template they are. Instantiating them was not enough to copy the ActiveBlueprint's BC
                        go.GetComponent <BeyondComponent>().CopyValues(bc);
                        draggedObjects.Add(go);
                    }

                    ActiveBlueprint.SetActive(false);
                }
            }
            Debug.Log("Start Dragging initialised draggedObjects: " + draggedObjects.Count);
        }
Ejemplo n.º 2
0
        public void CreateBlueprint(GameAction blueprint, List <BuildingMaterial> materials)
        {
            // Instantiate a prefab of that blueprint
            // Show it floating 5 units away from where the FPS is looking
            Template t = GameManager.instance.GetTemplate(blueprint.Name);

            if (t != null)
            {
                DestroyActiveBlueprint();
                ActiveBlueprint = Instantiate(t.Prefab, FPSCharacter.transform, false);
                BeyondComponent bc = ActiveBlueprint.AddComponent <BeyondComponent>();
                bc.SetValues(t, State.Ghost, materials);
                ActiveBlueprint.transform.Translate(new Vector3(0, 0, blueprintDistanceFromCamera));
                ActiveBlueprint.name = string.Format("Ghost ({0})", t.Name);
            }
            else
            {
                Debug.LogError("Attempting to create null template");
            }
        }