コード例 #1
0
        public static GameObject CreateText(Resources resources)
        {
            GameObject go = null;

            #if UNITY_EDITOR
            go = ObjectFactory.CreateGameObject("Text (TMP)");
            ObjectFactory.AddComponent <TextMeshProUGUI>(go);
            #else
            go = CreateUIElementRoot("Text (TMP)", s_TextElementSize);
            go.AddComponent <TextMeshProUGUI>();
            #endif

            return(go);
        }
コード例 #2
0
    static void DoLocaliseText()
    {
        var local = new HashSet <string>();

        foreach (var line in File.ReadAllLines(@"D:\Unity Projects\VR-Empathy\Assets\StreamingAssets\Languages\English.txt"))
        {
            local.Add(line.Split('=')[0]);
        }

        var objects = VRTK_SharedMethods.FindEvenInactiveComponentsInValidScenes <Text>(false);

        foreach (var obj in objects)
        {
            if (!local.Contains(obj.gameObject.name))
            {
                continue;
            }

            var textLocal = obj.GetComponent <LeanLocalizedText>();

            if (!textLocal)
            {
                textLocal = ObjectFactory.AddComponent <LeanLocalizedText>(obj.gameObject);
            }

            textLocal.FallbackText    = obj.text;
            textLocal.TranslationName = obj.gameObject.name;
        }

        var objects2 = VRTK_SharedMethods.FindEvenInactiveComponentsInValidScenes <TextMeshProUGUI>(false);

        foreach (var obj in objects2)
        {
            if (!local.Contains(obj.gameObject.name))
            {
                continue;
            }

            var textLocal = obj.GetComponent <LeanLocalizedTextMeshProUGUI>();

            if (!textLocal)
            {
                textLocal = ObjectFactory.AddComponent <LeanLocalizedTextMeshProUGUI>(obj.gameObject);
            }

            textLocal.FallbackText    = obj.text;
            textLocal.TranslationName = obj.gameObject.name;
        }
    }
コード例 #3
0
ファイル: AddToMenu.cs プロジェクト: condmaker/timefall
    private static void CreateEventSystem()
    {
        StageHandle stage = StageUtility.GetCurrentStageHandle();
        var         esys  = stage.FindComponentOfType <EventSystem>();

        if (esys == null)
        {
            var eventSystem = ObjectFactory.CreateGameObject("EventSystem");
            StageUtility.PlaceGameObjectInCurrentStage(eventSystem);
            esys = ObjectFactory.AddComponent <EventSystem>(eventSystem);
            ObjectFactory.AddComponent <StandaloneInputModule>(eventSystem);

            Undo.RegisterCreatedObjectUndo(eventSystem, "Create " + eventSystem.name);
        }
    }
コード例 #4
0
ファイル: BoBo.cs プロジェクト: zsq2010/Vimdesktop
    private static void CreateParticle(MenuCommand menuCommand)
    {
        // GameObject selectedObj = CheckSelection (menuCommand);
        // if (selectedObj == null)
        //     return;
        // GameObject go = new GameObject ();
        // GameObjectUtility.SetParentAndAlign (go, selectedObj);
        // Undo.RegisterCreatedObjectUndo (go, "Create " + go.name);
        // Selection.activeObject = go;
        // go.AddComponent<particlesystem> ();

        //创建粒子
        if (Selection.activeGameObject != null)
        {
            ParticleSystem particle = ObjectFactory.AddComponent <ParticleSystem>(Selection.activeGameObject);
        }
    }
コード例 #5
0
        static GameObject CreateAndPlacePrimitive(string name, Transform parent, PrimitiveType primitiveType, params Type[] types)
        {
            var go = ObjectFactory.CreatePrimitive(primitiveType);

            go.name = name;
            go.SetActive(false);
            foreach (var type in types)
            {
                ObjectFactory.AddComponent(go, type);
            }
            go.SetActive(true);

            Place(go, parent);
            Undo.SetCurrentGroupName("Create " + go.name);
            Selection.activeGameObject = go;

            return(go);
        }
コード例 #6
0
        static void CreateTextMeshProObjectPerform(MenuCommand command)
        {
            GameObject go = ObjectFactory.CreateGameObject("Text (TMP)");

            // Add support for new prefab mode
            StageUtility.PlaceGameObjectInCurrentStage(go);

            TextMeshPro textComponent = ObjectFactory.AddComponent <TextMeshPro>(go);

            if (textComponent.m_isWaitingOnResourceLoad == false)
            {
                // Get reference to potential Presets for <TextMeshPro> component
                Preset[] presets = Preset.GetDefaultPresetsForObject(textComponent);

                if (presets == null || presets.Length == 0)
                {
                    textComponent.text      = "Sample text";
                    textComponent.alignment = TextAlignmentOptions.TopLeft;
                }

                if (TMP_Settings.autoSizeTextContainer)
                {
                    Vector2 size = textComponent.GetPreferredValues(TMP_Math.FLOAT_MAX, TMP_Math.FLOAT_MAX);
                    textComponent.rectTransform.sizeDelta = size;
                }
                else
                {
                    textComponent.rectTransform.sizeDelta = TMP_Settings.defaultTextMeshProTextContainerSize;
                }
            }

            Undo.RegisterCreatedObjectUndo(go, "Create " + go.name);

            GameObject contextObject = command.context as GameObject;

            if (contextObject != null)
            {
                GameObjectUtility.SetParentAndAlign(go, contextObject);
                Undo.SetTransformParent(go.transform, contextObject.transform, "Parent " + go.name);
            }

            Selection.activeGameObject = go;
        }
コード例 #7
0
        public override void OnInspectorGUI()
        {
            DrawDefaultInspector();

            var eventSystem = target as EventSystem;

            if (eventSystem == null)
            {
                return;
            }

            if (eventSystem.GetComponent <BaseInputModule>() != null)
            {
                return;
            }

            // no input modules :(
            if (GUILayout.Button("Add Default Input Modules"))
            {
                ObjectFactory.AddComponent <StandaloneInputModule>(eventSystem.gameObject);
                Undo.RegisterCreatedObjectUndo(eventSystem.gameObject, "Add StandaloneInputModule");
            }
        }
コード例 #8
0
        private List <PropertyInfo> GetTypePropertyNames(Type type)
        {
            if (m_TypeProperties.TryGetValue(type, out var properties))
            {
                return(properties);
            }

            properties = new List <PropertyInfo>();
            GameObject go = null;

            try
            {
                bool objectCreated     = false;
                UnityEngine.Object obj = null;
                try
                {
                    if (obj == null)
                    {
                        if (typeof(Component).IsAssignableFrom(type))
                        {
                            go = new GameObject
                            {
                                layer = 0
                            };
                            go.AddComponent(typeof(BoxCollider));
                            obj = go.GetComponent(type);
                            if (!obj)
                            {
                                obj           = ObjectFactory.AddComponent(go, type);
                                objectCreated = true;
                            }
                        }
                        else
                        {
                            obj           = ObjectFactory.CreateInstance(type);
                            objectCreated = true;
                        }
                    }

                    using (var so = new SerializedObject(obj))
                    {
                        var p    = so.GetIterator();
                        var next = p.Next(true);
                        while (next)
                        {
                            if (p.propertyType != SerializedPropertyType.Generic &&
                                p.propertyType != SerializedPropertyType.LayerMask &&
                                p.propertyType != SerializedPropertyType.Character &&
                                p.propertyType != SerializedPropertyType.ArraySize &&
                                !p.isArray && !p.isFixedBuffer)
                            {
                                properties.Add(new PropertyInfo()
                                {
                                    name  = p.propertyPath,
                                    label = FormatPropertyLabel(p)
                                });
                            }

                            next = p.Next(p.hasVisibleChildren);
                        }
                    }
                }
                catch (Exception ex)
                {
                    Debug.LogWarning(ex.Message);
                }
                finally
                {
                    if (objectCreated)
                    {
                        UnityEngine.Object.DestroyImmediate(obj);
                    }
                }
            }
            catch (Exception ex)
            {
                Debug.LogWarning(ex.Message);
            }
            finally
            {
                if (go)
                {
                    UnityEngine.Object.DestroyImmediate(go);
                }
            }

            m_TypeProperties[type] = properties;
            return(properties);
        }
コード例 #9
0
 public Component ApplyScript(Type classType)
 {
     return(ObjectFactory.AddComponent(gameObject, classType));
 }