Ejemplo n.º 1
0
        /// <summary>
        /// Begin button drag
        /// </summary>
        /// <param name="selected">selected button</param>
        /// <param name="mousePosition">mouse position</param>
        /// <param name="cursor">cursor</param>
        /// <returns>true if button drag is started</returns>
        protected override bool BeginButtonDrag(UnitButton selected, Point mousePosition, ref Cursor cursor)
        {
            if (CanMoveByMouse == false)
            {
                return(true);
            }

            EventHandler <FormEventArgs> handler = UndockForm;

            if (handler != null)
            {
                _movedButton = selected;
                _movedForm   = (Form)_movedButton.Page;
                _movedIndex  = SelectedIndex;

                Point         mouseScreenPosition = Control.MousePosition;
                FormEventArgs args = new FormEventArgs(_movedForm, GetPageInfo(_movedForm).Id);
                handler(this, args);

                RemoveButton(_movedButton);

                _movedDecorator = HierarchyUtility.GetFormsDecorator(_movedForm);

                IsFocused = false;
                _movedDecorator.IsFocused = true;

                _movedDecorator.BeginMovementByMouse(mouseScreenPosition);

                cursor = Cursors.SizeAll;
            }

            return(true);
        }
    static void CreatePrefab()
    {
        var scene1file = "Assets/public/Testbed/UI/ui_work.unity";

        // load
        EditorSceneManager.OpenScene(scene1file);

        //念のため再度スプライト書き出し
        MakeSpriteInfo();

        // template検索
        var tmplgo = HierarchyUtility.FindGameObjectByUncPath(null, "UI/template");

        Debug.Log("target :" + HierarchyUtility.GetAbsoluteNodePath(tmplgo));

        var localpath = "Assets/Public/Testbed/UI/template.prefab";

        try {
            if (AssetDatabase.LoadAssetAtPath(localpath, typeof(GameObject)) != null)
            {
                AssetDatabase.DeleteAsset(localpath);
            }
        } catch { }

        var prefab    = PrefabUtility.CreateEmptyPrefab(localpath);
        var newprefab = PrefabUtility.ReplacePrefab(tmplgo, prefab);

        AssetDatabase.Refresh();

        var exportpath = Path.Combine(Application.dataPath, @"../template.unitypackage");

        AssetDatabase.ExportPackage(localpath, exportpath, ExportPackageOptions.Recurse);

        Debug.Log("Exported : " + exportpath);
    }
Ejemplo n.º 3
0
    private GameObject SpawnPedestrian()
    {
        GameObject ped = Instantiate(pedPrefab, Vector3.zero, Quaternion.identity, transform);

        //Ensure sure all pedestrians get unique names
        HierarchyUtility.ChangeToUniqueName(ped);
        var pedController = ped.GetComponent <PedestrianController>();

        pedController.SetGroundTruthBox();
        var modelIndex = RandomGenerator.Next(pedModels.Count);
        var model      = pedModels[modelIndex];

        Instantiate(model, ped.transform);
        ped.SetActive(false);
        SimulatorManager.Instance.UpdateSemanticTags(ped);
        currentPedPool.Add(pedController);

        //Add required components for distributing rigidbody from master to clients
        if (SimulatorManager.Instance.Network.IsMaster)
        {
            if (ped.GetComponent <DistributedObject>() == null)
            {
                ped.AddComponent <DistributedObject>();
            }
            if (ped.GetComponent <DistributedRigidbody>() == null)
            {
                ped.AddComponent <DistributedRigidbody>();
            }
            BroadcastMessage(new Message(Key,
                                         GetSpawnMessage(ped.name, modelIndex, ped.transform.position, ped.transform.rotation),
                                         MessageType.ReliableUnordered));
        }

        return(ped);
    }
Ejemplo n.º 4
0
    protected void set_content_to_parent(int width, int height)
    {
        var go = HierarchyUtility.FindGameObject(m_latest.transform, "Content");

        m_parent = go;

        var rt = go.GetComponent <RectTransform>();

        rt.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, width);
        rt.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, height);
    }
    void set_cam(string camname)
    {
        if (m_camroot == null)
        {
            m_camroot = GameObject.Find("camroot");
        }
        var camo   = HierarchyUtility.FindGameObject(m_camroot.transform, "Camera_" + camname);
        var dstcam = camo.GetComponent <Camera>();

        StartCoroutine(set_cam_co(dstcam, 30));
    }
Ejemplo n.º 6
0
    public static void setup_imported_ui_scrollview(Transform t)
    {
        var list = new List <ScrollRect>();

        HierarchyUtility.TraverseComponent <ScrollRect>(t, i => {
            list.Add(i);
        });
        foreach (var i in list)
        {
            var scrollviewevent = ComponentUtil.AddComponentIfNotExist <UIScrollViewEvent>(i.gameObject);
            i.onValueChanged.AddListener(scrollviewevent.Change);
        }
    }
Ejemplo n.º 7
0
    public static void setup_imported_ui_slider(Transform t)
    {
        var list = new List <Slider>();

        HierarchyUtility.TraverseComponent <Slider>(t, i => {
            list.Add(i);
        });
        foreach (var i in list)
        {
            var slider = ComponentUtil.AddComponentIfNotExist <UISliderEvent>(i.gameObject);
            i.onValueChanged.AddListener(slider.Change);
        }
    }
Ejemplo n.º 8
0
    public static void setup_imported_ui_button(Transform t)
    {
        var list = new List <Button>();

        HierarchyUtility.TraverseComponent <Button>(t, i => {
            list.Add(i);
        });
        foreach (var i in list)
        {
            var but = ComponentUtil.AddComponentIfNotExist <UIButtonEvent>(i.gameObject);
            i.onClick.AddListener(but.PushDown);
        }
    }
Ejemplo n.º 9
0
    public static void setup_imported_ui_toggle(Transform t)
    {
        var list = new List <Toggle>();

        HierarchyUtility.TraverseComponent <Toggle>(t, i => {
            list.Add(i);
        });
        foreach (var i in list)
        {
            var but = ComponentUtil.AddComponentIfNotExist <UIToggleEvent>(i.gameObject);
            i.onValueChanged.AddListener(but.PushDown);
        }
    }
Ejemplo n.º 10
0
    //Clone
    public static GameObject FindAndClone(Transform root, string name, GameObject parent)
    {
        var find = HierarchyUtility.FindGameObject(root, name);

        if (find != null)
        {
            var clone = GameObject.Instantiate(find);
            clone.transform.SetParent(parent.transform);
            HierarchyUtility.TraverseSetLayerMask(clone.transform, LayerMask.NameToLayer("UI"));
            return(clone);
        }
        return(null);
    }
Ejemplo n.º 11
0
    public static void setup_imported_ui_scrollbar(Transform t, object control = null)
    {
        var list = new List <Scrollbar>();

        HierarchyUtility.TraverseComponent <Scrollbar>(t, i => {
            list.Add(i);
        });
        foreach (var i in list)
        {
            var scrollbar = ComponentUtil.AddComponentIfNotExist <UIScrollbarEvent>(i.gameObject);
            scrollbar.m_control = control;
            i.onValueChanged.AddListener(scrollbar.Change);
        }
    }
Ejemplo n.º 12
0
    public static void setup_imported_ui_inputfield(Transform t)
    {
        var list = new List <InputField>();

        HierarchyUtility.TraverseComponent <InputField>(t, i => {
            list.Add(i);
        });
        foreach (var i in list)
        {
            var inputfield = ComponentUtil.AddComponentIfNotExist <UIInputFieldEvent>(i.gameObject);
            i.onValueChanged.AddListener(inputfield.Change);
            i.onEndEdit.AddListener(inputfield.End);
        }
    }
Ejemplo n.º 13
0
        /// <summary>
        /// Checks if this panel contains give panel
        /// </summary>
        /// <param name="panel">panel to check</param>
        /// <returns>true if this panel contains given pane</returns>
        public bool ContainsPanel(AutoHidePanel panel)
        {
            for (int index = ButtonsCount - 1; index >= 0; index--)
            {
                UnitButton button = GetButtonAt(index);

                FormsTabbedView view = HierarchyUtility.GetTabbedView((Form)button.Page);
                if (view.Parent == panel)
                {
                    return(true);
                }
            }

            return(false);
        }
Ejemplo n.º 14
0
        private static void SetPivot(MenuCommand command, PivotPosition pivot)
        {
            var gameObject = command.context as GameObject;

            if (gameObject == null)
            {
                return;
            }

            Undo.RegisterFullObjectHierarchyUndo(gameObject, "Set Pivot");

            var childMeshFilters = gameObject.GetComponentsInChildren <MeshFilter> ();
            var offset           = HierarchyUtility.GetPivotOffset(childMeshFilters, pivot);

            HierarchyUtility.OffsetChildren(gameObject.transform, offset);
        }
Ejemplo n.º 15
0
    private void Start()
    {
        m_templates = new List <Canvas>();
        m_templates.Add(m_temaplate_base);

        HierarchyUtility.TraverseComponent <Canvas>(
            m_add_from_unitypackage.transform,

            i => {
            var s = i.ToString();
            Debug.Log(s);
            m_templates.Add(i);
        }
            );

        m_sm = new UITest01Control();
    }
Ejemplo n.º 16
0
    public static void setup_imported_ui_button(Transform t, object control = null)
    {
        var list = new List <Button>();

        HierarchyUtility.TraverseComponent <Button>(t, i => {
            list.Add(i);
        });
        foreach (var i in list)
        {
            var et  = ComponentUtil.AddComponentIfNotExist <EventTrigger>(i.gameObject); // Use Event Trigger! (Default Event is not safe under static object.)
            var but = ComponentUtil.AddComponentIfNotExist <UIButtonEvent>(i.gameObject);
            but.m_control = control;

            var entry = new EventTrigger.Entry();
            entry.eventID = EventTriggerType.PointerDown;
            entry.callback.AddListener((data) => { but.PushDown(); });
            et.triggers.Add(entry);
        }
    }
Ejemplo n.º 17
0
        /// <summary>
        /// Instantiates selected prefab in the unique relative path
        /// </summary>
        /// <param name="prefabId">Id of instantiated prefab in <see cref="NetworkSettings.DistributedObjectPrefabs"/></param>
        /// <param name="relativePath">Relative path to the root where object will be created, can be changed if object name is not unique</param>
        /// <returns>Instantiated new distributed object</returns>
        /// <exception cref="ArgumentException">Invalid configuration of the instantiated prefab</exception>
        private DistributedObject InstantiatePrefab(int prefabId, string relativePath)
        {
            if (prefabId < 0 || prefabId >= Settings.DistributedObjectPrefabs.Length)
            {
                throw new ArgumentException(
                          $"Prefab of distributed object with id {prefabId} is not defined in {typeof(NetworkSettings).Name}.");
            }
            var distributedObjectParent = HierarchyUtility.GetOrCreateChild(transform, relativePath);
            var newGameObject           = Instantiate(Settings.DistributedObjectPrefabs[prefabId], distributedObjectParent);

            HierarchyUtility.ChangeToUniqueName(newGameObject);
            var distributedObject = newGameObject.GetComponent <DistributedObject>();

            if (distributedObject == null)
            {
                throw new ArgumentException(
                          $"Prefab of distributed object with id {prefabId} has no {typeof(DistributedObject).Name} component in the root game object.");
            }
            instantiatedObjects.Add(new InstantiatedObjectData(prefabId, distributedObject));
            return(distributedObject);
        }
    static void MakeSpriteInfo()
    {
        var scene1file = "Assets/public/Testbed/UI/ui_work.unity";

        // load
        EditorSceneManager.OpenScene(scene1file);

        // template検索
        var tmplgo = HierarchyUtility.FindGameObjectByUncPath(null, "UI/template");

        Debug.Log("target :" + HierarchyUtility.GetAbsoluteNodePath(tmplgo));

        HierarchyUtility.TraverseComponent <Image>(tmplgo.transform, c => {
            if (c.sprite == null)
            {
                Debug.Log(c.name);
                return;
            }

            GameObject sprite_go = null;
            for (var i = 0; i < c.transform.childCount; i++)
            {
                var ct = c.transform.GetChild(i);
                if (ct.name.StartsWith("*sprite=" + c.name + ":"))
                {
                    sprite_go = ct.gameObject;
                    break;
                }
            }
            if (sprite_go == null)
            {
                sprite_go = new GameObject();
            }
            sprite_go.name                    = "*sprite=" + c.name + ":" + c.sprite.name;
            sprite_go.transform.parent        = c.transform;
            sprite_go.transform.localPosition = Vector3.zero;
            sprite_go.transform.localRotation = Quaternion.identity;
            sprite_go.transform.localScale    = Vector3.one;
        });
    }
Ejemplo n.º 19
0
        /// <summary>
        /// Removes the panel if is contained here
        /// </summary>
        /// <param name="panel">panel to remove</param>
        /// <returns>true if is removed the panel</returns>
        public bool Remove(AutoHidePanel panel)
        {
            bool removed = false;

            for (int index = ButtonsCount - 1; index >= 0; index--)
            {
                UnitButton button = GetButtonAt(index);

                FormsTabbedView view = HierarchyUtility.GetTabbedView((Form)button.Page);
                if (view.Parent == panel)
                {
                    RemoveButton(button);
                    removed = true;
                }
            }

            panel.View.FormAdded    -= OnFormAddedToPanel;
            panel.View.FormRemoved  -= OnFormRemovedFromPanel;
            panel.View.FormSelected -= OnFormSelectedIntoView;

            return(removed);
        }
Ejemplo n.º 20
0
 public static void SetSprite(RectTransform rt, UnityEngine.Sprite s, string name = null)
 {
     UnityEngine.UI.Image tc = null;
     HierarchyUtility.TraverseComponent <UnityEngine.UI.Image>(rt.transform, i => {
         if (tc != null)
         {
             return;
         }
         var b = true;
         if (name != null)
         {
             b = (i.name == name);
         }
         if (b)
         {
             tc = i;
         }
     });
     if (tc != null)
     {
         tc.sprite = s;
     }
 }
Ejemplo n.º 21
0
        /// <summary>
        /// Instantiates new prefab
        /// </summary>
        public void InstantiatePrefab(int prefabId, string relativePath, string objectName)
        {
            if (prefabId < 0 || prefabId >= Settings.DistributedObjectPrefabs.Length)
            {
                throw new ArgumentException(
                          $"Prefab of distributed object with id {prefabId} is not defined in {typeof(NetworkSettings).Name}.");
            }
            var rootTransform = transform;
            var newGameObject = Instantiate(Settings.DistributedObjectPrefabs[prefabId],
                                            rootTransform.position,
                                            rootTransform.rotation,
                                            HierarchyUtility.GetOrCreateChild(rootTransform, relativePath));

            newGameObject.name = objectName;
            var distributedObject = newGameObject.GetComponent <DistributedObject>();

            if (distributedObject == null)
            {
                throw new ArgumentException(
                          $"Prefab of distributed object with id {prefabId} has no {typeof(DistributedObject).Name} component in the root game object.");
            }
            instantiatedObjects.Add(new InstantiatedObjectData(prefabId, newGameObject));
        }
Ejemplo n.º 22
0
    public static void setup_imported_ui_sprite(Transform t)
    {
        //  *spriteノード検索
        HierarchyUtility.TraverseGameObject(t, i => {
            //                     012345678
            if (i.name.StartsWith("*sprite="))
            {
                var partsname  = string.Empty;
                var spritename = string.Empty;

                var s = i.name.Substring(8);
                if (!string.IsNullOrEmpty(s))
                {
                    var l = s.Split(':');
                    if (l.Length >= 2)
                    {
                        partsname  = l[0].Trim();
                        spritename = l[1].Trim();
                    }
                }
                if (string.IsNullOrEmpty(partsname) || string.IsNullOrEmpty(spritename))
                {
                    Debug.LogError("Unexpected! {50F74FF0-84C1-444F-9F3A-7390659B591B}");
                    return;
                }
                var parent = i.parent;
                if (parent.name != partsname)
                {
                    Debug.LogError("Unexpected! {412AC75C-C9E5-4424-9F42-5F610ECA67D8}");
                    return;
                }
                var imagecompo    = parent.GetComponent <Image>();
                imagecompo.sprite = UISpriteManager.V.GetSprite(spritename);
            }
        });
    }
Ejemplo n.º 23
0
    //Clone
    public static GameObject FindAndClone(Canvas[] templates, string name, GameObject parent)
    {
        GameObject find = null;

        foreach (var canvas in templates)
        {
            var root    = canvas.transform;
            var find_tr = root.Find(name);
            if (find_tr != null)
            {
                find = find_tr.gameObject;
                break;
            }
        }

        if (find != null)
        {
            var clone = GameObject.Instantiate(find);
            clone.transform.SetParent(parent.transform);
            HierarchyUtility.TraverseSetLayerMask(clone.transform, LayerMask.NameToLayer("UI"));
            return(clone);
        }
        return(null);
    }
Ejemplo n.º 24
0
    public static void SetText(RectTransform rt, string s, string name = null)
    {
        UnityEngine.UI.Text tc = null;
        HierarchyUtility.TraverseComponent <UnityEngine.UI.Text>(rt.transform, i => {
            if (tc != null)
            {
                return;
            }
            var b = true;
            if (name != null)
            {
                b = (i.name == name);
            }

            if (b)
            {
                tc = i;
            }
        });
        if (tc != null)
        {
            tc.text = s;
        }
    }
Ejemplo n.º 25
0
    public void PushDown(bool b)
    {
        var toggle = GetComponent <Toggle>();

        MainEventMachine.V.PushEvent(MainStateEventId.TOGGLE, m_control, HierarchyUtility.GetAbsoluteNodePath(gameObject), b);
    }
Ejemplo n.º 26
0
 public void PushDown()
 {
     MainStateEvent.Push(MainStateEventId.BUTTON, HierarchyUtility.GetAbsoluteNodePath(gameObject));
 }
Ejemplo n.º 27
0
    public void Change(string val)
    {
        var inputfield = GetComponent <InputField>();

        MainEventMachine.V.PushEvent(MainStateEventId.INPUTFIELD_CHANGE, m_control, HierarchyUtility.GetAbsoluteNodePath(gameObject), val);
    }
Ejemplo n.º 28
0
    public void Change(float val)
    {
        var slider = GetComponent <Slider>();

        MainStateEvent.Push(MainStateEventId.SLIDER, HierarchyUtility.GetAbsoluteNodePath(gameObject), val);
    }
Ejemplo n.º 29
0
    public void Change(float val)
    {
        var scrollbar = GetComponent <Scrollbar>();

        MainEventMachine.V.PushEvent(MainStateEventId.SCROLLBAR, m_control, HierarchyUtility.GetAbsoluteNodePath(gameObject), val);
    }
Ejemplo n.º 30
0
    public void Change(Vector2 val)
    {
        var scrollrect = GetComponent <ScrollRect>();

        MainStateEvent.Push(MainStateEventId.SCROLLVIEW, HierarchyUtility.GetAbsoluteNodePath(gameObject), val);
    }