/// <summary>
 /// handle item events internally before broadcasting
 /// </summary>
 /// <param name="type">type</param>
 /// <param name="obj">item</param>
 /// <param name="param">param</param>
 private void onItemEvent0(EventTriggerType type, FBUIEx obj, params object[] param)
 {
     if (onItemEvent != null)
     {
         onItemEvent(type, obj, param);
     }
 }
    /// <summary>
    /// find objects defined in SceneObject and attach ui components so they can be interactive
    /// </summary>
    /// <param name="scene">current scene</param>
    /// <param name="root">root object to search, if not specified this function will search all objects, which may be slow</param>
    public void initSceneInteractiveObjects(Scene scene, GameObject[] rootObjects = null)
    {
        List <FBClassObject> interactiveObjects = FBGameData.instance.getClassData("UIObject").getObjects("sceneName", new FBValue(scene.name));

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

        if (rootObjects == null)
        {
            rootObjects = scene.GetRootGameObjects();
        }

        // use a dictionary to cache items for faster searching
        Dictionary <string, FBUIEx> objectDict = new Dictionary <string, FBUIEx>();

        for (int i = 0; i < interactiveObjects.Count; i++)
        {
            string objectName = interactiveObjects[i].getFieldValue("objectName").stringValue;

            // find
            FBUIEx fbuiex = null;
            objectDict.TryGetValue(objectName, out fbuiex);
            if (fbuiex == null)
            {
                GameObject interactiveObject = null;
                for (int j = 0; j < rootObjects.Length; j++)
                {
                    Transform transform = rootObjects[j].transform.findChildRecursively(objectName);
                    if (transform)
                    {
                        interactiveObject = transform.gameObject;
                        break;
                    }
                }
                if (interactiveObject)
                {
                    fbuiex = interactiveObject.addMissingComponent <FBUIEx>();
                    objectDict[objectName] = fbuiex;
                }
            }

            if (fbuiex)
            {
                // set trigger and action
                fbuiex.addEvent(interactiveObjects[i].getFieldValue("trigger").intValue, interactiveObjects[i].getFieldValue("action").intValue, interactiveObjects[i].getFieldValue("param").stringValue);
                fbuiex.isModel3D = true;
            }
            else
            {
                Debug.Log("FBUIManager::initSceneInteractiveObjects: object not found: " + objectName);
            }
        }
    }
Example #3
0
    /// <summary>
    /// check if we can drop current object on obj
    /// </summary>
    /// <param name="obj">obj to drop</param>
    /// <returns>true if droppable, false otherwise</returns>
    public bool canDropOn(FBUIEx obj)
    {
        if (obj.dropTag == null || obj.dropTag.Length <= 0)
        {
            return(false);
        }

        for (int i = 0; i < obj.dropTag.Length; i++)
        {
            for (int j = 0; j < dragTag.Length; j++)
            {
                if (obj.dropTag[i] == dragTag[j])
                {
                    return(true);
                }
            }
        }
        return(false);
    }
Example #4
0
    /// <summary>
    /// handle events internally before broadcasting
    /// </summary>
    /// <param name="type">type</param>
    void onEvent0(EventTriggerType type)
    {
        if (onEvent != null)
        {
            onEvent(type, this);
        }

        onEvent1(type);

        // drag
        if (canDrag)
        {
            if (type == EventTriggerType.PointerDown)
            {
                isDragging             = true;
                dragObject             = this;
                dropObject             = null;
                positionBeforeDragging = transform.position;
                scaleBeforeDragging    = transform.localScale.x;
                rotationBeforeDragging = transform.localRotation;

                onEvent(EventTriggerType.BeginDrag, this);
                onEvent1(EventTriggerType.BeginDrag);
            }

            if (type == EventTriggerType.PointerUp)
            {
                isDragging = false;
                dragObject = null;
                if (dropObject)
                {
                    transform.DOKill();
                    transform.position      = positionBeforeDragging;
                    transform.localScale    = Vector3.one * scaleBeforeDragging;
                    transform.localRotation = rotationBeforeDragging;
                    onEvent(EventTriggerType.Drop, this, dropObject);
                    onEvent1(EventTriggerType.Drop);
                    dropObject = null;
                }
                else
                {
                    transform.DOMove(positionBeforeDragging, 0.25f);
                    transform.DOScale(scaleBeforeDragging, 0.25f);
                    transform.localRotation = rotationBeforeDragging;
                    onEvent(EventTriggerType.EndDrag, this);
                    onEvent1(EventTriggerType.EndDrag);
                }
            }
        }

        // drop
        if (canDrop)
        {
            if (type == EventTriggerType.PointerEnter && dragObject != null)
            {
                if (dragObject.canDropOn(this))
                {
                    dropObject = this;

                    // gd feedback: should drop asap
                    dragObject.onEvent0(EventTriggerType.PointerUp);
                }
            }
            if (type == EventTriggerType.PointerExit && dropObject == this)
            {
                dropObject = null;
            }
        }
    }