private async void TryRenderControllerModelWithModelProvider()
        {
            if (controllerModelProvider == null)
            {
                controllerModelProvider = new WindowsMixedRealityControllerModelProvider(ControllerHandedness);
            }

            UnityEngine.GameObject controllerModel = await controllerModelProvider.TryGenerateControllerModelFromPlatformSDK();

            if (this != null)
            {
                if (controllerModel != null &&
                    MixedRealityControllerModelHelpers.TryAddVisualizationScript(controllerModel, GetType(), ControllerHandedness) &&
                    TryAddControllerModelToSceneHierarchy(controllerModel))
                {
                    controllerModel.SetActive(true);
                    return;
                }

                UnityEngine.Debug.LogWarning("Failed to create controller model from driver; defaulting to BaseController behavior.");
                base.TryRenderControllerModel(GetType(), InputSource.SourceType);
            }

            if (controllerModel != null)
            {
                // If we didn't successfully set up the model and add it to the hierarchy (which returns early), set it inactive.
                controllerModel.SetActive(false);
            }
        }
        public static T AddComponent <T>(UnityEngine.GameObject gameObject) where T : ChiselNode
        {
            // TODO: ensure we're creating this in the active scene
            // TODO: handle scene being locked by version control

            if (!gameObject)
            {
                return(null);
            }

            bool prevActive = gameObject.activeSelf;

            if (prevActive)
            {
                gameObject.SetActive(false);
            }
            try
            {
                var brushTransform = gameObject.transform;
#if UNITY_EDITOR
                return(UnityEditor.Undo.AddComponent <T>(gameObject));
#else
                return(gameObject.AddComponent <T>());
#endif
            }
            finally
            {
                if (prevActive)
                {
                    gameObject.SetActive(prevActive);
                }
            }
        }
        public static T Create <T>(string name, UnityEngine.Transform parent, Matrix4x4 trsMatrix) where T : ChiselNode
        {
            // TODO: ensure we're creating this in the active scene
            // TODO: handle scene being locked by version control

            if (string.IsNullOrEmpty(name))
            {
#if UNITY_EDITOR
                name = UnityEditor.GameObjectUtility.GetUniqueNameForSibling(parent, typeof(T).Name);
#else
                name = typeof(T).Name;
#endif
            }

            var newGameObject = new UnityEngine.GameObject(name);
#if UNITY_EDITOR
            UnityEditor.Undo.RegisterCreatedObjectUndo(newGameObject, "Created " + name);
#endif
            newGameObject.SetActive(false);
            try
            {
                var brushTransform = newGameObject.transform;
#if UNITY_EDITOR
                if (parent)
                {
                    UnityEditor.Undo.SetTransformParent(brushTransform, parent, "Move child node underneath parent operation");
                }
                UnityEditor.Undo.RecordObject(brushTransform, "Move child node to given position");
#else
                if (parent)
                {
                    brushTransform.SetParent(parent, false);
                }
#endif
                if (parent)
                {
                    brushTransform.Set(parent.worldToLocalMatrix * trsMatrix);
                }
                else
                {
                    brushTransform.Set(trsMatrix);
                }

#if UNITY_EDITOR
                return(UnityEditor.Undo.AddComponent <T>(newGameObject));
#else
                return(newGameObject.AddComponent <T>());
#endif
            }
            finally
            {
                newGameObject.SetActive(true);
            }
        }
Exemple #4
0
        public DiContainer CreateSubContainer(
            List <TypeValuePair> args, InjectContext parentContext)
        {
            UnityEngine.Object prefab = _prefabProvider.GetPrefab();

            bool shouldMakeActive;

            UnityEngine.GameObject gameObj = _container.CreateAndParentPrefab(
                prefab, _gameObjectBindInfo, null, out shouldMakeActive);

            if (gameObj.GetComponent <GameObjectContext>() != null)
            {
                throw Assert.CreateException(
                          "Found GameObjectContext already attached to prefab with name '{0}'!  When using ByNewPrefabMethod, the GameObjectContext is added to the prefab dynamically", prefab.name);
            }

            GameObjectContext context = gameObj.AddComponent <GameObjectContext>();

            AddInstallers(args, context);

            _container.Inject(context);

            if (shouldMakeActive)
            {
                gameObj.SetActive(true);
            }

            // Note: We don't need to call ResolveRoots here because GameObjectContext does this for us

            return(context.Container);
        }
        static int _m_SetActive(RealStatePtr L)
        {
		    try {
            
                ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);
            
            
                UnityEngine.GameObject __cl_gen_to_be_invoked = (UnityEngine.GameObject)translator.FastGetCSObj(L, 1);
            
            
                
                {
                    bool value = LuaAPI.lua_toboolean(L, 2);
                    
                    __cl_gen_to_be_invoked.SetActive( value );
                    
                    
                    
                    return 0;
                }
                
            } catch(System.Exception __gen_e) {
                return LuaAPI.luaL_error(L, "c# exception:" + __gen_e);
            }
            
        }
    private Data MakeData(UnityEngine.GameObject master, CreatureStateBody.BodyData bodyData, float scale)
    {
        var gameObject = new UnityEngine.GameObject(bodyData.m_name);

        gameObject.SetActive(true);

        UnityEngine.GameObject parent = null;
        foreach (var data in _dataArray)
        {
            if (data.m_name == bodyData.m_parentName)
            {
                parent = data.m_gameObject;
                break;
            }
        }

        gameObject.transform.position = master.transform.position + (bodyData.m_pos * scale);
        gameObject.layer = (int)Project.Layer.TIgnoreRaycast;

        var rigidbody = gameObject.AddComponent <UnityEngine.Rigidbody>();

        //rigidbody.drag = 1.0f;
        rigidbody.useGravity    = true; //true;
        rigidbody.centerOfMass  = new UnityEngine.Vector3(0.0f, 0.0f, 0.0f);
        rigidbody.inertiaTensor = new UnityEngine.Vector3(1.0f, 1.0f, 1.0f);

        if (0 != bodyData.m_radius)
        {
            var sphereCollider = gameObject.AddComponent <UnityEngine.SphereCollider>();
            sphereCollider.radius = 0.5f * scale * bodyData.m_radius;
        }

        if (null != parent)
        {
            //if (true == bodyData.m_jointParent)
            //{
            var characterJoint = gameObject.AddComponent <UnityEngine.CharacterJoint>();
            characterJoint.connectedBody = parent.GetComponent <UnityEngine.Rigidbody>();
            //}

            if (false == bodyData.m_jointParent)
            {
                //characterJoint.f
            }

            gameObject.transform.parent = parent.transform;
        }
        //attach to root if no parent
        if ((null == gameObject.transform.parent) && (null != _root))
        {
            gameObject.transform.parent = _root.transform;
        }

        return(new Data()
        {
            m_gameObject = gameObject,
            m_name = bodyData.m_name
        });
    }
 /// <summary>Initialization Method of SetActive.</summary>
 /// <remarks>Activate or deactivate the GameObject.</remarks>
 public override void OnStart()
 {
     if (!targetGameobject)
     {
         targetGameobject = gameObject;
     }
     targetGameobject.SetActive(active);
 }
Exemple #8
0
    public CreatureBodyVisualFace()
    {
        //Assets/Resources/prefab/creaturefaceratmesh.prefab
        _prefabFace = UnityEngine.Resources.Load <UnityEngine.GameObject>("prefab/creaturefacemesh");

        _faceGameObject = UnityEngine.Object.Instantiate(_prefabFace);
        _faceGameObject.SetActive(true);
        _facePropertyBlock = _faceGameObject.GetComponent <CreatureFaceShaderPropertyBlock>();
    }
        public static T Create <T>(string name, UnityEngine.Transform parent, Vector3 position, Quaternion rotation, Vector3 scale) where T : CSGNode
        {
            if (string.IsNullOrEmpty(name))
            {
#if UNITY_EDITOR
                name = UnityEditor.GameObjectUtility.GetUniqueNameForSibling(parent, typeof(T).Name);
#else
                name = typeof(T).Name;
#endif
            }

            var newGameObject = new UnityEngine.GameObject(name);
#if UNITY_EDITOR
            UnityEditor.Undo.RegisterCreatedObjectUndo(newGameObject, "Created " + name);
#endif
            newGameObject.SetActive(false);
            try
            {
                var brushTransform = newGameObject.transform;
#if UNITY_EDITOR
                UnityEditor.Undo.RecordObject(brushTransform, "Move child node to given position");
#endif
                brushTransform.localPosition = position;
                brushTransform.localRotation = rotation;
                brushTransform.localScale    = scale;
#if UNITY_EDITOR
                if (parent)
                {
                    UnityEditor.Undo.SetTransformParent(brushTransform, parent, "Move child node underneath parent operation");
                }
                return(UnityEditor.Undo.AddComponent <T>(newGameObject));
#else
                if (parent)
                {
                    brushTransform.SetParent(parent, false);
                }
                return(newGameObject.AddComponent <T>());
#endif
            }
            finally
            {
                newGameObject.SetActive(true);
            }
        }
Exemple #10
0
        public static void Load()
        {
            DisableAnticheat();
            while (BaseObject = UnityEngine.GameObject.Find("TemSharp"))
            {
                UnityEngine.Object.Destroy(BaseObject);
            }
            BaseObject = new UnityEngine.GameObject("TemSharp");
            UnityEngine.Object.DontDestroyOnLoad(BaseObject);
            BaseObject.SetActive(false);
            var types = Assembly.GetExecutingAssembly().GetTypes().ToList().Where(t => t.BaseType == typeof(UnityEngine.MonoBehaviour) && !t.IsNested);

            foreach (var type in types)
            {
                var component = (UnityEngine.MonoBehaviour)BaseObject.AddComponent(type);
                component.enabled = false;
            }
            BaseObject.GetComponent <Menu>().enabled = true;
            BaseObject.SetActive(true);
        }
 static private void CreatInstance()
 {
     if (sInstance == null)
     {
         UnityEngine.GameObject tobj = new UnityEngine.GameObject("PublicUpdateManager");
         UnityEngine.GameObject.DontDestroyOnLoad(tobj);
         sInstance = tobj.AddComponent <PublicUpdateManager>();
         AppCore.AddPublicMono("PublicUpdateManager", sInstance);
         tobj.SetActive(false);
     }
 }
        private async void TryRenderControllerModelWithModelProvider()
        {
            if (controllerModelProvider == null)
            {
                controllerModelProvider = new WindowsMixedRealityControllerModelProvider(ControllerHandedness);
            }

            UnityEngine.GameObject controllerModel = await controllerModelProvider.TryGenerateControllerModelFromPlatformSDK();

            if (controllerModel != null)
            {
                if (this != null)
                {
                    var visualizationProfile = GetControllerVisualizationProfile();
                    if (visualizationProfile != null)
                    {
                        var visualizationType = visualizationProfile.GetControllerVisualizationTypeOverride(GetType(), ControllerHandedness);
                        if (visualizationType != null)
                        {
                            // Set the platform controller model to not be destroyed when the source is lost. It'll be disabled instead,
                            // and re-enabled when the same controller is re-detected.
                            if (controllerModel.EnsureComponent(visualizationType.Type) is IMixedRealityControllerPoseSynchronizer visualizer)
                            {
                                visualizer.DestroyOnSourceLost = false;
                            }

                            if (TryAddControllerModelToSceneHierarchy(controllerModel))
                            {
                                return;
                            }
                        }
                        else
                        {
                            UnityEngine.Debug.LogError("Controller visualization type not defined for controller visualization profile");
                        }
                    }
                    else
                    {
                        UnityEngine.Debug.LogError("Failed to obtain a controller visualization profile");
                    }

                    UnityEngine.Debug.LogWarning("Failed to create controller model from driver; defaulting to BaseController behavior.");
                    base.TryRenderControllerModel(GetType(), InputSource.SourceType);
                }

                // If we didn't successfully set up the model and add it to the hierarchy (which returns early), set it inactive.
                controllerModel.SetActive(false);
            }
        }
Exemple #13
0
        /// <inheritdoc />
        protected internal override void AddToInMainThread(UnityEngine.GameObject parent)
        {
            var gameObject = new UnityEngine.GameObject(Name);

            gameObject.SetActive(false);
            _sleeping = AddComponentToInMainThread(gameObject);

            foreach (var node in this)
            {
                node.AddToInMainThread(gameObject);
            }

            _sleeping.SetParent(parent.transform, false);
            Body = _sleeping;
        }
Exemple #14
0
        static StackObject *SetActive_6(ILIntepreter __intp, StackObject *__esp, IList <object> __mStack, CLRMethod __method, bool isNewObj)
        {
            ILRuntime.Runtime.Enviorment.AppDomain __domain = __intp.AppDomain;
            StackObject *ptr_of_this_method;
            StackObject *__ret = ILIntepreter.Minus(__esp, 2);

            ptr_of_this_method = ILIntepreter.Minus(__esp, 1);
            System.Boolean @value = ptr_of_this_method->Value == 1;

            ptr_of_this_method = ILIntepreter.Minus(__esp, 2);
            UnityEngine.GameObject instance_of_this_method = (UnityEngine.GameObject) typeof(UnityEngine.GameObject).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack));
            __intp.Free(ptr_of_this_method);

            instance_of_this_method.SetActive(@value);

            return(__ret);
        }
        } /*  Update() */

        // OnEnable
        void OnEnable()
        {
            bool bOnce = true;

            // build up buttons
            foreach (string entry in io.ApollonIOManager.Instance.ListAvailableExperiment())
            {
                // is entry an already loaded button ?
                if (!this.m_loadedObject.ContainsKey(entry))
                {
                    // instantiate
                    UnityEngine.GameObject button = UnityEngine.GameObject.Instantiate(this.buttonPrefab);

                    // attach
                    button.transform.SetParent(this.parentObject.transform, false);

                    // add button click delegate
                    button.GetComponent <UnityEngine.UI.Button>().onClick.AddListener(() => this.OnListButtonClick(entry));

                    // add cancel trigger event delegate
                    UnityEngine.EventSystems.EventTrigger.Entry cancelEntry = new UnityEngine.EventSystems.EventTrigger.Entry();
                    cancelEntry.eventID = UnityEngine.EventSystems.EventTriggerType.Cancel;
                    cancelEntry.callback.AddListener(this.OnBackButtonClick);
                    button.GetComponent <UnityEngine.EventSystems.EventTrigger>().triggers.Add(cancelEntry);

                    // then configure
                    button.GetComponentInChildren <UnityEngine.UI.Text>().text = entry;
                    button.SetActive(true);

                    // add to the loaded element
                    this.m_loadedObject.Add(entry, button);
                    this.m_loadedOrder.Add(entry);
                } /* if() */
            }     /* for() */

            // set selected to the first element if list are not empty
            if (bOnce &&
                this.m_loadedOrder.Count != 0 &&
                this.m_loadedObject.Count != 0
                )
            {
                this.gameObject.GetComponentInChildren <UnityEngine.EventSystems.EventSystem>().firstSelectedGameObject
                      = this.m_loadedObject[this.m_loadedOrder[0]];
                bOnce = false;
            }
        } /* OnEnable() */
Exemple #16
0
        public static int SetActive(IntPtr L)
        {
            int result = 1;
            int count  = LuaDLL.lua_gettop(L);

            if (count != 2)
            {
                LuaStatic.traceback(L, "count not enough");
                LuaDLL.lua_error(L);
                return(result);
            }
            UnityEngine.GameObject obj = LuaStatic.GetObj(L, 1) as UnityEngine.GameObject;
            Boolean arg1 = (Boolean)LuaStatic.GetObj(L, 2);

            obj.SetActive(arg1);
            return(result);
        }
Exemple #17
0
        int UnityEngineGameObject_m_SetActive(RealStatePtr L, int gen_param_count)
        {
            ObjectTranslator translator = this;


            UnityEngine.GameObject gen_to_be_invoked = (UnityEngine.GameObject)translator.FastGetCSObj(L, 1);


            {
                bool _value = LuaAPI.lua_toboolean(L, 2);

                gen_to_be_invoked.SetActive(_value);



                return(0);
            }
        }
Exemple #18
0
        //Just pull the zombie down using gravity
        void Sink(float deltaT)
        {
            if (animatedDeath)
            {
                EnableRigidBodyPhysics();
            }

            if (ragdollColliders == null)
            {
                DisableAllColliders();
            }
            //This works because sink keeps getting repeated calls from Update() The ragdoll position is not the same as the gameobject position because of gravity
            zombieToKill.transform.Translate(0f, sinkRate * deltaT, 0f);
            if (zombieToKill.transform.position.y < graveDepth)
            {
                zombieToKill.SetActive(false);
                UnityEngine.Object.Destroy(zombieToKill);
            }
        }
Exemple #19
0
    public void Request(UnityEngine.Transform parentTransform, CreatureStateHud.HandPoseData handPoseData)
    {
        UnityEngine.GameObject gameObject = null;
        if (_array.Count <= _activeCount)
        {
            gameObject = UnityEngine.Object.Instantiate(_prefab);
            _array.Add(gameObject);
        }
        else
        {
            gameObject = _array[_activeCount];
        }
        _activeCount += 1;

        var fov      = 60.0f;                                                                  //todo
        var aspect   = ((float)UnityEngine.Screen.width) / ((float)UnityEngine.Screen.height); //16.0f / 9.0f;
        var verScale = UnityEngine.Mathf.Tan(UnityEngine.Mathf.Deg2Rad * (fov / 2.0f)) * 2.0f * 2.0f;
        var hozScale = verScale * aspect;

        gameObject.transform.parent = parentTransform;

        gameObject.SetActive(true);
        gameObject.transform.localPosition = new UnityEngine.Vector3(
            ((handPoseData.position.x / UnityEngine.Screen.width) - 0.5f) * hozScale,
            ((handPoseData.position.y / UnityEngine.Screen.height) - 0.5f) * verScale,
            2.0f
            );
        var rotY = (((handPoseData.position.x / UnityEngine.Screen.width) - 0.5f) * 2.0f);

        switch (handPoseData.handPose)
        {
        default:
            rotY *= -15.0f;
            break;

        case CreatureStateHud.THandPose.Swing:
            rotY *= 30.0f;
            break;
        }
        gameObject.transform.localRotation = UnityEngine.Quaternion.Euler(0.0f, rotY, 0.0f);
        gameObject.transform.localScale    = UnityEngine.Vector3.one;
    }
        /// <summary>Hides all the pooled batches.</summary>
        public static void HideAll()
        {
            UIBatch current = First;

            while (current != null)
            {
                UnityEngine.GameObject obj = current.Mesh.OutputGameObject;

                if (obj != null)
                {
                    // Hide it:
                                        #if PRE_UNITY4
                    obj.active = false;
                                        #else
                    obj.SetActive(false);
                                        #endif
                }

                current = current.BatchAfter;
            }
        }
        /// <summary>Gets a batch from the pool. Null if the pool is empty.</summary>
        public static UIBatch Get(Renderman renderer)
        {
            if (First == null)
            {
                return(null);
            }

            UIBatch result = First;

            First             = result.BatchAfter;
            result.BatchAfter = null;
            result.Setup      = false;

            // Get the GO:
            UnityEngine.GameObject gameobject = result.Mesh.OutputGameObject;

            if (gameobject == null)
            {
                // This occurs when a WorldUI gets destroyed but put its batches in the pool.
                // We've already removed the first so just go recursive - chances are the next one will be ok.
                return(Get(renderer));
            }

            // Show it:
                        #if PRE_UNITY4
            gameobject.active = true;
                        #else
            gameobject.SetActive(true);
                        #endif

            if (result.Renderer != renderer)
            {
                result.ChangeRenderer(renderer);
            }

            return(result);
        }
Exemple #22
0
        //private IEnumerator<float> CreateInstance()
        private void CreateInstance(bool worldPositionStays)
        {
            int val = requestedSize++;

            //while (WorkScheduler.Instance.IsToSkipToNextFrame)
            //{
            //    yield return 0;
            //}
            currentInstanceGameObject = Instantiate(m_prefab.gameObject);
            Debugging.AssertionHelper.Assert(currentInstanceGameObject.activeInHierarchy, () => $"Prefab '{currentInstanceGameObject.name}' is disabled!", m_prefab);
            nameBuilder.Append(val);
            currentInstanceGameObject.name = nameBuilder.ToString();
            nameBuilder.Remove(removeStartIndex, nameBuilder.Length - removeStartIndex);
            currentInstanceGameObject.transform.SetParent(controller.transform, worldPositionStays);
            currentInstanceGameObject.SetActive(false);
            currentInstancePoolable = currentInstanceGameObject.GetComponent <Poolable>();
            //while (WorkScheduler.Instance.IsToSkipToNextFrame || isTakingInstance)
            //{
            //    yield return 0;
            //}
            currentInstancePoolable.OnInitializePool(this);
            pooledObjects.Enqueue(currentInstancePoolable);
            currentSize++;
        }
Exemple #23
0
        public bool Activate()
        {
            PlayerController.InterpreterLock.Set();

            if (_isLooted)
            {
                return(false);
            }
            if (!IsReachable())
            {
                return(false);
            }

            GUITexts guiTexts = GUITexts.GetInstance();

            guiTexts.CollectCoin(GetValue());

            ChestClosed.SetActive(false);
            ChestOpened.SetActive(true);

            _isLooted = true;

            return(true);
        }
        /** インスタンス。作成。
         */
        public UnityEngine.GameObject Instantiate(string a_id, UnityEngine.Vector3 a_position, UnityEngine.Quaternion a_rotation)
        {
            UnityEngine.GameObject t_gameobject = null;

            switch (a_id)
            {
            case Pun_DataLoader.ID_NETWORKOBJECT_PLAYER:
            {
                t_gameobject = new UnityEngine.GameObject(Pun_DataLoader.ID_NETWORKOBJECT_PLAYER);
                t_gameobject.SetActive(false);
                UnityEngine.GameObject.DontDestroyOnLoad(t_gameobject);
                {
                    Sync t_sync = new Sync(t_gameobject);

                    if (this.player_component_type != null)
                    {
                        Fee.Network.NetworkObject_Player_MonoBehaviour_Base t_networkobject = (Fee.Network.NetworkObject_Player_MonoBehaviour_Base)t_gameobject.AddComponent(this.player_component_type);
                        if (t_networkobject != null)
                        {
                            t_sync.SetNetworkObject(t_networkobject);
                            t_networkobject.SetSync(t_sync);
                        }
                    }
                }
            } break;

            default:
            {
                UnityEngine.GameObject t_prefab = UnityEngine.Resources.Load <UnityEngine.GameObject>(a_id);
                t_prefab.SetActive(false);
                t_gameobject = UnityEngine.GameObject.Instantiate <UnityEngine.GameObject>(t_prefab, a_position, a_rotation);
            } break;
            }

            return(t_gameobject);
        }
Exemple #25
0
 public override void Apply(UnityEngine.GameObject obj)
 {
     obj.SetActive(this.GetValue());
 }
    void Start()
    {
        _prefabDebugOrientationHint = UnityEngine.Resources.Load <UnityEngine.GameObject>("prefab/debugorientationhint");

        _root = new UnityEngine.GameObject("root");
        _root.SetActive(true);
        //_root.transform.parent = gameObject.transform;
        _root.transform.position = new UnityEngine.Vector3(0.0f, 1.5f, 0.0f);
        _root.transform.rotation = UnityEngine.Quaternion.Euler(0.0f, 90.0f, 0.0f);
        _root.layer = (int)Project.Layer.TIgnoreRaycast;
        _rigidbody  = _root.AddComponent <UnityEngine.Rigidbody>();
        //_rigidbody.drag = 1.0f;
        _rigidbody.useGravity    = true;
        _rigidbody.centerOfMass  = new UnityEngine.Vector3(0.0f, 0.0f, 0.0f);
        _rigidbody.inertiaTensor = new UnityEngine.Vector3(1.0f, 1.0f, 1.0f);

        {
            var collider = _root.AddComponent <UnityEngine.SphereCollider>();
            collider.center = UnityEngine.Vector3.zero;
            collider.radius = 0.5f;
        }

        {
            var debugOrientationHint = UnityEngine.Object.Instantiate(_prefabDebugOrientationHint);
            debugOrientationHint.SetActive(true);
            debugOrientationHint.transform.parent        = _root.transform;
            debugOrientationHint.transform.localPosition = UnityEngine.Vector3.zero;
            debugOrientationHint.transform.localRotation = UnityEngine.Quaternion.identity;

            var renderer = debugOrientationHint.GetComponent <UnityEngine.Renderer>();
            _material = renderer.material;
        }

#if true
        {
            var child = new UnityEngine.GameObject("child");
            child.SetActive(true);
            child.transform.position = new UnityEngine.Vector3(-0.5f, 3.0f, 0.0f);
            child.transform.parent   = _root.transform;
            child.layer = (int)Project.Layer.TIgnoreRaycast;
            var rigidbody = child.AddComponent <UnityEngine.Rigidbody>();
            rigidbody.useGravity    = true;
            rigidbody.centerOfMass  = new UnityEngine.Vector3(0.0f, 0.0f, 0.0f);
            rigidbody.inertiaTensor = new UnityEngine.Vector3(1.0f, 1.0f, 1.0f);

            var collider = child.AddComponent <UnityEngine.SphereCollider>();
            collider.center = UnityEngine.Vector3.zero;
            collider.radius = 0.5f;

            var characterJoint = child.AddComponent <UnityEngine.CharacterJoint>();
            characterJoint.connectedBody = _rigidbody;

            {
                var debugOrientationHint = UnityEngine.Object.Instantiate(_prefabDebugOrientationHint);
                debugOrientationHint.SetActive(true);
                debugOrientationHint.transform.parent        = child.transform;
                debugOrientationHint.transform.localPosition = UnityEngine.Vector3.zero;
                debugOrientationHint.transform.localRotation = UnityEngine.Quaternion.identity;
            }
        }
#endif
    }
Exemple #27
0
        // OnEnable
        void OnEnable()
        {

            bool bOnce = true;

            // build up buttons
            foreach (string key in io.ApollonIOManager.Instance.Input.GetKeys())
            {
                // is entry an already loaded item ?
                if (!this.m_loadedObject.ContainsKey(key))
                {

                    // Switch on type
                    common.ApollonTypeSwitch.Do(
                        
                        // get data
                        io.ApollonIOManager.Instance.Input.GetData(key),

                        // case : boolean
                        common.ApollonTypeSwitch.Case<bool>(() => {

                            // instantiate
                            UnityEngine.GameObject toggle = UnityEngine.GameObject.Instantiate(this.togglePrefab);

                            // attach
                            toggle.transform.SetParent(this.parentObject.transform,false);

                            // initalize
                            toggle.GetComponentInChildren<UnityEngine.UI.Toggle>().isOn = (bool)io.ApollonIOManager.Instance.Input.GetData(key);

                            // add button click delegate
                            toggle.GetComponentInChildren<UnityEngine.UI.Toggle>().onValueChanged.AddListener(
                                (value) => { io.ApollonIOManager.Instance.Input.SetData(key, value); }
                            );

                            // add cancel trigger event delegate
                            UnityEngine.EventSystems.EventTrigger.Entry cancelEntry = new UnityEngine.EventSystems.EventTrigger.Entry();
                            cancelEntry.eventID = UnityEngine.EventSystems.EventTriggerType.Cancel;
                            cancelEntry.callback.AddListener(this.OnBackButtonClick);
                            toggle.GetComponent<UnityEngine.EventSystems.EventTrigger>().triggers.Add(cancelEntry);

                            // then configure
                            toggle.GetComponentInChildren<UnityEngine.UI.Text>().text = key;
                            toggle.SetActive(true);

                            // add to the loaded element
                            this.m_loadedObject.Add(key, toggle);
                            this.m_loadedOrder.Add(key);

                        }),
                        common.ApollonTypeSwitch.Case<int>(() => {

                            // instantiate
                            UnityEngine.GameObject slider = UnityEngine.GameObject.Instantiate(this.sliderPrefab);

                            // attach
                            slider.transform.SetParent(this.parentObject.transform, false);

                            // configure 

                            slider.GetComponentInChildren<UnityEngine.UI.Slider>().value =
                                System.Convert.ToInt32(io.ApollonIOManager.Instance.Input.GetData(key));

                            if (io.ApollonIOManager.Instance.Input.GetRangeMetadata(key) != null)
                            {
                                slider.GetComponentInChildren<UnityEngine.UI.Slider>().minValue =
                                    io.ApollonIOManager.Instance.Input.GetRangeMetadata(key).Min;
                                slider.GetComponentInChildren<UnityEngine.UI.Slider>().maxValue =
                                     io.ApollonIOManager.Instance.Input.GetRangeMetadata(key).Max;
                            }

                            slider.GetComponentInChildren<UnityEngine.UI.InputField>().text = 
                                System.Convert.ToString(io.ApollonIOManager.Instance.Input.GetData(key));

                            // add delegate

                            // slider -> data
                            slider.GetComponentInChildren<UnityEngine.UI.Slider>().onValueChanged.AddListener(
                                (value) => { io.ApollonIOManager.Instance.Input.SetData(key, System.Convert.ToInt32(value)); }
                            );
                            // slider -> input field 
                            slider.GetComponentInChildren<UnityEngine.UI.Slider>().onValueChanged.AddListener(
                                (value) => { slider.GetComponentInChildren<UnityEngine.UI.InputField>().text = System.Convert.ToString(System.Convert.ToInt32(value)); }
                            );
                            // input field -> data
                            slider.GetComponentInChildren<UnityEngine.UI.InputField>().onValueChanged.AddListener(
                                (value) => { io.ApollonIOManager.Instance.Input.SetData(key, System.Convert.ToInt32(value)); }
                            );
                            // input field -> slider
                            slider.GetComponentInChildren<UnityEngine.UI.InputField>().onValueChanged.AddListener(
                                (value) => { slider.GetComponentInChildren<UnityEngine.UI.Slider>().value = System.Convert.ToSingle(value); }
                            );

                            // add cancel trigger event delegate
                            UnityEngine.EventSystems.EventTrigger.Entry cancelEntry = new UnityEngine.EventSystems.EventTrigger.Entry();
                            cancelEntry.eventID = UnityEngine.EventSystems.EventTriggerType.Cancel;
                            cancelEntry.callback.AddListener(this.OnBackButtonClick);
                            slider.GetComponent<UnityEngine.EventSystems.EventTrigger>().triggers.Add(cancelEntry);

                            // then configure
                            slider.GetComponentInChildren<UnityEngine.UI.Text>().text = key;
                            slider.SetActive(true);

                            // add to the loaded element
                            this.m_loadedObject.Add(key, slider);
                            this.m_loadedOrder.Add(key);

                        }),
                        common.ApollonTypeSwitch.Case<uint>(() => {

                            // instantiate
                            UnityEngine.GameObject slider = UnityEngine.GameObject.Instantiate(this.sliderPrefab);

                            // attach
                            slider.transform.SetParent(this.parentObject.transform, false);
                            
                            // configure 

                            slider.GetComponentInChildren<UnityEngine.UI.Slider>().value =
                                System.Convert.ToUInt32(io.ApollonIOManager.Instance.Input.GetData(key));

                            if (io.ApollonIOManager.Instance.Input.GetRangeMetadata(key) != null)
                            {
                                slider.GetComponentInChildren<UnityEngine.UI.Slider>().minValue =
                                    io.ApollonIOManager.Instance.Input.GetRangeMetadata(key).Min;
                                slider.GetComponentInChildren<UnityEngine.UI.Slider>().maxValue =
                                     io.ApollonIOManager.Instance.Input.GetRangeMetadata(key).Max;
                            }

                            slider.GetComponentInChildren<UnityEngine.UI.InputField>().text = 
                                System.Convert.ToString(io.ApollonIOManager.Instance.Input.GetData(key));

                            // add delegate

                            // slider -> data
                            slider.GetComponentInChildren<UnityEngine.UI.Slider>().onValueChanged.AddListener(
                                (value) => { io.ApollonIOManager.Instance.Input.SetData(key, System.Convert.ToUInt32(value)); }
                            );
                            // slider -> input field 
                            slider.GetComponentInChildren<UnityEngine.UI.Slider>().onValueChanged.AddListener(
                                (value) => { slider.GetComponentInChildren<UnityEngine.UI.InputField>().text = System.Convert.ToString(System.Convert.ToUInt32(value)); }
                            );
                            // input field -> data
                            slider.GetComponentInChildren<UnityEngine.UI.InputField>().onValueChanged.AddListener(
                                (value) => { io.ApollonIOManager.Instance.Input.SetData(key, System.Convert.ToUInt32(value)); }
                            );
                            // input field -> slider
                            slider.GetComponentInChildren<UnityEngine.UI.InputField>().onValueChanged.AddListener(
                                (value) => { slider.GetComponentInChildren<UnityEngine.UI.Slider>().value = System.Convert.ToSingle(value); }
                            );

                            // add cancel trigger event delegate
                            UnityEngine.EventSystems.EventTrigger.Entry cancelEntry = new UnityEngine.EventSystems.EventTrigger.Entry();
                            cancelEntry.eventID = UnityEngine.EventSystems.EventTriggerType.Cancel;
                            cancelEntry.callback.AddListener(this.OnBackButtonClick);
                            slider.GetComponent<UnityEngine.EventSystems.EventTrigger>().triggers.Add(cancelEntry);

                            // then configure
                            slider.GetComponentInChildren<UnityEngine.UI.Text>().text = key;
                            slider.SetActive(true);

                            // add to the loaded element
                            this.m_loadedObject.Add(key, slider);
                            this.m_loadedOrder.Add(key);

                        }),
                        common.ApollonTypeSwitch.Case<double>(() => {
                         
                            // instantiate
                            UnityEngine.GameObject slider = UnityEngine.GameObject.Instantiate(this.sliderPrefab);

                            // attach
                            slider.transform.SetParent(this.parentObject.transform, false);
                            
                            // configure 

                            slider.GetComponentInChildren<UnityEngine.UI.Slider>().value =
                                System.Convert.ToSingle(io.ApollonIOManager.Instance.Input.GetData(key));

                            if (io.ApollonIOManager.Instance.Input.GetRangeMetadata(key) != null)
                            {
                                slider.GetComponentInChildren<UnityEngine.UI.Slider>().minValue =
                                    io.ApollonIOManager.Instance.Input.GetRangeMetadata(key).Min;
                                slider.GetComponentInChildren<UnityEngine.UI.Slider>().maxValue =
                                     io.ApollonIOManager.Instance.Input.GetRangeMetadata(key).Max;
                            }

                            slider.GetComponentInChildren<UnityEngine.UI.InputField>().text = 
                                System.Convert.ToString(io.ApollonIOManager.Instance.Input.GetData(key));

                            // add delegate

                            // slider -> data
                            slider.GetComponentInChildren<UnityEngine.UI.Slider>().onValueChanged.AddListener(
                                (value) => { io.ApollonIOManager.Instance.Input.SetData(key, System.Convert.ToDouble(value)); }
                            );
                            // slider -> input field 
                            slider.GetComponentInChildren<UnityEngine.UI.Slider>().onValueChanged.AddListener(
                                (value) => { slider.GetComponentInChildren<UnityEngine.UI.InputField>().text = System.Convert.ToString(System.Convert.ToDouble(value)); }
                            );
                            // input field -> data
                            slider.GetComponentInChildren<UnityEngine.UI.InputField>().onValueChanged.AddListener(
                                (value) => { io.ApollonIOManager.Instance.Input.SetData(key, System.Convert.ToDouble(value)); }
                            );
                            // input field -> slider
                            slider.GetComponentInChildren<UnityEngine.UI.InputField>().onValueChanged.AddListener(
                                (value) => { slider.GetComponentInChildren<UnityEngine.UI.Slider>().value = System.Convert.ToSingle(value); }
                            );

                            // add cancel trigger event delegate
                            UnityEngine.EventSystems.EventTrigger.Entry cancelEntry = new UnityEngine.EventSystems.EventTrigger.Entry();
                            cancelEntry.eventID = UnityEngine.EventSystems.EventTriggerType.Cancel;
                            cancelEntry.callback.AddListener(this.OnBackButtonClick);
                            slider.GetComponent<UnityEngine.EventSystems.EventTrigger>().triggers.Add(cancelEntry);

                            // then configure
                            slider.GetComponentInChildren<UnityEngine.UI.Text>().text = key;
                            slider.SetActive(true);

                            // add to the loaded element
                            this.m_loadedObject.Add(key, slider);
                            this.m_loadedOrder.Add(key);
                        
                        })

                    ); /* TypeSwitch */

                // if it is already there, then we should update values
                } else {

                    // Switch on type
                    common.ApollonTypeSwitch.Do(
                        
                        // get data
                        io.ApollonIOManager.Instance.Input.GetData(key),

                        // case : boolean
                        common.ApollonTypeSwitch.Case<bool>(() =>
                        {

                            // update
                            this.m_loadedObject[key].GetComponentInChildren<UnityEngine.UI.Toggle>().isOn = (bool)io.ApollonIOManager.Instance.Input.GetData(key);

                        }),
                        common.ApollonTypeSwitch.Case<int>(() =>
                        {

                            // update
                            this.m_loadedObject[key].GetComponentInChildren<UnityEngine.UI.Slider>().value =
                                System.Convert.ToInt32(io.ApollonIOManager.Instance.Input.GetData(key));

                        }),
                        common.ApollonTypeSwitch.Case<uint>(() =>
                        {

                            // update
                            this.m_loadedObject[key].GetComponentInChildren<UnityEngine.UI.Slider>().value =
                                System.Convert.ToUInt32(io.ApollonIOManager.Instance.Input.GetData(key));

                        }),
                        common.ApollonTypeSwitch.Case<double>(() =>
                        {

                            // update
                            this.m_loadedObject[key].GetComponentInChildren<UnityEngine.UI.Slider>().value =
                                System.Convert.ToSingle(io.ApollonIOManager.Instance.Input.GetData(key));

                        })

                    ); /* TypeSwitch */

                } /* if() */

            } /* for() */

            // set selected to the first element if list are not empty
            if (bOnce
                && this.m_loadedOrder.Count != 0
                && this.m_loadedObject.Count != 0
            )
            {
                this.gameObject.GetComponentInChildren<UnityEngine.EventSystems.EventSystem>().firstSelectedGameObject
                    = this.m_loadedObject[this.m_loadedOrder[0]];
                bOnce = false;
            }

        } /* OnEnable() */
Exemple #28
0
 public void Hide()
 {
     instance?.SetActive(false);
 }
Exemple #29
0
 //优化setActive函数
 internal void SetActiveOptim(UnityEngine.GameObject obj, bool active)
 {
     obj.SetActive(active);
 }
 public static void Activate(this UnityEngine.GameObject go)
 {
     go.SetActive(true);
 }