コード例 #1
0
    bool CheckCollisions(Vector3 sourceWorldPos, Vector3 deltaPosition, ref Vector3 oTargetPosition, ref Vector3 oVelocity)
    {
        Vector3 velocity                 = deltaPosition.normalized;
        Vector3 velForwardComponent      = Vector3.Dot(_host.transform.forward, velocity) * _host.transform.forward;
        Vector3 velRightcomponent        = Vector3.Dot(_host.transform.right, velocity) * _host.transform.right;
        Vector3 velForwardRightComponent = velForwardComponent + velRightcomponent;

        Vector3 normal = sourceWorldPos - _planet.transform.position;

        normal.Normalize();

        Vector3 positionBias     = normal * _collider.bounds.extents.x + velForwardRightComponent.normalized * _collider.bounds.extents.x;
        Vector3 rayStartWorldPos = sourceWorldPos + positionBias;
        Ray     ray = new Ray(rayStartWorldPos, velForwardRightComponent.normalized);

        Debug.DrawRay(rayStartWorldPos, velForwardRightComponent.normalized * velForwardRightComponent.magnitude * 1.0f, Color.red);

        BaseBox    voxel = null;
        RaycastHit hitInfo;

        if (Physics.Raycast(ray, out hitInfo, velForwardRightComponent.magnitude * 1.0f, 1 << Layer.Terrain))
        {
            oTargetPosition = hitInfo.point - velForwardRightComponent.normalized * _collider.bounds.extents.x - positionBias;
            oVelocity       = -oVelocity * 0.1f;

            return(true);
        }
        else
        {
            return(false);
        }
    }
コード例 #2
0
    public void OnBoxDestroyed(BaseBox box)
    {
        PlanetGenerator.BoxGenerationProperties properties = box.GenerationProperties;
        properties.Radius--;

        if (properties.Radius > 1f)
        {
            DoGenerateBox(properties.LeftRotation, properties.RightRotation, properties.BoxOrientation, properties.RotationCircleStep, properties.Radius);
        }
    }
コード例 #3
0
    public void Output()
    {
        BaseNode baseNode = MainViweModel.instance.baseNode;
        BaseBox  baseBox  = BoxViewModel.instance.baseBox;

        ConfirmViewModel.instance.ShowWindow(() => {
            TunagumIO.ExportBaseBox(baseBox);
            this.HideWiondow();
        }, null, "出力しますか?", "");
    }
コード例 #4
0
    /// <summary>
    /// 箱に接触した場合の処理
    /// </summary>
    /// <param name="box"></param>
    protected void CheckColliedingBox(BaseBox box)
    {
        if (state.name == (int)STATENAME.Damage)
        {
            box.Crash();
            parameter.damage.damageParameter.damage = 1;
            return;
        }

        transform.localPosition = box.PositionFix(transform.localPosition);
    }
コード例 #5
0
    /// <summary>
    /// 箱が押せる状態なら押す。成功したらtrue
    /// </summary>
    /// <param name="power"></param>
    /// <returns></returns>
    protected bool CheckPutBox(float power)
    {
        BaseBox near = GetNearBox();

        if (near != null)
        {
            near.Put(frontDirection, power);
            return(true);
        }
        return(false);
    }
コード例 #6
0
    public void test()
    {
        //ConfirmViewModel.instance.ShowWindow(() => Debug.Log("OK"), () => Debug.Log("NO"), "タイトルです", "てすとてすとてすと");
        //TunagumIO.LoadFromPath();

        //BaseBox bb = TunagumIO.LoadBaseBox();
        //string optionText = Import.ReadFile(DEFINE.OptionFileName);
        //var bb = BaseBox.ConvertOptionText(optionText);
        var bb = BaseBox.ConvertOptionText(input.text);

        BoxViewModel.instance.SetBaseBox(bb);
    }
コード例 #7
0
    public Vector3 GetSurfaceWorldPosition(Vector3 worldPosition)
    {
        BaseBox surface = GetVoxelInPosition(worldPosition);

        Vector3 surfaceLocalPosition = ConvertToLocalPosition(surface.transform.position);
        float   surfaceRadius        = surfaceLocalPosition.magnitude;

        Vector3 localPosition = ConvertToLocalPosition(worldPosition);

        localPosition = localPosition.normalized * surfaceRadius;

        return(ConvertToWorldPosition(localPosition));
    }
コード例 #8
0
    public void SetBaseBox(BaseBox box)
    {
        this.baseBox = box;
        this.baseBox.boxes
        .ObserveAdd()
        .Subscribe(x => AddWindow(x.Value));

        this.baseBox.boxes
        .ObserveRemove()
        .Subscribe(x => RemoveWindow(x.Value));

        OpenNewBaseNode();
        BoxPaletteViewModel.instance.LoadPalette(this.baseBox);
    }
コード例 #9
0
    // Update is called once per frame
    void Update()
    {
        float dist = Vector3.Distance(transform.position, playerTransform.position);

        if (dist <= triggerDistance)
        {
            BaseBox boxComponent = GetComponent <BaseBox>();
            boxComponent.OnApproach();
        }
        else
        {
            BaseBox boxComponent = GetComponent <BaseBox>();
            boxComponent.OnRetire();
        }
    }
コード例 #10
0
    GameObject Spawn(Vector3 position)
    {
        GameObject gameObject = new GameObject();

        MeshRenderer mr = gameObject.AddComponent <MeshRenderer>();

        mr.material = _material;

        MeshFilter mf = gameObject.AddComponent <MeshFilter>();

        mf.mesh = GenerateMesh();

        BaseBox box = gameObject.AddComponent <BaseBox>();

        return(gameObject);
    }
コード例 #11
0
ファイル: PlayerDetector.cs プロジェクト: qtLex/SmallGame_Box
    void OnTriggerEnter(Collider other)
    {
        if (other.gameObject.tag != "Player")
        {
            return;
        }

        GlobalOptions.CurrentBox = this.transform.parent.gameObject;
        BaseBox box = GlobalOptions.CurrentBox.GetComponent <BaseBox>();

        if (box != null)
        {
            box.UserStay();
            Messenger.AddListener("UserAction", box.UserAction);
        }
    }
コード例 #12
0
    public Vector3 GetSurfaceLocalPosition(Vector3 localPosition)
    {
        BaseBox surface = GetVoxelInPosition(ConvertToWorldPosition(localPosition));

        if (surface != null)
        {
            Vector3 surfaceLocalPosition = ConvertToLocalPosition(surface.transform.position);
            float   surfaceRadius        = surfaceLocalPosition.magnitude;

            return(localPosition.normalized * surfaceRadius);
        }
        else
        {
            return(localPosition);
        }
    }
コード例 #13
0
ファイル: PlayerDetector.cs プロジェクト: qtLex/SmallGame_Box
    void OnTriggerExit(Collider other)
    {
        if (other.gameObject.tag != "Player")
        {
            return;
        }

        BaseBox box = !GlobalOptions.CurrentBox ? null : GlobalOptions.CurrentBox.GetComponent <BaseBox>();

        if (box != null)
        {
            Messenger.RemoveListener("UserAction", box.UserAction);
        }

        GlobalOptions.CurrentBox = null;
    }
コード例 #14
0
    void Update()
    {
        if (Input.GetMouseButtonUp(0))
        {
            Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);

            RaycastHit hitInfo;
            if (Physics.Raycast(ray, out hitInfo))
            {
                BaseBox box = hitInfo.collider.GetComponentInParent <BaseBox>();
                if (box != null)
                {
                    box.OnTouched();
                }
            }
        }
    }
コード例 #15
0
    // Methods to be refactored into its own Planet
    public BaseBox GetVoxelInPosition(Vector3 worldPosition)
    {
        Vector3 dirToCore = (transform.position - worldPosition).normalized;
        Ray     ray       = new Ray(worldPosition, dirToCore);

        BaseBox    voxel = null;
        RaycastHit hitInfo;

        if (Physics.Raycast(ray, out hitInfo, 999999f, 1 << Layer.Terrain))
        {
            voxel = hitInfo.collider.GetComponentInParent <BaseBox>();
        }
        else
        {
            Debug.Log("Voxel Not Found :(, position: " + worldPosition + ", Direction: " + dirToCore);
        }

        return(voxel);
    }
コード例 #16
0
    void OnTriggerStay(Collider other)
    {
        if (other.gameObject.tag != "Player")
        {
            return;
        }


        if (!GlobalOptions.Player.GetComponent <PlayerController>().isMoving())
        {
            BaseBox box = this.transform.parent.gameObject.GetComponent <BaseBox>();
            if (!box)
            {
                return;
            }

            box.UserStay();
        }
    }
コード例 #17
0
 public void LoadPalette(BaseBox bb)
 {
     foreach (BaseBox.Palett p in bb.palette)
     {
         var tBox = bb.SearchTemplateBox(p.boxtag);
         if (p.category.IsBlank())
         {
             AddMaterial(tBox);
         }
         else
         {
             if (!categoryTable.ContainsKey(p.category))
             {
                 AddCategory(p.category);
             }
             AddMaterial(tBox, categoryTable[p.category]);
         }
     }
 }
コード例 #18
0
        public override void Draw(DrawingContext drawingContext, double scale, double x, double y)
        {
            BaseBox.Draw(drawingContext, scale, x, y);

            if (Over)
            {
                // Draw delimeter and script boxes over base box.
                var centerY      = y - BaseBox.Height - DelimeterBox.Width;
                var translationX = x + DelimeterBox.Width / 2;
                var translationY = centerY + DelimeterBox.Width / 2;

                drawingContext.PushTransform(new TranslateTransform(translationX * scale, translationY * scale));
                drawingContext.PushTransform(new RotateTransform(90));
                DelimeterBox.Draw(drawingContext, scale, -DelimeterBox.Width / 2,
                                  -DelimeterBox.Depth + DelimeterBox.Width / 2);
                drawingContext.Pop();
                drawingContext.Pop();

                // Draw script box as superscript.
                ScriptBox?.Draw(drawingContext, scale, x, centerY - Kern - ScriptBox.Depth);
            }
            else
            {
                // Draw delimeter and script boxes under base box.
                var centerY      = y + BaseBox.Depth + DelimeterBox.Width;
                var translationX = x + DelimeterBox.Width / 2;
                var translationY = centerY - DelimeterBox.Width / 2;

                drawingContext.PushTransform(new TranslateTransform(translationX * scale, translationY * scale));
                drawingContext.PushTransform(new RotateTransform(90));
                DelimeterBox.Draw(drawingContext, scale, -DelimeterBox.Width / 2,
                                  -DelimeterBox.Depth + DelimeterBox.Width / 2);
                drawingContext.Pop();
                drawingContext.Pop();

                // Draw script box as subscript.
                ScriptBox?.Draw(drawingContext, scale, x, centerY + Kern + ScriptBox.Height);
            }
        }
コード例 #19
0
    public static BaseBox LoadBaseBox()
    {
        string   optionText = Import.ReadFile(DEFINE.OptionFileName);
        var      bb         = BaseBox.ConvertOptionText(optionText);
        XElement root       = TunagumIO.LoadFromPath();
        var      programs   = root.Elements("program");

        foreach (XElement prog in programs)
        {
            var titles = prog.Descendants("object");
            if (titles != null)
            {
                Dictionary <string, string> idToNextid = new Dictionary <string, string>();
                List <Box> boxlist = new List <Box>();

                foreach (var title in titles)
                {
                    string v      = title.Attribute("name").Value;
                    string boxid  = title.Attribute("boxID").Value;
                    string nextid = title.Attribute("nextBox").Value;
                    idToNextid[boxid] = nextid;
                    if (v == "Time")
                    {
                        var cbox = bb.AddBoxForTag("@<time>@");
                        cbox.id = int.Parse(boxid);
                        boxlist.Add(cbox);
                    }
                    if (v == "screen")
                    {
                        var cbox = bb.AddBoxForTag("@<screen>@");
                        cbox.id = int.Parse(boxid);
                        boxlist.Add(cbox);
                    }
                    if (v == "DVD")
                    {
                        var cbox = bb.AddBoxForTag("@<DVD>@");
                        cbox.id = int.Parse(boxid);
                        boxlist.Add(cbox);
                    }
                    if (v == "door")
                    {
                        var cbox = bb.AddBoxForTag("@<door>@");
                        cbox.id = int.Parse(boxid);
                        boxlist.Add(cbox);
                    }
                }
                //nextboxをchildにする処理.
                foreach (var b in boxlist)
                {
                    if (idToNextid.ContainsKey(b.id.ToString()))
                    {
                        string[] arr = idToNextid[b.id.ToString()].Split(',');
                        foreach (var str in arr)
                        {
                            foreach (var b2 in boxlist)
                            {
                                if (b2.id.ToString() == str)
                                {
                                    b.AddChildBox(b2);
                                }
                            }
                        }
                    }
                    if (b.id == 0)
                    {
                        bb.AddChildBox(b);
                    }
                }
            }
        }

        bb.RefreshProgramID();
        return(bb);
    }
コード例 #20
0
    /// <summary>
    /// ���ɐڐG�����ꍇ�̏���
    /// </summary>
    /// <param name="box"></param>
    protected void CheckColliedingBox(BaseBox box)
    {
        if (state.name == (int)STATENAME.Damage)
        {
            box.Crash();
            parameter.damage.damageParameter.damage = 1;
            return;
        }

        transform.localPosition = box.PositionFix(transform.localPosition);
    }
コード例 #21
0
 public BoxStayState(BaseBox parent)
     : base(parent)
 {
     counter = new FrameCounter(10000);
 }
コード例 #22
0
    GameObject DoGenerateBox(Quaternion rotationLeft, Quaternion rotationRight, Quaternion boxOrientation, Quaternion rotationCircleStep, float radius)
    {
        Vector3 startPositionBackLeftBottomWS = transform.position + Vector3.up * (radius * 0.8f);
        Vector3 startPositionBackLeftTopWS    = transform.position + Vector3.up * (radius + _boxThickness);

        Vector3 backLeftBottomWS    = rotationLeft * startPositionBackLeftBottomWS;
        Vector3 forwardLeftBottomWS = rotationCircleStep * backLeftBottomWS;

        Vector3 backLeftTopWS    = rotationLeft * startPositionBackLeftTopWS;
        Vector3 forwardLeftTopWS = rotationCircleStep * backLeftTopWS;

        Vector3 backRightBottomWS    = rotationRight * startPositionBackLeftBottomWS;
        Vector3 forwardRightBottomWS = rotationCircleStep * backRightBottomWS;

        Vector3 backRightTopWS    = rotationRight * startPositionBackLeftTopWS;
        Vector3 forwardRightTopWS = rotationCircleStep * backRightTopWS;

        Vector3 boxMiddleTopWS    = (backLeftTopWS + forwardLeftTopWS + backRightTopWS + forwardRightTopWS) * 0.25f;
        Vector3 boxMiddleBottomWS = (backLeftBottomWS + forwardLeftBottomWS + backRightBottomWS + forwardRightBottomWS) * 0.25f;

        Quaternion inverseBoxOrientation = Quaternion.Inverse(boxOrientation);
        Vector3    backLeftBottom        = inverseBoxOrientation * (backLeftBottomWS - boxMiddleTopWS);
        Vector3    forwardLeftBottom     = inverseBoxOrientation * (forwardLeftBottomWS - boxMiddleTopWS);
        Vector3    backLeftTop           = inverseBoxOrientation * (backLeftTopWS - boxMiddleTopWS);
        Vector3    forwardLeftTop        = inverseBoxOrientation * (forwardLeftTopWS - boxMiddleTopWS);
        Vector3    backRightBottom       = inverseBoxOrientation * (backRightBottomWS - boxMiddleTopWS);
        Vector3    forwardRightBottom    = inverseBoxOrientation * (forwardRightBottomWS - boxMiddleTopWS);
        Vector3    backRightTop          = inverseBoxOrientation * (backRightTopWS - boxMiddleTopWS);
        Vector3    forwardRightTop       = inverseBoxOrientation * (forwardRightTopWS - boxMiddleTopWS);

        Color lateralColor  = mMath.color(1f, 0f, 0f, 0f);
        Color verticalColor = mMath.color(0f, 1f, 0f, 0f);
        Mesh  mesh          = _customBoxGenerator.Generate(new Vector3[] { backLeftBottom, forwardLeftBottom, backRightBottom, forwardRightBottom, backLeftTop, forwardLeftTop, backRightTop, forwardRightTop }, Quaternion.identity, new Color[] { verticalColor, verticalColor, lateralColor, lateralColor, lateralColor, lateralColor });
        //_treeGenerator.Genererate(this, boxMiddleTopWS, boxOrientation, GetAverageHalfDistance(backRightTopWS, backLeftTopWS,  forwardRightTopWS, forwardLeftTopWS), boxMiddleTopWS - boxMiddleBottomWS, GetAverageHalfDistance(forwardLeftTopWS, backLeftTopWS,  forwardRightTopWS, backRightTopWS));

        GameObject go = new GameObject();

        _boxCount++;
        go.name = "TerrainBox" + _boxCount.ToString();

        MeshFilter mf = go.AddComponent <MeshFilter>();

        mf.mesh = mesh;

        MeshRenderer mr = go.AddComponent <MeshRenderer>();

        mr.material = _materialGenerator.Get(radius, boxMiddleTopWS);

        BoxCollider collider = go.AddComponent <BoxCollider>();

        go.layer = Layer.Terrain;
        go.transform.position = boxMiddleTopWS;
        go.transform.rotation = boxOrientation;

        BaseBox box = go.AddComponent <BaseBox>();

        box.SetGenerationProperties(new BoxGenerationProperties(rotationLeft, rotationRight, boxOrientation, rotationCircleStep, radius));
        box.Init(this);

        box.transform.SetParent(_boxes, false);

        return(go);
    }
コード例 #23
0
        private void Button1_Click(object sender, EventArgs e)
        {
            BaseBox <bool> box = new BaseBox <bool>();

            box.ShowDialog();
        }
コード例 #24
0
 /// <summary>
 /// 箱と衝突した場合の処理
 /// </summary>
 /// <param name="box"></param>
 virtual protected void ColliedBox(BaseBox box)
 {
     box.Crash();
     SelfDestroy();
 }
コード例 #25
0
 /// <summary>
 /// ���ƏՓ˂����ꍇ�̏���
 /// </summary>
 /// <param name="box"></param>
 protected virtual void ColliedBox(BaseBox box)
 {
     box.Crash();
     SelfDestroy();
 }
コード例 #26
0
 public static void ExportBaseBox(BaseBox bb)
 {
     Export.Output(bb.value);
 }
コード例 #27
0
 public BoxStayState(BaseBox parent)
     : base(parent)
 {
     counter = new FrameCounter(10000);
 }