public async void Refresh()
        {
            for (int i = 0; i < m_List.Content.childCount; ++i)
            {
                Destroy(m_List.Content.GetChild(i));
            }
            m_List.Content.DetachChildren();

            foreach (SceneItemTemplateData data in m_Storage.data)
            {
                if (data.payloadType == PayloadType.Primitive ||
                    data.payloadType == PayloadType.Text ||
                    data.payloadType == PayloadType.ChatBot)
                {
                    SceneItemElementViewController controller =
                        m_ItemElementFactory.Create(data, data.itemName, sceneItemElementPrefab);
                    controller?.transform.SetParent(m_List.Content, false);
                }
                else
                {
                    CreateAllAtUrl(data, assetsUrl);
                }
            }

            await Task.Delay(20);

            for (int i = 0; i < m_List.Content.childCount; ++i)
            {
                m_List.Content.GetChild(i).GetComponent <ReorderableListElement>().isDroppableInSpace = true;
            }
        }
        private void CreateAllAtUrl(SceneItemTemplateData data, string url)
        {
            string pattern = "";

            switch (data.payloadType)
            {
            case PayloadType.Image:
                pattern = ".png";
                break;

            case PayloadType.Audio:
                pattern = ".wav";
                break;

            case PayloadType.Video:
                pattern = ".avi";
                break;
            }

            if (Directory.Exists(url))
            {
                string[] fileEntries = Directory.GetFiles(url);
                foreach (string file in fileEntries)
                {
                    if (!file.Contains(pattern))
                    {
                        continue;
                    }
                    string newPath = file.Replace("\\", "/");
                    SceneItemElementViewController controller =
                        m_ItemElementFactory.Create(data, newPath, sceneItemElementPrefab);
                    controller?.transform.SetParent(m_List.Content, false);
                }
            }
            else
            {
                HttpWebRequest request  = (HttpWebRequest)WebRequest.Create(assetsUrl);
                WebResponse    response = request.GetResponse();

                Regex regex = new Regex("<a href=\".*\">(?<name>.*)</a>");
                using (StreamReader reader = new StreamReader(response.GetResponseStream()))
                {
                    string result = reader.ReadToEnd();
                    Debug.Log(result);
                    MatchCollection matches = regex.Matches(result);
                    foreach (Match match in matches)
                    {
                        if (!match.Success || !match.Value.Contains(pattern))
                        {
                            continue;
                        }
                        SceneItemElementViewController controller =
                            m_ItemElementFactory.Create(data, assetsUrl + match.Value, sceneItemElementPrefab);
                        controller?.transform.SetParent(m_List.Content, false);
                    }
                }
            }
        }
예제 #3
0
        public void OnObjectGrabbed(ReorderableList.ReorderableListEventStruct e)
        {
            e.DroppedObject.transform.localScale = Vector3.one;
            SceneItemElementViewController source      = e.SourceObject.GetComponent <SceneItemElementViewController>();
            SceneItemElementViewController controller  = e.DroppedObject.GetComponent <SceneItemElementViewController>();
            ReorderableListElement         listElement = e.DroppedObject.GetComponent <ReorderableListElement>();

            listElement.isDroppableInSpace = true;
            controller.ToggleSelectable(false);
            controller.elementIcon.overrideSprite = source.elementIcon.overrideSprite;
        }
예제 #4
0
        public void OnObjectDropped(ReorderableList.ReorderableListEventStruct e)
        {
            RectTransform droppedTransform = e.DroppedObject.transform as RectTransform;
            Canvas        parentCanvas     = (e.DroppedObject.transform as RectTransform).GetParentCanvas();
            Camera        parentCamera     = parentCanvas.worldCamera;
            Vector2       canvasSize       = parentCanvas.pixelRect.size * parentCanvas.scaleFactor;
            Vector2       pivot            = droppedTransform.anchorMin * droppedTransform.anchorMax;
            Vector2       screenOffset     = pivot * canvasSize;
            Vector3       screenPosition   = screenOffset + droppedTransform.anchoredPosition * parentCanvas.scaleFactor;

            screenPosition.z = 1;
            Ray   ray   = new Ray(parentCamera.ScreenToWorldPoint(screenPosition), parentCamera.transform.forward);
            Plane plane = new Plane(-parentCamera.transform.forward, Vector3.zero);

            plane.Raycast(ray, out float d);
            Vector3 worldPos = ray.GetPoint(d);

            SceneItemElementViewController controller = e.DroppedObject.GetComponent <SceneItemElementViewController>();

            if ((e.FromList.transform as RectTransform).rect.Contains(e.DroppedObject.transform.position))
            {
                Destroy(e.DroppedObject);
                return;
            }

            // create scene item
            SceneItemData data = SceneItemData.Empty;

            data.position    = worldPos;
            data.payloadType = controller.sceneItemTemplateData.payloadType;
            data.payload     = data.payloadType == PayloadType.Primitive
                ? controller.sceneItemTemplateData.itemName
                : controller.payload;

            ISceneItem item = m_SceneItemFactory.Create(data);

            e.DroppedObject.transform.parent = null;
            Destroy(e.DroppedObject);
        }