コード例 #1
0
    /******************************************************/
    // Use this for initialization
    void Start()
    {
        m_camera = GameObject.FindWithTag("MainCamera").transform;
        var _collider = m_camera.GetComponent <Collider>();

        if (!_collider)
        {
            m_camera.AddComponent <SphereCollider>();
        }

        m_preMaterials = gameObject.GetComponent <Renderer>().materials;

        // Init transparent material
        Material alphaM = Resources.Load <Material>("Materials/TransparentMaterial");

        m_alphaMeterials = new Material[m_preMaterials.Length];
        for (int i = 0; i < m_alphaMeterials.Length; ++i)
        {
            m_alphaMeterials[i] = alphaM;
        }

        // Set defaul
        m_isShow = m_ShowStart;
        SetMaterial(m_ShowStart);
        StartCoroutine(ShelterControll());
    }
コード例 #2
0
        private void EnsureUIView(Dictionary <Transform, string> goPathDic)
        {
            EnsureUIContainer(mUIView);
            foreach (var item in goPathDic)
            {
                Transform child  = item.Key;
                UIView    uIView = child.GetComponent <UIView>();
                if (uIView)
                {
                    DestroyImmediate(uIView);
                }
                UIContainer uiConTainer = child.GetComponent <UIContainer>();

                if (child.name.Contains("(Item)"))
                {
                    if (!uiConTainer)
                    {
                        uiConTainer = child.AddComponent <UIContainer>();
                    }
                }
                else if (uiConTainer)
                {
                    DestroyImmediate(uiConTainer);
                }

                EnsureUIContainer(uiConTainer);
            }
        }
コード例 #3
0
    public static T AddOrGet <T>(this Transform trans) where T : Component
    {
        var t = trans.GetComponent <T>();

        if (t == null)
        {
            t = trans.AddComponent <T>();
        }

        return(t);
    }
コード例 #4
0
 public void Init(Transform transform, Vector2 axis, float startSpeed, float slowSpeed, float speedLimit)
 {
     _axis       = axis;
     _speed      = startSpeed;
     _slowSpeed  = slowSpeed;
     _speedLimit = speedLimit;
     if (_move == null)
     {
         _move = transform.AddComponent <MoveComponent>();
     }
 }
コード例 #5
0
    public void BuildPlayer()
    {
        Assert.IsNull(Player);
        Player = Instantiate(playerPrefab);
        IInput input;

        switch (bindings.inputType)
        {
        case Bindings.InputType.MOUSE:
            input = Player.AddComponent <MouseInput>();
            break;

        case Bindings.InputType.CONTROLLER:
            input = Player.AddComponent <ControllerInput>();
            break;

        default:
            input = Player.AddComponent <NullInput>();
            break;
        }
        input.Construct(bindings);

        Health health = Player.GetComponent <Health>();

        health.healthDisplayHolder = (Instantiate(healthBarPrefab) as Transform);
        health.healthDisplayHolder.Reset();

        foreach (Transform deathAction in deathActions)
        {
            (Instantiate(deathAction, health.deathActionsHolder) as Transform).Reset();
        }
        health.Construct();

        Transform weaponsHolder = Player.Find("CameraRotator/WeaponsHolder");

        foreach (Transform weapon in modules)
        {
            (Instantiate(weapon, weaponsHolder) as Transform).Reset();
        }
    }
コード例 #6
0
ファイル: TransformEx.cs プロジェクト: zxsean/UGUIDemo
    public static T AddCompIfNull <T>(this Transform pObj) where T : MonoBehaviour
    {
        T _com = pObj.GetComponent <T>();

        if (_com != null)
        {
            return(_com);
        }
        else
        {
            return(pObj.AddComponent <T>());
        }
    }
コード例 #7
0
        private static bool IsLegoComponent(Transform tram)
        {
            if (tram.name.StartsWith(LEGO_COMPONENT))
            {
                if (tram.GetComponent <YuLegoComponentHelper>() == null)
                {
                    tram.AddComponent <YuLegoComponentHelper>();
                    return(true);
                }

                return(true);
            }

            return(false);
        }
コード例 #8
0
 void addContent(GameObject obj, Sprite sprite, SpriteRenderer spriteRen, string name, string location, int i)
 {
     obj = new GameObject(name);
     sprite = Resources.Load<Sprite>(location);
     spriteRen = obj.AddComponent<SpriteRenderer>();
     obj.transform.parent = propertyMenuObject.transform;
     spriteRen.sprite = sprite;
     spriteRen.sortingOrder = 1;
     if (i < 3)
     {
         obj.transform.position = new Vector3(propertyMenuObject.transform.position.x + i * propertyMenuRenderer.sprite.bounds.size.x / 3, propertyMenuObject.transform.position.y, 0);
     }
     else
     {
         obj.transform.position = new Vector3(propertyMenuObject.transform.position.x + (i - (i / 3) * 3) * propertyMenuRenderer.sprite.bounds.size.x / 3, propertyMenuObject.transform.position.y - spriteRen.sprite.bounds.size.y, 0);
     }
 }
コード例 #9
0
        public void StartPanel(MissionManager missionMng)
        {
            this.missionMng           = missionMng;
            base.transform.localScale = Vector3.zero;
            Transform child = base.transform.FindChild("RightPanel/RequireDay").GetChild(1);

            UnityEngine.Object.Destroy(((Component)child).GetComponent <UISprite>());
            UILabel uILabel = child.AddComponent <UILabel>();

            child.localPositionX(-25f);
            uILabel.fontSize       = 22;
            uILabel.text           = "残り遠征日数";
            uILabel.overflowMethod = UILabel.Overflow.ResizeFreely;
            uILabel.font           = mLabel_RequireDay.font;
            uILabel.color          = new Color32(75, 75, 75, byte.MaxValue);
            dialogAnim.OpenAction  = delegate
            {
                Initialize(SingletonMonoBehaviour <AppInformation> .Instance.CurrentDeck);
                RightPanel.SafeGetTweenAlpha(0f, 1f, 0.4f, 0f, UITweener.Method.Linear, UITweener.Style.Once, null, string.Empty);
                GetKeyController();
            };
            dialogAnim.StartAnim(DialogAnimation.AnimType.POPUP, isOpen: true);
        }
コード例 #10
0
    void InitRigidBodies(Transform capsuleRoot)
    {
        Rigidbody pa = capsuleRoot.GetComponent <Rigidbody>();
        Rigidbody pb = capsuleRoot.GetChild(0).GetComponent <Rigidbody>();

        if (!pa)
        {
            pa = capsuleRoot.AddComponent <Rigidbody>();
        }

        pa.isKinematic   = true;
        pa.interpolation = RigidbodyInterpolation.Interpolate;

        if (!pb)
        {
            pb = capsuleRoot.GetChild(0).gameObject.AddComponent <Rigidbody>();
        }

        pb.isKinematic            = false;
        pb.interpolation          = RigidbodyInterpolation.Interpolate;
        pb.collisionDetectionMode = CollisionDetectionMode.ContinuousDynamic;
        pb.mass = 1f;
    }
 public static T GetComponent <T>(this Transform transform) where T : Component
 {
     return(transform.GetComponent <T>() ?? transform.AddComponent <T>());
 }