Exemple #1
0
        public override void LoadLevel(LevelFormat level)
        {
            foreach (ClickAbleInfo info in level.clickObjectsInfo)
            {
                ClickableObject clickObj = new ClickableObject();

                bool found = false;
                foreach (Tuple <string, Texture2D> tup in textures)
                {
                    if (tup.Item1 == info.texturePath)
                    {
                        found                = true;
                        clickObj.Image       = tup.Item2;
                        clickObj.TexturePath = tup.Item1;
                    }
                }

                // Texture not found just drop it
                if (!found)
                {
                    continue;
                }

                if (info.useCustomBounds)
                {
                    clickObj.SetCustomBounds(new Rectangle(info.X, info.Y, info.Width, info.Height));
                }

                clickObj.StartPosition  = info.position;
                clickObj.Position       = info.position;
                clickObj.moveToPosition = info.moveToPosition;
                clickObj.TexturePath    = info.texturePath;

                // Check if the object has an animation
                if (IOHelper.Instance.DoesFileExist(Constants.CONTENT_DIR + info.texturePath + ".ani"))
                {
                    AnimationInfo aInfo = JsonConvert.DeserializeObject <AnimationInfo>(IOHelper.Instance.ReadFile(Constants.CONTENT_DIR + info.texturePath + ".ani"));
                    clickObj.Animation = new Animation(Game1.Instance.Content.Load <Texture2D>(info.texturePath), aInfo.width, aInfo.height, aInfo.cols, aInfo.rows, aInfo.totalFrames, aInfo.fps);
                }

                clickObj.ObjectiveID = info.objectiveID;

                if (info.useCustomBounds)
                {
                    clickObj.SetCustomBounds(new Rectangle(info.X, info.Y, info.Width, info.Height));
                }
                clickables.Add(clickObj);
                clickablesCount++;
            }

            base.LoadLevel(level);
        }
    public void OnPlayerReachedTarget()
    {
        //Debug.Log("OnPlayerReached");
        isMoving = false;
        heroAnimator.SetBool("Moving", isMoving);

        reachedTarget = true;
        if (_goingClickableObject != null)
        {
            _goingClickableObject.Action();
            _goingClickableObject = null;
        }
    }
Exemple #3
0
    public static void MouseOverClickableObject(Transform script, ClickableObject co)
    {
        bool leftClick  = Input.GetMouseButtonDown(0);
        bool rightClick = Input.GetMouseButtonDown(1);

        // only register clicks if not over ui
        if (!EventSystem.current.IsPointerOverGameObject())
        {
            if (rightClick && !RightClickHandled)
            {
                RightClickHandled = true;

                /* TODO: handle building */

                /* TODO: handle  */

                Instance.TargetSelectedPeopleTo(script);
            }

            // check if not a person is behind object
            if (leftClick && !LeftClickHandled)
            {
                RaycastHit hit;
                Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);

                if (Physics.Raycast(ray, out hit, 200f, Instance.onlyPeople))
                {
                    Transform objectHit = hit.transform;

                    ClickableUnit hitCo = objectHit.GetComponentInChildren <ClickableUnit>();
                    if (hitCo)
                    {
                        MouseOverClickableUnit(hitCo.ScriptedParent(), hitCo);
                        LeftClickHandled = true;
                    }
                }
            }

            // Handle UI Hover and Click stuff
            if (leftClick && !LeftClickHandled && co.clickable)
            {
                uiManager.OnShowObjectInfo(script);
                LeftClickHandled = true;
                co.UpdateSelectionCircleMaterial();
            }
            else if (co.showSmallInfo)
            {
                uiManager.OnShowSmallObjectInfo(script);
            }
        }
    }
Exemple #4
0
    public void DisplayHoverItem(ClickableObject _object)
    {
        if (_object == null)
        {
            m_HoverText.text = "";
            return;
        }
        string action = "";

        switch (GameManager.Get.m_CurrentInteractionType)
        {
        case EInteractionType.OPEN:
            action = "Open";
            break;

        case EInteractionType.CLOSE:
            action = "Close";
            break;

        case EInteractionType.GIVE:
            action = "Give";
            break;

        case EInteractionType.PICK_UP:
            action = "Pick up";
            break;

        case EInteractionType.LOOK_AT:
            action = "Look at";
            break;

        case EInteractionType.TALK_TO:
            action = "Talk to";
            break;

        case EInteractionType.PUSH:
            action = "Push";
            break;

        case EInteractionType.PULL:
            action = "Pull";
            break;

        case EInteractionType.USE:
            action = "Use";
            break;
        }
        m_HoverText.text = action + " " + _object.m_ObjectName;
    }
    public ClickableObject[] getItems()
    {
        List <ClickableObject> objs = new List <ClickableObject>();
        int numItems = transform.childCount;

        for (int i = 0; i < numItems; i++)
        {
            ClickableObject c = transform.GetChild(i).GetComponentInChildren <ClickableObject>();
            if (c != null)
            {
                objs.Add(c);
            }
        }

        return(objs.OrderBy(o => o.transform.parent.gameObject.name).ToArray());
    }
Exemple #6
0
 void Update()
 {
     // Primary mouse button clicked
     if (Input.GetMouseButtonDown(0))
     {
         Ray        ray = activeCamera.ScreenPointToRay(Input.mousePosition);
         RaycastHit hit;
         if (Physics.Raycast(ray, out hit, rayLength))
         {
             ClickableObject hitClickableObjComp = hit.collider.gameObject.GetComponent <ClickableObject>();
             if (hitClickableObjComp != null)
             {
                 ClickEvent cEvent = new ClickEvent(hit.point, ray.direction);
                 hitClickableObjComp.Click(cEvent);
             }
         }
     }
 }
    // Update is called once per frame
    void Update()
    {
        int remaining             = 0;
        List <Transform> children = new List <Transform>(itemsParent.childCount);

        for (int i = 0; i < children.Capacity; i++)
        {
            children.Add(itemsParent.GetChild(i));
            if (children[i].GetComponent <BoxCollider>() == null)
            {
                BoxCollider collider = children[i].gameObject.AddComponent <BoxCollider>();
                collider.center = new Vector3(0f, 0f, 0f);
            }
            if (!children[i].gameObject.GetComponentInChildren <ClickableObject>().HasBeenClicked())
            {
                remaining++;
            }
        }
        if (remaining == 0 && !complete)
        {
            gameObject.AddComponent <AudioSource>().PlayOneShot(completeSound);
            complete = true;
        }
        itemsRemainingText.text = remaining + " Items Remaining";
        RaycastHit hit;

        if (InputManager.mainManager.GetButton(InputManager.ButtonType.Place, InputManager.ButtonState.RisingEdge))
        {
            Debug.Log("Click");

            if (Physics.Raycast(InputManager.mainManager.mouseScreenRay, out hit))
            {
                Debug.Log("Hit");
                if (children.Contains(hit.collider.gameObject.transform.parent))
                {
                    ClickableObject clickableObj = hit.collider.gameObject.GetComponentInChildren <ClickableObject>();
                    if (clickableObj.clickable)
                    {
                        clickableObj.Click();
                    }
                }
            }
        }
    }
    public override void Start()
    {
        allItemScripts.Add(this);
        tag = Tag;

        // handles all outline/interaction stuff
        co = gameObject.AddComponent <ClickableObject>();
        co.SetSelectionCircleRadius(0.3f);

        // disable physics collision, only trigger collision
        GetComponent <Collider>().isTrigger = true;

        SetGroundY();

        // start coroutine
        StartCoroutine(GameItemTransformAndNode());

        base.Start();
    }
Exemple #9
0
 private void renderText(string str, int x, int y, int layer = 0, Color?bgColor = null, Color?fgColor = null, bool clickable = false, bool hoverable = false)
 {
     for (int i = 0; i < str.Length; i++)
     {
         Cell cell = Display.CellAt(layer, x + i, y);
         cell.SetContent(str.Substring(i, 1), bgColor ?? Color.clear, fgColor ?? Color.yellow);
         ClickableObject c = new ClickableObject();
         c.setMyName(str);
         c.setMouseDownCallback(doSomething);
         if (clickable)
         {
             cell.clickAction = c;
         }
         if (hoverable)
         {
             cell.hoverAction = c;
         }
     }
 }
Exemple #10
0
    void OnClick()
    {
        Ray        ray = camera.ScreenPointToRay(Input.mousePosition);
        RaycastHit hit;

        if (Physics.Raycast(ray, out hit, Mathf.Infinity))
        {
            //Debug.Log(hit.collider.name);

            if (hit.collider.CompareTag("Clickable"))
            {
                ClickableObject co = hit.collider.GetComponent <ClickableObject>();

                if (co)
                {
                    co.OnClick();
                }
            }
        }
    }
Exemple #11
0
    public SerializedObject(GeneratedObject obj)
    {
        position = obj.rectTransform.position;
        scale    = obj.rectTransform.localScale;
        rotation = obj.rectTransform.localRotation;
        type     = obj.type;

        Texture2D tex = (Texture2D)obj.img.texture;

        texX      = tex.width;
        texY      = tex.height;
        rawRect   = obj.img.uvRect;
        sizeDelta = obj.rectTransform.sizeDelta;
        texbytes  = ImageConversion.EncodeToPNG(tex);
        if (obj is ClickableObject)
        {
            ClickableObject co = (ClickableObject)obj;
            additionalTextures = new List <SerializableTexture>();
            foreach (Texture2D s in co.imgFace)
            {
                additionalTextures.Add(new SerializableTexture(s));
            }
            currentIdClick = co.currentId;
            correctIdClick = co.correctId;
        }
        if (obj is DragDrop)
        {
            DragDrop dg = (DragDrop)obj;
            imageID   = dg.imageID;
            contextID = dg.contextID;
            color     = dg.img.color;
        }
        if (obj is ItemSlot)
        {
            ItemSlot dg = (ItemSlot)obj;
            imageID      = dg.imageID;
            contextID    = dg.contextID;
            textItemSlot = dg.text;
            color        = dg.img.color;
        }
    }
    public virtual void ChangeHidden(bool hidden)
    {
        if (destroyed || !gameObject)
        {
            return;
        }

        isHidden = hidden;

        ClickableObject co = GetComponent <ClickableObject>();

        if (!co)
        {
            co = GetComponentInChildren <ClickableObject>();
        }

        // make sure that this object is not selected when hiding
        if (UIManager.Instance && UIManager.Instance.IsTransformSelected(transform) && hidden)
        {
            UIManager.Instance.OnHideObjectInfo();
        }
        if (co && hidden)
        {
            co.outlined = false;
            co.UpdateSelectionCircleMaterial();
        }

        if (onlyNoRenderOnHide && modelParent)
        {
            modelParent.gameObject.SetActive(!isHidden);
        }
        else
        {
            gameObject.SetActive(!isHidden);
            if (this is AnimalScript)
            {
                Debug.Log("gameObj set to inactive");
            }
        }
    }
    private void m_gestureRecognizer_TappedEvent(InteractionSourceKind source, int tapCount, Ray headRay)
    {
        Debug.Log(string.Format("TappedEvent"));
        m_audioSource.PlayOneShot(m_audioSource.clip);

        GameObject targetGameObject = RaycastForInput.singleton.GetGameObjectUnderCursor();

        if (targetGameObject != null)
        {
            ClickableObject clickTarget = targetGameObject.GetComponent <ClickableObject>();
            if (clickTarget != null)
            {
                if (targetGameObject.layer == 31)
                {
                    openAirClickHandlers[activeOpenAirClickIndex].OnClick();
                }
                else
                {
                    clickTarget.OnClick();
                }
            }
            else
            {
                if (targetGameObject.layer == 31)
                {
                    openAirClickHandlers[activeOpenAirClickIndex].OnClick();
                }
            }
        }
        else
        {
            if (openAirClickHandlers != null)
            {
                if (activeOpenAirClickIndex < openAirClickHandlers.Length)
                {
                    openAirClickHandlers[activeOpenAirClickIndex].OnClick();
                }
            }
        }
    }
    private void Update()
    {
        if (Time.timeScale == 0.0f)
        {
            return;
        }

        if (cam == null)
        {
            cam = Camera.main;
        }

        if (Input.GetMouseButtonDown(1))
        {
            ZoomInScript.ZoomOut();
            return;
        }

        if (Input.GetMouseButtonDown(0))
        {
            RaycastHit2D hit = Physics2D.Raycast(cam.ScreenToWorldPoint(Input.mousePosition), Vector3.zero);
            if (hit)
            {
                curPoi = hit.collider.GetComponent <ClickableObject>();
                if (curPoi != null)
                {
                    curPoi.OnPress();
                }
            }
        }
        else if (Input.GetMouseButtonUp(0))
        {
            if (curPoi != null)
            {
                curPoi.OnRelease();
                curPoi = null;
            }
        }
    }
Exemple #15
0
    public void HandleObjectsInteraction(GameObject clickedGo, Vector3 point)
    {
        // build stuff, check if clicked snapgrid
        SnapGrid clickedGrid = clickedGo.GetComponent <SnapGrid>();

        if (clickedGrid)
        {
            ClearSelection();

            if (!chosenPrefabToBuild) // leave if there is no prefab
            {
                return;               // #todo: need to add some ui action like choose
            }

            // check if can build, and build
            if (CanBuildIt(chosenPrefabToBuild.GetComponent <PlaceableObject>()))
            {
                gameData.resources = gameData.resources - chosenPrefabToBuild.GetComponent <PlaceableObject>().cost;
                PlaceObjectWithParams(chosenPrefabToBuild, point, Quaternion.identity);
            }
            EnterBuildMode();
        }

        // for interaction with anything, like.. Building?
        ClickableObject clickableGo = clickedGo.GetComponent <ClickableObject>();

        if (clickableGo)
        {
            PlaceableObject clickedBuilding = clickableGo.GetComponent <PlaceableObject>();
            if (clickedBuilding)
            {
                selectedGO = clickableGo.gameObject; // set clicked go as selected
                EnableBuildingSelectionFrameTo(selectedGO);
                ExitBuildMode();
            }
            clickableGo.OnClick();
        }
    }
    void Update()
    {
        if (_current != null)
        {
            if (_current.ratioPassed > 0.99)
            {
                _current = null;
            }
        }
        if (Input.GetMouseButtonUp(0) && _current == null)
        {
            Debug.Log("Clicked!");
            Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            RaycastHit hit;

            if (Physics.Raycast(ray, out hit, 100))
            {
                ClickableObject co = hit.transform.gameObject.GetComponent <ClickableObject>();

                co?.OnClick?.Invoke();
            }
        }
    }
Exemple #17
0
    void InitializeObjectLists()
    {
        //Populate list of object children
        int numChildren = generator.gameObject.transform.childCount;
        List <ClickableObject> clickable = new List <ClickableObject>();

        objectHeldList = new LinkedList <int>();
        for (int i = 0; i < numChildren; i++)
        {
            ClickableObject tmp = generator.gameObject.transform.GetChild(i).GetComponentInChildren <ClickableObject>();
            if (tmp != null)
            {
                clickable.Add(tmp);
                tmp.gameObject.transform.parent.gameObject.SetActive(false);
            }
        }
        //Add objects to held-list
        clickableObjects = clickable.ToArray();
        for (int i = 0; i < clickableObjects.Length; i++)
        {
            objectHeldList.AddFirst(i);
        }
    }
Exemple #18
0
    // Use this for initialization
    public override void Start()
    {
        // keep track of all animals
        if (gameAnimal.nr == -1)
        {
            gameAnimal.nr = allAnimals.Count;
        }
        allAnimals.Add(this);
        tag = Animal.Tag;

        Transform modelParent = transform.GetChild(0);

        // handles all outline/interaction stuff
        co = modelParent.gameObject.AddComponent <ClickableObject>();
        co.SetScriptedParent(transform);
        co.SetSelectionCircleRadius(Animal.selectionCircleRadius);

        if (!modelParent.GetComponent <Collider>())
        {
            modelParent.gameObject.AddComponent <BoxCollider>();
        }


        animator = GetComponent <Animator>();

        nearestShore = null;

        onlyNoRenderOnHide = true;

        // get right herd center
        herdCenter = Nature.Instance.herdParent.GetChild(gameAnimal.herdId).GetComponent <HerdCenter>();
        herdCenter.animalCount++;

        StartCoroutine(UpdateRoutine());

        base.Start();
    }
    /*private int MineTimes()
     * {
     *  switch (type)
     *  {
     *      case NatureObjectType.Tree: // Spruce
     *          return size/2 + 3;
     *      case NatureObjectType.EnergySpot:
     *          return 10;
     *  }
     *  return 0;
     * }*/

    public void SetCurrentModel()
    {
        currentModel = GetCurrentModel();;
        currentModel.gameObject.SetActive(true);

        if (!currentModel.gameObject.GetComponent <ClickableObject>())
        {
            // automatically add box colliders if none attached
            meshCollider = currentModel.GetComponent <MeshCollider>();
            collider     = currentModel.GetComponent <Collider>();
            if (!collider && Type != NatureObjectType.Water)
            {
                collider = currentModel.gameObject.AddComponent <BoxCollider>();
            }

            co = currentModel.gameObject.AddComponent <ClickableObject>();
            co.SetScriptedParent(transform);

            if (IsBroken())
            {
                co.SetOriginalPosition(transform.position + Vector3.up);
            }
        }
        if (co)
        {
            co.keepOriginalPos = true;
        }

        // update clickable object selection circle radius
        co.SetSelectionCircleRadius(GetRadiusInMeters() * 1.5f + 0.2f);

        // get mesh renderer for trees to change leaves color
        meshRenderer = GetComponentInChildren <MeshRenderer>(false);

        // set colliders
        UpdateColliders();
    }
Exemple #20
0
        public void OnClickHandler(object sender)
        {
            if (sender is ClickableObject)
            {
                ClickableObject s = sender as ClickableObject;

                if (s == backButton)
                {
                    if (!testing)
                    {
                        LevelManager.Instance.WinLevel(levelID, player.Tries);
                        LevelManager.Instance.UnlockLevel(levelID + 1);
                        LevelManager.Instance.SaveData();
                        ScreenManager.Instance.PopScreen();
                    }
                    else
                    {
                        Reset();
                    }
                    return;
                }

                if (!objectives[s.ObjectiveID].Done)
                {
                    s.NextPos();
                }
            }
            else if (sender is Plank)
            {
                Plank s = sender as Plank;

                if (!objectives[s.ObjectiveID].Done)
                {
                    s.NextPos();
                }
            }
        }
Exemple #21
0
    public ClickableObject CopyObject <T>(ClickableObject source)
    {
        Texture2D  prevTexture      = source.mainTexture;
        Texture2D  prevClickTexture = source.clickTexture;
        bool       prevPlaySound    = source.playSoundEffect;
        Transform  prevParent       = source.gameObject.transform.parent.transform.parent;
        int        prevItemNum      = int.Parse(source.gameObject.transform.parent.gameObject.name.Substring(4));
        float      prevDelay        = source.transitionDelay;
        GameObject obj;
        Vector3    placePosition = source.gameObject.transform.parent.transform.localPosition;

        if (typeof(T) == typeof(FallFromSky))
        {
            obj = ItemGenerator.GenerateFall(fallPrefabItem, prevParent, placePosition, prevTexture, prevClickTexture, prevDelay, time, prevItemNum, prevPlaySound);
        }
        else if (typeof(T) == typeof(FlyToSky))
        {
            obj = ItemGenerator.GenerateFly(flyPrefabItem, prevParent, placePosition, prevTexture, prevClickTexture, prevDelay, time, prevItemNum, prevPlaySound);
        }
        else if (typeof(T) == typeof(Foil))
        {
            obj = ItemGenerator.GenerateFoil(foilPrefabItem, prevParent, placePosition, prevTexture, prevClickTexture, prevDelay, time, prevItemNum, prevPlaySound);
        }
        else if (typeof(T) == typeof(NullEvent))
        {
            obj = ItemGenerator.GenerateNull(nullPrefabItem, prevParent, placePosition, anonymousMaterial, prevTexture, prevClickTexture, prevDelay, time, prevItemNum, prevPlaySound);
        }
        else
        {
            return(null);
        }

        Debug.Log(obj.transform.localPosition.y);

        return(obj.GetComponentInChildren <ClickableObject>());
    }
	void Awake(){
		objectScript = GetComponent<ClickableObject> ();
	}
 /// <summary>
 /// Creates a ClickableText out of a ClickableObject and a string to display.
 /// The options are assumed to be the same as the Left Click option for the ClickableObject.
 /// </summary>
 /// <param name="text"></param>
 /// <param name="menuItem"></param>
 public void AddMenuItem(LocalizedString text, ClickableObject menuItem)
 {
     AddMenuItem(text, menuItem._LeftClicked);
 }
Exemple #24
0
    bool AttemptAssignItem(int hitIndex)
    {
        if (hitIndex >= 0 && (!placeWithMouse || clickableObjects[hitIndex].gameObject.GetComponent <MeshRenderer>().isVisible)) //And it is visible, within the min distance, and clickable
        {
            if (clickableObjects[hitIndex].gameObject.GetComponent <NullEvent>() != null)
            { // The event is unassigned, assign it
                Debug.Log("assign");

                if (objectHeldList.Count <= 0)
                {
                    return(false);
                }

                int index = objectHeldList.First.Value;

                //Replace the clicked item with the correct identity and type (maintaining position and delay)
                ClickableObject obj;
                if (currentItemTypeIndex == 2)
                {
                    obj = CopyObject <FallFromSky>(clickableObjects[index]);
                    obj.GetComponent <FallFromSky>().enableBumpStart = true;
                }
                else if (currentItemTypeIndex == 1)
                {
                    obj = CopyObject <FlyToSky>(clickableObjects[index]);
                    obj.GetComponent <FlyToSky>().enableBumpStart = true;
                }
                else
                {
                    obj = CopyObject <Foil>(clickableObjects[index]);
                }
                obj.transform.parent.transform.localPosition = clickableObjects[hitIndex].gameObject.transform.parent.transform.localPosition;
                obj.transitionDelay = clickableObjects[hitIndex].transitionDelay;

                if (index != hitIndex)
                { //Only neccessary to make a new object if we're swapping with an old one
                    //Replace the original item with a new null event (maintaining position and delay)
                    ClickableObject obj2 = CopyObject <NullEvent>(clickableObjects[hitIndex]);
                    obj2.transform.parent.transform.localPosition = clickableObjects[index].gameObject.transform.parent.transform.localPosition;
                    obj2.transitionDelay = clickableObjects[index].transitionDelay;

                    //Get the old replacement object
                    GameObject oldObj2 = clickableObjects[hitIndex].gameObject.transform.parent.gameObject;

                    //Replace the old object in the list with the new one
                    clickableObjects[hitIndex] = obj2;

                    //Delete the old object
                    Debug.Log("Destroy" + oldObj2.name);
                    DestroyImmediate(oldObj2);
                }

                //Get the old object
                GameObject oldObj = clickableObjects[index].gameObject.transform.parent.gameObject;

                //Replace the old object in the list with the new one
                clickableObjects[index] = obj;

                //Delete the old object and remove the inventory index
                Debug.Log("Destroy" + oldObj.name);
                DestroyImmediate(oldObj);
                objectHeldList.RemoveFirst();
            }
            else
            { // The event was already assigned previous, clear its assignment
                Debug.Log("unassign");

                //Generate a new object (replacing the old with a null event)
                ClickableObject obj = CopyObject <NullEvent>(clickableObjects[hitIndex]);

                //Get the old object
                GameObject oldObj = clickableObjects[hitIndex].gameObject.transform.parent.gameObject;

                //Replace the old object in the list with the new one
                clickableObjects[hitIndex] = obj;

                //Delete the old object and add the inventory index
                DestroyImmediate(oldObj);
                objectHeldList.AddFirst(hitIndex);
            }

            Debug.Log(hitIndex);
            audioSrc.pitch = 1f;
            audioSrc.clip  = soundEffect;
            audioSrc.Play();
            return(true);
        }
        return(false);
    }
Exemple #25
0
    bool AttemptPlaceItem()
    {
        Debug.Log("No Hit, Placing.");
        if (objectHeldList.Count > 0)
        {
            //Find the index of the item being placed
            int index = objectHeldList.First.Value;

            //Validate the placement
            bool validPlacement = true;
            if (time.time > 59.99 && currentItemTypeIndex != 0)
            {
                Debug.Log("Invalidated Placement Due To Event Type and Time");
                validPlacement = false;
            }
            if (validPlacement)
            {
                //Log debug information
                int prevItemNum = int.Parse(clickableObjects[index].gameObject.transform.parent.gameObject.name.Substring(4));
                Debug.Log("Valid Placement");
                Debug.Log(prevItemNum);

                //Determine the place position
                Vector3 placePosition = Vector3.zero;
                if (placeWithMouse)
                {
                    Vector3 mouse = InputManager.mainManager.mouseWorldPosition;
                    placePosition = new Vector3(mouse.x, mousePlaceHeight, mouse.z);
                }

                // Check boundary conditions and adjust the place position accordingly
                Vector3 originalPlacement = placePosition;
                if (placePosition.x < -18.5f)
                {
                    placePosition = new Vector3(-18.5f, placePosition.y, placePosition.z);
                }
                else if (placePosition.x > 18.5f)
                {
                    placePosition = new Vector3(18.5f, placePosition.y, placePosition.z);
                }
                if (placePosition.z < -18.5f)
                {
                    placePosition = new Vector3(placePosition.x, placePosition.y, -18.5f);
                }
                else if (placePosition.z > 18.5f)
                {
                    placePosition = new Vector3(placePosition.x, placePosition.y, 18.5f);
                }
                if (originalPlacement != placePosition)
                {
                    Debug.Log("Placed within wall, placement has been shifted.");
                }

                //Copy the object as a null event
                ClickableObject obj = CopyObject <NullEvent>(clickableObjects[index]);
                obj.gameObject.transform.parent.transform.localPosition = placePosition;
                obj.transitionDelay = time.time;

                //Get the old object
                GameObject oldObj = clickableObjects[index].gameObject.transform.parent.gameObject;

                //Replace the old object in the list with the new one
                clickableObjects[index] = obj.GetComponentInChildren <ClickableObject>();

                //Destroy the old object
                DestroyImmediate(oldObj);

                //Play the placement sound
                audioSrc.pitch = 1f;
                audioSrc.clip  = soundEffect;
                audioSrc.Play();

                //Remove the item from the inventory
                objectHeldList.RemoveFirst();

                return(true);
            }
            else
            {
                Debug.Log("No valid placement.");
            }
        }
        return(false);
    }
Exemple #26
0
 public void SetupPanel(ClickableObject clickableObject, ObjectT objectT)
 {
     this.objectT         = objectT;
     this.clickableObject = clickableObject;
     UpdatePanel();
 }
Exemple #27
0
        public override void LoadContent(ContentManager content)
        {
            loader.Load();
            // Is the level loading succesfull
            if (loader.LevelLoaded)
            {
                backgroundGrid = new Grid();
                backgroundGrid.LoadFromLevelInfo(loader.level);

                drawAbleItems.Add(backgroundGrid);
                GameObjects.Add(backgroundGrid);

                List <ClickAbleInfo> click = loader.level.clickObjectsInfo;

                foreach (ClickAbleInfo info in click)
                {
                    if (info.texturePath.Contains("car"))
                    {
                        Car clickObj = new Car();
                        // Check if the object has an custom bounds
                        if (info.useCustomBounds)
                        {
                            clickObj.SetCustomBounds(new Rectangle(info.X, info.Y, info.Width, info.Height));
                        }

                        if (info.texturePath.Contains("blue"))
                        {
                            clickObj.Position      = info.position - new Vector2(400, 0);
                            clickObj.StartPosition = clickObj.Position;
                        }
                        else
                        {
                            clickObj.StartPosition = info.position;
                            clickObj.Position      = info.position;
                        }
                        clickObj.moveToPosition = info.moveToPosition;
                        clickObj.TexturePath    = info.texturePath;

                        // Check if the object has an animation
                        if (IOHelper.Instance.DoesFileExist(Constants.CONTENT_DIR + info.texturePath + ".ani"))
                        {
                            AnimationInfo aInfo = JsonConvert.DeserializeObject <AnimationInfo>(IOHelper.Instance.ReadFile(Constants.CONTENT_DIR + info.texturePath + ".ani"));
                            clickObj.Animation = new Animation(content.Load <Texture2D>(info.texturePath), aInfo.width, aInfo.height, aInfo.cols, aInfo.rows, aInfo.totalFrames, aInfo.fps);
                        }
                        else
                        {
                            clickObj.Image = content.Load <Texture2D>(info.texturePath);
                        }
                        clickObj.ObjectiveID = info.objectiveID;

                        if (info.useCustomBounds)
                        {
                            clickObj.SetCustomBounds(new Rectangle(info.X, info.Y, info.Width, info.Height));
                        }

                        clickObj.onClick += OnClickHandler;

                        objectives.Add(new Objective("Objective " + info.objectiveID));

                        drawAbleItems.Add(clickObj);
                        GameObjects.Add(clickObj);
                    }
                    else if (info.texturePath.Contains("plank"))
                    {
                        Plank clickObj = new Plank();
                        // Check if the object has an custom bounds
                        if (info.useCustomBounds)
                        {
                            clickObj.SetCustomBounds(new Rectangle(info.X, info.Y, info.Width, info.Height));
                        }

                        clickObj.StartPosition  = info.position;
                        clickObj.Position       = info.position;
                        clickObj.moveToPosition = info.moveToPosition;
                        clickObj.TexturePath    = info.texturePath;

                        // Check if the object has an animation
                        if (IOHelper.Instance.DoesFileExist(Constants.CONTENT_DIR + info.texturePath + ".ani"))
                        {
                            AnimationInfo aInfo = JsonConvert.DeserializeObject <AnimationInfo>(IOHelper.Instance.ReadFile(Constants.CONTENT_DIR + info.texturePath + ".ani"));
                            clickObj.Animation = new Animation(content.Load <Texture2D>(info.texturePath), aInfo.width, aInfo.height, aInfo.cols, aInfo.rows, aInfo.totalFrames, aInfo.fps);
                        }
                        else
                        {
                            clickObj.Image = content.Load <Texture2D>(info.texturePath);
                        }
                        clickObj.ObjectiveID = info.objectiveID;

                        if (info.useCustomBounds)
                        {
                            clickObj.SetCustomBounds(new Rectangle(info.X, info.Y, info.Width, info.Height));
                        }

                        clickObj.onClick += OnClickHandler;

                        objectives.Add(new Objective("Objective " + info.objectiveID));

                        drawAbleItems.Add(clickObj);
                        GameObjects.Add(clickObj);
                    }
                    else
                    {
                        ClickableObject clickObj = new ClickableObject();
                        // Check if the object has an custom bounds
                        if (info.useCustomBounds)
                        {
                            clickObj.SetCustomBounds(new Rectangle(info.X, info.Y, info.Width, info.Height));
                        }

                        clickObj.StartPosition  = info.position;
                        clickObj.Position       = info.position;
                        clickObj.moveToPosition = info.moveToPosition;
                        clickObj.TexturePath    = info.texturePath;

                        // Check if the object has an animation
                        if (IOHelper.Instance.DoesFileExist(Constants.CONTENT_DIR + info.texturePath + ".ani"))
                        {
                            AnimationInfo aInfo = JsonConvert.DeserializeObject <AnimationInfo>(IOHelper.Instance.ReadFile(Constants.CONTENT_DIR + info.texturePath + ".ani"));
                            clickObj.Animation = new Animation(content.Load <Texture2D>(info.texturePath), aInfo.width, aInfo.height, aInfo.cols, aInfo.rows, aInfo.totalFrames, aInfo.fps);
                        }
                        else
                        {
                            clickObj.Image = content.Load <Texture2D>(info.texturePath);
                        }
                        clickObj.ObjectiveID = info.objectiveID;

                        if (info.useCustomBounds)
                        {
                            clickObj.SetCustomBounds(new Rectangle(info.X, info.Y, info.Width, info.Height));
                        }

                        clickObj.onClick += OnClickHandler;

                        objectives.Add(new Objective("Objective " + info.objectiveID));

                        drawAbleItems.Add(clickObj);
                        GameObjects.Add(clickObj);
                    }
                }

                {// create scope for info
                    PlayerInfo info = loader.level.playerInfo;
                    player = new Player();
                    player.StartPosition = loader.level.playerInfo.position;
                    player.StartMovement = loader.level.playerInfo.startMovement;
                    player.LoadContent(content);
                    player.ChangeMovement(loader.level.playerInfo.startMovement);

                    if (loader.level.playerInfo.useCustomBoundingbox)
                    {
                        player.SetCustomBoundingbox(new Rectangle(info.x, info.y, info.width, info.height));
                    }
                    drawAbleItems.Add(player);
                }

                GameObjects.Add(player);

                foreach (MovementTileInfo info in loader.level.moveTiles)
                {
                    if (info.WinningTile)
                    {
                        GameObjects.Add(new WinTile(new Rectangle(info.X, info.Y, info.Width, info.Height)));
                    }
                    else
                    {
                        GameObjects.Add(new MovementTile(new Rectangle(info.X, info.Y, info.Width, info.Height), info.movement, testing));
                    }
                }

                foreach (DecorationInfo info in loader.level.decoration)
                {
                    Decoration decoration = new Decoration();
                    decoration.Position = info.position;
                    decoration.Image    = content.Load <Texture2D>(info.ImagePath);
                    drawAbleItems.Add(decoration);
                    GameObjects.Add(decoration);
                }

                drawAbleItems = drawAbleItems.OrderBy(o => o.DrawIndex()).ToList();
            }
            else
            {
                // TODO: show error
                player.Won = true;
            }

            pause = new Button();
            pause.LoadImage(@"buttons\pause");
            pause.Position = new Vector2(Game1.Instance.ScreenRect.Width - pause.Hitbox.Width - 10, 10);
            pause.OnClick += Pause_OnClick;

            pauseBack = new Button();
            pauseBack.LoadImage(@"buttons\menu");
            pauseBack.Position = new Vector2(Game1.Instance.ScreenRect.Width / 2 - pauseBack.Hitbox.Width / 2, Game1.Instance.ScreenRect.Height / 2 - pauseBack.Hitbox.Height / 2);
            pauseBack.OnClick += Pause_OnClick;

            backButton = new ClickableObject();

            backButton.TexturePath = @"buttons\reset";
            backButton.Image       = content.Load <Texture2D>(backButton.TexturePath);

            backButton.onClick    += OnClickHandler;
            backButton.ObjectiveID = -1;
            backButton.Position    = new Vector2(Game1.Instance.ScreenRect.Width - backButton.Image.Width - 20, Game1.Instance.ScreenRect.Height - backButton.Image.Height - 20);

            base.LoadContent(content);
        }
 public void SetClickableObjectAsCallback(ClickableObject objectTo)
 {
     _goingClickableObject = objectTo;
 }
Exemple #29
0
        public override void Update(GameTime time)
        {
            if (InputHelper.Instance.IsKeyPressed(Keys.A) && curObject > 0 && !placing)
            {
                curObject--;
            }
            else if (InputHelper.Instance.IsKeyPressed(Keys.D) && curObject < textures.Count - 1 && !placing)
            {
                curObject++;
            }

            if (InputHelper.Instance.IsLeftMouseReleased())
            {
                if (placing)
                {
                    moveToPositions.Add(InputHelper.Instance.MousePos());
                }
                else
                {
                    startPos = InputHelper.Instance.MousePos();
                    placing  = true;
                }
            }
            else if (InputHelper.Instance.IsRightMousePressed())
            {
                if (placing)
                {
                    ClickableObject obj = new ClickableObject();
                    obj.StartPosition  = obj.Position = startPos;
                    obj.TexturePath    = textures[curObject].Item1;
                    obj.moveToPosition = moveToPositions;
                    obj.ObjectiveID    = clickablesCount;
                    if (!ClickableObjectManager.Instance.NoBoxesLoaded && !ClickableObjectManager.Instance.GetBoundingbox(textures[curObject].Item1).IsEmpty)
                    {
                        obj.SetCustomBounds(ClickableObjectManager.Instance.GetBoundingbox(textures[curObject].Item1));
                    }

                    if (IOHelper.Instance.DoesFileExist(Constants.CONTENT_DIR + obj.TexturePath + ".ani"))
                    {
                        AnimationInfo aInfo = JsonConvert.DeserializeObject <AnimationInfo>(IOHelper.Instance.ReadFile(Constants.CONTENT_DIR + obj.TexturePath + ".ani"));
                        obj.Animation = new Animation(Game1.Instance.Content.Load <Texture2D>(obj.TexturePath), aInfo.width, aInfo.height, aInfo.cols, aInfo.rows, aInfo.totalFrames, aInfo.fps);
                    }
                    else
                    {
                        obj.Image = textures[curObject].Item2;
                    }

                    clickables.Add(obj);
                    clickablesCount++;
                    moveToPositions = new List <Vector2>();
                    placing         = false;
                }
                else
                {
                    bool reset = false;

                    for (int i = 0; i < clickables.Count; i++)
                    {
                        ClickableObject o = clickables[i];

                        if (o.Boundingbox.Contains(InputHelper.Instance.MousePos().toPoint()))
                        {
                            clickables.Remove(o);
                            clickablesCount--;
                            reset = true;
                        }
                    }

                    if (reset)
                    {
                        ResetIDs();
                    }
                }
            }

            if (placing)
            {
                blockLayerChange = true;
            }
            else
            {
                blockLayerChange = false;
            }

            base.Update(time);
        }
    void Update()
    {
        if (firstCall)
        {
            //Needs to be run on first update because Start() order isn't promised
            int numChildren = generator.gameObject.transform.childCount;
            List <ClickableObject> clickable = new List <ClickableObject>();
            objectHeldList = new LinkedList <int>();
            for (int i = 0; i < numChildren; i++)
            {
                ClickableObject tmp = generator.gameObject.transform.GetChild(i).GetComponentInChildren <ClickableObject>();
                if (tmp != null)
                {
                    clickable.Add(tmp);
                    tmp.gameObject.transform.parent.gameObject.SetActive(false);
                }
            }
            Shuffle <ClickableObject>(clickable);
            clickableObjects = clickable.ToArray();
            for (int i = 0; i < clickableObjects.Length; i++)
            {
                objectHeldList.AddFirst(i);
            }
            firstCall = false;
        }
        Vector3 comparisonDistance = gameObject.transform.position;

        if (placeWithMouse)
        {
            Vector3 mouse = InputManager.mainManager.mouseWorldPosition;
            comparisonDistance = new Vector3(mouse.x, mousePlaceHeight * 2, mouse.z);
        }

        if (InputManager.mainManager.GetButton(InputManager.ButtonType.NextEvent, InputManager.ButtonState.RisingEdge))
        {
            currentItemTypeIndex = (currentItemTypeIndex + 1) % 3;
            switch (currentItemTypeIndex)
            {
            case 0:
                typeDisplayImage.material = infinityMaterial;
                break;

            case 1:
                typeDisplayImage.material = upMaterial;
                break;

            case 2:
                typeDisplayImage.material = downMaterial;
                break;

            default:
                typeDisplayImage.material = null;
                break;
            }
        }

        else if (InputManager.mainManager.GetButton(InputManager.ButtonType.Place, InputManager.ButtonState.RisingEdge))
        {
            RaycastHit hit;
            var        cameraCenter = targetingCamera.ScreenToWorldPoint(new Vector3(Screen.width / 2f, Screen.height / 2f, targetingCamera.nearClipPlane));
            if (placeWithMouse)
            {
                cameraCenter = InputManager.mainManager.mouseScreenPosition;
            }
            Physics.SphereCast(cameraCenter, 0.5f, targetingCamera.transform.forward, out hit, 1000f, 1 << LayerMask.NameToLayer("UI"));
            int hitIndex = -1;
            if (hit.transform != null)
            {
                GameObject hitObj = hit.transform.gameObject;
                Debug.Log("Hit: " + hitObj.name);
                for (int i = 0; i < clickableObjects.Length; i++)
                {
                    if (hitObj == clickableObjects[i].gameObject)
                    {
                        hitIndex = i;
                    }
                }
            }
            if (hitIndex >= 0 && (!placeWithMouse || clickableObjects[hitIndex].gameObject.GetComponent <MeshRenderer>().isVisible)) //And it is visible, within the min distance, and clickable
            {
                clickableObjects[hitIndex].gameObject.transform.parent.gameObject.SetActive(false);
                objectHeldList.AddFirst(hitIndex);
                // Log item number, event type, location, time,
                //itemLogger.logMessage("Item Picked Up : " + clickableObjects[closestIndex].gameObject.transform.parent.name + " type ");
                Debug.Log(hitIndex);
                audioSrc.pitch = 1f;
                audioSrc.clip  = soundEffect;
                audioSrc.Play();
            }
            else //No object is being picked up, drop the current item
            {
                Debug.Log("No Hit, Placing.");
                if (objectHeldList.Count > 0)
                {
                    int         index            = objectHeldList.First.Value;
                    Texture2D   prevTexture      = clickableObjects[index].mainTexture;
                    Texture2D   prevClickTexture = clickableObjects[index].clickTexture;
                    bool        prevPlaySound    = clickableObjects[index].playSoundEffect;
                    Transform   prevParent       = clickableObjects[index].gameObject.transform.parent.transform.parent;
                    FallFromSky fallScript       = clickableObjects[index].gameObject.GetComponent <FallFromSky>();
                    FlyToSky    flyScript        = clickableObjects[index].gameObject.GetComponent <FlyToSky>();
                    int         prevItemNum      = int.Parse(clickableObjects[index].gameObject.transform.parent.gameObject.name.Substring(4));
                    GameObject  obj;
                    Vector3     placePosition  = transform.position + (transform.forward * placeDistance);
                    bool        validPlacement = true;
                    for (int i = 0; i < clickableObjects.Length; i++)
                    {
                        if (i == index)
                        {
                            continue;
                        }
                        float dist = Vector3.Distance(placePosition, clickableObjects[i].transform.parent.position);
                        //If object is enabled and visible and within the minPlaceDistance, invalidate the placement
                        if (clickableObjects[i].isActiveAndEnabled && clickableObjects[i].GetComponent <MeshRenderer>().isVisible&& dist < minObjectPlaceDistance)
                        {
                            validPlacement = false;                                         //Invalid object placement, do nothing
                        }
                        if (placePosition == clickableObjects[i].transform.parent.position) //As an additional check, if the objects are in precisely the same place, invalidate as well
                        {
                            validPlacement = false;
                        }
                    }
                    if (time.time > 59.99 && currentItemTypeIndex != 0)
                    {
                        Debug.Log("Invalidated Placement Due To Event Type and Time");
                        validPlacement = false;
                    }
                    if (validPlacement)
                    {
                        Debug.Log("Valid Placement");
                        Debug.Log(prevItemNum);
                        objectHeldList.RemoveFirst();
                        // Check boundary conditions
                        Vector3 originalPlacement = placePosition;
                        if (placePosition.x < -18.5f)
                        {
                            placePosition = new Vector3(-18.5f, placePosition.y, placePosition.z);
                        }
                        else if (placePosition.x > 18.5f)
                        {
                            placePosition = new Vector3(18.5f, placePosition.y, placePosition.z);
                        }
                        if (placePosition.z < -18.5f)
                        {
                            placePosition = new Vector3(placePosition.x, placePosition.y, -18.5f);
                        }
                        else if (placePosition.z > 18.5f)
                        {
                            placePosition = new Vector3(placePosition.x, placePosition.y, 18.5f);
                        }
                        if (originalPlacement != placePosition)
                        {
                            Debug.Log("Placed within wall, placement has been shifted.");
                        }
                        if (placeWithMouse)
                        {
                            Vector3 mouse = InputManager.mainManager.mouseWorldPosition;
                            placePosition = new Vector3(mouse.x, mousePlaceHeight, mouse.z);
                        }
                        else
                        {
                            placePosition = new Vector3(placePosition.x, (float)ItemGenerator.itemHeight, placePosition.z);
                        }
                        if (currentItemTypeIndex == 2)
                        {
                            obj = ItemGenerator.GenerateFall(fallPrefabItem, prevParent, placePosition, prevTexture, prevClickTexture, time.time, time, prevItemNum, prevPlaySound);
                        }
                        else if (currentItemTypeIndex == 1)
                        {
                            obj = ItemGenerator.GenerateFly(flyPrefabItem, prevParent, placePosition, prevTexture, prevClickTexture, time.time, time, prevItemNum, prevPlaySound);
                        }
                        else
                        {
                            obj = ItemGenerator.GenerateFoil(foilPrefabItem, prevParent, placePosition, prevTexture, prevClickTexture, time.time, time, prevItemNum, prevPlaySound);
                        }
                        GameObject oldObj = clickableObjects[index].gameObject.transform.parent.gameObject;
                        clickableObjects[index] = obj.GetComponentInChildren <ClickableObject>();
                        DestroyImmediate(oldObj);
                        audioSrc.pitch = 1f;
                        audioSrc.clip  = soundEffect;
                        audioSrc.Play();
                    }
                    else
                    {
                        Debug.Log("No valid placement.");
                    }
                }
            }
        }

        bool nextInputState = InputManager.mainManager.GetButton(InputManager.ButtonType.NextItem, InputManager.ButtonState.RisingEdge);

        if (nextInputState && objectHeldList.Count != 0)
        {
            objectHeldList.AddLast(objectHeldList.First.Value);
            objectHeldList.RemoveFirst();
        }

        if (objectHeldList.Count != 0)
        {
            displayImage.material = clickableObjects[objectHeldList.First.Value].gameObject.GetComponent <MeshRenderer>().material;
        }
        else
        {
            displayImage.material = emptyMaterial;
        }

        if (forceTransparency != 1f)
        {
            Material m = displayImage.material;
            m.SetFloat("_Mode", 2);
            m.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.SrcAlpha);
            m.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha);
            m.SetInt("_ZWrite", 0);
            m.DisableKeyword("_ALPHATEST_ON");
            m.EnableKeyword("_ALPHABLEND_ON");
            m.DisableKeyword("_ALPHAPREMULTIPLY_ON");
            m.renderQueue = 3000;
        }

        if (InputManager.mainManager.GetButton(InputManager.ButtonType.PickAll, InputManager.ButtonState.RisingEdge))
        {
            for (int i = 0; i < clickableObjects.Length; i++)
            {
                if (clickableObjects[i].gameObject.transform.parent.gameObject.activeSelf)
                {
                    clickableObjects[i].gameObject.transform.parent.gameObject.SetActive(false);
                    objectHeldList.AddFirst(i);

                    audioSrc.pitch = 1f;
                    audioSrc.clip  = multiSoundEffect;
                    audioSrc.Play();
                }
            }
        }
    }
Exemple #31
0
    public void CreateObj()
    {
        GameObject go = Instantiate(selected, spawnArea.transform);
        ObjectT    OT = go.AddComponent <ObjectT>();

        OT.prefabTyp = prefabType;
        switch (type)
        {
        case GenObjectType.Drag:
            DragDrop dg = go.AddComponent <DragDrop>();
            dg.DisableMovement();
            OT.SetTyp(GenObjectType.Drag, icons[0]);
            if (OT.prefabTyp.Equals(PrefabType.Tvar))
            {
                AssignId(dg, OT);
                dg.type = "Drag";
            }
            if (OT.prefabTyp.Equals(PrefabType.Basic))
            {
                AssignId(dg, OT);
                dg.type    = "Drag";
                dg.imageID = 900;
            }
            break;

        case GenObjectType.Click:
            ClickableObject co = go.AddComponent <ClickableObject>();
            OT.SetTyp(GenObjectType.Click, icons[1]);
            co.imgFace     = new List <Texture2D>(basicTextures);
            co.img.texture = basicTextures[0];
            co.type        = "Click";
            OT.prefabTyp   = PrefabType.Swap;
            co.editor      = true;
            break;

        case GenObjectType.Static:
            ItemSlot itemslot = go.AddComponent <ItemSlot>();
            OT.SetTyp(GenObjectType.Static, icons[2]);
            if (prefabType.Equals(PrefabType.Tvar))
            {
                itemslot.img.color   = Color.gray;
                itemslot.img.texture = rectangleText;
                itemslot.objectName  = "Static tvar " + staticContextID;
                itemslot.type        = "Stat";
                staticContextID++;
            }
            if (prefabType.Equals(PrefabType.Basic))
            {
            }
            break;

        case GenObjectType.Afk:
            OT.SetTyp(GenObjectType.Afk, icons[2]);
            ItemSlot itemSlot = go.AddComponent <ItemSlot>();
            itemSlot.contextID  = -999;
            itemSlot.imageID    = -999;
            itemSlot.objectName = "Statický obj";
            itemSlot.type       = "Afk";
            itemSlot.editor     = true;
            break;
        }
        ObjectModificator.Instance.SelectObject(OT.GetComponent <GeneratedObject>(), OT);
    }
Exemple #32
0
 public void OnEnable()
 {
     co = target as ClickableObject;
     co.SetSprite();
 }