コード例 #1
0
 private void Awake()
 {
     if (_shipFrame == null)
     {
         _shipFrame = base.transform.FindChild("ShipFrame").gameObject;
     }
     Util.FindParentToChild(ref shipBanner, _shipFrame.transform, "CommonShipBanner2");
     Util.FindParentToChild(ref _bannerPanel, base.transform, "ShipFrame");
     Util.FindParentToChild(ref _shutterPanel, base.transform, "ShutterPanel");
     Util.FindParentToChild(ref _frame, _shipFrame.transform, "Frame");
     Util.FindParentToChild(ref _gauge, _shipFrame.transform, "Gauge");
     Util.FindParentToChild(ref _labelNumber, _shipFrame.transform, "LabelNumber");
     Util.FindParentToChild(ref _labelLevel, _shipFrame.transform, "LabelLevel");
     Util.FindParentToChild(ref _labelName, _shipFrame.transform, "LabelName");
     Util.FindParentToChild(ref _labelTaikyu, _shipFrame.transform, "LabelTaikyu");
     if (_shutterObj == null)
     {
         _shutterObj = _shutterPanel.transform.FindChild("ShutterObj").gameObject;
     }
     Util.FindParentToChild(ref _shutterL, _shutterPanel.transform, "ShutterObj/ShutterL");
     Util.FindParentToChild(ref _shutterR, _shutterPanel.transform, "ShutterObj/ShutterR");
     Util.FindParentToChild(ref _shutterLShadow, _shutterL.transform, "ShutterL_Shadow");
     Util.FindParentToChild(ref _shutterRShadow, _shutterR.transform, "ShutterR_Shadow");
     Util.FindParentToChild(ref StarManager, _shipFrame.transform, "StarManager");
     bannerDragDrop     = GetComponent <ShipBannerDragDrop>();
     _strDragDropParams = new DragDropParams(Vector3.zero, _bannerPanel.depth, _shutterPanel.depth);
 }
コード例 #2
0
        public override async Task <ReqResult> OnUiRequestAsync(string command, DataValue parameters)
        {
            bool   hasModuleID = !(configuration == null || string.IsNullOrEmpty(configuration.ModuleID));
            string moduleID    = hasModuleID ? configuration !.ModuleID : "IO";

            switch (command)
            {
            case "GetModel": {
                objects = await Connection.GetAllObjects(moduleID);

                mapVariables.Clear();
                ObjectInfo           root      = objects.FirstOrDefault(o => !o.Parent.HasValue);
                List <VariableValue> variables = await Connection.ReadAllVariablesOfObjectTree(root.ID);

                await Connection.EnableVariableValueChangedEvents(SubOptions.AllUpdates(sendValueWithEvent: true), root.ID);

                foreach (VariableValue vv in variables)
                {
                    mapVariables[vv.Variable] = vv.Value;
                }

                TreeNode node = TransformModel(objects);

                MetaInfos types = await Connection.GetMetaInfos(moduleID);

                objTypes.Clear();
                foreach (ClassInfo ci in types.Classes)
                {
                    objTypes[ci.FullName] = ci;
                }
                enumTypes.Clear();
                foreach (EnumInfo en in types.Enums)
                {
                    enumTypes[en.FullName] = en;
                }
                structTypes.Clear();
                foreach (StructInfo sn in types.Structs)
                {
                    structTypes[sn.FullName] = sn;
                }

                JObject typMap = new JObject();
                foreach (ClassInfo ci in types.Classes)
                {
                    var members = ci.ObjectMember
                                  .Where(m => m.Dimension == Dimension.Array)
                                  .Select(m => new {
                            Array = m.Name,
                            Type  = m.ClassName
                        }).ToArray();

                    var entry = new {
                        ObjectMembers = members
                    };

                    typMap[ci.FullName] = new JRaw(StdJson.ObjectToString(entry));
                }

                var locations = await Connection.GetLocations();

                hasLocations = locations.Count > 0;
                rootLocation = hasLocations ? LocationRef.FromLocationID(locations[0].ID) : (LocationRef?)null;

                return(ReqResult.OK(new {
                        ObjectTree = node,
                        TypeInfo = typMap,
                        Locations = locations,
                    }));
            }

            case "GetObject": {
                GetObjectParams pars   = parameters.Object <GetObjectParams>() ?? throw new Exception("GetObjectParams is null");
                var             values = await GetObjectMembers(pars.ID, pars.Type);

                ClassInfo info       = objTypes[pars.Type];
                var       childTypes = info.ObjectMember
                                       .GroupBy(om => om.ClassName)
                                       .Select(g => new ChildType()
                    {
                        TypeName = g.Key,
                        Members  = g.Select(x => x.Name).ToArray()
                    }).ToList();

                var res = new {
                    ObjectValues = values,
                    ChildTypes   = childTypes
                };
                return(ReqResult.OK(res));
            }

            case "Save": {
                SaveParams saveParams = parameters.Object <SaveParams>() ?? throw new Exception("SaveParams is null");

                foreach (var m in saveParams.Members)
                {
                    Console.WriteLine(m.Name + " => " + m.Value);
                }
                ObjectRef     obj = ObjectRef.FromEncodedString(saveParams.ID);
                MemberValue[] mw  = saveParams.Members.Select(m => MemberValue.Make(obj, m.Name, DataValue.FromJSON(m.Value))).ToArray();

                await Connection.UpdateConfig(mw);

                objects = await Connection.GetAllObjects(moduleID);

                TreeNode node = TransformModel(objects);

                var values = await GetObjectMembers(saveParams.ID, saveParams.Type);

                return(ReqResult.OK(new {
                        ObjectValues = values,
                        ObjectTree = node
                    }));
            }

            case "Delete": {
                ObjectRef obj = ObjectRef.FromEncodedString(parameters.GetString() ?? "");
                await Connection.UpdateConfig(ObjectValue.Make(obj, DataValue.Empty));

                objects = await Connection.GetAllObjects(moduleID);

                TreeNode node = TransformModel(objects);
                return(ReqResult.OK(node));
            }

            case "AddObject": {
                AddObjectParams addParams = parameters.Object <AddObjectParams>() ?? throw new Exception("AddObjectParams is null");
                ObjectRef       objParent = ObjectRef.FromEncodedString(addParams.ParentObjID);
                DataValue       dataValue = DataValue.FromObject(new {
                        ID   = addParams.NewObjID,
                        Name = addParams.NewObjName
                    });
                var element = AddArrayElement.Make(objParent, addParams.ParentMember, dataValue);
                await Connection.UpdateConfig(element);

                objects = await Connection.GetAllObjects(moduleID);

                List <VariableValue> newVarVals = await Connection.ReadAllVariablesOfObjectTree(ObjectRef.Make(objParent.ModuleID, addParams.NewObjID));

                foreach (VariableValue vv in newVarVals)
                {
                    mapVariables[vv.Variable] = vv.Value;
                }

                TreeNode node = TransformModel(objects);
                return(ReqResult.OK(new {
                        ObjectID = ObjectRef.Make(moduleID, addParams.NewObjID),
                        Tree = node
                    }));
            }

            case "DragDrop": {
                DragDropParams dropParams = parameters.Object <DragDropParams>() ?? throw new Exception("DragDropParams is null");

                ObjectRef   obj      = ObjectRef.FromEncodedString(dropParams.FromID);
                ObjectValue objValue = await Connection.GetObjectValueByID(obj);

                var deleteObj = ObjectValue.Make(obj, DataValue.Empty);

                ObjectRef objParent = ObjectRef.FromEncodedString(dropParams.ToID);

                var addElement = AddArrayElement.Make(objParent, dropParams.ToArray, objValue.Value);

                await Connection.UpdateConfig(new ObjectValue[] { deleteObj }, new MemberValue[0], new AddArrayElement[] { addElement });

                objects = await Connection.GetAllObjects(moduleID);

                TreeNode node = TransformModel(objects);
                return(ReqResult.OK(node));
            }

            case "WriteVariable": {
                var write = parameters.Object <WriteVariable_Params>() ?? throw new Exception("WriteVariable_Params is null");
                VTQ vtq   = new VTQ(Timestamp.Now, Quality.Good, DataValue.FromJSON(write.V));
                await Connection.WriteVariable(ObjectRef.FromEncodedString(write.ObjID), write.Var, vtq);

                return(ReqResult.OK());
            }

            case "MoveObject": {
                var  move = parameters.Object <MoveObject_Params>() ?? throw new Exception("MoveObject_Params is null");
                bool up   = move.Up;

                ObjectRef  obj     = ObjectRef.FromEncodedString(move.ObjID);
                ObjectInfo objInfo = await Connection.GetObjectByID(obj);

                MemberRefIdx?parentMember = objInfo.Parent;

                if (parentMember.HasValue)
                {
                    MemberValue value = await Connection.GetMemberValue(parentMember.Value.ToMemberRef());

                    DataValue v = value.Value;
                    if (v.IsArray)
                    {
                        JArray array = (JArray)StdJson.JTokenFromString(v.JSON);
                        int    index = parentMember.Value.Index;
                        if (up && index > 0)
                        {
                            JToken tmp = array[index - 1];
                            array[index - 1] = array[index];
                            array[index]     = tmp;

                            MemberValue mv = MemberValue.Make(parentMember.Value.ToMemberRef(), DataValue.FromObject(array));
                            await Connection.UpdateConfig(mv);
                        }
                        else if (!up && index < array.Count - 1)
                        {
                            JToken tmp = array[index + 1];
                            array[index + 1] = array[index];
                            array[index]     = tmp;

                            MemberValue mv = MemberValue.Make(parentMember.Value.ToMemberRef(), DataValue.FromObject(array));
                            await Connection.UpdateConfig(mv);
                        }
                    }
                }

                objects = await Connection.GetAllObjects(moduleID);

                TreeNode node = TransformModel(objects);
                return(ReqResult.OK(node));
            }

            case "Browse": {
                var browse = parameters.Object <Browse_Params>() ?? throw new Exception("Browse_Params is null");

                var          m   = MemberRef.Make(ObjectRef.FromEncodedString(browse.ObjID), browse.Member);
                BrowseResult res = await Connection.BrowseObjectMemberValues(m);

                return(ReqResult.OK(res.Values.Select(d => d.GetString())));
            }

            case "GetNewID": {
                string type = parameters.GetString() ?? throw new Exception("Type parameter is null");
                string id   = GetObjectID(type);
                return(ReqResult.OK(id));
            }

            default:
                return(ReqResult.Bad("Unknown command: " + command));
            }
        }