示例#1
0
        //--------------------------------------------------------------------------------------------------

        public void Exclude(InteractiveEntity excludeShape)
        {
            if (excludeShape != null)
            {
                _SelectionContext.Exclude(excludeShape);
            }
        }
示例#2
0
        //--------------------------------------------------------------------------------------------------

        public SelectSubshapeAction(object owner, SubshapeTypes subshapeTypes, InteractiveEntity sourceEntity = null, ISelectionFilter selectionFilter = null)
            : base(owner)
        {
            _SubshapeTypes   = subshapeTypes;
            _SourceEntity    = sourceEntity;
            _SelectionFilter = selectionFilter;
        }
示例#3
0
        //--------------------------------------------------------------------------------------------------

        void _InteractiveEntity_OnVisualChanged(InteractiveEntity entity)
        {
            if (entity == _Body)
            {
                _BeginUpdateReconstructed();
            }
        }
        //--------------------------------------------------------------------------------------------------

        public void SelectEntity(InteractiveEntity entity, bool exclusiveSelection = true)
        {
            if (RaiseSelectionChanging(
                    entity != null ? new List <InteractiveEntity>()
            {
                entity
            } : new List <InteractiveEntity>(),
                    exclusiveSelection ? SelectedEntities : null))
            {
                return;
            }

            if (exclusiveSelection)
            {
                ClearSelection(true);
            }

            if (entity != null)
            {
                _AddEntityToSelectionList(entity);
                _SyncToAisSelection();
            }
            else
            {
                _WorkspaceController.Workspace.AisContext.ClearSelected(false);
            }

            RaiseSelectionChanged();
        }
示例#5
0
        //--------------------------------------------------------------------------------------------------

        public void UpdateVisualShape(InteractiveEntity entity)
        {
            if (!entity.IsVisible)
            {
                RemoveShape(entity);
                return;
            }

            var visualShape = GetVisualShape(entity);

            if (visualShape == null)
            {
                AddVisualShape(entity);
                return;
            }

            var ocShape = entity.GetTransformedBRep();

            if (ocShape != null)
            {
                foreach (var item in _BRepToInteractiveDictionary.Where(kvp => kvp.Value == entity).ToList())
                {
                    _BRepToInteractiveDictionary.Remove(item.Key);
                }

                _BRepToInteractiveDictionary.Add(ocShape, entity);
            }

            visualShape.UpdateShape();
        }
示例#6
0
        //--------------------------------------------------------------------------------------------------

        public VisualShape AddVisualShape(InteractiveEntity entity)
        {
            foreach (var item in _BRepToInteractiveDictionary.Where(kvp => kvp.Value == entity).ToList())
            {
                _BRepToInteractiveDictionary.Remove(item.Key);
            }

            var ocShape = entity.GetTransformedBRep();

            if (ocShape != null)
            {
                _BRepToInteractiveDictionary.Add(ocShape, entity);

                var visualShape = GetVisualShape(entity);
                if (visualShape != null)
                {
                    visualShape.UpdateShape();
                }
                else
                {
                    visualShape = new VisualShape(_WorkspaceController, entity);
                    _InteractiveToVisualShapeDictionary.Add(entity, visualShape);
                }

                return(visualShape);
            }
            return(null);
        }
示例#7
0
        //--------------------------------------------------------------------------------------------------

        void _InteractiveEntity_VisualChanged(InteractiveEntity entity)
        {
            if (entity == Entity)
            {
                _GhostVisualObject?.UpdateShape();
            }
        }
示例#8
0
 bool TryAttack(Vector2 pos)
 {
     Collider2D[] colliderCollection = Physics2D.OverlapCircleAll(pos, attackRange);
     foreach (var collider in colliderCollection)
     {
         if (collider.tag == "interact")
         {
             targetAttack = collider.gameObject;
             InteractiveEntity targetAttack_ie = targetAttack.GetComponent <InteractiveEntity>();
             if (targetAttack_ie.AttackCheck())
             {
                 int           r          = Random.Range(0, 4);
                 CatAttackType attackType = CatAttackType.bite;
                 if (r < 2)
                 {
                     attackType = CatAttackType.pee;
                     animator.SetInteger("catAtkType", 2);
                 }
                 else
                 {
                     animator.SetInteger("catAtkType", r - 3);
                 }
                 CatAttack(targetAttack_ie, attackType);
                 return(true);
             }
         }
     }
     return(false);
 }
示例#9
0
        //--------------------------------------------------------------------------------------------------

        void _InteractiveEntity_VisualChanged(InteractiveEntity entity)
        {
            if (!_InvalidatedInteractiveEntities.Contains(entity))
            {
                _InvalidatedInteractiveEntities.Add(entity);
            }

            _WorkspaceController.Invalidate();
        }
示例#10
0
        //--------------------------------------------------------------------------------------------------

        public static VisualPlane Create(WorkspaceController workspaceController, InteractiveEntity entity)
        {
            if (entity is DatumPlane imagePlane)
            {
                return(new VisualPlane(workspaceController, imagePlane));
            }

            return(null);
        }
        //--------------------------------------------------------------------------------------------------

        void _RemoveEntityFromSelectionList(InteractiveEntity entity)
        {
            if (entity == null)
            {
                return;
            }

            SelectedEntities.Remove(entity);
        }
示例#12
0
        //--------------------------------------------------------------------------------------------------

        #region In-/Exclusion

        public void Include(InteractiveEntity entity)
        {
            var visShape = _WorkspaceController.VisualShapes.GetVisualShape(entity, true);

            if (visShape != null)
            {
                Include(visShape);
            }
        }
        //--------------------------------------------------------------------------------------------------

        void _AddEntityToSelectionList(InteractiveEntity entity)
        {
            if (entity == null)
            {
                return;
            }

            SelectedEntities.Add(entity);
        }
示例#14
0
        //--------------------------------------------------------------------------------------------------

        public void RemoveShape(InteractiveEntity entity)
        {
            var visualShape = GetVisualShape(entity);

            if (visualShape != null)
            {
                visualShape.Remove();
                _InteractiveToVisualShapeDictionary.Remove(entity);
            }

            foreach (var item in _BRepToInteractiveDictionary.Where(kvp => kvp.Value == entity).ToList())
            {
                _BRepToInteractiveDictionary.Remove(item.Key);
            }
        }
        //--------------------------------------------------------------------------------------------------

        #endregion

        #region C'tor, Remove

        public VisualShape(WorkspaceController workspaceController, InteractiveEntity shapeSource, Options options = Options.None)
            : base(workspaceController)
        {
            _Options     = options;
            _ShapeSource = shapeSource;
            if (_ShapeSource != null)
            {
                _VisualStyle = _ShapeSource.GetVisualStyleComponent();
                if (_VisualStyle != null)
                {
                    _VisualStyle.VisualStyleChanged += _VisualStyle_VisualStyleChanged;
                }
            }
            UpdateShape();
        }
示例#16
0
        //--------------------------------------------------------------------------------------------------

        #endregion

        public VisualShape GetVisualShape(InteractiveEntity obj, bool forceCreation = false)
        {
            if (obj == null)
            {
                return(null);
            }

            if (_InteractiveToVisualShapeDictionary.ContainsKey(obj))
            {
                return(_InteractiveToVisualShapeDictionary[obj]);
            }

            if (forceCreation)
            {
                return(AddVisualShape(obj));
            }

            return(null);
        }
示例#17
0
        public override void InteractionBetween(InteractiveEntity main, InteractiveEntity other)
        {
            if (main is IFoodChainEntity m && other is IFoodChainEntity o)
            {
                float value = 0;

                // if my rank > other rank -> eat it : add its food chain value
                // if my rank < other rank -> get eat : remove its food chain value
                if (m.foodChainRank > o.foodChainRank)
                {
                    value = o.foodChainValue;
                }
                else if (m.foodChainRank < o.foodChainRank)
                {
                    value = -o.foodChainValue;
                }

                m.FoodChainInteraction(value);
            }
        }
示例#18
0
 protected VisualObject(WorkspaceController workspaceController, InteractiveEntity entity)
 {
     WorkspaceController = workspaceController;
     Entity = entity;
 }
示例#19
0
 public abstract void InteractionBetween(InteractiveEntity main, InteractiveEntity other);
示例#20
0
 void CatAttack(InteractiveEntity target, CatAttackType attackType)
 {
     target.OnCatInteract(attackType);
     state = CatState.attack;
     timer = attackTime;
 }
        //--------------------------------------------------------------------------------------------------

        public void MouseMove(Point pos, ViewportController viewportController)
        {
            _LastMouseMovePosition           = pos;
            _LastMouseMoveViewportController = viewportController;

            Selection.Update();

            if (pos.X < 0 || pos.Y < 0)
            {
                // Position is out of bounds, reset highlighting
                Workspace.AisContext.MoveTo(Int32.MinValue, Int32.MinValue, viewportController.Viewport.V3dView, false);;
                Invalidate(true);
                return;
            }

            var status = Workspace.AisContext.MoveTo(Convert.ToInt32(pos.X), Convert.ToInt32(pos.Y), viewportController.Viewport.V3dView, false);

            Invalidate(true);

            if (status != AIS_StatusOfDetection.AIS_SOD_Error)
            {
                Pnt rawPoint;
                if (!viewportController.Viewport.ScreenToPoint(Convert.ToInt32(pos.X), Convert.ToInt32(pos.Y), out rawPoint))
                {
                    IsMouseEventDataValid = false;
                    IsCursorPositionValid = false;
                    return;
                }

                Pnt planePoint;
                if (!viewportController.Viewport.ScreenToPoint(Workspace.WorkingPlane, Convert.ToInt32(pos.X), Convert.ToInt32(pos.Y), out planePoint))
                {
                    IsMouseEventDataValid = false;
                    IsCursorPositionValid = false;
                }

                _LastDetectedInteractive = null;
                _LastDetectedOwner       = null;
                InteractiveEntity detectedEntity = null;
                TopoDS_Shape      detectedShape  = null;
                if (Workspace.AisContext.HasDetected())
                {
                    _LastDetectedInteractive = Workspace.AisContext.DetectedInteractive();
                    _LastDetectedOwner       = Workspace.AisContext.DetectedOwner();
                    detectedEntity           = VisualShapes.GetVisibleEntity(_LastDetectedInteractive);
                    detectedShape            = Occt.Helper.Ais.GetDetectedShapeFromContext(Workspace.AisContext);
                }

                _MouseEventData.Set(viewportController.Viewport, pos, rawPoint, planePoint, detectedEntity, _LastDetectedInteractive, detectedShape);
                IsMouseEventDataValid = true;

                CursorPosition        = planePoint;
                CursorPosition2d      = Workspace.WorkingPlane.Parameters(planePoint);
                IsCursorPositionValid = true;
                bool handled = false;

                if (CurrentTool != null)
                {
                    handled = CurrentTool.OnMouseMove(_MouseEventData);
                }

                if (_ToolActions.Any() && !handled)
                {
                    foreach (var toolAction in _ToolActions)
                    {
                        if (toolAction.OnMouseMove(_MouseEventData))
                        {
                            break;
                        }
                    }
                }

                if (_MouseEventData.ForceReDetection)
                {
                    Workspace.AisContext.MoveTo(Convert.ToInt32(pos.X), Convert.ToInt32(pos.Y), viewportController.Viewport.V3dView, false);
                }

                return;
            }

            IsMouseEventDataValid = false;
            IsCursorPositionValid = false;
        }
示例#22
0
    // float val = 0f;

    public override void OnInspectorGUI()
    {
        InteractiveEntity script = target as InteractiveEntity;

        DrawDefaultInspector();

        if (!Application.isPlaying)
        {
            return;
        }

        EditorGUILayout.Space();
        showInteractiveInfo = EditorGUILayout.Foldout(showInteractiveInfo, "");
        rect         = EditorGUILayout.GetControlRect(true, 0);
        rect.y      += -18;
        rect.height += 20;
        EditorGUI.LabelField(rect, "Interactive Information", EditorStyles.boldLabel);

        // Rect n = new Rect();
        // n.x = rect.x;
        // n.y += 500;
        // n.width = 200;
        // n.height = 16;
        // val = EditorGUI.FloatField(n, "Val", val);

        if (showInteractiveInfo)
        {
            EditorGUI.indentLevel++;
            GUI.enabled = false;

            rect.x += rect.width + -110;

            if (EditorApplication.isPlaying)
            {
                // physical state
                rect.y += 19;
                EditorGUILayout.LabelField("Physical state");
                EditorGUI.LabelField(rect, script.physical.ToString(), EditorStyles.boldLabel);

                // chemical element
                rect.y += 18;
                EditorGUILayout.LabelField("Chemical element");
                EditorGUI.LabelField(rect, script.chemical.ToString(), EditorStyles.boldLabel);

                // chemical material
                rect.y += 18;
                EditorGUILayout.LabelField("Chemical material");
                EditorGUI.LabelField(rect, script.material.ToString(), EditorStyles.boldLabel);
            }

            // life
            GUI.enabled = true;
            EditorGUI.indentLevel--;

            EditorGUILayout.Space();
        }


        if (script.cellable.initialized)
        {
            hasCell = (script.cellable.currentCell != null);

            showCellInfo = EditorGUILayout.Foldout(showCellInfo, "");
            rect         = EditorGUILayout.GetControlRect(true, 0);
            rect.y      += -18;
            rect.width   = 150;
            rect.height  = 50;
            EditorGUI.LabelField(rect, "Cell Information", EditorStyles.boldLabel);

            if (showCellInfo)
            {
                EditorGUI.indentLevel++;
                GUI.enabled = false;

                if (hasCell)
                {
                    EditorGUILayout.Vector3Field("Position :", script.cellable.currentCell.position);
                    EditorGUILayout.Toggle("Is Inner :", script.cellable.currentCell.isInner);
                }

                EditorGUILayout.Toggle("Is Walkable :", script.cellable.isWalkable);

                GUI.enabled = true;
                EditorGUI.indentLevel--;
            }
        }

        serializedObject.ApplyModifiedProperties();
    }
示例#23
0
 public ChemicalElementEntity InteractionBetween(InteractiveEntity main, InteractiveEntity other)
 {
     // only does that
     return((main.chemical * other.chemical) * main.material);
 }