Пример #1
0
    public override void OnInspectorGUI()
    {
        ActManager myTarget = (ActManager)target;

        EditorGUILayout.BeginHorizontal();
        Rect resetBut = new Rect(
            0, 0,
            UsefullUtils.GetPercent(Screen.width, 25),
            25
            );

        if (GUI.Button(resetBut, "Reset Start"))
        {
            myTarget.gameObject.GetComponent <ActController>().SetStartAtAct("");
        }

        Rect resetSBut = new Rect(
            UsefullUtils.GetPercent(Screen.width, 25) + 15, 0,
            UsefullUtils.GetPercent(Screen.width, 25),
            25
            );

        if (GUI.Button(resetSBut, "Reset Speed"))
        {
            myTarget.gameObject.GetComponent <ActController>().SetStartAtAct("");
        }

        // GUILayout.FlexibleSpace();
        EditorGUILayout.EndHorizontal();

        // Show default inspector property editor
        DrawDefaultInspector();
    }
Пример #2
0
 public void Curve()
 {
     _isCurving      = true;
     _maxLeftAmmount = UsefullUtils.GetPercent(Mathf.Abs(_rb.velocity.x), MaxLeftPerc);
     _curveId        = LeanTween.value(LeftAmmount, _maxLeftAmmount, TimeInMagnus).id;
     LeanTween.descr(_curveId.Value)
     .setOnUpdate(ChangeLeftAmmount);
     LeanTween.descr(_curveId.Value).setEase(LeanTweenType.easeInOutBack);
     LeanTween.descr(_curveId.Value)
     .setOnComplete(() =>
     {
         _curveId     = null;
         _isTorqueing = true;
         _curveId     = LeanTween.value(LeftAmmount, _minLeftAmmount, TimeOutMagnus).id;
         LeanTween.descr(_curveId.Value)
         .setOnUpdate(ChangeLeftAmmount);
         LeanTween.descr(_curveId.Value)
         .setOnComplete(() =>
         {
             _curveId     = null;
             _isCurving   = false;
             _isTorqueing = false;
         });
     });
 }
Пример #3
0
    private void PlayShot()
    {
        _shotIndex++;
        if (_shotIndex >= ReplayOptions.Count)
        {
            return;
        }

        if (_playId.HasValue)
        {
            LeanTween.cancel(_playId.Value);
            _playId = null;
        }
        if (_playRotId.HasValue)
        {
            LeanTween.cancel(_playRotId.Value);
            _playRotId = null;
        }

        float time = UsefullUtils.GetPercent(ReplayOptions[_shotIndex].Seconds, PercentOffset);

        time += UsefullUtils.GetPercent(time, ReplaySpeed);

        _playId = LeanTween.move(Game.Instance.ReplayBall, ReplayOptions[_shotIndex].BallPos, time).id;
        LeanTween.descr(_playId.Value).setEase(LeanTweenType.linear);

        _playRotId = LeanTween.rotate(Game.Instance.ReplayBall, ReplayOptions[_shotIndex].BallRot, time).id;
        LeanTween.descr(_playRotId.Value).setEase(LeanTweenType.linear);

        LeanTween.descr(_playId.Value)
        .setOnComplete(() =>
        {
            PlayShot();
        });
    }
Пример #4
0
    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    {
        // base.OnGUI(position, property, label);

        EditorGUI.BeginProperty(position, label, property);
        EditorGUI.BeginChangeCheck();

        Rect foldPos = new Rect(position.x + 0, position.y + 0, position.width, 15);

        Rect startHLabelPos = new Rect(
            position.x + UsefullUtils.GetPercent(position.width, 0), position.y + 15,
            UsefullUtils.GetPercent(position.width, 25),
            25
            );
        Rect speedPos = new Rect(
            position.x + UsefullUtils.GetPercent(position.width, 30), position.y + 15,
            UsefullUtils.GetPercent(position.width, 25),
            25
            );
        Rect goPos = new Rect(
            position.x + UsefullUtils.GetPercent(position.width, 60), position.y + 15,
            UsefullUtils.GetPercent(position.width, 40),
            25
            );

        SerializedProperty p = property.FindPropertyRelative("_editor_foldout");

        if (p.boolValue = EditorGUI.Foldout(foldPos, p.boolValue, property.displayName))
        {
            GUI.Label(foldPos, property.displayName);

            if (GUI.Button(startHLabelPos, "Start Here"))
            {
                (property.serializedObject.targetObject as ActManager).GetComponent <ActController>()
                .SetStartAtAct(property.propertyPath);
            }

            GameObject value = (GameObject)EditorGUI.ObjectField(
                goPos, "",
                (property.FindPropertyRelative("Go").objectReferenceValue as GameObject),
                typeof(GameObject), true
                );

            property.FindPropertyRelative("_choiceIndex").intValue
                = EditorGUI.Popup(speedPos, property.FindPropertyRelative("_choiceIndex").intValue, _speeds);
            // var someClass = target as SomeClass;
            // Update the selected choice in the underlying object
            // someClass.choice = _choices[_choiceIndex];
            // Save the changes back to the object
            // EditorUtility.SetDirty(target);

            if (EditorGUI.EndChangeCheck())
            {
                property.FindPropertyRelative("Go").objectReferenceValue = value;
                property.serializedObject.ApplyModifiedPropertiesWithoutUndo();
            }
        }
        EditorGUI.EndProperty();
    }
Пример #5
0
    private void ToForthFold()
    {
        topY += 25;
        Rect secondToggled = new Rect(topX, topY, insideFoldWidth, 100);

        GUILayout.BeginArea(secondToggled);
        myTarget.UseForth = GUILayout.Toggle(myTarget.UseForth, "Forth", "Button",
                                             GUILayout.Width(UsefullUtils.GetPercent(Screen.width, 10)), GUILayout.Height(height));
        GUILayout.EndArea();
    }
Пример #6
0
    private void RegisterPoint(Block block)
    {
        if (block == null)
        {
            Debug.Break();
        }
        int scoreToAdd = block.Points;

        if (_previousBlockTypeHit == BlockType.Proppeler)
        {
            // bonus if you hit the first time: 100%
            scoreToAdd = (scoreToAdd * 2);

            // bonus points based on distance from proppeler to sphere
            // the bigger the better
            var distance     = Vector3.Distance(_previousHitPoint, _currentHitPoint);
            var percentToHit = UsefullUtils.GetValuePercent(distance, _maxPossibleDistance);

            float bonusDistancePoints;
            if (percentToHit > 40)  // bigger value decreases points
            {
                // bonus points based on distance from a contact point to proppeler
                // the smaller the better
                distance = Vector3.Distance(_pastPreviousHitPoint, _previousHitPoint);
                var percentToProppeler = UsefullUtils.GetValuePercent(distance, _maxPossibleDistance);
                percentToProppeler = percentToHit - percentToProppeler;

                bonusDistancePoints = UsefullUtils.GetPercent(scoreToAdd, percentToProppeler);
                scoreToAdd         += (int)Mathf.Ceil(bonusDistancePoints);
            }

            bonusDistancePoints = UsefullUtils.GetPercent(scoreToAdd, percentToHit);
            scoreToAdd         += (int)Mathf.Ceil(bonusDistancePoints);


            // score is a bit high, so lets trim it down a bit.
            //
            // WE CAN REMOVE THIS LATER
            //
            //var percentToDecrease =
            scoreToAdd = (int)Mathf.Ceil(UsefullUtils.GetPercent(scoreToAdd, 60));

            Score += scoreToAdd;
        }
        else
        {
            Score += scoreToAdd;
        }

        ScoreText.text = Score.ToString();
        Game.Instance.CanvasController.ShowcasePoints(scoreToAdd, _currentHitPoint);
    }
Пример #7
0
    private void OnProductsLoaded(List <Product> products)
    {
        _products = products;

        if (_productsPool != null)
        {
            foreach (var item in _productsPool)
            {
                item.GameObject.SetActive(false);
            }
        }

        foreach (Product product in _products)
        {
            var wasNull = UsefullUtils.CheckInPool(
                product.id,
                GameHiddenOptions.Instance.ProductPrefab,
                ProductsParent.transform,
                out IPrefabComponent productComponent,
                ref _productsPool
                );

            productComponent.Id    = product.id;
            productComponent.Route = new Route()
            {
                RoutePath = "Product",
                RouteKey  = product.id
            };

            productComponent.GameObject.name = product.name;
            (productComponent as ProductComponent).Name.text     = product.name;
            (productComponent as ProductComponent).PriceOld.text = product.product_price.ToString() + " Lei";
            var randomNr = ((int)Random.Range(1, 4)) * 10;
            var oldPrice = UsefullUtils.GetPercent(product.product_price, 100 - randomNr);
            (productComponent as ProductComponent).ReducePercent.text = "- " + randomNr.ToString() + " %";
            (productComponent as ProductComponent).Price.text         = oldPrice + " Lei";

            Sprite sprite = Resources.Load("ProductImages/" + product.picture_path, typeof(Sprite)) as Sprite;
            (productComponent as ProductComponent).SetImage(sprite);

            if (wasNull)
            {
                _productsPool.Add(productComponent);
            }
        }

        var newHeight = (_products.Count / 2) * 240;

        ProductsParent.sizeDelta = new Vector2(ProductsParent.sizeDelta.x, newHeight);
    }
Пример #8
0
    public void KeepElementInView(RectTransform toGameObject)
    {
        Assets.Scripts.Utils.UIX.UpdateLayout(ScrollRect.transform);

        // Debug.Log("----------------------------------------------------------------------");

        var byWhatPercent = 0f;
        var topSpace      = 250f;
        var percent       = GetCarretPositionPercent(Mathf.Abs(toGameObject.anchoredPosition.y) + topSpace);

        // Debug.Log("percent: " + percent);
        if (percent > 50)
        {
            // Debug.Log("Lower part of the document");
            byWhatPercent = Mathf.Abs(100 - (percent - 50));
            // Debug.Log(percent + ", " + byWhatPercent);
            topSpace = UsefullUtils.GetPercent(550, byWhatPercent);
            // Debug.Log(topSpace);
            percent = GetCarretPositionPercent(Mathf.Abs(toGameObject.anchoredPosition.y) + topSpace);
        }
        else
        {
            byWhatPercent = Mathf.Abs(100 - (50 - percent));
            // Debug.Log(percent + ", " + byWhatPercent);
            topSpace = UsefullUtils.GetPercent(250f, byWhatPercent);
            // Debug.Log(topSpace);
            percent = GetCarretPositionPercent(Mathf.Abs(toGameObject.anchoredPosition.y) + topSpace);
            // Debug.Log("Upper part of the document");
        }
        // Debug.Log("percent: " + percent);

        var scrollValue = UsefullUtils.InvertPercent(percent) / 100;

        // Debug.Log("scrollValue: " + scrollValue);

        Scroll(scrollValue);
    }
Пример #9
0
    public void ApplyStyle(bool atRunTime = false)
    {
        RectTransform thisRect = gameObject.GetComponent <RectTransform>();
        RectTransform thisParentRect;

        if (UseCustomParent)
        {
            if (ParentRect == null)
            {
                thisParentRect  = gameObject.transform.parent.GetComponent <RectTransform>();
                UseCustomParent = false;
            }
            else
            {
                thisParentRect = ParentRect;
            }
        }
        else
        {
            thisParentRect = gameObject.transform.parent.GetComponent <RectTransform>();
            ParentRect     = null;
        }

        var newWidth  = thisRect.sizeDelta.x;
        var newHeight = thisRect.sizeDelta.y;

        if (ApplyWidth)
        {
            switch (WidthSizeUnit)
            {
            case SizeUnit.Pixels:
                newWidth = Width;
                break;

            case SizeUnit.Percent:
                newWidth = UsefullUtils.GetPercent(thisParentRect.sizeDelta.x, Width);
                break;

            default:
                float screenSizeWidth = (float)Screen.width;
                if (atRunTime == false)
                {
                    screenSizeWidth = ((CompileStyles)FindObjectOfType(typeof(CompileStyles))).ReferenceResolution.x;
                }
                newWidth = UsefullUtils.GetPercent(screenSizeWidth, Width);
                break;
            }
        }

        if (ApplyHeight)
        {
            switch (HeightSizeUnit)
            {
            case SizeUnit.Pixels:
                newHeight = Height;
                break;

            case SizeUnit.Percent:
                newHeight = UsefullUtils.GetPercent(thisParentRect.sizeDelta.y, Height);
                break;

            default:
                float screenSizeHeight = (float)Screen.height;
                if (atRunTime == false)
                {
                    screenSizeHeight = ((CompileStyles)FindObjectOfType(typeof(CompileStyles))).ReferenceResolution.y;
                }
                newHeight = UsefullUtils.GetPercent(screenSizeHeight, Height);
                break;
            }
        }

        thisRect.sizeDelta = new Vector2(newWidth, newHeight);
    }
Пример #10
0
    public override void OnInspectorGUI()
    {
        DrawDefaultInspector();

        EditorGUILayout.BeginVertical("box");
        GUILayout.Space(5);

        GUILayout.Label("Database");
        GUILayout.Space(5);

        if (GUILayout.Button("Recreate User Table"))
        {
            _action = InspectorButton.RecreateUserTable;
        }

        if (GUILayout.Button("Recreate Story Table"))
        {
            _action = InspectorButton.RecreateStoryTable;
        }

        if (GUILayout.Button("Recreate Page Table"))
        {
            _action = InspectorButton.RecreatePageTable;
        }

        if (GUILayout.Button("Recreate Element Table"))
        {
            _action = InspectorButton.RecreateElementTable;
        }

        GUILayout.Space(5);
        GUILayout.Label("Write Data");
        GUILayout.Space(5);

        //if (GUILayout.Button("Write Categories Data"))
        //    _action = InspectorButton.WriteCategoriesData;

        //if (GUILayout.Button("Update Categories Questions"))
        //    _action = InspectorButton.UpdateCategoriesQuestions;

        GUILayout.Space(5);

        //if (GUILayout.Button("Write Default Data"))
        //    _action = InspectorButton.WriteDefaultData;

        GUILayout.Space(5);
        EditorGUILayout.EndVertical();

        //--------------------------------------------------------------------------------------------------------------------------------------------------------
        GUILayout.Space(20);    // CONFIRM
        //--------------------------------------------------------------------------------------------------------------------------------------------------------

        if (_setupConfirm)
        {
            EditorGUILayout.BeginVertical("box");
            GUILayout.Space(5);

            EditorGUILayout.BeginHorizontal();

            GUILayout.FlexibleSpace();

            if (GUILayout.Button("Confirm", GUILayout.Width(UsefullUtils.GetPercent(Screen.width, 25)), GUILayout.Height(50)))
            {
                ConfirmAccepted();
            }

            if (GUILayout.Button("Cancel", GUILayout.Width(UsefullUtils.GetPercent(Screen.width, 25)), GUILayout.Height(50)))
            {
                _setupConfirm = false;
            }

            GUILayout.FlexibleSpace();

            EditorGUILayout.EndHorizontal();
            GUILayout.Space(5);
            EditorGUILayout.EndVertical();
        }
    }
Пример #11
0
    private void OriginalFold()
    {
        topY += 25;
        Rect foldPos = new Rect(topX - 5, topY, Screen.width, 15);

        if (myTarget.OriginalFoldout = EditorGUI.Foldout(foldPos, myTarget.OriginalFoldout, "Original"))
        {
            topY += height;
            Rect buttonLock = new Rect(topX, topY, UsefullUtils.GetPercent(insideFoldWidth, 10), height);
            Rect buttonSet  = new Rect(topX + UsefullUtils.GetPercent(insideFoldWidth, 10), topY, UsefullUtils.GetPercent(insideFoldWidth, 40), height);
            Rect buttonView = new Rect(topX + UsefullUtils.GetPercent(insideFoldWidth, 50), topY, UsefullUtils.GetPercent(insideFoldWidth, 50), height);
            if (GUI.Button(buttonLock, myTarget.OriginalLocked ? "Unlock" : "Lock"))
            {
                myTarget.OriginalLocked = !myTarget.OriginalLocked;
            }
            EditorGUI.BeginDisabledGroup(myTarget.OriginalLocked);
            if (GUI.Button(buttonSet, "Set Current" + (myTarget.OriginalLocked ? " (L)" : "")))
            {
                if (myTarget.OriginalLocked)
                {
                    return;
                }
                myTarget.SetCurrent();
            }
            EditorGUI.EndDisabledGroup();

            if (GUI.Button(buttonView, "View Now"))
            {
                myTarget.ViewNow();
            }

            EditorGUI.BeginDisabledGroup(myTarget.OriginalLocked);

            if (myTarget.TransformAnchorPos)
            {
                topY += height;
                Rect origPos = new Rect(topX, topY, Screen.width, height);
                GUILayout.BeginArea(origPos);
                myTarget.OriginalAnchorPos = EditorGUILayout.Vector3Field("Anchor Pos", myTarget.OriginalAnchorPos,
                                                                          GUILayout.Height(height), GUILayout.Width(insideFoldWidth));
                GUILayout.EndArea();
            }

            if (myTarget.TransformDelta)
            {
                topY += height;
                Rect origDelta = new Rect(topX, topY, Screen.width, height);
                GUILayout.BeginArea(origDelta);
                myTarget.OriginalScaleDelta = EditorGUILayout.Vector2Field("Original Delta", myTarget.OriginalScaleDelta,
                                                                           GUILayout.Height(height), GUILayout.Width(insideFoldWidth));
                GUILayout.EndArea();
            }

            if (myTarget.TransformRotation)
            {
                topY += height;
                Rect origRot = new Rect(topX, topY, Screen.width, height);
                GUILayout.BeginArea(origRot);
                myTarget.OriginalRotation = EditorGUILayout.Vector3Field("Original Rotation", myTarget.OriginalRotation,
                                                                         GUILayout.Height(height), GUILayout.Width(insideFoldWidth));
                GUILayout.EndArea();
            }

            EditorGUI.EndDisabledGroup();
        }
    }
Пример #12
0
    private void ToThirdFold()
    {
        topY += 25;
        Rect secondToggled = new Rect(topX, topY, insideFoldWidth, 100);

        GUILayout.BeginArea(secondToggled);
        myTarget.UseThird = GUILayout.Toggle(myTarget.UseThird, "Third", "Button",
                                             GUILayout.Width(UsefullUtils.GetPercent(Screen.width, 10)), GUILayout.Height(height));
        GUILayout.EndArea();

        if (myTarget.UseThird)
        {
            topY += 25;
            Rect foldPos = new Rect(topXSecondLevel - 5, topY, Screen.width, 15);
            if (myTarget.ToThirdFoldout = EditorGUI.Foldout(foldPos, myTarget.ToThirdFoldout, "To Third"))
            {
                topY += height;
                Rect buttonLock = new Rect(topXSecondLevel, topY, UsefullUtils.GetPercent(insideFoldSecondLevelWidth, 10), height);
                Rect buttonSet  = new Rect(topXSecondLevel + UsefullUtils.GetPercent(insideFoldSecondLevelWidth, 10), topY, UsefullUtils.GetPercent(insideFoldSecondLevelWidth, 40), height);
                Rect buttonView = new Rect(topXSecondLevel + UsefullUtils.GetPercent(insideFoldSecondLevelWidth, 50), topY, UsefullUtils.GetPercent(insideFoldSecondLevelWidth, 50), height);
                if (GUI.Button(buttonLock, myTarget.ThirdLocked ? "Unlock" : "Lock"))
                {
                    myTarget.ThirdLocked = !myTarget.ThirdLocked;
                }
                EditorGUI.BeginDisabledGroup(myTarget.ThirdLocked);
                if (GUI.Button(buttonSet, "Set Current" + (myTarget.ThirdLocked ? " (L)" : "")))
                {
                    if (myTarget.ThirdLocked)
                    {
                        return;
                    }
                    myTarget.SetCurrentThird();
                }
                EditorGUI.EndDisabledGroup();

                if (GUI.Button(buttonView, "View Now"))
                {
                    myTarget.ViewNowThird();
                }

                EditorGUI.BeginDisabledGroup(myTarget.ThirdLocked);

                if (myTarget.TransformAnchorPos)
                {
                    topY += height;
                    Rect origPos = new Rect(topXSecondLevel, topY, Screen.width, height);
                    GUILayout.BeginArea(origPos);
                    myTarget.ThirdAnchorPos = EditorGUILayout.Vector3Field("Anchor Pos", myTarget.ThirdAnchorPos,
                                                                           GUILayout.Height(height), GUILayout.Width(insideFoldSecondLevelWidth));
                    GUILayout.EndArea();
                }

                if (myTarget.TransformDelta)
                {
                    topY += height;
                    Rect origDelta = new Rect(topXSecondLevel, topY, Screen.width, height);
                    GUILayout.BeginArea(origDelta);
                    myTarget.ThirdScaleDelta = EditorGUILayout.Vector2Field("Delta", myTarget.ThirdScaleDelta,
                                                                            GUILayout.Height(height), GUILayout.Width(insideFoldSecondLevelWidth));
                    GUILayout.EndArea();
                }

                if (myTarget.TransformRotation)
                {
                    topY += height;
                    Rect origRot = new Rect(topXSecondLevel, topY, Screen.width, height);
                    GUILayout.BeginArea(origRot);
                    myTarget.ThirdRotation = EditorGUILayout.Vector3Field("Rotation", myTarget.ThirdRotation,
                                                                          GUILayout.Height(height), GUILayout.Width(insideFoldSecondLevelWidth));
                    GUILayout.EndArea();
                }

                EditorGUI.EndDisabledGroup();
            }
        }
    }
Пример #13
0
    public override void OnInspectorGUI()
    {
        if (ToggleButtonStyleNormal == null)
        {
            ToggleButtonStyleNormal  = "Button";
            ToggleButtonStyleToggled = new GUIStyle(ToggleButtonStyleNormal);
            ToggleButtonStyleToggled.normal.background = ToggleButtonStyleToggled.active.background;
        }

        myTarget = (TransformChanges)target;

        var minHeight = 30;

        if (myTarget.OriginalFoldout)
        {
            minHeight = 150;
        }
        if (myTarget.ToSecondFoldout)
        {
            minHeight = 200;
        }
        var componentHeight = ((topY + 30) < minHeight) ? minHeight : (topY + 30);

        EditorGUILayout.BeginHorizontal(GUILayout.Width(Screen.width), GUILayout.Height(componentHeight));

        EditorGUILayout.Space(5);

        topY = 5;
        topX = 20;
        Rect buttonPos = new Rect(topX - 10, topY, Screen.width, 100);

        GUILayout.BeginArea(buttonPos);
        EditorGUILayout.BeginHorizontal();

        myTarget.TransformAnchorPos = GUILayout.Toggle(myTarget.TransformAnchorPos, "Anchor Pos", "Button",
                                                       GUILayout.Width(UsefullUtils.GetPercent(Screen.width, 20)), GUILayout.Height(height));
        myTarget.TransformDelta = GUILayout.Toggle(myTarget.TransformDelta, "Delta", "Button",
                                                   GUILayout.Width(UsefullUtils.GetPercent(Screen.width, 20)), GUILayout.Height(height));
        myTarget.TransformRotation = GUILayout.Toggle(myTarget.TransformRotation, "Rotation", "Button",
                                                      GUILayout.Width(UsefullUtils.GetPercent(Screen.width, 20)), GUILayout.Height(height));

        EditorGUILayout.EndHorizontal();
        GUILayout.EndArea();
        //

        insideFoldWidth = Screen.width - 40;

        if (myTarget.TransformAnchorPos || myTarget.TransformDelta || myTarget.TransformRotation)
        {
            OriginalFold();
            ToSecondFold();
            topY += 25;
            Rect foldPos = new Rect(topX - 5, topY, Screen.width, 15);
            if (myTarget.MoreThenOne = EditorGUI.Foldout(foldPos, myTarget.MoreThenOne, "More"))
            {
                insideFoldSecondLevelWidth = Screen.width - 60;
                topXSecondLevel            = topX + 20;
                ToThirdFold();
                ToForthFold();
            }
        }
        else
        {
            topY += 25;
            Rect textPos = new Rect(topX - 5, topY, Screen.width, 30);
            GUILayout.BeginArea(textPos);
            EditorGUILayout.LabelField("Nothing to change so you should remove it!");
            GUILayout.EndArea();
        }

        EditorGUILayout.Space(10);
        EditorGUILayout.EndVertical();

        EditorUtility.SetDirty(myTarget);
        EditorSceneManager.MarkSceneDirty(myTarget.gameObject.scene);
    }